Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b70f094

Browse files
Support trailing commas in typeof import()
1 parent 29e6d66 commit b70f094

10 files changed

+103
-1
lines changed

src/compiler/parser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4551,7 +4551,7 @@ namespace Parser {
45514551
parseExpected(SyntaxKind.OpenParenToken);
45524552
const type = parseType();
45534553
let attributes: ImportAttributes | undefined;
4554-
if (parseOptional(SyntaxKind.CommaToken)) {
4554+
if (parseOptional(SyntaxKind.CommaToken) && token() !== SyntaxKind.CloseParenToken) {
45554555
const openBracePosition = scanner.getTokenStart();
45564556
parseExpected(SyntaxKind.OpenBraceToken);
45574557
const currentToken = token();
@@ -4572,6 +4572,7 @@ namespace Parser {
45724572
);
45734573
}
45744574
}
4575+
parseOptional(SyntaxKind.CommaToken);
45754576
}
45764577
parseExpected(SyntaxKind.CloseParenToken);
45774578
const qualifier = parseOptional(SyntaxKind.DotToken) ? parseEntityNameOfTypeReference() : undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
main.ts(1,39): error TS1005: '{' expected.
2+
3+
4+
==== input.ts (0 errors) ====
5+
export type X = 1;
6+
7+
==== main.ts (1 errors) ====
8+
type T2 = typeof import('./input.js', ,);
9+
~
10+
!!! error TS1005: '{' expected.
11+
!!! related TS1007 main.ts:1:39: The parser expected to find a '}' to match the '{' token here.
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/typeofImportInvalidElision.ts] ////
2+
3+
//// [input.ts]
4+
export type X = 1;
5+
6+
//// [main.ts]
7+
type T2 = typeof import('./input.js', ,);
8+
9+
10+
//// [input.js]
11+
"use strict";
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
//// [main.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [tests/cases/compiler/typeofImportInvalidElision.ts] ////
2+
3+
=== input.ts ===
4+
export type X = 1;
5+
>X : Symbol(X, Decl(input.ts, 0, 0))
6+
7+
=== main.ts ===
8+
type T2 = typeof import('./input.js', ,);
9+
>T2 : Symbol(T2, Decl(main.ts, 0, 0))
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/typeofImportInvalidElision.ts] ////
2+
3+
=== input.ts ===
4+
export type X = 1;
5+
>X : 1
6+
> : ^
7+
8+
=== main.ts ===
9+
type T2 = typeof import('./input.js', ,);
10+
>T2 : typeof import("input")
11+
> : ^^^^^^^^^^^^^^^^^^^^^^
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/typeofImportTrailingCommas.ts] ////
2+
3+
//// [input.ts]
4+
export type X = 1;
5+
6+
//// [main.ts]
7+
type T1 = typeof import('./input.js',)
8+
type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },);
9+
10+
11+
//// [input.js]
12+
"use strict";
13+
Object.defineProperty(exports, "__esModule", { value: true });
14+
//// [main.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/typeofImportTrailingCommas.ts] ////
2+
3+
=== input.ts ===
4+
export type X = 1;
5+
>X : Symbol(X, Decl(input.ts, 0, 0))
6+
7+
=== main.ts ===
8+
type T1 = typeof import('./input.js',)
9+
>T1 : Symbol(T1, Decl(main.ts, 0, 0))
10+
11+
type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },);
12+
>T2 : Symbol(T2, Decl(main.ts, 0, 38))
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/typeofImportTrailingCommas.ts] ////
2+
3+
=== input.ts ===
4+
export type X = 1;
5+
>X : 1
6+
> : ^
7+
8+
=== main.ts ===
9+
type T1 = typeof import('./input.js',)
10+
>T1 : typeof import("input")
11+
> : ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },);
14+
>T2 : typeof import("input")
15+
> : ^^^^^^^^^^^^^^^^^^^^^^
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @filename: input.ts
2+
export type X = 1;
3+
4+
// @filename: main.ts
5+
type T2 = typeof import('./input.js', ,);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @filename: input.ts
2+
export type X = 1;
3+
4+
// @filename: main.ts
5+
type T1 = typeof import('./input.js',)
6+
type T2 = typeof import('./input.js', { with: { "resolution-mode": "import" } },);

0 commit comments

Comments
 (0)