mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
fix(55494): Invalid declaration with computed property using imported symbol (#55529)
This commit is contained in:
parent
788239ff87
commit
9d0dc77712
@ -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(
|
||||
|
||||
@ -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;
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
11
tests/cases/compiler/computedPropertyNameWithImportedKey.ts
Normal file
11
tests/cases/compiler/computedPropertyNameWithImportedKey.ts
Normal file
@ -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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user