fix(css/parser): Fix error recovery logic of property values (#2331)

swc_css_parser:
 - Fix `state` used for error recovery.
This commit is contained in:
Donny/강동윤 2021-10-01 20:04:24 +09:00 committed by GitHub
parent dad73926e6
commit 9f4c5b7ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 262 additions and 3 deletions

2
Cargo.lock generated
View File

@ -2525,7 +2525,7 @@ dependencies = [
[[package]]
name = "swc_css_parser"
version = "0.8.1"
version = "0.8.2"
dependencies = [
"bitflags",
"lexical",

View File

@ -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.8.1"
version = "0.8.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]

View File

@ -21,6 +21,7 @@ where
///
/// Returned [BytePos] is `hi`.
pub(super) fn parse_property_values(&mut self) -> PResult<(Vec<Value>, BytePos)> {
let start = self.input.state();
let mut values = vec![];
let mut state = self.input.state();
let start_pos = self.input.cur_span()?.lo;
@ -47,7 +48,7 @@ where
if self.ctx.recover_from_property_value
&& !is_one_of!(self, EOF, ";", "}", "!", ")")
{
self.input.reset(&state);
self.input.reset(&start);
let mut tokens = vec![];
while !is_one_of!(self, EOF, ";", "}", "!", ")") {

View File

@ -368,6 +368,24 @@
"ctxt": 0
},
"tokens": [
{
"span": {
"start": 236,
"end": 237,
"ctxt": 0
},
"token": "WhiteSpace"
},
{
"span": {
"start": 237,
"end": 264,
"ctxt": 0
},
"token": {
"Ident": "__styled-jsx-placeholder__2"
}
},
{
"span": {
"start": 264,
@ -587,6 +605,24 @@
"ctxt": 0
},
"tokens": [
{
"span": {
"start": 377,
"end": 378,
"ctxt": 0
},
"token": "WhiteSpace"
},
{
"span": {
"start": 378,
"end": 405,
"ctxt": 0
},
"token": {
"Ident": "__styled-jsx-placeholder__3"
}
},
{
"span": {
"start": 405,
@ -779,6 +815,24 @@
"ctxt": 0
},
"tokens": [
{
"span": {
"start": 506,
"end": 507,
"ctxt": 0
},
"token": "WhiteSpace"
},
{
"span": {
"start": 507,
"end": 534,
"ctxt": 0
},
"token": {
"Ident": "__styled-jsx-placeholder__4"
}
},
{
"span": {
"start": 534,

View File

@ -0,0 +1,3 @@
.a :global(> .b) {
flex-basis: __styled-jsx-placeholder__0%;
}

View File

@ -0,0 +1,201 @@
{
"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": 16,
"ctxt": 0
},
"selectors": [
{
"type": "CompoundSelector",
"span": {
"start": 0,
"end": 2,
"ctxt": 0
},
"hasNestPrefix": false,
"combinator": null,
"typeSelector": null,
"subclassSelectors": [
{
"type": "ClassSelector",
"span": {
"start": 0,
"end": 2,
"ctxt": 0
},
"text": {
"type": "Text",
"span": {
"start": 1,
"end": 2,
"ctxt": 0
},
"value": "a"
}
}
]
},
{
"type": "CompoundSelector",
"span": {
"start": 3,
"end": 16,
"ctxt": 0
},
"hasNestPrefix": false,
"combinator": null,
"typeSelector": null,
"subclassSelectors": [
{
"type": "PseudoSelector",
"span": {
"start": 3,
"end": 16,
"ctxt": 0
},
"isElement": false,
"name": {
"type": "Text",
"span": {
"start": 4,
"end": 10,
"ctxt": 0
},
"value": "global"
},
"args": {
"type": "Tokens",
"span": {
"start": 11,
"end": 15,
"ctxt": 0
},
"tokens": [
{
"span": {
"start": 11,
"end": 12,
"ctxt": 0
},
"token": "GreaterThan"
},
{
"span": {
"start": 12,
"end": 13,
"ctxt": 0
},
"token": "WhiteSpace"
},
{
"span": {
"start": 13,
"end": 14,
"ctxt": 0
},
"token": "Dot"
},
{
"span": {
"start": 14,
"end": 15,
"ctxt": 0
},
"token": {
"Ident": "b"
}
}
]
}
}
]
}
]
}
],
"block": {
"type": "DeclBlock",
"span": {
"start": 17,
"end": 66,
"ctxt": 0
},
"items": [
{
"type": "Property",
"span": {
"start": 23,
"end": 62,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 23,
"end": 33,
"ctxt": 0
},
"value": "flex-basis"
},
"values": [
{
"type": "Tokens",
"span": {
"start": 34,
"end": 63,
"ctxt": 0
},
"tokens": [
{
"span": {
"start": 34,
"end": 35,
"ctxt": 0
},
"token": "WhiteSpace"
},
{
"span": {
"start": 35,
"end": 62,
"ctxt": 0
},
"token": {
"Ident": "__styled-jsx-placeholder__0"
}
},
{
"span": {
"start": 62,
"end": 63,
"ctxt": 0
},
"token": "Percent"
}
]
}
],
"important": null
}
]
}
}
]
}