diff --git a/src/parse/index.ts b/src/parse/index.ts index 03c7cb95e5..e9341fa720 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -202,14 +202,20 @@ 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(parser.template), + hash: hash(getHashSource(parser, options)), html: parser.html, css: parser.css, js: parser.js, diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 487665fe9d..fd2c6d9b03 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -198,13 +198,13 @@ function data() { } function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); + setAttribute(node, "svelte-2794052100", ""); } function add_css() { var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + style.id = 'svelte-2794052100-style'; + style.textContent = "p[svelte-2794052100],[svelte-2794052100] p{color:red}"; appendNode(style, document.head); } @@ -245,7 +245,7 @@ function SvelteComponent(options) { init(this, options); this._state = assign(data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-2794052100-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 0ad2ccd29e..babc926f91 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -6,13 +6,13 @@ function data() { }; function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); + setAttribute(node, "svelte-2794052100", ""); } function add_css() { var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + style.id = 'svelte-2794052100-style'; + style.textContent = "p[svelte-2794052100],[svelte-2794052100] p{color:red}"; appendNode(style, document.head); } @@ -53,7 +53,7 @@ function SvelteComponent(options) { init(this, options); this._state = assign(data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-2794052100-style")) add_css(); this._fragment = create_main_fragment(this._state, this); @@ -64,4 +64,4 @@ function SvelteComponent(options) { } assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent; diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 0d653764f2..e5502c0a31 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -190,13 +190,13 @@ var proto = { /* generated by Svelte vX.Y.Z */ function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); + setAttribute(node, "svelte-3905933315", ""); } function add_css() { var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + style.id = 'svelte-3905933315-style'; + style.textContent = "@media(min-width: 1px){div[svelte-3905933315],[svelte-3905933315] div{color:red}}"; appendNode(style, document.head); } @@ -231,7 +231,7 @@ function SvelteComponent(options) { init(this, options); this._state = assign({}, options.data); - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-3905933315-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 3c36f9c6ce..567ae27255 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -2,13 +2,13 @@ import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); + setAttribute(node, "svelte-3905933315", ""); } function add_css() { var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + style.id = 'svelte-3905933315-style'; + style.textContent = "@media(min-width: 1px){div[svelte-3905933315],[svelte-3905933315] div{color:red}}"; appendNode(style, document.head); } @@ -43,7 +43,7 @@ function SvelteComponent(options) { init(this, options); this._state = assign({}, options.data); - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-3905933315-style")) add_css(); this._fragment = create_main_fragment(this._state, this); @@ -54,4 +54,4 @@ function SvelteComponent(options) { } assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent; diff --git a/test/server-side-rendering/samples/styles-nested/_actual.css b/test/server-side-rendering/samples/styles-nested/_actual.css index 5888415ac1..e0b5eb0a7c 100644 --- a/test/server-side-rendering/samples/styles-nested/_actual.css +++ b/test/server-side-rendering/samples/styles-nested/_actual.css @@ -1,2 +1,2 @@ -div[svelte-1408461649],[svelte-1408461649] div{color:red} -div[svelte-1580141456],[svelte-1580141456] div{color:green} \ No newline at end of file +div[svelte-724714405],[svelte-724714405] div{color:red} +div[svelte-300476157],[svelte-300476157] div{color:green} \ No newline at end of file diff --git a/test/server-side-rendering/samples/styles-nested/_actual.html b/test/server-side-rendering/samples/styles-nested/_actual.html index 25b7d5c4f3..39dc0d55a4 100644 --- a/test/server-side-rendering/samples/styles-nested/_actual.html +++ b/test/server-side-rendering/samples/styles-nested/_actual.html @@ -1,8 +1,8 @@ -