base stylesheet.hash on css content, and revert parsed.hash

pull/1119/head
Rich Harris 8 years ago
parent df5a32a577
commit 9fbcddf338

@ -3,6 +3,7 @@ import { walk } from 'estree-walker';
import { getLocator } from 'locate-character'; import { getLocator } from 'locate-character';
import Selector from './Selector'; import Selector from './Selector';
import getCodeFrame from '../utils/getCodeFrame'; import getCodeFrame from '../utils/getCodeFrame';
import hash from '../utils/hash';
import Element from '../generators/nodes/Element'; import Element from '../generators/nodes/Element';
import { Validator } from '../validate/index'; import { Validator } from '../validate/index';
import { Node, Parsed, Warning } from '../interfaces'; import { Node, Parsed, Warning } from '../interfaces';
@ -269,12 +270,12 @@ export default class Stylesheet {
this.cascade = cascade; this.cascade = cascade;
this.filename = filename; this.filename = filename;
this.id = `svelte-${parsed.hash}`;
this.children = []; this.children = [];
this.keyframes = new Map(); this.keyframes = new Map();
if (parsed.css && parsed.css.children.length) { if (parsed.css && parsed.css.children.length) {
this.id = `svelte-${hash(parsed.css.content.styles)}`;
this.hasStyles = true; this.hasStyles = true;
const stack: (Rule | Atrule)[] = []; const stack: (Rule | Atrule)[] = [];

@ -6,7 +6,7 @@ import { trimStart, trimEnd } from '../utils/trim';
import getCodeFrame from '../utils/getCodeFrame'; import getCodeFrame from '../utils/getCodeFrame';
import reservedNames from '../utils/reservedNames'; import reservedNames from '../utils/reservedNames';
import fullCharCodeAt from '../utils/fullCharCodeAt'; import fullCharCodeAt from '../utils/fullCharCodeAt';
import hash from './utils/hash'; import hash from '../utils/hash';
import { Node, Parsed } from '../interfaces'; import { Node, Parsed } from '../interfaces';
import CompileError from '../utils/CompileError'; 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( export default function parse(
template: string, template: string,
options: ParserOptions = {} options: ParserOptions = {}
): Parsed { ): Parsed {
const parser = new Parser(template, options); const parser = new Parser(template, options);
return { return {
hash: hash(getHashSource(parser, options)), hash: hash(parser.template),
html: parser.html, html: parser.html,
css: parser.css, css: parser.css,
js: parser.js, js: parser.js,

Loading…
Cancel
Save