diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f23e26f51fc..154e6ea9b27 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3222,15 +3222,17 @@ namespace ts { } if (type.flags & TypeFlags.EnumLiteral && !(type.flags & TypeFlags.Union)) { const parentSymbol = getParentOfSymbol(type.symbol)!; - const parentName = symbolToName(parentSymbol, context, SymbolFlags.Type, /*expectsIdentifier*/ false); - const enumLiteralName = getDeclaredTypeOfSymbol(parentSymbol) === type ? parentName : createQualifiedName(parentName, symbolName(type.symbol)); - context.approximateLength += symbolName(type.symbol).length; - return createTypeReferenceNode(enumLiteralName, /*typeArguments*/ undefined); + const parentName = symbolToTypeNode(parentSymbol, context, SymbolFlags.Type); + const enumLiteralName = getDeclaredTypeOfSymbol(parentSymbol) === type + ? parentName + : appendReferenceToType( + parentName as TypeReferenceNode | ImportTypeNode, + createTypeReferenceNode(symbolName(type.symbol), /*typeArguments*/ undefined) + ); + return enumLiteralName; } if (type.flags & TypeFlags.EnumLike) { - const name = symbolToName(type.symbol, context, SymbolFlags.Type, /*expectsIdentifier*/ false); - context.approximateLength += symbolName(type.symbol).length; - return createTypeReferenceNode(name, /*typeArguments*/ undefined); + return symbolToTypeNode(type.symbol, context, SymbolFlags.Type); } if (type.flags & TypeFlags.StringLiteral) { context.approximateLength += ((type).value.length + 2); diff --git a/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.js b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.js new file mode 100644 index 00000000000..bc895b62ace --- /dev/null +++ b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/declarationEmitQualifiedAliasTypeArgument.ts] //// + +//// [bbb.d.ts] +export interface INode { + data: T; +} + +export function create(): () => INode; +//// [lib.d.ts] +export type G = { [P in T]: string }; + +export enum E { + A = "a", + B = "b" +} + +export type T = G; + +export type Q = G; + +//// [index.ts] +import { T, Q } from "./lib"; +import { create } from "./bbb"; + +export const fun = create(); + +export const fun2 = create(); + + +//// [index.js] +"use strict"; +exports.__esModule = true; +var bbb_1 = require("./bbb"); +exports.fun = bbb_1.create(); +exports.fun2 = bbb_1.create(); + + +//// [index.d.ts] +export declare const fun: () => import("./bbb").INode>; +export declare const fun2: () => import("./bbb").INode>; diff --git a/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.symbols b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.symbols new file mode 100644 index 00000000000..a6debc526ea --- /dev/null +++ b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.symbols @@ -0,0 +1,62 @@ +=== tests/cases/compiler/bbb.d.ts === +export interface INode { +>INode : Symbol(INode, Decl(bbb.d.ts, 0, 0)) +>T : Symbol(T, Decl(bbb.d.ts, 0, 23)) + + data: T; +>data : Symbol(INode.data, Decl(bbb.d.ts, 0, 27)) +>T : Symbol(T, Decl(bbb.d.ts, 0, 23)) +} + +export function create(): () => INode; +>create : Symbol(create, Decl(bbb.d.ts, 2, 1)) +>T : Symbol(T, Decl(bbb.d.ts, 4, 23)) +>INode : Symbol(INode, Decl(bbb.d.ts, 0, 0)) +>T : Symbol(T, Decl(bbb.d.ts, 4, 23)) + +=== tests/cases/compiler/lib.d.ts === +export type G = { [P in T]: string }; +>G : Symbol(G, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(lib.d.ts, --, --)) +>P : Symbol(P, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(lib.d.ts, --, --)) + +export enum E { +>E : Symbol(E, Decl(lib.d.ts, --, --)) + + A = "a", +>A : Symbol(E.A, Decl(lib.d.ts, --, --)) + + B = "b" +>B : Symbol(E.B, Decl(lib.d.ts, --, --)) +} + +export type T = G; +>T : Symbol(T, Decl(lib.d.ts, --, --)) +>G : Symbol(G, Decl(lib.d.ts, --, --)) +>E : Symbol(E, Decl(lib.d.ts, --, --)) + +export type Q = G; +>Q : Symbol(Q, Decl(lib.d.ts, --, --)) +>G : Symbol(G, Decl(lib.d.ts, --, --)) +>E : Symbol(E, Decl(lib.d.ts, --, --)) +>A : Symbol(E.A, Decl(lib.d.ts, --, --)) + +=== tests/cases/compiler/index.ts === +import { T, Q } from "./lib"; +>T : Symbol(T, Decl(index.ts, 0, 8)) +>Q : Symbol(Q, Decl(index.ts, 0, 11)) + +import { create } from "./bbb"; +>create : Symbol(create, Decl(index.ts, 1, 8)) + +export const fun = create(); +>fun : Symbol(fun, Decl(index.ts, 3, 12)) +>create : Symbol(create, Decl(index.ts, 1, 8)) +>T : Symbol(T, Decl(index.ts, 0, 8)) + +export const fun2 = create(); +>fun2 : Symbol(fun2, Decl(index.ts, 5, 12)) +>create : Symbol(create, Decl(index.ts, 1, 8)) +>Q : Symbol(Q, Decl(index.ts, 0, 11)) + diff --git a/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.types b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.types new file mode 100644 index 00000000000..e660e7d0bb9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitQualifiedAliasTypeArgument.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/bbb.d.ts === +export interface INode { + data: T; +>data : T +} + +export function create(): () => INode; +>create : () => () => INode + +=== tests/cases/compiler/lib.d.ts === +export type G = { [P in T]: string }; +>G : G + +export enum E { +>E : E + + A = "a", +>A : E.A +>"a" : "a" + + B = "b" +>B : E.B +>"b" : "b" +} + +export type T = G; +>T : G + +export type Q = G; +>Q : G +>E : any + +=== tests/cases/compiler/index.ts === +import { T, Q } from "./lib"; +>T : any +>Q : any + +import { create } from "./bbb"; +>create : () => () => import("tests/cases/compiler/bbb").INode + +export const fun = create(); +>fun : () => import("tests/cases/compiler/bbb").INode> +>create() : () => import("tests/cases/compiler/bbb").INode> +>create : () => () => import("tests/cases/compiler/bbb").INode + +export const fun2 = create(); +>fun2 : () => import("tests/cases/compiler/bbb").INode> +>create() : () => import("tests/cases/compiler/bbb").INode> +>create : () => () => import("tests/cases/compiler/bbb").INode + diff --git a/tests/cases/compiler/declarationEmitQualifiedAliasTypeArgument.ts b/tests/cases/compiler/declarationEmitQualifiedAliasTypeArgument.ts new file mode 100644 index 00000000000..0a3c346a430 --- /dev/null +++ b/tests/cases/compiler/declarationEmitQualifiedAliasTypeArgument.ts @@ -0,0 +1,26 @@ +// @declaration: true +// @filename: bbb.d.ts +export interface INode { + data: T; +} + +export function create(): () => INode; +// @filename: lib.d.ts +export type G = { [P in T]: string }; + +export enum E { + A = "a", + B = "b" +} + +export type T = G; + +export type Q = G; + +// @filename: index.ts +import { T, Q } from "./lib"; +import { create } from "./bbb"; + +export const fun = create(); + +export const fun2 = create(); diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 2402a2a07b4..67f1c4877ee 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 2402a2a07b434411dbc8a529b41d0d1d41befca5 +Subproject commit 67f1c4877ee1090b66d468a847caccca411a6f82