Skip to content

Commit 9a40d85

Browse files
authored
[Babel 8]: Remove record and tuple syntax support (#17242)
* breaking: remove record-and-tuple parsing support * remove outdated typescript tests * remove Babel 8 only record/tuple tests * fix test error due to record/tuple removal * fix test error * remove record and tuple from stage 2 preset
1 parent afe6ae2 commit 9a40d85

122 files changed

Lines changed: 70 additions & 1254 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint/babel-eslint-parser/test/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import escope from "eslint-scope";
33
import unpad from "dedent";
44
import { parseForESLint as parseForESLintOriginal } from "../lib/index.cjs";
55
import { ESLint } from "eslint";
6-
import { itDummy, commonJS, IS_BABEL_8, itBabel7 } from "$repo-utils";
6+
import { itDummy, commonJS, itBabel7 } from "$repo-utils";
77

88
function parseForESLint(code, options) {
99
return parseForESLintOriginal(code, {
@@ -430,19 +430,15 @@ describe("Babel and Espree", () => {
430430
expect(babylonAST.tokens[1].type).toEqual("Punctuator");
431431
});
432432

433-
it("brace and bracket hash operator (token)", () => {
433+
itBabel7("brace and bracket hash operator (token)", () => {
434434
const code = "#[]; #{}";
435435
const babylonAST = parseForESLint(code, {
436436
eslintVisitorKeys: true,
437437
eslintScopeManager: true,
438438
babelOptions: {
439439
filename: "test.js",
440440
parserOpts: {
441-
plugins: [
442-
IS_BABEL_8()
443-
? "recordAndTuple"
444-
: ["recordAndTuple", { syntaxType: "hash" }],
445-
],
441+
plugins: [["recordAndTuple", { syntaxType: "hash" }]],
446442
tokens: true,
447443
},
448444
},

packages/babel-generator/test/fixtures/recordAndTuple/default/input.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/babel-generator/test/fixtures/recordAndTuple/default/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/babel-generator/test/fixtures/recordAndTuple/default/output.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/babel-generator/test/fixtures/recordAndTuple/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/input.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/options.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/output.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/source-map.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/babel-parser/src/parser/expression.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,14 +1146,6 @@ export default abstract class ExpressionParser extends LValParser {
11461146
return this.parseParenAndDistinguishExpression(canBeArrow);
11471147
}
11481148

1149-
case tt.bracketBarL:
1150-
case tt.bracketHashL: {
1151-
return this.parseArrayLike(
1152-
this.state.type === tt.bracketBarL ? tt.bracketBarR : tt.bracketR,
1153-
/* canBePattern */ false,
1154-
/* isTuple */ true,
1155-
);
1156-
}
11571149
case tt.bracketL: {
11581150
return this.parseArrayLike(
11591151
tt.bracketR,
@@ -1162,14 +1154,6 @@ export default abstract class ExpressionParser extends LValParser {
11621154
refExpressionErrors,
11631155
);
11641156
}
1165-
case tt.braceBarL:
1166-
case tt.braceHashL: {
1167-
return this.parseObjectLike(
1168-
this.state.type === tt.braceBarL ? tt.braceBarR : tt.braceR,
1169-
/* isPattern */ false,
1170-
/* isRecord */ true,
1171-
);
1172-
}
11731157
case tt.braceL: {
11741158
return this.parseObjectLike(
11751159
tt.braceR,
@@ -1269,8 +1253,22 @@ export default abstract class ExpressionParser extends LValParser {
12691253
}
12701254

12711255
default:
1272-
if (!process.env.BABEL_8_BREAKING && type === tt.decimal) {
1273-
return this.parseDecimalLiteral(this.state.value);
1256+
if (!process.env.BABEL_8_BREAKING) {
1257+
if (type === tt.decimal) {
1258+
return this.parseDecimalLiteral(this.state.value);
1259+
} else if (type === tt.bracketBarL || type === tt.bracketHashL) {
1260+
return this.parseArrayLike(
1261+
this.state.type === tt.bracketBarL ? tt.bracketBarR : tt.bracketR,
1262+
/* canBePattern */ false,
1263+
/* isTuple */ true,
1264+
);
1265+
} else if (type === tt.braceBarL || type === tt.braceHashL) {
1266+
return this.parseObjectLike(
1267+
this.state.type === tt.braceBarL ? tt.braceBarR : tt.braceR,
1268+
/* isPattern */ false,
1269+
/* isRecord */ true,
1270+
);
1271+
}
12741272
}
12751273

12761274
if (tokenIsIdentifier(type)) {

0 commit comments

Comments
 (0)