diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1b57e5def701..303e03c7d85b0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23439,17 +23439,20 @@ namespace ts { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { - const importClause = node.importClause; - if (importClause) { - if (importClause.name) { - checkImportBinding(importClause); - } - if (importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - checkImportBinding(importClause.namedBindings); - } - else { - forEach((importClause.namedBindings).elements, checkImportBinding); + const resolvedModule = resolveExternalModuleName(node, node.moduleSpecifier); + if (resolvedModule) { + const importClause = node.importClause; + if (importClause) { + if (importClause.name) { + checkImportBinding(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + checkImportBinding(importClause.namedBindings); + } + else { + forEach((importClause.namedBindings).elements, checkImportBinding); + } } } } diff --git a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt index 246ff5147b2a1..031ffcb3d6eb8 100644 --- a/tests/baselines/reference/ambientExportDefaultErrors.errors.txt +++ b/tests/baselines/reference/ambientExportDefaultErrors.errors.txt @@ -1,16 +1,22 @@ +tests/cases/compiler/consumer.ts(4,8): error TS2307: Cannot find module 'foo'. +tests/cases/compiler/consumer.ts(6,8): error TS2307: Cannot find module 'foo2'. tests/cases/compiler/foo.d.ts(1,16): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. tests/cases/compiler/foo2.d.ts(1,10): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. tests/cases/compiler/indirection.d.ts(3,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. tests/cases/compiler/indirection2.d.ts(3,14): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context. -==== tests/cases/compiler/consumer.ts (0 errors) ==== +==== tests/cases/compiler/consumer.ts (2 errors) ==== /// /// import "indirect"; import "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo'. import "indirect2"; import "foo2"; + ~~~~~~ +!!! error TS2307: Cannot find module 'foo2'. ==== tests/cases/compiler/foo.d.ts (1 errors) ==== export default 2 + 2; ~~~~~ diff --git a/tests/baselines/reference/amdDependencyCommentName4.errors.txt b/tests/baselines/reference/amdDependencyCommentName4.errors.txt index 8031a651d0a6d..af3330495e547 100644 --- a/tests/baselines/reference/amdDependencyCommentName4.errors.txt +++ b/tests/baselines/reference/amdDependencyCommentName4.errors.txt @@ -1,16 +1,20 @@ +tests/cases/compiler/amdDependencyCommentName4.ts(6,8): error TS2307: Cannot find module 'unaliasedModule1'. tests/cases/compiler/amdDependencyCommentName4.ts(8,21): error TS2307: Cannot find module 'aliasedModule1'. tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2'. tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3'. tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4'. +tests/cases/compiler/amdDependencyCommentName4.ts(20,8): error TS2307: Cannot find module 'unaliasedModule2'. -==== tests/cases/compiler/amdDependencyCommentName4.ts (4 errors) ==== +==== tests/cases/compiler/amdDependencyCommentName4.ts (6 errors) ==== /// /// /// /// import "unaliasedModule1"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'unaliasedModule1'. import r1 = require("aliasedModule1"); ~~~~~~~~~~~~~~~~ @@ -32,4 +36,6 @@ tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot f !!! error TS2307: Cannot find module 'aliasedModule4'. ns; - import "unaliasedModule2"; \ No newline at end of file + import "unaliasedModule2"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'unaliasedModule2'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index d0a96043465c0..9ccf29c8ea9e1 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -4,7 +4,7 @@ export var a = 10; //// [es6ImportWithoutFromClauseInEs5_1.ts] -import "es6ImportWithoutFromClauseInEs5_0"; +import "./es6ImportWithoutFromClauseInEs5_0"; //// [es6ImportWithoutFromClauseInEs5_0.js] "use strict"; @@ -13,10 +13,10 @@ exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -require("es6ImportWithoutFromClauseInEs5_0"); +require("./es6ImportWithoutFromClauseInEs5_0"); //// [es6ImportWithoutFromClauseInEs5_0.d.ts] export declare var a: number; //// [es6ImportWithoutFromClauseInEs5_1.d.ts] -import "es6ImportWithoutFromClauseInEs5_0"; +import "./es6ImportWithoutFromClauseInEs5_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.symbols b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.symbols index b1701aa72081c..6216b94e9bdfc 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.symbols +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.symbols @@ -3,5 +3,5 @@ export var a = 10; >a : Symbol(a, Decl(es6ImportWithoutFromClauseInEs5_0.ts, 0, 10)) === tests/cases/compiler/es6ImportWithoutFromClauseInEs5_1.ts === -import "es6ImportWithoutFromClauseInEs5_0"; +import "./es6ImportWithoutFromClauseInEs5_0"; No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types index 02eacf11b25f7..6a37e3a6cd766 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types @@ -4,5 +4,5 @@ export var a = 10; >10 : 10 === tests/cases/compiler/es6ImportWithoutFromClauseInEs5_1.ts === -import "es6ImportWithoutFromClauseInEs5_0"; +import "./es6ImportWithoutFromClauseInEs5_0"; No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt index cda3f545070bd..7348f90e32b5c 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -1,10 +1,13 @@ tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS2307: Cannot find module 'server'. ==== tests/cases/compiler/server.ts (0 errors) ==== export var a = 10; -==== tests/cases/compiler/client.ts (1 errors) ==== +==== tests/cases/compiler/client.ts (2 errors) ==== export import "server"; ~~~~~~ -!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~ +!!! error TS2307: Cannot find module 'server'. \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt new file mode 100644 index 0000000000000..cd355483099b8 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/index.tsx(1,8): error TS2307: Cannot find module './jsx'. + + +==== tests/cases/compiler/index.tsx (1 errors) ==== + import "./jsx"; + ~~~~~~~ +!!! error TS2307: Cannot find module './jsx'. + + var skate: any; + const React = { createElement: skate.h }; + + class Component { + renderCallback() { + return
test
; + } + }; \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt new file mode 100644 index 0000000000000..31b11e91c8386 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.errors.txt @@ -0,0 +1,16 @@ +/a.ts(1,8): error TS2307: Cannot find module 'normalize.css'. + + +==== /a.ts (1 errors) ==== + import "normalize.css"; + ~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'normalize.css'. + +==== /node_modules/normalize.css/normalize.css (0 errors) ==== + // This tests that a package.json "main" with an unexpected extension is ignored. + + This file is not read. + +==== /node_modules/normalize.css/package.json (0 errors) ==== + { "main": "normalize.css" } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt new file mode 100644 index 0000000000000..7d7d9a290838f --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.errors.txt @@ -0,0 +1,16 @@ +/a.ts(1,8): error TS2307: Cannot find module 'foo'. + + +==== /a.ts (1 errors) ==== + import "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo'. + +==== /node_modules/foo/foo.js (0 errors) ==== + // This tests that a package.json "types" with an unexpected extension is ignored. + + This file is not read. + +==== /node_modules/foo/package.json (0 errors) ==== + { "types": "foo.js" } + \ No newline at end of file diff --git a/tests/baselines/reference/systemModule9.errors.txt b/tests/baselines/reference/systemModule9.errors.txt index bedcc561058f2..13ac6d55d38f1 100644 --- a/tests/baselines/reference/systemModule9.errors.txt +++ b/tests/baselines/reference/systemModule9.errors.txt @@ -1,12 +1,13 @@ tests/cases/compiler/systemModule9.ts(1,21): error TS2307: Cannot find module 'file1'. tests/cases/compiler/systemModule9.ts(2,25): error TS2307: Cannot find module 'file2'. tests/cases/compiler/systemModule9.ts(3,15): error TS2307: Cannot find module 'file3'. +tests/cases/compiler/systemModule9.ts(4,8): error TS2307: Cannot find module 'file4'. tests/cases/compiler/systemModule9.ts(5,25): error TS2307: Cannot find module 'file5'. tests/cases/compiler/systemModule9.ts(6,22): error TS2307: Cannot find module 'file6'. tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find module 'file7'. -==== tests/cases/compiler/systemModule9.ts (6 errors) ==== +==== tests/cases/compiler/systemModule9.ts (7 errors) ==== import * as ns from 'file1'; ~~~~~~~ !!! error TS2307: Cannot find module 'file1'. @@ -17,6 +18,8 @@ tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find module ' ~~~~~~~ !!! error TS2307: Cannot find module 'file3'. import 'file4' + ~~~~~~~ +!!! error TS2307: Cannot find module 'file4'. import e, * as ns2 from 'file5'; ~~~~~~~ !!! error TS2307: Cannot find module 'file5'. diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts index 08c21c236443a..55fe9430a0576 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts @@ -6,4 +6,4 @@ export var a = 10; // @filename: es6ImportWithoutFromClauseInEs5_1.ts -import "es6ImportWithoutFromClauseInEs5_0"; \ No newline at end of file +import "./es6ImportWithoutFromClauseInEs5_0"; \ No newline at end of file