mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
allow top level 'import x = identifier | qname' in module augmentations
This commit is contained in:
@@ -355,7 +355,7 @@ namespace ts {
|
||||
function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
|
||||
const hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export;
|
||||
if (symbolFlags & SymbolFlags.Alias) {
|
||||
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) {
|
||||
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && (hasExportModifier || container.flags & NodeFlags.ExportContext))) {
|
||||
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -15572,7 +15572,9 @@ namespace ts {
|
||||
break;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
if ((<ImportEqualsDeclaration>node).moduleReference.kind !== SyntaxKind.StringLiteral) {
|
||||
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
|
||||
if (!isGlobalAugmentation) {
|
||||
error((<ImportEqualsDeclaration>node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
|
||||
@@ -4,19 +4,25 @@
|
||||
|
||||
export {};
|
||||
|
||||
declare module M.M1 {
|
||||
export let x: number;
|
||||
}
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
observable: symbol;
|
||||
}
|
||||
class Cls {x}
|
||||
let [a, b]: number[];
|
||||
import X = M.M1.x;
|
||||
}
|
||||
|
||||
//// [main.ts]
|
||||
|
||||
Symbol.observable;
|
||||
new Cls().x
|
||||
new Cls().x
|
||||
let c = a + b + X;
|
||||
|
||||
//// [main.js]
|
||||
Symbol.observable;
|
||||
new Cls().x;
|
||||
let c = a + b + X;
|
||||
|
||||
@@ -2,33 +2,52 @@
|
||||
|
||||
export {};
|
||||
|
||||
declare module M.M1 {
|
||||
>M : Symbol(M, Decl(f1.d.ts, 1, 10))
|
||||
>M1 : Symbol(M1, Decl(f1.d.ts, 3, 17))
|
||||
|
||||
export let x: number;
|
||||
>x : Symbol(x, Decl(f1.d.ts, 4, 14))
|
||||
}
|
||||
declare global {
|
||||
>global : Symbol(, Decl(f1.d.ts, 1, 10))
|
||||
>global : Symbol(, Decl(f1.d.ts, 5, 1))
|
||||
|
||||
interface SymbolConstructor {
|
||||
>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(f1.d.ts, 3, 16))
|
||||
>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(f1.d.ts, 6, 16))
|
||||
|
||||
observable: symbol;
|
||||
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
|
||||
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
|
||||
}
|
||||
class Cls {x}
|
||||
>Cls : Symbol(Cls, Decl(f1.d.ts, 6, 5))
|
||||
>x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
|
||||
>Cls : Symbol(Cls, Decl(f1.d.ts, 9, 5))
|
||||
>x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
|
||||
|
||||
let [a, b]: number[];
|
||||
>a : Symbol(a, Decl(f1.d.ts, 8, 9))
|
||||
>b : Symbol(b, Decl(f1.d.ts, 8, 11))
|
||||
>a : Symbol(a, Decl(f1.d.ts, 11, 9))
|
||||
>b : Symbol(b, Decl(f1.d.ts, 11, 11))
|
||||
|
||||
import X = M.M1.x;
|
||||
>X : Symbol(X, Decl(f1.d.ts, 11, 25))
|
||||
>M : Symbol(M, Decl(f1.d.ts, 1, 10))
|
||||
>M1 : Symbol(M.M1, Decl(f1.d.ts, 3, 17))
|
||||
>x : Symbol(X, Decl(f1.d.ts, 4, 14))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/main.ts ===
|
||||
|
||||
Symbol.observable;
|
||||
>Symbol.observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
|
||||
>Symbol.observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
|
||||
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
|
||||
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 4, 33))
|
||||
>observable : Symbol(SymbolConstructor.observable, Decl(f1.d.ts, 7, 33))
|
||||
|
||||
new Cls().x
|
||||
>new Cls().x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
|
||||
>Cls : Symbol(Cls, Decl(f1.d.ts, 6, 5))
|
||||
>x : Symbol(Cls.x, Decl(f1.d.ts, 7, 15))
|
||||
>new Cls().x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
|
||||
>Cls : Symbol(Cls, Decl(f1.d.ts, 9, 5))
|
||||
>x : Symbol(Cls.x, Decl(f1.d.ts, 10, 15))
|
||||
|
||||
let c = a + b + X;
|
||||
>c : Symbol(c, Decl(main.ts, 3, 3))
|
||||
>a : Symbol(a, Decl(f1.d.ts, 11, 9))
|
||||
>b : Symbol(b, Decl(f1.d.ts, 11, 11))
|
||||
>X : Symbol(X, Decl(f1.d.ts, 11, 25))
|
||||
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
export {};
|
||||
|
||||
declare module M.M1 {
|
||||
>M : typeof M
|
||||
>M1 : typeof M1
|
||||
|
||||
export let x: number;
|
||||
>x : number
|
||||
}
|
||||
declare global {
|
||||
>global : any
|
||||
|
||||
@@ -18,6 +25,12 @@ declare global {
|
||||
let [a, b]: number[];
|
||||
>a : number
|
||||
>b : number
|
||||
|
||||
import X = M.M1.x;
|
||||
>X : number
|
||||
>M : typeof M
|
||||
>M1 : typeof M.M1
|
||||
>x : number
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/main.ts ===
|
||||
@@ -33,3 +46,11 @@ new Cls().x
|
||||
>Cls : typeof Cls
|
||||
>x : any
|
||||
|
||||
let c = a + b + X;
|
||||
>c : number
|
||||
>a + b + X : number
|
||||
>a + b : number
|
||||
>a : number
|
||||
>b : number
|
||||
>X : number
|
||||
|
||||
|
||||
@@ -3,15 +3,20 @@
|
||||
// @filename: f1.d.ts
|
||||
export {};
|
||||
|
||||
declare module M.M1 {
|
||||
export let x: number;
|
||||
}
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
observable: symbol;
|
||||
}
|
||||
class Cls {x}
|
||||
let [a, b]: number[];
|
||||
import X = M.M1.x;
|
||||
}
|
||||
|
||||
// @filename: main.ts
|
||||
|
||||
Symbol.observable;
|
||||
new Cls().x
|
||||
new Cls().x
|
||||
let c = a + b + X;
|
||||
Reference in New Issue
Block a user