Allow isSymbolAccessible to paint object literal declarations as visible (#24668)
* Dont use resolveEntityName for computed property name symbol resolution - use checkExpression and resolvedSymbol instead * Fix lint
This commit is contained in:
parent
69c7e67c88
commit
0b1183a461
|
@ -2871,7 +2871,18 @@ namespace ts {
|
|||
// we are going to see if c can be accessed in scope directly.
|
||||
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
|
||||
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
|
||||
const parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible);
|
||||
|
||||
let containers = getContainersOfSymbol(symbol, enclosingDeclaration);
|
||||
// If we're trying to reference some object literal in, eg `var a = { x: 1 }`, the symbol for the literal, `__object`, is distinct
|
||||
// from the symbol of the declaration it is being assigned to. Since we can use the declaration to refer to the literal, however,
|
||||
// we'd like to make that connection here - potentially causing us to paint the declararation's visibiility, and therefore the literal.
|
||||
const firstDecl: Node = first(symbol.declarations);
|
||||
if (!length(containers) && meaning & SymbolFlags.Value && firstDecl && isObjectLiteralExpression(firstDecl)) {
|
||||
if (firstDecl.parent && isVariableDeclaration(firstDecl.parent) && firstDecl === firstDecl.parent.initializer) {
|
||||
containers = [getSymbolOfNode(firstDecl.parent)];
|
||||
}
|
||||
}
|
||||
const parentResult = isAnySymbolAccessible(containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible);
|
||||
if (parentResult) {
|
||||
return parentResult;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//// [objectLiteralComputedNameNoDeclarationError.ts]
|
||||
const Foo = {
|
||||
BANANA: 'banana' as 'banana',
|
||||
}
|
||||
|
||||
export const Baa = {
|
||||
[Foo.BANANA]: 1
|
||||
};
|
||||
|
||||
//// [objectLiteralComputedNameNoDeclarationError.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var _a;
|
||||
var Foo = {
|
||||
BANANA: 'banana'
|
||||
};
|
||||
exports.Baa = (_a = {},
|
||||
_a[Foo.BANANA] = 1,
|
||||
_a);
|
||||
|
||||
|
||||
//// [objectLiteralComputedNameNoDeclarationError.d.ts]
|
||||
declare const Foo: {
|
||||
BANANA: "banana";
|
||||
};
|
||||
export declare const Baa: {
|
||||
[Foo.BANANA]: number;
|
||||
};
|
||||
export {};
|
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/objectLiteralComputedNameNoDeclarationError.ts ===
|
||||
const Foo = {
|
||||
>Foo : Symbol(Foo, Decl(objectLiteralComputedNameNoDeclarationError.ts, 0, 5))
|
||||
|
||||
BANANA: 'banana' as 'banana',
|
||||
>BANANA : Symbol(BANANA, Decl(objectLiteralComputedNameNoDeclarationError.ts, 0, 13))
|
||||
}
|
||||
|
||||
export const Baa = {
|
||||
>Baa : Symbol(Baa, Decl(objectLiteralComputedNameNoDeclarationError.ts, 4, 12))
|
||||
|
||||
[Foo.BANANA]: 1
|
||||
>[Foo.BANANA] : Symbol([Foo.BANANA], Decl(objectLiteralComputedNameNoDeclarationError.ts, 4, 20))
|
||||
>Foo.BANANA : Symbol(BANANA, Decl(objectLiteralComputedNameNoDeclarationError.ts, 0, 13))
|
||||
>Foo : Symbol(Foo, Decl(objectLiteralComputedNameNoDeclarationError.ts, 0, 5))
|
||||
>BANANA : Symbol(BANANA, Decl(objectLiteralComputedNameNoDeclarationError.ts, 0, 13))
|
||||
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
=== tests/cases/compiler/objectLiteralComputedNameNoDeclarationError.ts ===
|
||||
const Foo = {
|
||||
>Foo : { BANANA: "banana"; }
|
||||
>{ BANANA: 'banana' as 'banana',} : { BANANA: "banana"; }
|
||||
|
||||
BANANA: 'banana' as 'banana',
|
||||
>BANANA : "banana"
|
||||
>'banana' as 'banana' : "banana"
|
||||
>'banana' : "banana"
|
||||
}
|
||||
|
||||
export const Baa = {
|
||||
>Baa : { [Foo.BANANA]: number; }
|
||||
>{ [Foo.BANANA]: 1} : { [Foo.BANANA]: number; }
|
||||
|
||||
[Foo.BANANA]: 1
|
||||
>[Foo.BANANA] : number
|
||||
>Foo.BANANA : "banana"
|
||||
>Foo : { BANANA: "banana"; }
|
||||
>BANANA : "banana"
|
||||
>1 : 1
|
||||
|
||||
};
|
|
@ -0,0 +1,8 @@
|
|||
// @declaration: true
|
||||
const Foo = {
|
||||
BANANA: 'banana' as 'banana',
|
||||
}
|
||||
|
||||
export const Baa = {
|
||||
[Foo.BANANA]: 1
|
||||
};
|
Loading…
Reference in a new issue