mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Inform getDeclarationSpaces about how an imported exportAssignment may merge (#23816)
This commit is contained in:
@@ -21611,7 +21611,8 @@ namespace ts {
|
||||
ExportType = 1 << 1,
|
||||
ExportNamespace = 1 << 2,
|
||||
}
|
||||
function getDeclarationSpaces(d: Declaration): DeclarationSpaces {
|
||||
function getDeclarationSpaces(decl: Declaration): DeclarationSpaces {
|
||||
let d = decl as Node;
|
||||
switch (d.kind) {
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
@@ -21627,6 +21628,13 @@ namespace ts {
|
||||
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
|
||||
case SyntaxKind.SourceFile:
|
||||
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue | DeclarationSpaces.ExportNamespace;
|
||||
case SyntaxKind.ExportAssignment:
|
||||
// Export assigned entity name expressions act as aliases and should fall through, otherwise they export values
|
||||
if (!isEntityNameExpression((d as ExportAssignment).expression)) {
|
||||
return DeclarationSpaces.ExportValue;
|
||||
}
|
||||
d = (d as ExportAssignment).expression;
|
||||
/* falls through */
|
||||
// The below options all declare an Alias, which is allowed to merge with other values within the importing module
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
tests/cases/compiler/user.ts(1,8): error TS2395: Individual declarations in merged declaration 'Obj' must be all exported or all local.
|
||||
tests/cases/compiler/user.ts(1,8): error TS2440: Import declaration conflicts with local declaration of 'Obj'.
|
||||
tests/cases/compiler/user.ts(3,14): error TS2395: Individual declarations in merged declaration 'Obj' must be all exported or all local.
|
||||
tests/cases/compiler/user.ts(3,25): error TS2448: Block-scoped variable 'Obj' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assignment.ts (0 errors) ====
|
||||
export default {
|
||||
foo: 12
|
||||
};
|
||||
|
||||
==== tests/cases/compiler/user.ts (4 errors) ====
|
||||
import Obj from "./assignment";
|
||||
~~~
|
||||
!!! error TS2395: Individual declarations in merged declaration 'Obj' must be all exported or all local.
|
||||
~~~
|
||||
!!! error TS2440: Import declaration conflicts with local declaration of 'Obj'.
|
||||
|
||||
export const Obj = void Obj;
|
||||
~~~
|
||||
!!! error TS2395: Individual declarations in merged declaration 'Obj' must be all exported or all local.
|
||||
~~~
|
||||
!!! error TS2448: Block-scoped variable 'Obj' used before its declaration.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//// [tests/cases/compiler/exportAssignmentImportMergeNoCrash.ts] ////
|
||||
|
||||
//// [assignment.ts]
|
||||
export default {
|
||||
foo: 12
|
||||
};
|
||||
|
||||
//// [user.ts]
|
||||
import Obj from "./assignment";
|
||||
|
||||
export const Obj = void Obj;
|
||||
|
||||
|
||||
//// [assignment.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = {
|
||||
foo: 12
|
||||
};
|
||||
//// [user.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var assignment_1 = require("./assignment");
|
||||
exports.Obj = void exports.Obj;
|
||||
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/assignment.ts ===
|
||||
export default {
|
||||
foo: 12
|
||||
>foo : Symbol(foo, Decl(assignment.ts, 0, 16))
|
||||
|
||||
};
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Obj from "./assignment";
|
||||
>Obj : Symbol(Obj, Decl(user.ts, 0, 6), Decl(user.ts, 2, 12))
|
||||
|
||||
export const Obj = void Obj;
|
||||
>Obj : Symbol(Obj, Decl(user.ts, 2, 12))
|
||||
>Obj : Symbol(Obj, Decl(user.ts, 0, 6), Decl(user.ts, 2, 12))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/assignment.ts ===
|
||||
export default {
|
||||
>{ foo: 12} : { foo: number; }
|
||||
|
||||
foo: 12
|
||||
>foo : number
|
||||
>12 : 12
|
||||
|
||||
};
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Obj from "./assignment";
|
||||
>Obj : { foo: number; }
|
||||
|
||||
export const Obj = void Obj;
|
||||
>Obj : any
|
||||
>void Obj : undefined
|
||||
>Obj : any
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// @filename: assignment.ts
|
||||
export default {
|
||||
foo: 12
|
||||
};
|
||||
|
||||
// @filename: user.ts
|
||||
import Obj from "./assignment";
|
||||
|
||||
export const Obj = void Obj;
|
||||
Reference in New Issue
Block a user