Address PR: don't early exit when there are grammar errors

This commit is contained in:
Yui T 2017-06-01 22:33:39 -07:00
parent faab927c8d
commit a02edb1cd0
4 changed files with 31 additions and 18 deletions

View file

@ -16099,15 +16099,22 @@ namespace ts {
function checkImportCallExpression(node: ImportCall): Type {
// Check grammar of dynamic import
if (checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node)) {
checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node);
if (node.arguments.length === 0) {
return createPromiseReturnType(node, anyType);
}
const specifier = node.arguments[0];
const specifierType = checkNonNullExpression(specifier);
if (!isTypeAssignableTo(specifierType, stringType)) {
const specifierType = checkExpressionCached(specifier);
// Even though multiple arugments is grammatically incorrect, type-check extra arguments for completion
for (let i = 1; i < node.arguments.length; ++i) {
checkExpressionCached(node.arguments[i]);
}
if (specifierType.flags & TypeFlags.Undefined || specifierType.flags & TypeFlags.Null || !isTypeAssignableTo(specifierType, stringType)) {
error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType));
}
// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
const moduleSymbol = resolveExternalModuleName(node, specifier);
if (moduleSymbol) {

View file

@ -1,7 +1,7 @@
tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS2532: Object is possibly 'undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS2531: Object is possibly 'null'.
tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'.
tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'.
tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.
==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ====
@ -19,13 +19,13 @@ tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is
const specify = bar() ? "./0" : undefined;
let myModule = import(specify);
~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'.
let myModule1 = import(undefined);
~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
let myModule2 = import(bar() ? "./1" : null);
~~~~~~~~~~~~~~~~~~~~
!!! error TS2531: Object is possibly 'null'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'.
let myModule3 = import(null);
~~~~
!!! error TS2531: Object is possibly 'null'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.

View file

@ -1,5 +1,5 @@
tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'.
tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.
==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ====
@ -18,8 +18,8 @@ tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is
let myModule = import(specify);
let myModule1 = import(undefined);
~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
~~~~
!!! error TS2531: Object is possibly 'null'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.

View file

@ -2,10 +2,12 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element.
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument.
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected.
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument.
tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'.
==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ====
==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ====
declare function getSpecifier(): string;
declare var whatToLoad: boolean;
@ -23,6 +25,10 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts
const p3 = import(,);
!!! error TS1135: Argument expression expected.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
const p4 = import("pathToModule", "secondModule");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1324: Dynamic import must have one specifier as an argument.
!!! error TS1324: Dynamic import must have one specifier as an argument.
~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'pathToModule'.