From 13313182227c993c748fad146be000f841f7b23c Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 8 Aug 2024 11:33:33 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#59493=20(Use=20loca?= =?UTF-8?q?l=20symbol=20rather=20then=20target...)=20into=20release-5.5=20?= =?UTF-8?q?(#59502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wesley Wigham --- src/compiler/checker.ts | 3 + ...arationEmitEnumReferenceViaImportEquals.js | 88 +++++++++++++++ ...onEmitEnumReferenceViaImportEquals.symbols | 70 ++++++++++++ ...tionEmitEnumReferenceViaImportEquals.types | 106 ++++++++++++++++++ ...rtingModuleAugmentationRetainsImport.types | 4 +- .../declarationEmitUsingTypeAlias2.types | 8 +- .../exportClassExtendingIntersection.types | 4 +- ...nctionVariableInReturnTypeAnnotation.types | 4 +- tests/baselines/reference/importDecl.types | 4 +- ...solatedDeclarationErrorsAugmentation.types | 4 +- .../reference/umd-augmentation-1.types | 8 +- .../reference/umd-augmentation-2.types | 4 +- .../reference/umd-augmentation-3.types | 8 +- .../reference/umd-augmentation-4.types | 4 +- ...arationEmitEnumReferenceViaImportEquals.ts | 31 +++++ 15 files changed, 324 insertions(+), 26 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.js create mode 100644 tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.symbols create mode 100644 tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.types create mode 100644 tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c5cd771cfff..fd43fd02ee0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8387,6 +8387,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { introducesError = true; return { introducesError, node, sym }; } + else { + sym = symAtLocation; + } } if (sym) { diff --git a/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.js b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.js new file mode 100644 index 00000000000..e1ec678e65d --- /dev/null +++ b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.js @@ -0,0 +1,88 @@ +//// [tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts] //// + +//// [translation.ts] +export interface Translation { + translationKey: Translation.TranslationKeyEnum; +} + +export namespace Translation { + export type TranslationKeyEnum = 'translation1' | 'translation2'; + export const TranslationKeyEnum = { + Translation1: 'translation1' as TranslationKeyEnum, + Translation2: 'translation2' as TranslationKeyEnum, + } +} + + +//// [test.ts] +import { Translation } from "./translation"; +import TranslationKeyEnum = Translation.TranslationKeyEnum; + +export class Test { + TranslationKeyEnum = TranslationKeyEnum; + print() { + console.log(TranslationKeyEnum.Translation1); + } +} + +//// [index.ts] +import { Test } from "./test"; +new Test().print(); + +//// [translation.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Translation = void 0; +var Translation; +(function (Translation) { + Translation.TranslationKeyEnum = { + Translation1: 'translation1', + Translation2: 'translation2', + }; +})(Translation || (exports.Translation = Translation = {})); +//// [test.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Test = void 0; +var translation_1 = require("./translation"); +var TranslationKeyEnum = translation_1.Translation.TranslationKeyEnum; +var Test = /** @class */ (function () { + function Test() { + this.TranslationKeyEnum = TranslationKeyEnum; + } + Test.prototype.print = function () { + console.log(TranslationKeyEnum.Translation1); + }; + return Test; +}()); +exports.Test = Test; +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var test_1 = require("./test"); +new test_1.Test().print(); + + +//// [translation.d.ts] +export interface Translation { + translationKey: Translation.TranslationKeyEnum; +} +export declare namespace Translation { + type TranslationKeyEnum = 'translation1' | 'translation2'; + const TranslationKeyEnum: { + Translation1: TranslationKeyEnum; + Translation2: TranslationKeyEnum; + }; +} +//// [test.d.ts] +import { Translation } from "./translation"; +import TranslationKeyEnum = Translation.TranslationKeyEnum; +export declare class Test { + TranslationKeyEnum: { + Translation1: TranslationKeyEnum; + Translation2: TranslationKeyEnum; + }; + print(): void; +} +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.symbols b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.symbols new file mode 100644 index 00000000000..8a88df9f883 --- /dev/null +++ b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.symbols @@ -0,0 +1,70 @@ +//// [tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts] //// + +=== translation.ts === +export interface Translation { +>Translation : Symbol(Translation, Decl(translation.ts, 0, 0), Decl(translation.ts, 2, 1)) + + translationKey: Translation.TranslationKeyEnum; +>translationKey : Symbol(Translation.translationKey, Decl(translation.ts, 0, 30)) +>Translation : Symbol(Translation, Decl(translation.ts, 0, 0), Decl(translation.ts, 2, 1)) +>TranslationKeyEnum : Symbol(Translation.TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) +} + +export namespace Translation { +>Translation : Symbol(Translation, Decl(translation.ts, 0, 0), Decl(translation.ts, 2, 1)) + + export type TranslationKeyEnum = 'translation1' | 'translation2'; +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) + + export const TranslationKeyEnum = { +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) + + Translation1: 'translation1' as TranslationKeyEnum, +>Translation1 : Symbol(Translation1, Decl(translation.ts, 6, 37)) +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) + + Translation2: 'translation2' as TranslationKeyEnum, +>Translation2 : Symbol(Translation2, Decl(translation.ts, 7, 55)) +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) + } +} + + +=== test.ts === +import { Translation } from "./translation"; +>Translation : Symbol(Translation, Decl(test.ts, 0, 8)) + +import TranslationKeyEnum = Translation.TranslationKeyEnum; +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(test.ts, 0, 44)) +>Translation : Symbol(Translation, Decl(test.ts, 0, 8)) +>TranslationKeyEnum : Symbol(Translation.TranslationKeyEnum, Decl(translation.ts, 4, 30), Decl(translation.ts, 6, 14)) + +export class Test { +>Test : Symbol(Test, Decl(test.ts, 1, 59)) + + TranslationKeyEnum = TranslationKeyEnum; +>TranslationKeyEnum : Symbol(Test.TranslationKeyEnum, Decl(test.ts, 3, 19)) +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(test.ts, 0, 44)) + + print() { +>print : Symbol(Test.print, Decl(test.ts, 4, 42)) + + console.log(TranslationKeyEnum.Translation1); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>TranslationKeyEnum.Translation1 : Symbol(Translation1, Decl(translation.ts, 6, 37)) +>TranslationKeyEnum : Symbol(TranslationKeyEnum, Decl(test.ts, 0, 44)) +>Translation1 : Symbol(Translation1, Decl(translation.ts, 6, 37)) + } +} + +=== index.ts === +import { Test } from "./test"; +>Test : Symbol(Test, Decl(index.ts, 0, 8)) + +new Test().print(); +>new Test().print : Symbol(Test.print, Decl(test.ts, 4, 42)) +>Test : Symbol(Test, Decl(index.ts, 0, 8)) +>print : Symbol(Test.print, Decl(test.ts, 4, 42)) + diff --git a/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.types b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.types new file mode 100644 index 00000000000..87ddff957a5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitEnumReferenceViaImportEquals.types @@ -0,0 +1,106 @@ +//// [tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts] //// + +=== translation.ts === +export interface Translation { + translationKey: Translation.TranslationKeyEnum; +>translationKey : Translation.TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Translation : any +> : ^^^ +} + +export namespace Translation { +>Translation : typeof Translation +> : ^^^^^^^^^^^^^^^^^^ + + export type TranslationKeyEnum = 'translation1' | 'translation2'; +>TranslationKeyEnum : TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^ + + export const TranslationKeyEnum = { +>TranslationKeyEnum : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ +>{ Translation1: 'translation1' as TranslationKeyEnum, Translation2: 'translation2' as TranslationKeyEnum, } : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ + + Translation1: 'translation1' as TranslationKeyEnum, +>Translation1 : TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^ +>'translation1' as TranslationKeyEnum : TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^ +>'translation1' : "translation1" +> : ^^^^^^^^^^^^^^ + + Translation2: 'translation2' as TranslationKeyEnum, +>Translation2 : TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^ +>'translation2' as TranslationKeyEnum : TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^ +>'translation2' : "translation2" +> : ^^^^^^^^^^^^^^ + } +} + + +=== test.ts === +import { Translation } from "./translation"; +>Translation : typeof Translation +> : ^^^^^^^^^^^^^^^^^^ + +import TranslationKeyEnum = Translation.TranslationKeyEnum; +>TranslationKeyEnum : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ +>Translation : Translation +> : ^^^^^^^^^^^ +>TranslationKeyEnum : Translation.TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export class Test { +>Test : Test +> : ^^^^ + + TranslationKeyEnum = TranslationKeyEnum; +>TranslationKeyEnum : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ +>TranslationKeyEnum : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ + + print() { +>print : () => void +> : ^^^^^^^^^^ + + console.log(TranslationKeyEnum.Translation1); +>console.log(TranslationKeyEnum.Translation1) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>TranslationKeyEnum.Translation1 : Translation.TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>TranslationKeyEnum : { Translation1: TranslationKeyEnum; Translation2: TranslationKeyEnum; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^ +>Translation1 : Translation.TranslationKeyEnum +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + } +} + +=== index.ts === +import { Test } from "./test"; +>Test : typeof Test +> : ^^^^^^^^^^^ + +new Test().print(); +>new Test().print() : void +> : ^^^^ +>new Test().print : () => void +> : ^^^^^^^^^^ +>new Test() : Test +> : ^^^^ +>Test : typeof Test +> : ^^^^^^^^^^^ +>print : () => void +> : ^^^^^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.types b/tests/baselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.types index b19648a579c..5e6804230c2 100644 --- a/tests/baselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.types +++ b/tests/baselines/reference/declarationEmitForModuleImportingModuleAugmentationRetainsImport.types @@ -52,7 +52,7 @@ export function child1(prototype: ParentThing) { === parent.ts === import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module >child1 : (prototype: ParentThing) => void -> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^^^^^^^^ export class ParentThing implements ParentThing {} >ParentThing : ParentThing @@ -62,7 +62,7 @@ child1(ParentThing.prototype); >child1(ParentThing.prototype) : void > : ^^^^ >child1 : (prototype: ParentThing) => void -> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^^^^^^^^ >ParentThing.prototype : ParentThing > : ^^^^^^^^^^^ >ParentThing : typeof ParentThing diff --git a/tests/baselines/reference/declarationEmitUsingTypeAlias2.types b/tests/baselines/reference/declarationEmitUsingTypeAlias2.types index a64aa378cc9..b99ee19d2b2 100644 --- a/tests/baselines/reference/declarationEmitUsingTypeAlias2.types +++ b/tests/baselines/reference/declarationEmitUsingTypeAlias2.types @@ -98,7 +98,7 @@ export { shouldLookupName, shouldReuseLocalName, reuseDepName, shouldBeElided }; === src/index.ts === import { goodDeclaration, shouldReuseLocalName, shouldBeElided } from "some-dep"; >goodDeclaration : () => () => { shouldPrintResult: T extends import("node_modules/some-dep/dist/inner").Other ? "O" : "N"; shouldPrintResult2: T extends typeof shouldBeElided ? import("node_modules/some-dep/dist/inner").Other : "N"; shouldLookupName: typeof import("node_modules/some-dep/dist/other").shouldLookupName; shouldReuseLocalName: typeof shouldReuseLocalName; reuseDepName: typeof import("node_modules/some-dep/dist/other").reuseDepName; } -> : ^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ >shouldReuseLocalName : unique symbol > : ^^^^^^^^^^^^^ >shouldBeElided : unique symbol @@ -106,10 +106,10 @@ import { goodDeclaration, shouldReuseLocalName, shouldBeElided } from "some-dep" export const bar = goodDeclaration<{}>; >bar : () => () => { shouldPrintResult: "N"; shouldPrintResult2: "N"; shouldLookupName: typeof import("node_modules/some-dep/dist/other").shouldLookupName; shouldReuseLocalName: typeof shouldReuseLocalName; reuseDepName: typeof import("node_modules/some-dep/dist/other").reuseDepName; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ >goodDeclaration<{}> : () => () => { shouldPrintResult: "N"; shouldPrintResult2: "N"; shouldLookupName: typeof import("node_modules/some-dep/dist/other").shouldLookupName; shouldReuseLocalName: typeof shouldReuseLocalName; reuseDepName: typeof import("node_modules/some-dep/dist/other").reuseDepName; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ >goodDeclaration : () => () => { shouldPrintResult: T extends import("node_modules/some-dep/dist/inner").Other ? "O" : "N"; shouldPrintResult2: T extends typeof shouldBeElided ? import("node_modules/some-dep/dist/inner").Other : "N"; shouldLookupName: typeof import("node_modules/some-dep/dist/other").shouldLookupName; shouldReuseLocalName: typeof shouldReuseLocalName; reuseDepName: typeof import("node_modules/some-dep/dist/other").reuseDepName; } -> : ^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ diff --git a/tests/baselines/reference/exportClassExtendingIntersection.types b/tests/baselines/reference/exportClassExtendingIntersection.types index bfda7a0dca2..25dad432c7c 100644 --- a/tests/baselines/reference/exportClassExtendingIntersection.types +++ b/tests/baselines/reference/exportClassExtendingIntersection.types @@ -56,7 +56,7 @@ import { MyBaseClass } from './BaseClass'; import { MyMixin } from './MixinClass'; >MyMixin : >>(base: T) => T & import("BaseClass").Constructor -> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ export class MyExtendedClass extends MyMixin(MyBaseClass) { >MyExtendedClass : MyExtendedClass @@ -64,7 +64,7 @@ export class MyExtendedClass extends MyMixin(MyBaseClass) { >MyMixin(MyBaseClass) : MyBaseClass & MyMixin > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >MyMixin : >>(base: T) => T & import("BaseClass").Constructor -> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ >MyBaseClass : typeof MyBaseClass > : ^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/functionVariableInReturnTypeAnnotation.types b/tests/baselines/reference/functionVariableInReturnTypeAnnotation.types index a411dc6efca..e09690cad70 100644 --- a/tests/baselines/reference/functionVariableInReturnTypeAnnotation.types +++ b/tests/baselines/reference/functionVariableInReturnTypeAnnotation.types @@ -2,8 +2,8 @@ === functionVariableInReturnTypeAnnotation.ts === function bar(): typeof b { ->bar : () => typeof b -> : ^^^^^^ +>bar : () => any +> : ^^^^^^^^^ >b : any > : ^^^ diff --git a/tests/baselines/reference/importDecl.types b/tests/baselines/reference/importDecl.types index 34c0f7121bc..118f58ccd51 100644 --- a/tests/baselines/reference/importDecl.types +++ b/tests/baselines/reference/importDecl.types @@ -208,11 +208,11 @@ export var d = m5.foo2(); >m5.foo2() : m4.d > : ^^^^ >m5.foo2 : () => m4.d -> : ^^^^^^^^^^ +> : ^^^^^^ >m5 : typeof m5 > : ^^^^^^^^^ >foo2 : () => m4.d -> : ^^^^^^^^^^ +> : ^^^^^^ // Do not emit multiple used import statements import multiImport_m4 = require("./importDecl_require"); // Emit used diff --git a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types index a8186114cc0..7dd57f78696 100644 --- a/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types +++ b/tests/baselines/reference/isolatedDeclarationErrorsAugmentation.types @@ -52,7 +52,7 @@ export function child1(prototype: ParentThing) { === parent.ts === import { child1 } from './child1'; // this import should still exist in some form in the output, since it augments this module >child1 : (prototype: ParentThing) => void -> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^^^^^^^^ export class ParentThing implements ParentThing {} >ParentThing : ParentThing @@ -62,7 +62,7 @@ child1(ParentThing.prototype); >child1(ParentThing.prototype) : void > : ^^^^ >child1 : (prototype: ParentThing) => void -> : ^ ^^^^^^^^^^^^^^^^^^^^^^ +> : ^ ^^ ^^^^^^^^^ >ParentThing.prototype : ParentThing > : ^^^^^^^^^^^ >ParentThing : typeof ParentThing diff --git a/tests/baselines/reference/umd-augmentation-1.types b/tests/baselines/reference/umd-augmentation-1.types index c7f9c95e8f0..4bf383a94ae 100644 --- a/tests/baselines/reference/umd-augmentation-1.types +++ b/tests/baselines/reference/umd-augmentation-1.types @@ -61,12 +61,12 @@ p = v.reverse(); > : ^^^^^^^ >v.reverse() : m.Point > : ^^^^^^^ ->v.reverse : () => m.Point -> : ^^^^^^^^^^^^^ +>v.reverse : () => Math2d.Point +> : ^^^^^^ >v : m.Vector > : ^^^^^^^^ ->reverse : () => m.Point -> : ^^^^^^^^^^^^^ +>reverse : () => Math2d.Point +> : ^^^^^^ var t = p.x; >t : number diff --git a/tests/baselines/reference/umd-augmentation-2.types b/tests/baselines/reference/umd-augmentation-2.types index 6d5c3dde26b..526d70a16a7 100644 --- a/tests/baselines/reference/umd-augmentation-2.types +++ b/tests/baselines/reference/umd-augmentation-2.types @@ -59,11 +59,11 @@ p = v.reverse(); >v.reverse() : Math2d.Point > : ^^^^^^^^^^^^ >v.reverse : () => Math2d.Point -> : ^^^^^^^^^^^^^^^^^^ +> : ^^^^^^ >v : Math2d.Vector > : ^^^^^^^^^^^^^ >reverse : () => Math2d.Point -> : ^^^^^^^^^^^^^^^^^^ +> : ^^^^^^ var t = p.x; >t : number diff --git a/tests/baselines/reference/umd-augmentation-3.types b/tests/baselines/reference/umd-augmentation-3.types index 2a8dbeeb746..2e538ad4bd9 100644 --- a/tests/baselines/reference/umd-augmentation-3.types +++ b/tests/baselines/reference/umd-augmentation-3.types @@ -61,12 +61,12 @@ p = v.reverse(); > : ^^^^^^^ >v.reverse() : m.Point > : ^^^^^^^ ->v.reverse : () => m.Point -> : ^^^^^^^^^^^^^ +>v.reverse : () => Math2d.Point +> : ^^^^^^ >v : m.Vector > : ^^^^^^^^ ->reverse : () => m.Point -> : ^^^^^^^^^^^^^ +>reverse : () => Math2d.Point +> : ^^^^^^ var t = p.x; >t : number diff --git a/tests/baselines/reference/umd-augmentation-4.types b/tests/baselines/reference/umd-augmentation-4.types index 5d1217759b6..2c930c86d2a 100644 --- a/tests/baselines/reference/umd-augmentation-4.types +++ b/tests/baselines/reference/umd-augmentation-4.types @@ -59,11 +59,11 @@ p = v.reverse(); >v.reverse() : Math2d.Point > : ^^^^^^^^^^^^ >v.reverse : () => Math2d.Point -> : ^^^^^^^^^^^^^^^^^^ +> : ^^^^^^ >v : Math2d.Vector > : ^^^^^^^^^^^^^ >reverse : () => Math2d.Point -> : ^^^^^^^^^^^^^^^^^^ +> : ^^^^^^ var t = p.x; >t : number diff --git a/tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts b/tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts new file mode 100644 index 00000000000..1d368e4bcd1 --- /dev/null +++ b/tests/cases/compiler/declarationEmitEnumReferenceViaImportEquals.ts @@ -0,0 +1,31 @@ +// @strict: true +// @declaration: true + +// @filename: translation.ts +export interface Translation { + translationKey: Translation.TranslationKeyEnum; +} + +export namespace Translation { + export type TranslationKeyEnum = 'translation1' | 'translation2'; + export const TranslationKeyEnum = { + Translation1: 'translation1' as TranslationKeyEnum, + Translation2: 'translation2' as TranslationKeyEnum, + } +} + + +// @filename: test.ts +import { Translation } from "./translation"; +import TranslationKeyEnum = Translation.TranslationKeyEnum; + +export class Test { + TranslationKeyEnum = TranslationKeyEnum; + print() { + console.log(TranslationKeyEnum.Translation1); + } +} + +// @filename: index.ts +import { Test } from "./test"; +new Test().print(); \ No newline at end of file