parser: Parse member expression is object patterns (#1068)

This commit is contained in:
강동윤 2020-09-12 18:39:25 +09:00 committed by GitHub
parent 5c76aea82b
commit 0972db98a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 4 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecmascript"
repository = "https://github.com/swc-project/swc.git"
version = "0.7.4"
version = "0.7.5"
[features]
codegen = ["swc_ecma_codegen"]

View File

@ -1,6 +1,6 @@
[package]
name = "swc_ecma_parser"
version = "0.37.1"
version = "0.37.2"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"

View File

@ -623,6 +623,7 @@ impl<'a, I: Tokens> Parser<I> {
}))
}
Expr::Ident(ident) => Ok(ident.into()),
Expr::Member(..) => Ok(Pat::Expr(expr)),
Expr::Array(ArrayLit {
elems: mut exprs, ..
}) => {
@ -710,7 +711,7 @@ impl<'a, I: Tokens> Parser<I> {
// Invalid patterns.
// Note that assignment expression with '=' is valid, and handled above.
Expr::Lit(..) | Expr::Member(..) | Expr::Assign(..) => {
Expr::Lit(..) | Expr::Assign(..) => {
self.emit_err(span, SyntaxError::InvalidPat);
Ok(Pat::Invalid(Invalid { span }))
}

View File

@ -102,6 +102,11 @@ fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
const IGNORED_ERROR_TESTS: &[&str] = &[
// Old (wrong) tests
"569a2c1bad3beeb2.js",
"3b6f737a4ac948a8.js",
"829d9261aa6cd22c.js",
"b03ee881dce1a367.js",
"cb92787da5075fd1.js",
"f0f498d6ae70038f.js",
// Wrong tests
"0d5e450f1da8a92a.js",
"346316bef54d805a.js",

View File

@ -0,0 +1 @@
({ ...foo.bar } = baz);

View File

@ -0,0 +1,104 @@
{
"type": "Module",
"span": {
"start": 0,
"end": 23,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 0,
"end": 23,
"ctxt": 0
},
"expression": {
"type": "ParenthesisExpression",
"span": {
"start": 0,
"end": 22,
"ctxt": 0
},
"expression": {
"type": "AssignmentExpression",
"span": {
"start": 1,
"end": 21,
"ctxt": 0
},
"operator": "=",
"left": {
"type": "ObjectPattern",
"span": {
"start": 1,
"end": 15,
"ctxt": 0
},
"properties": [
{
"type": "RestElement",
"span": {
"start": 3,
"end": 13,
"ctxt": 0
},
"rest": {
"start": 3,
"end": 6,
"ctxt": 0
},
"argument": {
"type": "MemberExpression",
"span": {
"start": 6,
"end": 13,
"ctxt": 0
},
"object": {
"type": "Identifier",
"span": {
"start": 6,
"end": 9,
"ctxt": 0
},
"value": "foo",
"typeAnnotation": null,
"optional": false
},
"property": {
"type": "Identifier",
"span": {
"start": 10,
"end": 13,
"ctxt": 0
},
"value": "bar",
"typeAnnotation": null,
"optional": false
},
"computed": false
},
"typeAnnotation": null
}
],
"optional": false,
"typeAnnotation": null
},
"right": {
"type": "Identifier",
"span": {
"start": 18,
"end": 21,
"ctxt": 0
},
"value": "baz",
"typeAnnotation": null,
"optional": false
}
}
}
}
],
"interpreter": null
}

View File

@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.26",
"version": "1.2.27",
"description": "Super-fast alternative for babel",
"homepage": "https://swc-project.github.io",
"main": "./index.js",