diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c69cccba1282..9bf7288436651 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4551,7 +4551,7 @@ namespace Parser { parseExpected(SyntaxKind.OpenParenToken); const type = parseType(); let attributes: ImportAttributes | undefined; - if (parseOptional(SyntaxKind.CommaToken)) { + if (parseOptional(SyntaxKind.CommaToken) && token() !== SyntaxKind.CloseParenToken) { const openBracePosition = scanner.getTokenStart(); parseExpected(SyntaxKind.OpenBraceToken); const currentToken = token(); @@ -4572,6 +4572,7 @@ namespace Parser { ); } } + parseOptional(SyntaxKind.CommaToken); } parseExpected(SyntaxKind.CloseParenToken); const qualifier = parseOptional(SyntaxKind.DotToken) ? parseEntityNameOfTypeReference() : undefined; diff --git a/tests/baselines/reference/typeofImportInvalidElision.errors.txt b/tests/baselines/reference/typeofImportInvalidElision.errors.txt new file mode 100644 index 0000000000000..ebc5054293a63 --- /dev/null +++ b/tests/baselines/reference/typeofImportInvalidElision.errors.txt @@ -0,0 +1,12 @@ +main.ts(1,39): error TS1005: '{' expected. + + +==== input.ts (0 errors) ==== + export type X = 1; + +==== main.ts (1 errors) ==== + type T2 = typeof import('./input.js', ,); + ~ +!!! error TS1005: '{' expected. +!!! related TS1007 main.ts:1:39: The parser expected to find a '}' to match the '{' token here. + \ No newline at end of file diff --git a/tests/baselines/reference/typeofImportInvalidElision.js b/tests/baselines/reference/typeofImportInvalidElision.js new file mode 100644 index 0000000000000..827d709c7ddbf --- /dev/null +++ b/tests/baselines/reference/typeofImportInvalidElision.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/typeofImportInvalidElision.ts] //// + +//// [input.ts] +export type X = 1; + +//// [main.ts] +type T2 = typeof import('./input.js', ,); + + +//// [input.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [main.js] diff --git a/tests/baselines/reference/typeofImportInvalidElision.symbols b/tests/baselines/reference/typeofImportInvalidElision.symbols new file mode 100644 index 0000000000000..480f233b94e0e --- /dev/null +++ b/tests/baselines/reference/typeofImportInvalidElision.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/typeofImportInvalidElision.ts] //// + +=== input.ts === +export type X = 1; +>X : Symbol(X, Decl(input.ts, 0, 0)) + +=== main.ts === +type T2 = typeof import('./input.js', ,); +>T2 : Symbol(T2, Decl(main.ts, 0, 0)) + diff --git a/tests/baselines/reference/typeofImportInvalidElision.types b/tests/baselines/reference/typeofImportInvalidElision.types new file mode 100644 index 0000000000000..2a42a7e8e3d63 --- /dev/null +++ b/tests/baselines/reference/typeofImportInvalidElision.types @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/typeofImportInvalidElision.ts] //// + +=== input.ts === +export type X = 1; +>X : 1 +> : ^ + +=== main.ts === +type T2 = typeof import('./input.js', ,); +>T2 : typeof import("input") +> : ^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/typeofImportTrailingCommas.js b/tests/baselines/reference/typeofImportTrailingCommas.js new file mode 100644 index 0000000000000..446beb6aefd27 --- /dev/null +++ b/tests/baselines/reference/typeofImportTrailingCommas.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/typeofImportTrailingCommas.ts] //// + +//// [input.ts] +export type X = 1; + +//// [main.ts] +type T1 = typeof import('./input.js',) +type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },); + + +//// [input.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [main.js] diff --git a/tests/baselines/reference/typeofImportTrailingCommas.symbols b/tests/baselines/reference/typeofImportTrailingCommas.symbols new file mode 100644 index 0000000000000..1b0dd90a47133 --- /dev/null +++ b/tests/baselines/reference/typeofImportTrailingCommas.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/typeofImportTrailingCommas.ts] //// + +=== input.ts === +export type X = 1; +>X : Symbol(X, Decl(input.ts, 0, 0)) + +=== main.ts === +type T1 = typeof import('./input.js',) +>T1 : Symbol(T1, Decl(main.ts, 0, 0)) + +type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },); +>T2 : Symbol(T2, Decl(main.ts, 0, 38)) + diff --git a/tests/baselines/reference/typeofImportTrailingCommas.types b/tests/baselines/reference/typeofImportTrailingCommas.types new file mode 100644 index 0000000000000..16d3db586f7d3 --- /dev/null +++ b/tests/baselines/reference/typeofImportTrailingCommas.types @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/typeofImportTrailingCommas.ts] //// + +=== input.ts === +export type X = 1; +>X : 1 +> : ^ + +=== main.ts === +type T1 = typeof import('./input.js',) +>T1 : typeof import("input") +> : ^^^^^^^^^^^^^^^^^^^^^^ + +type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },); +>T2 : typeof import("input") +> : ^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/cases/compiler/typeofImportInvalidElision.ts b/tests/cases/compiler/typeofImportInvalidElision.ts new file mode 100644 index 0000000000000..da39f1ba5f6e1 --- /dev/null +++ b/tests/cases/compiler/typeofImportInvalidElision.ts @@ -0,0 +1,5 @@ +// @filename: input.ts +export type X = 1; + +// @filename: main.ts +type T2 = typeof import('./input.js', ,); diff --git a/tests/cases/compiler/typeofImportTrailingCommas.ts b/tests/cases/compiler/typeofImportTrailingCommas.ts new file mode 100644 index 0000000000000..26aefad3c1051 --- /dev/null +++ b/tests/cases/compiler/typeofImportTrailingCommas.ts @@ -0,0 +1,6 @@ +// @filename: input.ts +export type X = 1; + +// @filename: main.ts +type T1 = typeof import('./input.js',) +type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },);