Skip to content

Commit d782a54

Browse files
Merge pull request #29556 from fuafa/trailing-comma
fix trailing comma should not allowed in dynamic import argument
2 parents 387201c + d7601b7 commit d782a54

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31178,7 +31178,7 @@ namespace ts {
3117831178
if (nodeArguments.length !== 1) {
3117931179
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
3118031180
}
31181-
31181+
checkGrammarForDisallowedTrailingComma(nodeArguments);
3118231182
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
3118331183
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
3118431184
if (isSpreadElement(nodeArguments[0])) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/dynamicImportTrailingComma.ts(2,12): error TS1009: Trailing comma not allowed.
2+
3+
4+
==== tests/cases/compiler/dynamicImportTrailingComma.ts (1 errors) ====
5+
const path = './foo';
6+
import(path,);
7+
~
8+
!!! error TS1009: Trailing comma not allowed.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [dynamicImportTrailingComma.ts]
2+
const path = './foo';
3+
import(path,);
4+
5+
//// [dynamicImportTrailingComma.js]
6+
var path = './foo';
7+
Promise.resolve().then(function () { return require(path); });
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/dynamicImportTrailingComma.ts ===
2+
const path = './foo';
3+
>path : Symbol(path, Decl(dynamicImportTrailingComma.ts, 0, 5))
4+
5+
import(path,);
6+
>path : Symbol(path, Decl(dynamicImportTrailingComma.ts, 0, 5))
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/dynamicImportTrailingComma.ts ===
2+
const path = './foo';
3+
>path : "./foo"
4+
>'./foo' : "./foo"
5+
6+
import(path,);
7+
>import(path,) : Promise<any>
8+
>path : "./foo"
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @skipLibCheck: true
2+
// @lib: es6
3+
const path = './foo';
4+
import(path,);

0 commit comments

Comments
 (0)