Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update css-tree@^1.1.2 #5958

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 11 additions & 11 deletions src/compiler/compile/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -182,29 +182,29 @@ 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;
});

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);
Expand Down Expand Up @@ -235,7 +235,7 @@ class Atrule {

transform(code: MagicString, id: string, keyframes: Map<string, string>, 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);
Expand Down Expand Up @@ -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}`);
}
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/parse/read/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/parser/samples/css/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"children": [
{
"type": "Rule",
"selector": {
"prelude": {
"type": "SelectorList",
"children": [
{
Expand Down Expand Up @@ -74,7 +74,7 @@
"end": 43
}
],
"start": 39,
"start": 40,
"end": 43
},
"start": 33,
Expand Down