diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 048615abb1f13..aa8ab4f9fbee0 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -100,6 +100,7 @@ import { isBindingPattern, isClassDeclaration, isClassElement, + isComputedPropertyName, isDeclaration, isElementAccessExpression, isEntityName, @@ -701,6 +702,9 @@ export function transformDeclarations(context: TransformationContext) { if (elem.kind === SyntaxKind.OmittedExpression) { return elem; } + if (elem.propertyName && isComputedPropertyName(elem.propertyName) && isEntityNameExpression(elem.propertyName.expression)) { + checkEntityNameVisibility(elem.propertyName.expression, enclosingDeclaration); + } if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name) && !elem.symbol.isReferenced && !isIdentifierANonContextualKeyword(elem.propertyName)) { // Unnecessary property renaming is forbidden in types, so remove renaming return factory.updateBindingElement( diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.js b/tests/baselines/reference/computedPropertyNameWithImportedKey.js new file mode 100644 index 0000000000000..7854938f7c522 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +//// [a.ts] +export const a = Symbol(); + +//// [b.ts] +import { a } from "./a"; +export function fn({ [a]: value }: any): string { + return value; +} + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = Symbol(); +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.fn = void 0; +var a_1 = require("./a"); +function fn(_a) { + var _b = a_1.a, value = _a[_b]; + return value; +} +exports.fn = fn; + + +//// [a.d.ts] +export declare const a: unique symbol; +//// [b.d.ts] +import { a } from "./a"; +export declare function fn({ [a]: value }: any): string; diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols b/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols new file mode 100644 index 0000000000000..ba006a9861328 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +=== /a.ts === +export const a = Symbol(); +>a : Symbol(a, Decl(a.ts, 0, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +=== /b.ts === +import { a } from "./a"; +>a : Symbol(a, Decl(b.ts, 0, 8)) + +export function fn({ [a]: value }: any): string { +>fn : Symbol(fn, Decl(b.ts, 0, 24)) +>a : Symbol(a, Decl(b.ts, 0, 8)) +>value : Symbol(value, Decl(b.ts, 1, 20)) + + return value; +>value : Symbol(value, Decl(b.ts, 1, 20)) +} + diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.types b/tests/baselines/reference/computedPropertyNameWithImportedKey.types new file mode 100644 index 0000000000000..2058f5b58ce4d --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.types @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +=== /a.ts === +export const a = Symbol(); +>a : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +=== /b.ts === +import { a } from "./a"; +>a : unique symbol + +export function fn({ [a]: value }: any): string { +>fn : ({ [a]: value }: any) => string +>a : unique symbol +>value : any + + return value; +>value : any +} + diff --git a/tests/cases/compiler/computedPropertyNameWithImportedKey.ts b/tests/cases/compiler/computedPropertyNameWithImportedKey.ts new file mode 100644 index 0000000000000..142d4cfb6d9af --- /dev/null +++ b/tests/cases/compiler/computedPropertyNameWithImportedKey.ts @@ -0,0 +1,11 @@ +// @declaration: true +// @lib: es6 + +// @filename: /a.ts +export const a = Symbol(); + +// @filename: /b.ts +import { a } from "./a"; +export function fn({ [a]: value }: any): string { + return value; +}