Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 7, 2020
1 parent ac81ee8 commit 0c1c38e
Show file tree
Hide file tree
Showing 42 changed files with 567 additions and 61 deletions.
10 changes: 6 additions & 4 deletions packages/babel-parser/src/parser/lval.js
@@ -1,5 +1,6 @@
// @flow

/*:: declare var invariant; */
import * as charCodes from "charcodes";
import { types as tt, type TokenType } from "../tokenizer/types";
import type {
Expand All @@ -24,7 +25,7 @@ import { type BindingTypes, BIND_NONE } from "../util/scopeflags";
import { ExpressionErrors } from "./util";
import { Errors } from "./error";

const unwrapParenthesizedExpression = (node: Node) => {
const unwrapParenthesizedExpression = (node: Node): Node => {
return node.type === "ParenthesizedExpression"
? unwrapParenthesizedExpression(node.expression)
: node;
Expand Down Expand Up @@ -112,7 +113,7 @@ export default class LValParser extends NodeUtils {

case "ObjectProperty":
// ObjectProperty is not allowed in LHS
this.toAssignable(node.value, /* isLHS */ false);
this.toAssignable(node.value);
break;

case "SpreadElement": {
Expand All @@ -137,11 +138,12 @@ export default class LValParser extends NodeUtils {
node.type = "AssignmentPattern";
delete node.operator;
// AssignmentPattern is not allowed in LHS
this.toAssignable(node.left, /* isLHS */ false);
this.toAssignable(node.left);
break;

case "ParenthesizedExpression":
this.toAssignable(((parenthesized: any): Expression), isLHS);
/*::invariant (parenthesized !== undefined) */
this.toAssignable(parenthesized, isLHS);
break;

default:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1 @@
([...(a)]) => {}
@@ -0,0 +1,54 @@
{
"type": "File",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"errors": [
"SyntaxError: Invalid parenthesized assignment pattern (1:5)"
],
"program": {
"type": "Program",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"expression": {
"type": "ArrowFunctionExpression",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "ArrayPattern",
"start":1,"end":9,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":9}},
"elements": [
{
"type": "RestElement",
"start":2,"end":8,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":8}},
"argument": {
"type": "ParenthesizedExpression",
"start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8}},
"expression": {
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"a"},
"name": "a"
}
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16}},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1 @@
[...(a)] = []
@@ -0,0 +1,46 @@
{
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"program": {
"type": "Program",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"expression": {
"type": "AssignmentExpression",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"operator": "=",
"left": {
"type": "ArrayPattern",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
"elements": [
{
"type": "RestElement",
"start":1,"end":7,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":7}},
"argument": {
"type": "ParenthesizedExpression",
"start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7}},
"expression": {
"type": "Identifier",
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"a"},
"name": "a"
}
}
}
]
},
"right": {
"type": "ArrayExpression",
"start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}},
"elements": []
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
[...(a.b)] = []
@@ -0,0 +1,56 @@
{
"type": "File",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"program": {
"type": "Program",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"expression": {
"type": "AssignmentExpression",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"operator": "=",
"left": {
"type": "ArrayPattern",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
"elements": [
{
"type": "RestElement",
"start":1,"end":9,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":9}},
"argument": {
"type": "ParenthesizedExpression",
"start":4,"end":9,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":9}},
"expression": {
"type": "MemberExpression",
"start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8}},
"object": {
"type": "Identifier",
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"a"},
"name": "a"
},
"computed": false,
"property": {
"type": "Identifier",
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"b"},
"name": "b"
}
}
}
}
]
},
"right": {
"type": "ArrayExpression",
"start":13,"end":15,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":15}},
"elements": []
}
}
}
],
"directives": []
}
}
@@ -0,0 +1,52 @@
{
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Invalid parenthesized assignment pattern (1:5)"
],
"program": {
"type": "Program",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"expression": {
"type": "ArrowFunctionExpression",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"a"},
"name": "a"
},
{
"type": "Identifier",
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"b"},
"extra": {
"parenthesized": true,
"parenStart": 4
},
"name": "b"
}
],
"body": {
"type": "NumericLiteral",
"start":12,"end":14,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":14}},
"extra": {
"rawValue": 42,
"raw": "42"
},
"value": 42
}
}
}
],
"directives": []
}
}

This file was deleted.

@@ -0,0 +1,56 @@
{
"type": "File",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"errors": [
"SyntaxError: Invalid parenthesized assignment pattern (1:12)"
],
"program": {
"type": "Program",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":23,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":23}},
"id": {
"type": "Identifier",
"start":4,"end":7,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":7},"identifierName":"foo"},
"name": "foo"
},
"init": {
"type": "ArrowFunctionExpression",
"start":10,"end":23,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":23}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15},"identifierName":"foo"},
"extra": {
"parenthesized": true,
"parenStart": 11
},
"name": "foo"
}
],
"body": {
"type": "BlockStatement",
"start":21,"end":23,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":23}},
"body": [],
"directives": []
}
}
}
],
"kind": "var"
}
],
"directives": []
}
}
@@ -0,0 +1 @@
[...(a.b)] = [];

0 comments on commit 0c1c38e

Please sign in to comment.