From 8867bc31c2a8e8d64a09e3ad626a39a4b107914c Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 9 Feb 2021 01:05:39 +0800 Subject: [PATCH] update css-tree@^1.1.2 (#5958) --- package-lock.json | 22 +++++++++++----------- package.json | 2 +- src/compiler/compile/css/Stylesheet.ts | 22 +++++++++++----------- src/compiler/parse/read/style.ts | 7 +++++-- test/parser/samples/css/output.json | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 482acd470a..8251c3a298 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1051,19 +1051,19 @@ } }, "css-tree": { - "version": "1.0.0-alpha22", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha22.tgz", - "integrity": "sha1-M4oAbjMce0+dq3tq9Tns5W/3ivI=", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.1.2.tgz", + "integrity": "sha512-wCoWush5Aeo48GLhfHPbmvZs59Z+M7k5+B1xDnXbdWNcEF423DoFdqSWE0PM5aNk5nI5cp1q7ms36zGApY/sKQ==", "dev": true, "requires": { - "mdn-data": "^1.0.0", - "source-map": "^0.5.3" + "mdn-data": "2.0.14", + "source-map": "^0.6.1" }, "dependencies": { "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true } } @@ -2904,9 +2904,9 @@ } }, "mdn-data": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.2.0.tgz", - "integrity": "sha512-esDqNvsJB2q5V28+u7NdtdMg6Rmg4khQmAVSjUiX7BY/7haIv0K2yWM43hYp0or+3nvG7+UaTF1JHz31hgU1TA==", + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz", + "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "dev": true }, "mem": { diff --git a/package.json b/package.json index 1c88873065..231d26eb47 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "c8": "^5.0.1", "code-red": "^0.1.4", "codecov": "^3.5.0", - "css-tree": "1.0.0-alpha22", + "css-tree": "^1.1.2", "eslint": "^7.15.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-svelte3": "^2.7.3", diff --git a/src/compiler/compile/css/Stylesheet.ts b/src/compiler/compile/css/Stylesheet.ts index b0dab12b19..b730079a89 100644 --- a/src/compiler/compile/css/Stylesheet.ts +++ b/src/compiler/compile/css/Stylesheet.ts @@ -47,7 +47,7 @@ class Rule { constructor(node: CssNode, stylesheet, parent?: Atrule) { this.node = node; this.parent = parent; - this.selectors = node.selector.children.map((node: CssNode) => new Selector(node, stylesheet)); + this.selectors = node.prelude.children.map((node: CssNode) => new Selector(node, stylesheet)); this.declarations = node.block.children.map((node: CssNode) => new Declaration(node)); } @@ -182,11 +182,11 @@ class Atrule { minify(code: MagicString, dev: boolean) { if (this.node.name === 'media') { - const expression_char = code.original[this.node.expression.start]; + const expression_char = code.original[this.node.prelude.start]; let c = this.node.start + (expression_char === '(' ? 6 : 7); - if (this.node.expression.start > c) code.remove(c, this.node.expression.start); + if (this.node.prelude.start > c) code.remove(c, this.node.prelude.start); - this.node.expression.children.forEach((query: CssNode) => { + this.node.prelude.children.forEach((query: CssNode) => { // TODO minify queries c = query.end; }); @@ -194,17 +194,17 @@ class Atrule { code.remove(c, this.node.block.start); } else if (this.node.name === 'supports') { let c = this.node.start + 9; - if (this.node.expression.start - c > 1) code.overwrite(c, this.node.expression.start, ' '); - this.node.expression.children.forEach((query: CssNode) => { + if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' '); + this.node.prelude.children.forEach((query: CssNode) => { // TODO minify queries c = query.end; }); code.remove(c, this.node.block.start); } else { let c = this.node.start + this.node.name.length + 1; - if (this.node.expression) { - if (this.node.expression.start - c > 1) code.overwrite(c, this.node.expression.start, ' '); - c = this.node.expression.end; + if (this.node.prelude) { + if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' '); + c = this.node.prelude.end; } if (this.node.block && this.node.block.start - c > 0) { code.remove(c, this.node.block.start); @@ -235,7 +235,7 @@ class Atrule { transform(code: MagicString, id: string, keyframes: Map, max_amount_class_specificity_increased: number) { if (is_keyframes_node(this.node)) { - this.node.expression.children.forEach(({ type, name, start, end }: CssNode) => { + this.node.prelude.children.forEach(({ type, name, start, end }: CssNode) => { if (type === 'Identifier') { if (name.startsWith('-global-')) { code.remove(start, start + 8); @@ -317,7 +317,7 @@ export default class Stylesheet { } if (is_keyframes_node(node)) { - node.expression.children.forEach((expression: CssNode) => { + node.prelude.children.forEach((expression: CssNode) => { if (expression.type === 'Identifier' && !expression.name.startsWith('-global-')) { this.keyframes.set(expression.name, `${this.id}-${expression.name}`); } diff --git a/src/compiler/parse/read/style.ts b/src/compiler/parse/read/style.ts index 72fd8aeca1..d8f85c0f3b 100644 --- a/src/compiler/parse/read/style.ts +++ b/src/compiler/parse/read/style.ts @@ -14,10 +14,13 @@ export default function read_style(parser: Parser, start: number, attributes: No try { ast = parse(styles, { positions: true, - offset: content_start + offset: content_start, + onParseError(error) { + throw error; + } }); } catch (err) { - if (err.name === 'CssSyntaxError') { + if (err.name === 'SyntaxError') { parser.error({ code: 'css-syntax-error', message: err.message diff --git a/test/parser/samples/css/output.json b/test/parser/samples/css/output.json index 676b11f6a9..a39f718cf1 100644 --- a/test/parser/samples/css/output.json +++ b/test/parser/samples/css/output.json @@ -37,7 +37,7 @@ "children": [ { "type": "Rule", - "selector": { + "prelude": { "type": "SelectorList", "children": [ { @@ -74,7 +74,7 @@ "end": 43 } ], - "start": 39, + "start": 40, "end": 43 }, "start": 33,