diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 702c8850afe..4680ae60a03 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47029,6 +47029,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { grammarErrorOnFirstToken(node, Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations); break; case SyntaxKind.ImportEqualsDeclaration: + // import a = e.x; in module augmentation is ok, but not import a = require('fs) + if (isInternalModuleImportEqualsDeclaration(node)) break; + // falls through case SyntaxKind.ImportDeclaration: grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module); break; diff --git a/tests/baselines/reference/importAliasInModuleAugmentation.errors.txt b/tests/baselines/reference/importAliasInModuleAugmentation.errors.txt new file mode 100644 index 00000000000..d8b96f63170 --- /dev/null +++ b/tests/baselines/reference/importAliasInModuleAugmentation.errors.txt @@ -0,0 +1,26 @@ +importAliasInModuleAugmentation.ts(12,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. +importAliasInModuleAugmentation.ts(12,24): error TS2307: Cannot find module 'fs' or its corresponding type declarations. + + +==== importAliasInModuleAugmentation.ts (2 errors) ==== + export { } + + namespace A { + export const y = 34; + export interface y { s: string } + } + + declare global { + export import x = A.y; + + // Should still error + import f = require("fs"); + ~~~~~~ +!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. + ~~~~ +!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations. + } + + const m: number = x; + let s: x = { s: "" }; + void s.s; \ No newline at end of file diff --git a/tests/baselines/reference/importAliasInModuleAugmentation.js b/tests/baselines/reference/importAliasInModuleAugmentation.js new file mode 100644 index 00000000000..f6616d7af9c --- /dev/null +++ b/tests/baselines/reference/importAliasInModuleAugmentation.js @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/importAliasInModuleAugmentation.ts] //// + +//// [importAliasInModuleAugmentation.ts] +export { } + +namespace A { + export const y = 34; + export interface y { s: string } +} + +declare global { + export import x = A.y; + + // Should still error + import f = require("fs"); +} + +const m: number = x; +let s: x = { s: "" }; +void s.s; + +//// [importAliasInModuleAugmentation.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var A; +(function (A) { + A.y = 34; +})(A || (A = {})); +var m = x; +var s = { s: "" }; +void s.s; diff --git a/tests/baselines/reference/importAliasInModuleAugmentation.symbols b/tests/baselines/reference/importAliasInModuleAugmentation.symbols new file mode 100644 index 00000000000..ff1228d4bd6 --- /dev/null +++ b/tests/baselines/reference/importAliasInModuleAugmentation.symbols @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/importAliasInModuleAugmentation.ts] //// + +=== importAliasInModuleAugmentation.ts === +export { } + +namespace A { +>A : Symbol(A, Decl(importAliasInModuleAugmentation.ts, 0, 10)) + + export const y = 34; +>y : Symbol(y, Decl(importAliasInModuleAugmentation.ts, 3, 16), Decl(importAliasInModuleAugmentation.ts, 3, 24)) + + export interface y { s: string } +>y : Symbol(y, Decl(importAliasInModuleAugmentation.ts, 3, 16), Decl(importAliasInModuleAugmentation.ts, 3, 24)) +>s : Symbol(y.s, Decl(importAliasInModuleAugmentation.ts, 4, 24)) +} + +declare global { +>global : Symbol(global, Decl(importAliasInModuleAugmentation.ts, 5, 1)) + + export import x = A.y; +>x : Symbol(x, Decl(importAliasInModuleAugmentation.ts, 7, 16)) +>A : Symbol(A, Decl(importAliasInModuleAugmentation.ts, 0, 10)) +>y : Symbol(x, Decl(importAliasInModuleAugmentation.ts, 3, 16), Decl(importAliasInModuleAugmentation.ts, 3, 24)) + + // Should still error + import f = require("fs"); +>f : Symbol(f, Decl(importAliasInModuleAugmentation.ts, 8, 26)) +} + +const m: number = x; +>m : Symbol(m, Decl(importAliasInModuleAugmentation.ts, 14, 5)) +>x : Symbol(x, Decl(importAliasInModuleAugmentation.ts, 7, 16)) + +let s: x = { s: "" }; +>s : Symbol(s, Decl(importAliasInModuleAugmentation.ts, 15, 3)) +>x : Symbol(x, Decl(importAliasInModuleAugmentation.ts, 7, 16)) +>s : Symbol(s, Decl(importAliasInModuleAugmentation.ts, 15, 12)) + +void s.s; +>s.s : Symbol(x.s, Decl(importAliasInModuleAugmentation.ts, 4, 24)) +>s : Symbol(s, Decl(importAliasInModuleAugmentation.ts, 15, 3)) +>s : Symbol(x.s, Decl(importAliasInModuleAugmentation.ts, 4, 24)) + diff --git a/tests/baselines/reference/importAliasInModuleAugmentation.types b/tests/baselines/reference/importAliasInModuleAugmentation.types new file mode 100644 index 00000000000..5733d12e0d4 --- /dev/null +++ b/tests/baselines/reference/importAliasInModuleAugmentation.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/importAliasInModuleAugmentation.ts] //// + +=== importAliasInModuleAugmentation.ts === +export { } + +namespace A { +>A : typeof A + + export const y = 34; +>y : 34 +>34 : 34 + + export interface y { s: string } +>s : string +} + +declare global { +>global : typeof global + + export import x = A.y; +>x : 34 +>A : typeof A +>y : x + + // Should still error + import f = require("fs"); +>f : any +} + +const m: number = x; +>m : number +>x : 34 + +let s: x = { s: "" }; +>s : x +>{ s: "" } : { s: string; } +>s : string +>"" : "" + +void s.s; +>void s.s : undefined +>s.s : string +>s : x +>s : string + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt index 9f94f43b614..f472daec04d 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt @@ -3,8 +3,6 @@ f3.ts(11,5): error TS2667: Imports are not permitted in module augmentations. Co f3.ts(11,21): error TS2307: Cannot find module './f2' or its corresponding type declarations. f3.ts(12,5): error TS2666: Exports and export assignments are not permitted in module augmentations. f3.ts(12,21): error TS2307: Cannot find module './f2' or its corresponding type declarations. -f3.ts(13,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. -f3.ts(14,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. f4.ts(5,11): error TS2339: Property 'foo' does not exist on type 'A'. @@ -16,7 +14,7 @@ f4.ts(5,11): error TS2339: Property 'foo' does not exist on type 'A'. n: number; } -==== f3.ts (7 errors) ==== +==== f3.ts (5 errors) ==== import {A} from "./f1"; A.prototype.foo = function () { return undefined; } @@ -40,11 +38,7 @@ f4.ts(5,11): error TS2339: Property 'foo' does not exist on type 'A'. ~~~~~~ !!! error TS2307: Cannot find module './f2' or its corresponding type declarations. import I = N.Ifc; - ~~~~~~ -!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. import C = N.Cls; - ~~~~~~ -!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. // should have explicit export interface A { foo(): B; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt index ecd0eb189d4..f66ce9db2bf 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt @@ -1,7 +1,5 @@ f3.ts(11,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. f3.ts(11,21): error TS2307: Cannot find module './f2' or its corresponding type declarations. -f3.ts(12,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. -f3.ts(13,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. ==== f1.ts (0 errors) ==== @@ -12,7 +10,7 @@ f3.ts(13,5): error TS2667: Imports are not permitted in module augmentations. Co n: number; } -==== f3.ts (4 errors) ==== +==== f3.ts (2 errors) ==== import {A} from "./f1"; A.prototype.foo = function () { return undefined; } @@ -29,11 +27,7 @@ f3.ts(13,5): error TS2667: Imports are not permitted in module augmentations. Co ~~~~~~ !!! error TS2307: Cannot find module './f2' or its corresponding type declarations. import I = N.Ifc; - ~~~~~~ -!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. import C = N.Cls; - ~~~~~~ -!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. interface A { foo(): B; bar(): I; diff --git a/tests/baselines/reference/newNamesInGlobalAugmentations1.errors.txt b/tests/baselines/reference/newNamesInGlobalAugmentations1.errors.txt deleted file mode 100644 index 01daf853a5d..00000000000 --- a/tests/baselines/reference/newNamesInGlobalAugmentations1.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -f1.d.ts(12,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. - - -==== f1.d.ts (1 errors) ==== - export {}; - - declare module M.M1 { - export let x: number; - } - declare global { - interface SymbolConstructor { - observable: symbol; - } - class Cls {x} - let [a, b]: number[]; - export import X = M.M1.x; - ~~~~~~ -!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. - } - -==== main.ts (0 errors) ==== - Symbol.observable; - new Cls().x - let c = a + b + X; \ No newline at end of file diff --git a/tests/cases/compiler/importAliasInModuleAugmentation.ts b/tests/cases/compiler/importAliasInModuleAugmentation.ts new file mode 100644 index 00000000000..99ec85396ea --- /dev/null +++ b/tests/cases/compiler/importAliasInModuleAugmentation.ts @@ -0,0 +1,17 @@ +export { } + +namespace A { + export const y = 34; + export interface y { s: string } +} + +declare global { + export import x = A.y; + + // Should still error + import f = require("fs"); +} + +const m: number = x; +let s: x = { s: "" }; +void s.s; \ No newline at end of file