Restore @babel/parser tests (#10854)
* Make parser tests work again * Update failing fixtures * Fix serialization of BigInt * Fix
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid parenthesized assignment pattern (1:1)",
|
||||
"SyntaxError: Invalid left-hand side in assignment expression (1:1)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid parenthesized assignment pattern (1:5)",
|
||||
"SyntaxError: Invalid left-hand side in for-in statement (1:5)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid parenthesized assignment pattern (1:1)",
|
||||
"SyntaxError: Invalid left-hand side in assignment expression (1:1)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid parenthesized assignment pattern (1:1)",
|
||||
"SyntaxError: Invalid left-hand side in assignment expression (1:1)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: Invalid parenthesized assignment pattern (1:5)",
|
||||
"SyntaxError: Invalid left-hand side in for-in statement (1:5)"
|
||||
],
|
||||
"program": {
|
||||
|
||||
@@ -89,7 +89,10 @@
|
||||
"column": 12
|
||||
}
|
||||
},
|
||||
"value": "1",
|
||||
"value": {
|
||||
"$$ babel internal serialized type": "BigInt",
|
||||
"value": "1n"
|
||||
},
|
||||
"raw": "1n",
|
||||
"bigint": "1"
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user