mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 12:57:11 -06:00
[Release-2.0] Fix 9829 : do not report error using import, export, module augmentation in d.t.s (#9894)
* Only error in non-declaration file * Add tests and baselines * Addess PR: get the first non-ambient external module file * Rename test file and update baseline * Add tests and baselines * Update baselines
This commit is contained in:
parent
da212960b1
commit
bd6d2c0251
@ -2263,7 +2263,7 @@ namespace ts {
|
||||
const languageVersion = options.target || ScriptTarget.ES3;
|
||||
const outFile = options.outFile || options.out;
|
||||
|
||||
const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
|
||||
const firstNonAmbientExternalModuleSourceFile = forEach(files, f => isExternalModule(f) && !isDeclarationFile(f) ? f : undefined);
|
||||
if (options.isolatedModules) {
|
||||
if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES6) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
|
||||
@ -2275,10 +2275,10 @@ namespace ts {
|
||||
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
|
||||
}
|
||||
}
|
||||
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) {
|
||||
else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) {
|
||||
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
|
||||
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
|
||||
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
|
||||
const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
|
||||
programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
|
||||
}
|
||||
|
||||
// Cannot specify module gen that isn't amd or system with --out
|
||||
@ -2286,9 +2286,9 @@ namespace ts {
|
||||
if (options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile"));
|
||||
}
|
||||
else if (options.module === undefined && firstExternalModuleSourceFile) {
|
||||
const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
|
||||
programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile"));
|
||||
else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) {
|
||||
const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
|
||||
programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/0.d.ts ===
|
||||
|
||||
export = a;
|
||||
>a : Symbol(a, Decl(0.d.ts, 2, 11))
|
||||
|
||||
declare var a: number;
|
||||
>a : Symbol(a, Decl(0.d.ts, 2, 11))
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/0.d.ts ===
|
||||
|
||||
export = a;
|
||||
>a : number
|
||||
|
||||
declare var a: number;
|
||||
>a : number
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
tests/cases/compiler/1.ts(2,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/1.ts (1 errors) ====
|
||||
|
||||
export var j = "hello"; // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
|
||||
|
||||
==== tests/cases/compiler/0.d.ts (0 errors) ====
|
||||
export = a;
|
||||
declare var a: number;
|
||||
@ -0,0 +1,13 @@
|
||||
//// [tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.ts] ////
|
||||
|
||||
//// [1.ts]
|
||||
|
||||
export var j = "hello"; // error
|
||||
|
||||
//// [0.d.ts]
|
||||
export = a;
|
||||
declare var a: number;
|
||||
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
exports.j = "hello"; // error
|
||||
@ -0,0 +1,13 @@
|
||||
tests/cases/compiler/1.ts(1,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/0.d.ts (0 errors) ====
|
||||
|
||||
export = a;
|
||||
declare var a: number;
|
||||
|
||||
==== tests/cases/compiler/1.ts (1 errors) ====
|
||||
export var j = "hello"; // error
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
//// [tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.ts] ////
|
||||
|
||||
//// [0.d.ts]
|
||||
|
||||
export = a;
|
||||
declare var a: number;
|
||||
|
||||
//// [1.ts]
|
||||
export var j = "hello"; // error
|
||||
|
||||
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
exports.j = "hello"; // error
|
||||
@ -0,0 +1,5 @@
|
||||
// @module: none
|
||||
// @filename: 0.d.ts
|
||||
|
||||
export = a;
|
||||
declare var a: number;
|
||||
@ -0,0 +1,8 @@
|
||||
// @module: none
|
||||
|
||||
// @filename: 1.ts
|
||||
export var j = "hello"; // error
|
||||
|
||||
// @filename: 0.d.ts
|
||||
export = a;
|
||||
declare var a: number;
|
||||
@ -0,0 +1,8 @@
|
||||
// @module: none
|
||||
|
||||
// @filename: 0.d.ts
|
||||
export = a;
|
||||
declare var a: number;
|
||||
|
||||
// @filename: 1.ts
|
||||
export var j = "hello"; // error
|
||||
Loading…
x
Reference in New Issue
Block a user