From 4f0473616d0a61796b8f24384290065fceb3b4ae Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:48:31 +0300 Subject: [PATCH] feat(css/ast): Add `value` to the whitespace token (#2533) --- Cargo.lock | 14 +- css/Cargo.toml | 12 +- css/ast/Cargo.toml | 2 +- css/ast/src/token.rs | 4 +- css/codegen/Cargo.toml | 8 +- css/codegen/src/lib.rs | 4 +- css/parser/Cargo.toml | 6 +- css/parser/src/lexer/mod.rs | 50 +++- css/parser/src/macros.rs | 2 +- .../tests/fixture/at-rule/unknown/output.json | 30 ++- .../fixture/at-rule/unknown/span.rust-debug | 13 +- .../misc/L0mEf41IMkWcP7NotllkAg/output.json | 30 ++- .../L0mEf41IMkWcP7NotllkAg/span.rust-debug | 13 +- .../rome/custom-properties/output.json | 6 +- .../rome/custom-properties/span.rust-debug | 2 +- .../tests/fixture/rome/selectors/output.json | 12 +- .../fixture/rome/selectors/span.rust-debug | 4 +- .../fixture/styled-jsx/selector/1/output.json | 12 +- .../styled-jsx/selector/1/span.rust-debug | 4 +- .../fixture/value/custom-property/output.json | 30 ++- .../value/custom-property/span.rust-debug | 10 +- .../bad-url-token/double-quotes/output.json | 6 +- .../left-parenthesis/output.json | 6 +- .../bad-url-token/single-quotes/output.json | 6 +- .../bad-url-token/whitespace/output.json | 6 +- .../delim-token/ampersand/output.json | 6 +- .../recovery/delim-token/asterisk/output.json | 6 +- .../recovery/delim-token/at-sign/output.json | 12 +- .../recovery/delim-token/bang/output.json | 6 +- .../recovery/delim-token/bar/output.json | 6 +- .../recovery/delim-token/caret/output.json | 6 +- .../recovery/delim-token/div/output.json | 6 +- .../recovery/delim-token/dollar/output.json | 6 +- .../recovery/delim-token/equals/output.json | 6 +- .../delim-token/greater-than/output.json | 6 +- .../recovery/delim-token/hash/output.json | 6 +- .../delim-token/less-than/output.json | 6 +- .../recovery/delim-token/minus/output.json | 6 +- .../recovery/delim-token/percent/output.json | 6 +- .../recovery/delim-token/plus/output.json | 6 +- .../delim-token/question-mark/output.json | 6 +- .../recovery/delim-token/star/output.json | 6 +- .../recovery/delim-token/tilde/output.json | 6 +- .../tests/recovery/function-token/output.json | 18 +- .../tests/recovery/styled-jsx/1/output.json | 36 ++- .../tests/recovery/styled-jsx/2/output.json | 12 +- .../tests/recovery/value/quotes/output.json | 12 +- .../tests/recovery/vercel/001/output.json | 6 +- .../tests/recovery/whitespaces/input.css | 10 + .../tests/recovery/whitespaces/output.json | 242 ++++++++++++++++++ .../recovery/whitespaces/output.swc-stderr | 24 ++ css/stylis/Cargo.toml | 12 +- css/stylis/tests/prefixer.rs | 5 +- css/utils/Cargo.toml | 6 +- css/visit/Cargo.toml | 4 +- 55 files changed, 668 insertions(+), 125 deletions(-) create mode 100644 css/parser/tests/recovery/whitespaces/input.css create mode 100644 css/parser/tests/recovery/whitespaces/output.json create mode 100644 css/parser/tests/recovery/whitespaces/output.swc-stderr diff --git a/Cargo.lock b/Cargo.lock index a7a866eec69..4b8418dea31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2504,7 +2504,7 @@ dependencies = [ [[package]] name = "swc_css" -version = "0.24.0" +version = "0.25.0" dependencies = [ "swc_css_ast", "swc_css_codegen", @@ -2515,7 +2515,7 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.22.0" +version = "0.23.0" dependencies = [ "is-macro", "serde", @@ -2526,7 +2526,7 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.22.0" +version = "0.23.0" dependencies = [ "auto_impl", "bitflags", @@ -2552,7 +2552,7 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.24.0" +version = "0.25.0" dependencies = [ "bitflags", "lexical", @@ -2568,7 +2568,7 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.19.0" +version = "0.20.0" dependencies = [ "swc_atoms 0.2.9", "swc_common", @@ -2578,7 +2578,7 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.21.0" +version = "0.22.0" dependencies = [ "swc_atoms 0.2.9", "swc_common", @@ -3154,7 +3154,7 @@ dependencies = [ [[package]] name = "swc_stylis" -version = "0.21.0" +version = "0.22.0" dependencies = [ "swc_atoms 0.2.9", "swc_common", diff --git a/css/Cargo.toml b/css/Cargo.toml index b4d92d934dc..86024a10042 100644 --- a/css/Cargo.toml +++ b/css/Cargo.toml @@ -6,11 +6,11 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_css" repository = "https://github.com/swc-project/swc.git" -version = "0.24.0" +version = "0.25.0" [dependencies] -swc_css_ast = {version = "0.22.0", path = "./ast"} -swc_css_codegen = {version = "0.22.0", path = "./codegen"} -swc_css_parser = {version = "0.24.0", path = "./parser"} -swc_css_utils = {version = "0.19.0", path = "./utils/"} -swc_css_visit = {version = "0.21.0", path = "./visit"} +swc_css_ast = {version = "0.23.0", path = "./ast"} +swc_css_codegen = {version = "0.23.0", path = "./codegen"} +swc_css_parser = {version = "0.25.0", path = "./parser"} +swc_css_utils = {version = "0.20.0", path = "./utils/"} +swc_css_visit = {version = "0.22.0", path = "./visit"} diff --git a/css/ast/Cargo.toml b/css/ast/Cargo.toml index d09cc66d2f8..dd8482a082f 100644 --- a/css/ast/Cargo.toml +++ b/css/ast/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_css_ast" repository = "https://github.com/swc-project/swc.git" -version = "0.22.0" +version = "0.23.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/css/ast/src/token.rs b/css/ast/src/token.rs index fa6f36f035f..7fdfe51fb4f 100644 --- a/css/ast/src/token.rs +++ b/css/ast/src/token.rs @@ -83,7 +83,9 @@ pub enum Token { }, /// One or more whitespace. - WhiteSpace, + WhiteSpace { + value: JsWord, + }, /// `"); diff --git a/css/parser/Cargo.toml b/css/parser/Cargo.toml index 0831cd4bda9..ac3ebb70007 100644 --- a/css/parser/Cargo.toml +++ b/css/parser/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_css_parser" repository = "https://github.com/swc-project/swc.git" -version = "0.24.0" +version = "0.25.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -17,11 +17,11 @@ bitflags = "1.2.1" lexical = "5.2.2" swc_atoms = {version = "0.2.7", path = "../../atoms"} swc_common = {version = "0.14.0", path = "../../common"} -swc_css_ast = {version = "0.22.0", path = "../ast"} +swc_css_ast = {version = "0.23.0", path = "../ast"} unicode-xid = "0.2.2" [dev-dependencies] serde = "1.0.127" serde_json = "1.0.66" -swc_css_visit = {version = "0.21.0", path = "../visit"} +swc_css_visit = {version = "0.22.0", path = "../visit"} testing = {version = "0.15.0", path = "../../testing"} diff --git a/css/parser/src/lexer/mod.rs b/css/parser/src/lexer/mod.rs index 9a95d4a5e41..0c7d1e8fdca 100644 --- a/css/parser/src/lexer/mod.rs +++ b/css/parser/src/lexer/mod.rs @@ -121,9 +121,11 @@ where if let Some(c) = self.input.cur() { if is_whitespace(c) { - self.skip_ws()?; + let value = self.read_ws()?; - return Ok(tok!(" ")); + return Ok(Token::WhiteSpace { + value: value.into(), + }); } } @@ -302,6 +304,34 @@ where return Ok(Token::Delim { value: c }); } + fn read_ws(&mut self) -> LexResult { + let mut value = String::new(); + + loop { + let c = self.input.cur(); + + match c { + Some(c) if is_whitespace(c) => { + self.input.bump(); + + value.push(c); + } + _ => { + break; + } + } + } + + if self.config.allow_wrong_line_comments { + if self.input.is_byte(b'/') && self.input.peek() == Some('/') { + self.skip_line_comment()?; + self.start_pos = self.input.cur_pos(); + } + } + + Ok(value) + } + fn would_start_number( &mut self, maybe_first: Option, @@ -877,16 +907,16 @@ where fn skip_ws(&mut self) -> LexResult<()> { loop { - if self.input.cur().is_none() { - break; - } + let c = self.input.cur(); - if is_whitespace(self.input.cur().unwrap()) { - self.input.bump(); - continue; + match c { + Some(c) if is_whitespace(c) => { + self.input.bump(); + } + _ => { + break; + } } - - break; } if self.config.allow_wrong_line_comments { diff --git a/css/parser/src/macros.rs b/css/parser/src/macros.rs index 64c3c58c425..c80b39f0b7e 100644 --- a/css/parser/src/macros.rs +++ b/css/parser/src/macros.rs @@ -89,7 +89,7 @@ macro_rules! tok { }; (" ") => { - swc_css_ast::Token::WhiteSpace + swc_css_ast::Token::WhiteSpace { .. } }; (" $DIR/tests/fixture/at-rule/unknown/input.css:33:11 | 33 | @unknown { @@ -355,7 +356,7 @@ error: CDC 34 | --> {} | ^^^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/at-rule/unknown/input.css:34:8 | 34 | --> {} @@ -373,7 +374,8 @@ error: RBrace 34 | --> {} | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' + ' type=inline) } --> $DIR/tests/fixture/at-rule/unknown/input.css:34:11 | 34 | --> {} @@ -387,7 +389,7 @@ error: CDO 35 | $DIR/tests/fixture/at-rule/unknown/input.css:35:9 | 35 | $DIR/tests/fixture/at-rule/unknown/input.css:35:12 | 35 | $DIR/tests/fixture/esbuild/misc/L0mEf41IMkWcP7NotllkAg/input.css:1:10 | 1 | @unknown{ @@ -76,7 +77,7 @@ error: Colon 2 | a: b; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/esbuild/misc/L0mEf41IMkWcP7NotllkAg/input.css:2:3 | 2 | a: b; @@ -94,7 +95,8 @@ error: Semi 2 | a: b; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' +' type=inline) } --> $DIR/tests/fixture/esbuild/misc/L0mEf41IMkWcP7NotllkAg/input.css:2:6 | 2 | a: b; @@ -114,7 +116,7 @@ error: Colon 3 | c: d; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/esbuild/misc/L0mEf41IMkWcP7NotllkAg/input.css:3:3 | 3 | c: d; @@ -132,7 +134,8 @@ error: Semi 3 | c: d; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' +' type=inline) } --> $DIR/tests/fixture/esbuild/misc/L0mEf41IMkWcP7NotllkAg/input.css:3:6 | 3 | c: d; diff --git a/css/parser/tests/fixture/rome/custom-properties/output.json b/css/parser/tests/fixture/rome/custom-properties/output.json index 07cd82b1e07..4f7bb802c41 100644 --- a/css/parser/tests/fixture/rome/custom-properties/output.json +++ b/css/parser/tests/fixture/rome/custom-properties/output.json @@ -523,7 +523,11 @@ "end": 233, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } } ] } diff --git a/css/parser/tests/fixture/rome/custom-properties/span.rust-debug b/css/parser/tests/fixture/rome/custom-properties/span.rust-debug index e188292e470..4877a9bc188 100644 --- a/css/parser/tests/fixture/rome/custom-properties/span.rust-debug +++ b/css/parser/tests/fixture/rome/custom-properties/span.rust-debug @@ -437,7 +437,7 @@ error: Tokens 13 | --braces: { }; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/rome/custom-properties/input.css:13:13 | 13 | --braces: { }; diff --git a/css/parser/tests/fixture/rome/selectors/output.json b/css/parser/tests/fixture/rome/selectors/output.json index b32be78f8c6..c0065c860af 100644 --- a/css/parser/tests/fixture/rome/selectors/output.json +++ b/css/parser/tests/fixture/rome/selectors/output.json @@ -1164,7 +1164,11 @@ "end": 298, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -1347,7 +1351,11 @@ "end": 345, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/fixture/rome/selectors/span.rust-debug b/css/parser/tests/fixture/rome/selectors/span.rust-debug index 05736240d6c..0e37186f0a7 100644 --- a/css/parser/tests/fixture/rome/selectors/span.rust-debug +++ b/css/parser/tests/fixture/rome/selectors/span.rust-debug @@ -905,7 +905,7 @@ error: Comma 32 | :lang(en, ko) { | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/rome/selectors/input.css:32:10 | 32 | :lang(en, ko) { @@ -1045,7 +1045,7 @@ error: Comma 38 | ::pseudo-elem(a, b) { | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/rome/selectors/input.css:38:17 | 38 | ::pseudo-elem(a, b) { diff --git a/css/parser/tests/fixture/styled-jsx/selector/1/output.json b/css/parser/tests/fixture/styled-jsx/selector/1/output.json index 0b5195dd594..be04f647c46 100644 --- a/css/parser/tests/fixture/styled-jsx/selector/1/output.json +++ b/css/parser/tests/fixture/styled-jsx/selector/1/output.json @@ -90,7 +90,11 @@ "end": 13, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -110,7 +114,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/fixture/styled-jsx/selector/1/span.rust-debug b/css/parser/tests/fixture/styled-jsx/selector/1/span.rust-debug index 5fd3f5d81f4..48c65c4edf7 100644 --- a/css/parser/tests/fixture/styled-jsx/selector/1/span.rust-debug +++ b/css/parser/tests/fixture/styled-jsx/selector/1/span.rust-debug @@ -70,7 +70,7 @@ error: Ident { value: Atom('foo' type=inline), raw: Atom('foo' type=inline) } 1 | :global(.foo + a) { | ^^^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/styled-jsx/selector/1/input.css:1:13 | 1 | :global(.foo + a) { @@ -82,7 +82,7 @@ error: Delim { value: '+' } 1 | :global(.foo + a) { | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/styled-jsx/selector/1/input.css:1:15 | 1 | :global(.foo + a) { diff --git a/css/parser/tests/fixture/value/custom-property/output.json b/css/parser/tests/fixture/value/custom-property/output.json index 73e98186a73..08e00a1209b 100644 --- a/css/parser/tests/fixture/value/custom-property/output.json +++ b/css/parser/tests/fixture/value/custom-property/output.json @@ -567,7 +567,11 @@ "end": 287, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -596,7 +600,11 @@ "end": 290, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -713,7 +721,11 @@ "end": 325, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -864,7 +876,11 @@ "end": 376, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -939,7 +955,11 @@ "end": 394, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } } ] } diff --git a/css/parser/tests/fixture/value/custom-property/span.rust-debug b/css/parser/tests/fixture/value/custom-property/span.rust-debug index 969d03c8cf6..f7939406e2b 100644 --- a/css/parser/tests/fixture/value/custom-property/span.rust-debug +++ b/css/parser/tests/fixture/value/custom-property/span.rust-debug @@ -499,7 +499,7 @@ error: Comma 15 | --bracket-block: {1, 2, 3}; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/value/custom-property/input.css:15:25 | 15 | --bracket-block: {1, 2, 3}; @@ -517,7 +517,7 @@ error: Comma 15 | --bracket-block: {1, 2, 3}; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/value/custom-property/input.css:15:28 | 15 | --bracket-block: {1, 2, 3}; @@ -619,7 +619,7 @@ error: Colon 16 | --JSON: [1, "2", {"three": {"a":1}}, [4]]; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/value/custom-property/input.css:16:31 | 16 | --JSON: [1, "2", {"three": {"a":1}}, [4]]; @@ -745,7 +745,7 @@ error: Tokens 17 | --javascript: function(rule) { console.log(rule) }; | ^^^^^^^^^^^^^^^^^^^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/value/custom-property/input.css:17:35 | 17 | --javascript: function(rule) { console.log(rule) }; @@ -787,7 +787,7 @@ error: RParen 17 | --javascript: function(rule) { console.log(rule) }; | ^ -error: WhiteSpace +error: WhiteSpace { value: Atom(' ' type=inline) } --> $DIR/tests/fixture/value/custom-property/input.css:17:53 | 17 | --javascript: function(rule) { console.log(rule) }; diff --git a/css/parser/tests/recovery/bad-url-token/double-quotes/output.json b/css/parser/tests/recovery/bad-url-token/double-quotes/output.json index 38c9d33f083..0ad4de24b4c 100644 --- a/css/parser/tests/recovery/bad-url-token/double-quotes/output.json +++ b/css/parser/tests/recovery/bad-url-token/double-quotes/output.json @@ -98,7 +98,11 @@ "end": 22, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/bad-url-token/left-parenthesis/output.json b/css/parser/tests/recovery/bad-url-token/left-parenthesis/output.json index 31ef2da2a7d..add93e108d8 100644 --- a/css/parser/tests/recovery/bad-url-token/left-parenthesis/output.json +++ b/css/parser/tests/recovery/bad-url-token/left-parenthesis/output.json @@ -98,7 +98,11 @@ "end": 22, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/bad-url-token/single-quotes/output.json b/css/parser/tests/recovery/bad-url-token/single-quotes/output.json index 40d3398f529..a404a79e3a5 100644 --- a/css/parser/tests/recovery/bad-url-token/single-quotes/output.json +++ b/css/parser/tests/recovery/bad-url-token/single-quotes/output.json @@ -98,7 +98,11 @@ "end": 22, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/bad-url-token/whitespace/output.json b/css/parser/tests/recovery/bad-url-token/whitespace/output.json index 1ad3c535b31..5145e1fe6b8 100644 --- a/css/parser/tests/recovery/bad-url-token/whitespace/output.json +++ b/css/parser/tests/recovery/bad-url-token/whitespace/output.json @@ -98,7 +98,11 @@ "end": 22, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/ampersand/output.json b/css/parser/tests/recovery/delim-token/ampersand/output.json index 0068dbde6b0..2f455069a6b 100644 --- a/css/parser/tests/recovery/delim-token/ampersand/output.json +++ b/css/parser/tests/recovery/delim-token/ampersand/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/asterisk/output.json b/css/parser/tests/recovery/delim-token/asterisk/output.json index aad0c3c7630..039cc1af2e5 100644 --- a/css/parser/tests/recovery/delim-token/asterisk/output.json +++ b/css/parser/tests/recovery/delim-token/asterisk/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/at-sign/output.json b/css/parser/tests/recovery/delim-token/at-sign/output.json index 62ab738e7a8..c31ee5b2b29 100644 --- a/css/parser/tests/recovery/delim-token/at-sign/output.json +++ b/css/parser/tests/recovery/delim-token/at-sign/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -118,7 +122,11 @@ "end": 17, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/bang/output.json b/css/parser/tests/recovery/delim-token/bang/output.json index da5dd3a5e63..7c7ce20c600 100644 --- a/css/parser/tests/recovery/delim-token/bang/output.json +++ b/css/parser/tests/recovery/delim-token/bang/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/bar/output.json b/css/parser/tests/recovery/delim-token/bar/output.json index 64451b15a86..707329974ae 100644 --- a/css/parser/tests/recovery/delim-token/bar/output.json +++ b/css/parser/tests/recovery/delim-token/bar/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/caret/output.json b/css/parser/tests/recovery/delim-token/caret/output.json index d65ab1ce361..5a3c57abf8f 100644 --- a/css/parser/tests/recovery/delim-token/caret/output.json +++ b/css/parser/tests/recovery/delim-token/caret/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/div/output.json b/css/parser/tests/recovery/delim-token/div/output.json index 8c758d62dbb..53717ef64df 100644 --- a/css/parser/tests/recovery/delim-token/div/output.json +++ b/css/parser/tests/recovery/delim-token/div/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/dollar/output.json b/css/parser/tests/recovery/delim-token/dollar/output.json index 4aba98e6aea..30f12263231 100644 --- a/css/parser/tests/recovery/delim-token/dollar/output.json +++ b/css/parser/tests/recovery/delim-token/dollar/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/equals/output.json b/css/parser/tests/recovery/delim-token/equals/output.json index 291f693337f..ad6b77068c8 100644 --- a/css/parser/tests/recovery/delim-token/equals/output.json +++ b/css/parser/tests/recovery/delim-token/equals/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/greater-than/output.json b/css/parser/tests/recovery/delim-token/greater-than/output.json index efd8a2fe598..08e5c0a8186 100644 --- a/css/parser/tests/recovery/delim-token/greater-than/output.json +++ b/css/parser/tests/recovery/delim-token/greater-than/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/hash/output.json b/css/parser/tests/recovery/delim-token/hash/output.json index d15cb43b412..71b251c7371 100644 --- a/css/parser/tests/recovery/delim-token/hash/output.json +++ b/css/parser/tests/recovery/delim-token/hash/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/less-than/output.json b/css/parser/tests/recovery/delim-token/less-than/output.json index 16be1c739bf..0ddfa030537 100644 --- a/css/parser/tests/recovery/delim-token/less-than/output.json +++ b/css/parser/tests/recovery/delim-token/less-than/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/minus/output.json b/css/parser/tests/recovery/delim-token/minus/output.json index 30bf19b22ea..c5b6cce65a2 100644 --- a/css/parser/tests/recovery/delim-token/minus/output.json +++ b/css/parser/tests/recovery/delim-token/minus/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/percent/output.json b/css/parser/tests/recovery/delim-token/percent/output.json index 9883fa1e37f..58972e9e92e 100644 --- a/css/parser/tests/recovery/delim-token/percent/output.json +++ b/css/parser/tests/recovery/delim-token/percent/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/plus/output.json b/css/parser/tests/recovery/delim-token/plus/output.json index eb74cf6ece3..419f7c50c19 100644 --- a/css/parser/tests/recovery/delim-token/plus/output.json +++ b/css/parser/tests/recovery/delim-token/plus/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/question-mark/output.json b/css/parser/tests/recovery/delim-token/question-mark/output.json index 9f3e2c11472..4e05de24ea9 100644 --- a/css/parser/tests/recovery/delim-token/question-mark/output.json +++ b/css/parser/tests/recovery/delim-token/question-mark/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/star/output.json b/css/parser/tests/recovery/delim-token/star/output.json index aad0c3c7630..039cc1af2e5 100644 --- a/css/parser/tests/recovery/delim-token/star/output.json +++ b/css/parser/tests/recovery/delim-token/star/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/delim-token/tilde/output.json b/css/parser/tests/recovery/delim-token/tilde/output.json index 5f22dfaf272..05c98c33051 100644 --- a/css/parser/tests/recovery/delim-token/tilde/output.json +++ b/css/parser/tests/recovery/delim-token/tilde/output.json @@ -98,7 +98,11 @@ "end": 15, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/function-token/output.json b/css/parser/tests/recovery/function-token/output.json index 57571905439..ce3a9e9893e 100644 --- a/css/parser/tests/recovery/function-token/output.json +++ b/css/parser/tests/recovery/function-token/output.json @@ -98,7 +98,11 @@ "end": 14, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -140,7 +144,11 @@ "end": 26, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -156,7 +164,11 @@ "end": 28, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": "\n" + } + } } ] } diff --git a/css/parser/tests/recovery/styled-jsx/1/output.json b/css/parser/tests/recovery/styled-jsx/1/output.json index 5e9f0617303..12937385df7 100644 --- a/css/parser/tests/recovery/styled-jsx/1/output.json +++ b/css/parser/tests/recovery/styled-jsx/1/output.json @@ -262,7 +262,11 @@ "end": 137, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -399,7 +403,11 @@ "end": 237, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -585,7 +593,11 @@ "end": 334, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -660,7 +672,11 @@ "end": 378, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -817,7 +833,11 @@ "end": 463, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -892,7 +912,11 @@ "end": 507, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/styled-jsx/2/output.json b/css/parser/tests/recovery/styled-jsx/2/output.json index 12b61262928..3a8b72cc44c 100644 --- a/css/parser/tests/recovery/styled-jsx/2/output.json +++ b/css/parser/tests/recovery/styled-jsx/2/output.json @@ -108,7 +108,11 @@ "end": 13, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -183,7 +187,11 @@ "end": 35, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/value/quotes/output.json b/css/parser/tests/recovery/value/quotes/output.json index 1cce31da757..04f2f61ef7d 100644 --- a/css/parser/tests/recovery/value/quotes/output.json +++ b/css/parser/tests/recovery/value/quotes/output.json @@ -127,7 +127,11 @@ "end": 25, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { @@ -148,7 +152,11 @@ "end": 34, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": " " + } + } }, { "span": { diff --git a/css/parser/tests/recovery/vercel/001/output.json b/css/parser/tests/recovery/vercel/001/output.json index 936f589dd3d..e3d4567eab9 100644 --- a/css/parser/tests/recovery/vercel/001/output.json +++ b/css/parser/tests/recovery/vercel/001/output.json @@ -714,7 +714,11 @@ "end": 304, "ctxt": 0 }, - "token": "WhiteSpace" + "token": { + "WhiteSpace": { + "value": "\n" + } + } } ] } diff --git a/css/parser/tests/recovery/whitespaces/input.css b/css/parser/tests/recovery/whitespaces/input.css new file mode 100644 index 00000000000..82e3a48dfcf --- /dev/null +++ b/css/parser/tests/recovery/whitespaces/input.css @@ -0,0 +1,10 @@ +a { + prop: ; + prop: ; + prop: + +; + prop: + + ; +} diff --git a/css/parser/tests/recovery/whitespaces/output.json b/css/parser/tests/recovery/whitespaces/output.json new file mode 100644 index 00000000000..2e03b7db285 --- /dev/null +++ b/css/parser/tests/recovery/whitespaces/output.json @@ -0,0 +1,242 @@ +{ + "type": "Stylesheet", + "span": { + "start": 0, + "end": 67, + "ctxt": 0 + }, + "rules": [ + { + "type": "StyleRule", + "span": { + "start": 0, + "end": 66, + "ctxt": 0 + }, + "selectors": [ + { + "type": "ComplexSelector", + "span": { + "start": 0, + "end": 1, + "ctxt": 0 + }, + "selectors": [ + { + "type": "CompoundSelector", + "span": { + "start": 0, + "end": 1, + "ctxt": 0 + }, + "hasNestPrefix": false, + "combinator": null, + "typeSelector": { + "type": "NamespacedName", + "span": { + "start": 0, + "end": 1, + "ctxt": 0 + }, + "prefix": null, + "name": { + "type": "Text", + "span": { + "start": 0, + "end": 1, + "ctxt": 0 + }, + "value": "a", + "raw": "a" + } + }, + "subclassSelectors": [] + } + ] + } + ], + "block": { + "type": "Block", + "span": { + "start": 2, + "end": 66, + "ctxt": 0 + }, + "items": [ + { + "type": "Tokens", + "span": { + "start": 8, + "end": 14, + "ctxt": 0 + }, + "tokens": [ + { + "span": { + "start": 8, + "end": 12, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "prop", + "raw": "prop" + } + } + }, + { + "span": { + "start": 12, + "end": 13, + "ctxt": 0 + }, + "token": "Colon" + }, + { + "span": { + "start": 13, + "end": 14, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + } + ] + }, + { + "type": "Tokens", + "span": { + "start": 20, + "end": 29, + "ctxt": 0 + }, + "tokens": [ + { + "span": { + "start": 20, + "end": 24, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "prop", + "raw": "prop" + } + } + }, + { + "span": { + "start": 24, + "end": 25, + "ctxt": 0 + }, + "token": "Colon" + }, + { + "span": { + "start": 25, + "end": 29, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + } + ] + }, + { + "type": "Tokens", + "span": { + "start": 35, + "end": 42, + "ctxt": 0 + }, + "tokens": [ + { + "span": { + "start": 35, + "end": 39, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "prop", + "raw": "prop" + } + } + }, + { + "span": { + "start": 39, + "end": 40, + "ctxt": 0 + }, + "token": "Colon" + }, + { + "span": { + "start": 40, + "end": 42, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": "\n\n" + } + } + } + ] + }, + { + "type": "Tokens", + "span": { + "start": 48, + "end": 63, + "ctxt": 0 + }, + "tokens": [ + { + "span": { + "start": 48, + "end": 52, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "prop", + "raw": "prop" + } + } + }, + { + "span": { + "start": 52, + "end": 53, + "ctxt": 0 + }, + "token": "Colon" + }, + { + "span": { + "start": 53, + "end": 63, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " \n\n " + } + } + } + ] + } + ] + } + } + ] +} diff --git a/css/parser/tests/recovery/whitespaces/output.swc-stderr b/css/parser/tests/recovery/whitespaces/output.swc-stderr new file mode 100644 index 00000000000..b4e1c4e80b2 --- /dev/null +++ b/css/parser/tests/recovery/whitespaces/output.swc-stderr @@ -0,0 +1,24 @@ +error: Expected Declaration value + --> $DIR/tests/recovery/whitespaces/input.css:2:11 + | +2 | prop: ; + | ^ + +error: Expected Declaration value + --> $DIR/tests/recovery/whitespaces/input.css:3:14 + | +3 | prop: ; + | ^ + +error: Expected Declaration value + --> $DIR/tests/recovery/whitespaces/input.css:6:1 + | +6 | ; + | ^ + +error: Expected Declaration value + --> $DIR/tests/recovery/whitespaces/input.css:9:5 + | +9 | ; + | ^ + diff --git a/css/stylis/Cargo.toml b/css/stylis/Cargo.toml index 6c6f2d60b70..cfc614fc196 100644 --- a/css/stylis/Cargo.toml +++ b/css/stylis/Cargo.toml @@ -6,18 +6,18 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_stylis" repository = "https://github.com/swc-project/swc.git" -version = "0.21.0" +version = "0.22.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] swc_atoms = {version = "0.2.7", path = "../../atoms"} swc_common = {version = "0.14.0", path = "../../common"} -swc_css_ast = {version = "0.22.0", path = "../ast"} -swc_css_utils = {version = "0.19.0", path = "../utils/"} -swc_css_visit = {version = "0.21.0", path = "../visit"} +swc_css_ast = {version = "0.23.0", path = "../ast"} +swc_css_utils = {version = "0.20.0", path = "../utils/"} +swc_css_visit = {version = "0.22.0", path = "../visit"} [dev-dependencies] -swc_css_codegen = {version = "0.22.0", path = "../codegen"} -swc_css_parser = {version = "0.24.0", path = "../parser"} +swc_css_codegen = {version = "0.23.0", path = "../codegen"} +swc_css_parser = {version = "0.25.0", path = "../parser"} testing = {version = "0.15.0", path = "../../testing"} diff --git a/css/stylis/tests/prefixer.rs b/css/stylis/tests/prefixer.rs index a9e39857195..035c562ee6b 100644 --- a/css/stylis/tests/prefixer.rs +++ b/css/stylis/tests/prefixer.rs @@ -454,7 +454,8 @@ fn error_recovery_1() { "__styled-jsx-placeholder__1 animation: slide 3s ease infinite; ", - "__styled-jsx-placeholder__1 animation: slide 3s ease infinite;", + "__styled-jsx-placeholder__1 + animation: slide 3s ease infinite;", ); t( @@ -462,7 +463,7 @@ fn error_recovery_1() { __styled-jsx-placeholder__1 ", "-webkit-animation:slide 3s ease infinite;animation:slide 3s ease \ - infinite;__styled-jsx-placeholder__1 ;", + infinite;__styled-jsx-placeholder__1\n ;", ); } diff --git a/css/utils/Cargo.toml b/css/utils/Cargo.toml index 0652eb30d59..4256e9c6b9f 100644 --- a/css/utils/Cargo.toml +++ b/css/utils/Cargo.toml @@ -6,11 +6,11 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_css_utils" repository = "https://github.com/swc-project/swc.git" -version = "0.19.0" +version = "0.20.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] swc_atoms = {version = "0.2.7", path = "../../atoms"} swc_common = {version = "0.14.0", path = "../../common"} -swc_css_ast = {version = "0.22.0", path = "../ast"} -swc_css_visit = {version = "0.21.0", path = "../visit"} +swc_css_ast = {version = "0.23.0", path = "../ast"} +swc_css_visit = {version = "0.22.0", path = "../visit"} diff --git a/css/visit/Cargo.toml b/css/visit/Cargo.toml index bdff4c90682..481b9c1e773 100644 --- a/css/visit/Cargo.toml +++ b/css/visit/Cargo.toml @@ -6,12 +6,12 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_css_visit" repository = "https://github.com/swc-project/swc.git" -version = "0.21.0" +version = "0.22.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] swc_atoms = {version = "0.2.7", path = "../../atoms"} swc_common = {version = "0.14.0", path = "../../common"} -swc_css_ast = {version = "0.22.0", path = "../ast/"} +swc_css_ast = {version = "0.23.0", path = "../ast/"} swc_visit = {version = "0.2.6", path = "../../visit"}