diff --git a/src/css/Stylesheet.ts b/src/css/Stylesheet.ts index e94dce6a62..6254795697 100644 --- a/src/css/Stylesheet.ts +++ b/src/css/Stylesheet.ts @@ -3,6 +3,7 @@ import { walk } from 'estree-walker'; import { getLocator } from 'locate-character'; import Selector from './Selector'; import getCodeFrame from '../utils/getCodeFrame'; +import hash from '../utils/hash'; import Element from '../generators/nodes/Element'; import { Validator } from '../validate/index'; import { Node, Parsed, Warning } from '../interfaces'; @@ -269,12 +270,12 @@ export default class Stylesheet { this.cascade = cascade; this.filename = filename; - this.id = `svelte-${parsed.hash}`; - this.children = []; this.keyframes = new Map(); if (parsed.css && parsed.css.children.length) { + this.id = `svelte-${hash(parsed.css.content.styles)}`; + this.hasStyles = true; const stack: (Rule | Atrule)[] = []; diff --git a/src/parse/index.ts b/src/parse/index.ts index e9341fa720..c81d2f61b0 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -6,7 +6,7 @@ import { trimStart, trimEnd } from '../utils/trim'; import getCodeFrame from '../utils/getCodeFrame'; import reservedNames from '../utils/reservedNames'; import fullCharCodeAt from '../utils/fullCharCodeAt'; -import hash from './utils/hash'; +import hash from '../utils/hash'; import { Node, Parsed } from '../interfaces'; import CompileError from '../utils/CompileError'; @@ -202,20 +202,13 @@ export class Parser { } } -function getHashSource (parser: Parser, options: ParserOptions) { - if (options.css === false || !parser.css) { - return parser.template; - } - return parser.css.content.styles; -} - export default function parse( template: string, options: ParserOptions = {} ): Parsed { const parser = new Parser(template, options); return { - hash: hash(getHashSource(parser, options)), + hash: hash(parser.template), html: parser.html, css: parser.css, js: parser.js, diff --git a/src/parse/utils/hash.ts b/src/utils/hash.ts similarity index 100% rename from src/parse/utils/hash.ts rename to src/utils/hash.ts