diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 173ffcb8fee..de3d8fde307 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14289,8 +14289,9 @@ namespace ts { } } break; + case SyntaxKind.ExportAssignment: case SyntaxKind.ExportDeclaration: - grammarErrorOnFirstToken(node, Diagnostics.Exports_are_not_permitted_in_module_augmentations); + grammarErrorOnFirstToken(node, Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations); break; case SyntaxKind.ImportEqualsDeclaration: if ((node).moduleReference.kind !== SyntaxKind.StringLiteral) { @@ -14564,7 +14565,9 @@ namespace ts { const exportEqualsSymbol = moduleSymbol.exports["export="]; if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) { const declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration; - error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + if (!isTopLevelInExternalModuleAugmentation(declaration)) { + error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } } // Checks for export * conflicts const exports = getExportsOfModule(moduleSymbol); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fff6f75d20d..2ffaccec7f0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1783,7 +1783,7 @@ "category": "Error", "code": 2663 }, - "Exports are not permitted in module augmentations.": { + "Exports and export assignments are not permitted in module augmentations.": { "category": "Error", "code": 2664 }, diff --git a/tests/baselines/reference/globalIsContextualKeyword.js b/tests/baselines/reference/globalIsContextualKeyword.js new file mode 100644 index 00000000000..b6fa566c91a --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.js @@ -0,0 +1,34 @@ +//// [globalIsContextualKeyword.ts] +function a() { + let global = 1; +} +function b() { + class global {} +} + +namespace global { +} + +function foo(global: number) { +} + +let obj = { + global: "123" +} + +//// [globalIsContextualKeyword.js] +function a() { + var global = 1; +} +function b() { + var global = (function () { + function global() { + } + return global; + }()); +} +function foo(global) { +} +var obj = { + global: "123" +}; diff --git a/tests/baselines/reference/globalIsContextualKeyword.symbols b/tests/baselines/reference/globalIsContextualKeyword.symbols new file mode 100644 index 00000000000..edc1cebbc95 --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/globalIsContextualKeyword.ts === +function a() { +>a : Symbol(a, Decl(globalIsContextualKeyword.ts, 0, 0)) + + let global = 1; +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 1, 7)) +} +function b() { +>b : Symbol(b, Decl(globalIsContextualKeyword.ts, 2, 1)) + + class global {} +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 3, 14)) +} + +namespace global { +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 5, 1)) +} + +function foo(global: number) { +>foo : Symbol(foo, Decl(globalIsContextualKeyword.ts, 8, 1)) +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 10, 13)) +} + +let obj = { +>obj : Symbol(obj, Decl(globalIsContextualKeyword.ts, 13, 3)) + + global: "123" +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 13, 11)) +} diff --git a/tests/baselines/reference/globalIsContextualKeyword.types b/tests/baselines/reference/globalIsContextualKeyword.types new file mode 100644 index 00000000000..d0bf624af6d --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/globalIsContextualKeyword.ts === +function a() { +>a : () => void + + let global = 1; +>global : number +>1 : number +} +function b() { +>b : () => void + + class global {} +>global : global +} + +namespace global { +>global : any +} + +function foo(global: number) { +>foo : (global: number) => void +>global : number +} + +let obj = { +>obj : { global: string; } +>{ global: "123"} : { global: string; } + + global: "123" +>global : string +>"123" : string +} diff --git a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt index b4ca1bfa667..f90b07dd815 100644 --- a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt +++ b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt @@ -12,17 +12,18 @@ tests/cases/compiler/x.ts(18,5): error TS2665: Imports are not permitted in modu tests/cases/compiler/x.ts(18,26): error TS2307: Cannot find module './x0'. tests/cases/compiler/x.ts(19,5): error TS2665: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. tests/cases/compiler/x.ts(19,21): error TS2307: Cannot find module './x0'. -tests/cases/compiler/x.ts(20,5): error TS2664: Exports are not permitted in module augmentations. +tests/cases/compiler/x.ts(20,5): error TS2664: Exports and export assignments are not permitted in module augmentations. tests/cases/compiler/x.ts(20,19): error TS2307: Cannot find module './x0'. -tests/cases/compiler/x.ts(21,5): error TS2664: Exports are not permitted in module augmentations. +tests/cases/compiler/x.ts(21,5): error TS2664: Exports and export assignments are not permitted in module augmentations. tests/cases/compiler/x.ts(21,21): error TS2307: Cannot find module './x0'. +tests/cases/compiler/x.ts(25,5): error TS2664: Exports and export assignments are not permitted in module augmentations. ==== tests/cases/compiler/x0.ts (0 errors) ==== export let a = 1; -==== tests/cases/compiler/x.ts (18 errors) ==== +==== tests/cases/compiler/x.ts (19 errors) ==== namespace N1 { export let x = 1; @@ -72,15 +73,21 @@ tests/cases/compiler/x.ts(21,21): error TS2307: Cannot find module './x0'. !!! error TS2307: Cannot find module './x0'. export * from "./x0"; ~~~~~~ -!!! error TS2664: Exports are not permitted in module augmentations. +!!! error TS2664: Exports and export assignments are not permitted in module augmentations. ~~~~~~ !!! error TS2307: Cannot find module './x0'. export {a} from "./x0"; ~~~~~~ -!!! error TS2664: Exports are not permitted in module augmentations. +!!! error TS2664: Exports and export assignments are not permitted in module augmentations. ~~~~~~ !!! error TS2307: Cannot find module './x0'. } + + declare module "./test" { + export = N1; + ~~~~~~ +!!! error TS2664: Exports and export assignments are not permitted in module augmentations. + } export {} ==== tests/cases/compiler/observable.ts (0 errors) ==== @@ -89,6 +96,9 @@ tests/cases/compiler/x.ts(21,21): error TS2307: Cannot find module './x0'. } export var x = 1; +==== tests/cases/compiler/test.ts (0 errors) ==== + export let b = 1; + ==== tests/cases/compiler/main.ts (0 errors) ==== import { Observable } from "./observable" import "./x"; diff --git a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js index f5378b7c5bd..62b14d71277 100644 --- a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js +++ b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js @@ -27,6 +27,10 @@ declare module "./observable" { export * from "./x0"; export {a} from "./x0"; } + +declare module "./test" { + export = N1; +} export {} //// [observable.ts] @@ -35,6 +39,9 @@ export declare class Observable { } export var x = 1; +//// [test.ts] +export let b = 1; + //// [main.ts] import { Observable } from "./observable" import "./x"; @@ -52,6 +59,9 @@ var N1; //// [observable.js] "use strict"; exports.x = 1; +//// [test.js] +"use strict"; +exports.b = 1; //// [main.js] "use strict"; require("./x"); diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt index 360c89080a9..95bd0a714e0 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/f3.ts(11,5): error TS2665: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. tests/cases/compiler/f3.ts(11,21): error TS2307: Cannot find module './f2'. -tests/cases/compiler/f3.ts(12,5): error TS2664: Exports are not permitted in module augmentations. +tests/cases/compiler/f3.ts(12,5): error TS2664: Exports and export assignments are not permitted in module augmentations. tests/cases/compiler/f3.ts(12,21): error TS2307: Cannot find module './f2'. tests/cases/compiler/f3.ts(13,12): error TS2663: Module augmentation cannot introduce new names in the top level scope. tests/cases/compiler/f3.ts(13,16): error TS4000: Import declaration 'I' is using private name 'N'. @@ -37,7 +37,7 @@ tests/cases/compiler/f4.ts(5,11): error TS2339: Property 'foo' does not exist on !!! error TS2307: Cannot find module './f2'. export {B} from "./f2"; ~~~~~~ -!!! error TS2664: Exports are not permitted in module augmentations. +!!! error TS2664: Exports and export assignments are not permitted in module augmentations. ~~~~~~ !!! error TS2307: Cannot find module './f2'. import I = N.Ifc; diff --git a/tests/cases/compiler/globalIsContextualKeyword.ts b/tests/cases/compiler/globalIsContextualKeyword.ts new file mode 100644 index 00000000000..ceae834a267 --- /dev/null +++ b/tests/cases/compiler/globalIsContextualKeyword.ts @@ -0,0 +1,16 @@ +function a() { + let global = 1; +} +function b() { + class global {} +} + +namespace global { +} + +function foo(global: number) { +} + +let obj = { + global: "123" +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts b/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts index 28e46c71b33..116c5cb7820 100644 --- a/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts +++ b/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts @@ -26,6 +26,10 @@ declare module "./observable" { export * from "./x0"; export {a} from "./x0"; } + +declare module "./test" { + export = N1; +} export {} // @filename: observable.ts @@ -34,6 +38,9 @@ export declare class Observable { } export var x = 1; +// @filename: test.ts +export let b = 1; + // @filename: main.ts import { Observable } from "./observable" import "./x";