From 5d4380372e794be7c2707ad16b215b63df2ef144 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 6 Feb 2023 10:44:46 +0800 Subject: [PATCH] TypeScript: Forbid invalid tuple label (#14256) --- src/language-js/parse/babel.js | 1 - .../tuple/__snapshots__/jsfmt.spec.js.snap | 25 +++++++++++++++++++ .../errors/typescript/tuple/jsfmt.spec.js | 12 +++++++++ .../__snapshots__/jsfmt.spec.js.snap | 22 ---------------- .../typescript-babel-only/tuple-labeled-ts.ts | 5 ---- 5 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 tests/format/misc/errors/typescript/tuple/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/typescript/tuple/jsfmt.spec.js delete mode 100644 tests/format/misc/typescript-babel-only/tuple-labeled-ts.ts diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 26c0a089e..f022230cb 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -189,7 +189,6 @@ const allowedMessageCodes = new Set([ "UnsupportedParameterPropertyKind", "MixedLabeledAndUnlabeledElements", - "InvalidTupleMemberLabel", "DuplicateAccessibilityModifier", "IndexSignatureHasDeclare", diff --git a/tests/format/misc/errors/typescript/tuple/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/tuple/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..6a3a77256 --- /dev/null +++ b/tests/format/misc/errors/typescript/tuple/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel-ts] format 1`] = ` +"Tuple members must be labeled with a simple identifier. (1:11) +> 1 | type T = [x.y: A]; + | ^" +`; + +exports[`snippet: #0 [typescript] format 1`] = ` +"',' expected. (1:14) +> 1 | type T = [x.y: A]; + | ^" +`; + +exports[`snippet: #1 [babel-ts] format 1`] = ` +"Tuple members must be labeled with a simple identifier. (1:11) +> 1 | type T = [x: A]; + | ^" +`; + +exports[`snippet: #1 [typescript] format 1`] = ` +"',' expected. (1:15) +> 1 | type T = [x: A]; + | ^" +`; diff --git a/tests/format/misc/errors/typescript/tuple/jsfmt.spec.js b/tests/format/misc/errors/typescript/tuple/jsfmt.spec.js new file mode 100644 index 000000000..c46685eff --- /dev/null +++ b/tests/format/misc/errors/typescript/tuple/jsfmt.spec.js @@ -0,0 +1,12 @@ +run_spec( + { + importMeta: import.meta, + snippets: [ + // Invalid label 1 + "type T = [x.y: A];", + // Invalid label 2 + "type T = [x: A];", + ], + }, + ["babel-ts", "typescript"] +); diff --git a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 4fd5776ae..d8ce50547 100644 --- a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -183,25 +183,3 @@ type Foo = ================================================================================ `; - -exports[`tuple-labeled-ts.ts format 1`] = ` -====================================options===================================== -parsers: ["babel-ts"] -printWidth: 80 - | printWidth -=====================================input====================================== -// Invalid label 1 -type T = [x.y: A]; - -// Invalid label 2 -type T = [x: A]; - -=====================================output===================================== -// Invalid label 1 -type T = [x.y: A]; - -// Invalid label 2 -type T = [x: A]; - -================================================================================ -`; diff --git a/tests/format/misc/typescript-babel-only/tuple-labeled-ts.ts b/tests/format/misc/typescript-babel-only/tuple-labeled-ts.ts deleted file mode 100644 index 42eb03cb2..000000000 --- a/tests/format/misc/typescript-babel-only/tuple-labeled-ts.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Invalid label 1 -type T = [x.y: A]; - -// Invalid label 2 -type T = [x: A];