diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/369/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/369/output.json index 42614106f157..ec3792255a15 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/369/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/369/output.json @@ -13,6 +13,7 @@ } }, "errors": [ + "SyntaxError: Invalid parenthesized assignment pattern (1:1)", "SyntaxError: Invalid left-hand side in assignment expression (1:1)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/374/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/374/output.json index f9e5df01e76a..6cbd0876600e 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/374/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/374/output.json @@ -13,6 +13,7 @@ } }, "errors": [ + "SyntaxError: Invalid parenthesized assignment pattern (1:5)", "SyntaxError: Invalid left-hand side in for-in statement (1:5)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/556/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/556/output.json index 448578186a0a..fe203d04bcc6 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/556/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/556/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)" + "SyntaxError: Invalid parenthesized assignment pattern (1:0)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/558/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/558/output.json index e2a0d2a8ba52..c59930c19e03 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/558/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/558/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)" + "SyntaxError: Invalid parenthesized assignment pattern (1:0)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/output.json index 111c55cd65bd..16f7d7f8e50f 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)" + "SyntaxError: Invalid parenthesized assignment pattern (1:1)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/output.json index 34adca287e3e..b84a7826945b 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/output.json @@ -13,7 +13,7 @@ } }, "errors": [ - "SyntaxError: You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)" + "SyntaxError: Invalid parenthesized assignment pattern (1:1)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/223/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/223/output.json index 426006b7cdfb..d5fe95dd82c4 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/223/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/223/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 22, + "end": 20, "loc": { "start": { "line": 1, @@ -9,16 +9,16 @@ }, "end": { "line": 1, - "column": 22 + "column": 20 } }, "errors": [ - "SyntaxError: Object pattern can't contain getter or setter (1:8)" + "SyntaxError: Object pattern can't contain getter or setter (1:7)" ], "program": { "type": "Program", "start": 0, - "end": 22, + "end": 20, "loc": { "start": { "line": 1, @@ -26,7 +26,7 @@ }, "end": { "line": 1, - "column": 22 + "column": 20 } }, "sourceType": "script", @@ -35,7 +35,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 22, + "end": 20, "loc": { "start": { "line": 1, @@ -43,66 +43,66 @@ }, "end": { "line": 1, - "column": 22 + "column": 20 } }, "expression": { "type": "AssignmentExpression", - "start": 2, - "end": 20, + "start": 1, + "end": 19, "loc": { "start": { "line": 1, - "column": 2 + "column": 1 }, "end": { "line": 1, - "column": 20 + "column": 19 } }, "operator": "=", "left": { "type": "ObjectPattern", - "start": 2, - "end": 16, + "start": 1, + "end": 15, "loc": { "start": { "line": 1, - "column": 2 + "column": 1 }, "end": { "line": 1, - "column": 16 + "column": 15 } }, "properties": [ { "type": "ObjectMethod", - "start": 4, - "end": 14, + "start": 3, + "end": 13, "loc": { "start": { "line": 1, - "column": 4 + "column": 3 }, "end": { "line": 1, - "column": 14 + "column": 13 } }, "method": false, "key": { "type": "Identifier", - "start": 8, - "end": 9, + "start": 7, + "end": 8, "loc": { "start": { "line": 1, - "column": 8 + "column": 7 }, "end": { "line": 1, - "column": 9 + "column": 8 }, "identifierName": "x" }, @@ -116,16 +116,16 @@ "params": [], "body": { "type": "BlockStatement", - "start": 12, - "end": 14, + "start": 11, + "end": 13, "loc": { "start": { "line": 1, - "column": 12 + "column": 11 }, "end": { "line": 1, - "column": 14 + "column": 13 } }, "body": [], @@ -136,16 +136,16 @@ }, "right": { "type": "NumericLiteral", - "start": 19, - "end": 20, + "start": 18, + "end": 19, "loc": { "start": { "line": 1, - "column": 19 + "column": 18 }, "end": { "line": 1, - "column": 20 + "column": 19 } }, "extra": { diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-group-assignment/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-group-assignment/output.json index a6616604e7dd..02c910998853 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-group-assignment/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-group-assignment/output.json @@ -13,6 +13,7 @@ } }, "errors": [ + "SyntaxError: Invalid parenthesized assignment pattern (1:1)", "SyntaxError: Invalid left-hand side in assignment expression (1:1)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0047/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0047/output.json index 42614106f157..ec3792255a15 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0047/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0047/output.json @@ -13,6 +13,7 @@ } }, "errors": [ + "SyntaxError: Invalid parenthesized assignment pattern (1:1)", "SyntaxError: Invalid left-hand side in assignment expression (1:1)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0056/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0056/output.json index f9e5df01e76a..6cbd0876600e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0056/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0056/output.json @@ -13,6 +13,7 @@ } }, "errors": [ + "SyntaxError: Invalid parenthesized assignment pattern (1:5)", "SyntaxError: Invalid left-hand side in for-in statement (1:5)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/estree/bigInt/basic/output.json b/packages/babel-parser/test/fixtures/estree/bigInt/basic/output.json index 8723c3f23444..ca8e42197417 100644 --- a/packages/babel-parser/test/fixtures/estree/bigInt/basic/output.json +++ b/packages/babel-parser/test/fixtures/estree/bigInt/basic/output.json @@ -89,7 +89,10 @@ "column": 12 } }, - "value": "1", + "value": { + "$$ babel internal serialized type": "BigInt", + "value": "1n" + }, "raw": "1n", "bigint": "1" } diff --git a/packages/babel-parser/test/helpers/runFixtureTests.js b/packages/babel-parser/test/helpers/runFixtureTests.js index 288ecbb2fe0a..62efd1fb7f80 100644 --- a/packages/babel-parser/test/helpers/runFixtureTests.js +++ b/packages/babel-parser/test/helpers/runFixtureTests.js @@ -7,6 +7,8 @@ import path from "path"; const rootPath = path.join(__dirname, "../../../.."); +const serialized = "$$ babel internal serialized type"; + class FixtureError extends Error { constructor(previousError, fixturePath, code) { super(previousError.message); @@ -127,15 +129,21 @@ function overrideToJSON(cb) { const { toJSON } = obj.prototype; originalToJSONMap.set(obj, toJSON); obj.prototype.toJSON = function() { + if (typeof this === "bigint") { + return { [serialized]: "BigInt", value: serialize(this) }; + } + return this.toString(); }; } - cb(); + const result = cb(); for (const obj of notJSONparseableObj) { obj.prototype.toJSON = originalToJSONMap.get(obj); } + + return result; } function runTest(test, parseFunction) { @@ -213,8 +221,22 @@ function runTest(test, parseFunction) { } } +function serialize(value) { + if (typeof value === "bigint") { + return value.toString() + "n"; + } + return JSON.stringify(value, null, 2); +} + function ppJSON(v) { - return JSON.stringify(v, null, 2); + if (v && typeof v === "object" && v[serialized]) { + switch (v[serialized]) { + case "BigInt": + return typeof BigInt === "undefined" ? "null" : v.value; + } + } + + return serialize(v); } function addPath(str, pt) { @@ -226,12 +248,12 @@ function addPath(str, pt) { } function misMatch(exp, act) { - overrideToJSON(() => { + return overrideToJSON(() => { if ( - exp instanceof RegExp || act instanceof RegExp || - exp instanceof Error || - act instanceof Error + act instanceof Error || + typeof act === "bigint" || + (exp && typeof exp === "object" && exp[serialized]) ) { const left = ppJSON(exp); const right = ppJSON(act);