fix trailing comma should not allowed in dynamic import argument

This commit is contained in:
xiaofa 2019-01-24 18:16:34 +08:00
parent 2f6c65e691
commit d7601b755f
6 changed files with 36 additions and 1 deletions

View file

@ -31178,7 +31178,7 @@ namespace ts {
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (isSpreadElement(nodeArguments[0])) {

View file

@ -0,0 +1,8 @@
tests/cases/compiler/dynamicImportTrailingComma.ts(2,12): error TS1009: Trailing comma not allowed.
==== tests/cases/compiler/dynamicImportTrailingComma.ts (1 errors) ====
const path = './foo';
import(path,);
~
!!! error TS1009: Trailing comma not allowed.

View file

@ -0,0 +1,7 @@
//// [dynamicImportTrailingComma.ts]
const path = './foo';
import(path,);
//// [dynamicImportTrailingComma.js]
var path = './foo';
Promise.resolve().then(function () { return require(path); });

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/dynamicImportTrailingComma.ts ===
const path = './foo';
>path : Symbol(path, Decl(dynamicImportTrailingComma.ts, 0, 5))
import(path,);
>path : Symbol(path, Decl(dynamicImportTrailingComma.ts, 0, 5))

View file

@ -0,0 +1,9 @@
=== tests/cases/compiler/dynamicImportTrailingComma.ts ===
const path = './foo';
>path : "./foo"
>'./foo' : "./foo"
import(path,);
>import(path,) : Promise<any>
>path : "./foo"

View file

@ -0,0 +1,4 @@
// @skipLibCheck: true
// @lib: es6
const path = './foo';
import(path,);