From fb99a6697d10d3b6143fef06ec33278a94ecbcb6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 2 Feb 2016 11:36:38 -0800 Subject: [PATCH] do not error if typings for external library is empty .d.ts file --- src/compiler/program.ts | 2 +- tests/baselines/reference/noErrorOnEmptyDts.js | 13 +++++++++++++ tests/baselines/reference/noErrorOnEmptyDts.symbols | 8 ++++++++ tests/baselines/reference/noErrorOnEmptyDts.types | 8 ++++++++ tests/cases/compiler/noErrorOnEmptyDts.ts | 8 ++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/noErrorOnEmptyDts.js create mode 100644 tests/baselines/reference/noErrorOnEmptyDts.symbols create mode 100644 tests/baselines/reference/noErrorOnEmptyDts.types create mode 100644 tests/cases/compiler/noErrorOnEmptyDts.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index fd3d44ff3f..9852b2354e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1490,7 +1490,7 @@ namespace ts { if (importedFile && resolution.isExternalLibraryImport) { // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, // this check is ok. Otherwise this would be never true for javascript file - if (!isExternalModule(importedFile)) { + if (!isExternalModule(importedFile) && importedFile.statements.length) { const start = getTokenPosOfNode(file.imports[i], file); fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); } diff --git a/tests/baselines/reference/noErrorOnEmptyDts.js b/tests/baselines/reference/noErrorOnEmptyDts.js new file mode 100644 index 0000000000..83595e3d2a --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/noErrorOnEmptyDts.ts] //// + +//// [test.d.ts] + + +// comment + +//// [main.ts] +import "test" + +//// [main.js] +"use strict"; +require("test"); diff --git a/tests/baselines/reference/noErrorOnEmptyDts.symbols b/tests/baselines/reference/noErrorOnEmptyDts.symbols new file mode 100644 index 0000000000..78446a19fb --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.symbols @@ -0,0 +1,8 @@ +=== c:/node_modules/test.d.ts === + +No type information for this code. +No type information for this code.// comment +No type information for this code. +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/noErrorOnEmptyDts.types b/tests/baselines/reference/noErrorOnEmptyDts.types new file mode 100644 index 0000000000..78446a19fb --- /dev/null +++ b/tests/baselines/reference/noErrorOnEmptyDts.types @@ -0,0 +1,8 @@ +=== c:/node_modules/test.d.ts === + +No type information for this code. +No type information for this code.// comment +No type information for this code. +No type information for this code.=== c:/app/main.ts === +import "test" +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/noErrorOnEmptyDts.ts b/tests/cases/compiler/noErrorOnEmptyDts.ts new file mode 100644 index 0000000000..1266ea2bd7 --- /dev/null +++ b/tests/cases/compiler/noErrorOnEmptyDts.ts @@ -0,0 +1,8 @@ +// @module: commonjs + +// @filename: c:/node_modules/test.d.ts + +// comment + +// @filename: c:/app/main.ts +import "test" \ No newline at end of file