Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions tsc/internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,15 +805,26 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index
break
}
}
if name != nil && ast.IsComputedPropertyName(name) && ast.IsEntityName(name.Expression()) {
lhs := b.createAccessFromSymbolChain(chain, index-1, stopper, overrideTypeArguments)
if ast.IsEntityName(lhs) {
if name != nil && ast.IsComputedPropertyName(name) && ast.IsEntityNameExpression(name.Expression()) {
keyType := b.ch.checkComputedPropertyName(name)
if keyType.flags&TypeFlagsUniqueESSymbol != 0 || ast.IsEntityName(name.Expression()) {
lhs := b.createAccessFromSymbolChain(chain, index-1, stopper, overrideTypeArguments)
if !ast.IsEntityName(lhs) {
return lhs
}
var indexType *ast.TypeNode
if keyType.flags&TypeFlagsUniqueESSymbol != 0 {
// The original name belongs to the declaration's scope. Serialize
// the symbol in the destination scope so aliases are tracked.
indexType = b.symbolToTypeNode(keyType.symbol, ast.SymbolFlagsValue, nil)
} else {
indexType = b.f.NewTypeQueryNode(name.Expression(), nil)
}
return b.f.NewIndexedAccessTypeNode(
b.f.NewParenthesizedTypeNode(b.f.NewTypeQueryNode(lhs, nil)),
b.f.NewTypeQueryNode(name.Expression(), nil),
indexType,
)
}
return lhs
}
symbolName = b.getNameOfSymbolAsWritten(symbol)
exportName = symbol.Name()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//// [tests/cases/compiler/declarationEmitImportedComputedUniqueSymbolStatic.ts] ////

//// [statics.ts]
export declare const key: unique symbol;
export declare class K {
static readonly [key]: unique symbol;
}

//// [main.ts]
import { K, key } from "./statics";
export const obj = { k: K[key] } as const;

//// [aliased.ts]
import { K, key as importedKey } from "./statics";
const key = "unrelated";
export const obj = { k: K[importedKey], key } as const;

//// [qualified-statics.ts]
export declare namespace keys {
const key: unique symbol;
}
export declare class Qualified {
static readonly [keys.key]: unique symbol;
}

//// [qualified.ts]
import { Qualified, keys as importedKeys } from "./qualified-statics";
export const obj = { k: Qualified[importedKeys.key] } as const;

//// [indexer.ts]
import { key } from "./statics";
export declare function getKey(): typeof key;

//// [import-type.ts]
import { K } from "./statics";
import { getKey } from "./indexer";
export const obj = { k: K[getKey()] } as const;


//// [statics.js]
export {};
//// [main.js]
import { K, key } from "./statics";
export const obj = { k: K[key] };
//// [aliased.js]
import { K, key as importedKey } from "./statics";
const key = "unrelated";
export const obj = { k: K[importedKey], key };
//// [qualified-statics.js]
export {};
//// [qualified.js]
import { Qualified, keys as importedKeys } from "./qualified-statics";
export const obj = { k: Qualified[importedKeys.key] };
//// [indexer.js]
export {};
//// [import-type.js]
import { K } from "./statics";
import { getKey } from "./indexer";
export const obj = { k: K[getKey()] };


//// [statics.d.ts]
export declare const key: unique symbol;
export declare class K {
static readonly [key]: unique symbol;
}
//// [main.d.ts]
import { K, key } from "./statics";
export declare const obj: {
readonly k: (typeof K)[typeof key];
};
//// [aliased.d.ts]
import { K, key as importedKey } from "./statics";
export declare const obj: {
readonly k: (typeof K)[typeof importedKey];
readonly key: "unrelated";
};
//// [qualified-statics.d.ts]
export declare namespace keys {
const key: unique symbol;
}
export declare class Qualified {
static readonly [keys.key]: unique symbol;
}
//// [qualified.d.ts]
import { Qualified, keys as importedKeys } from "./qualified-statics";
export declare const obj: {
readonly k: (typeof Qualified)[typeof importedKeys.key];
};
//// [indexer.d.ts]
import { key } from "./statics";
export declare function getKey(): typeof key;
//// [import-type.d.ts]
import { K } from "./statics";
export declare const obj: {
readonly k: (typeof K)[typeof import("./statics").key];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @declaration: true
// @module: esnext
// @strict: true
// @noTypesAndSymbols: true

// @filename: statics.ts
export declare const key: unique symbol;
export declare class K {
static readonly [key]: unique symbol;
}

// @filename: main.ts
import { K, key } from "./statics";
export const obj = { k: K[key] } as const;

// @filename: aliased.ts
import { K, key as importedKey } from "./statics";
const key = "unrelated";
export const obj = { k: K[importedKey], key } as const;

// @filename: qualified-statics.ts
export declare namespace keys {
const key: unique symbol;
}
export declare class Qualified {
static readonly [keys.key]: unique symbol;
}

// @filename: qualified.ts
import { Qualified, keys as importedKeys } from "./qualified-statics";
export const obj = { k: Qualified[importedKeys.key] } as const;

// @filename: indexer.ts
import { key } from "./statics";
export declare function getKey(): typeof key;

// @filename: import-type.ts
import { K } from "./statics";
import { getKey } from "./indexer";
export const obj = { k: K[getKey()] } as const;