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
6 changes: 6 additions & 0 deletions tsc/internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ func (b *Binder) bindDeferredExpandoAssignment(node *ast.Node) {
if symbol = getInitializerSymbol(symbol); symbol != nil {
if ast.HasDynamicName(node) {
b.bindAnonymousDeclaration(node, ast.SymbolFlagsProperty|ast.SymbolFlagsAssignment, ast.InternalSymbolNameComputed)
// Point the anonymous computed assignment at the expando host. For top-level
// scripts, bindAnonymousDeclaration would otherwise set parent to a nil
// SourceFile symbol, which breaks getLateBoundSymbol under --noCheck.
if declSym := node.Symbol(); declSym != nil {
declSym.SetParent(symbol)
}
b.addLateBoundAssignmentDeclarationToSymbol(node, symbol)
} else {
// We declare expandos only when there are no non-expando declarations for that name.
Expand Down
5 changes: 4 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14687,7 +14687,10 @@ func (c *Checker) getLateBoundSymbol(symbol *ast.Symbol) *ast.Symbol {
if links.lateSymbol == nil && core.Some(symbol.Declarations(), c.hasLateBindableName) {
// force late binding of members/exports. This will set the late-bound symbol
parent := c.getMergedSymbol(symbol.Parent())
if core.Some(symbol.Declarations(), ast.HasStaticModifier) {
// Function/namespace expandos are stored on exports (see AssignmentDeclaration),
// not members. BinaryExpression declarations never have a static modifier, so
// Assignment is the signal to resolve exports.
if core.Some(symbol.Declarations(), ast.HasStaticModifier) || symbol.Flags()&ast.SymbolFlagsAssignment != 0 {
c.getExportsOfSymbol(parent)
} else {
c.getMembersOfSymbol(parent)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignment.ts] ////

//// [noCheckExpandoElementAccessAssignment.ts]
const k = "bar";
foo[k] = 1;
function foo() {}




//// [noCheckExpandoElementAccessAssignment.d.ts]
declare const k = "bar";
declare function foo(): void;
declare namespace foo {
var bar: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignment.ts] ////

=== noCheckExpandoElementAccessAssignment.ts ===
const k = "bar";
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignment.ts, 0, 5))

foo[k] = 1;
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignment.ts, 1, 11))
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignment.ts, 0, 5))

function foo() {}
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignment.ts, 1, 11))

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignment.ts] ////

=== noCheckExpandoElementAccessAssignment.ts ===
const k = "bar";
>k : "bar"
>"bar" : "bar"

foo[k] = 1;
>foo[k] = 1 : 1
>foo[k] : number
>foo : { (): void; bar: number; }
>k : "bar"
>1 : 1

function foo() {}
>foo : { (): void; bar: number; }

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentInitializer.ts] ////

//// [noCheckExpandoElementAccessAssignmentInitializer.ts]
const k = "bar";
const foo = () => {};
foo[k] = 1;




//// [noCheckExpandoElementAccessAssignmentInitializer.d.ts]
declare const k = "bar";
declare function foo(): void;
declare namespace foo {
var bar: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentInitializer.ts] ////

=== noCheckExpandoElementAccessAssignmentInitializer.ts ===
const k = "bar";
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignmentInitializer.ts, 0, 5))

const foo = () => {};
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignmentInitializer.ts, 1, 5))

foo[k] = 1;
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignmentInitializer.ts, 1, 5))
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignmentInitializer.ts, 0, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentInitializer.ts] ////

=== noCheckExpandoElementAccessAssignmentInitializer.ts ===
const k = "bar";
>k : "bar"
>"bar" : "bar"

const foo = () => {};
>foo : { (): void; bar: number; }
>() => {} : { (): void; bar: number; }

foo[k] = 1;
>foo[k] = 1 : 1
>foo[k] : number
>foo : { (): void; bar: number; }
>k : "bar"
>1 : 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentModule.ts] ////

//// [noCheckExpandoElementAccessAssignmentModule.ts]
const k = "bar";
export function foo() {}
foo[k] = 1;




//// [noCheckExpandoElementAccessAssignmentModule.d.ts]
export declare function foo(): void;
export declare namespace foo {
var bar: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentModule.ts] ////

=== noCheckExpandoElementAccessAssignmentModule.ts ===
const k = "bar";
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignmentModule.ts, 0, 5))

export function foo() {}
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignmentModule.ts, 0, 16))

foo[k] = 1;
>foo : Symbol(foo, Decl(noCheckExpandoElementAccessAssignmentModule.ts, 0, 16))
>k : Symbol(k, Decl(noCheckExpandoElementAccessAssignmentModule.ts, 0, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/noCheckExpandoElementAccessAssignmentModule.ts] ////

=== noCheckExpandoElementAccessAssignmentModule.ts ===
const k = "bar";
>k : "bar"
>"bar" : "bar"

export function foo() {}
>foo : { (): void; bar: number; }

foo[k] = 1;
>foo[k] = 1 : 1
>foo[k] : number
>foo : { (): void; bar: number; }
>k : "bar"
>1 : 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: es2015
// @noCheck: true
// @emitDeclarationOnly: true
// @declaration: true

const k = "bar";
foo[k] = 1;
function foo() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: es2015
// @noCheck: true
// @emitDeclarationOnly: true
// @declaration: true

const k = "bar";
const foo = () => {};
foo[k] = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: es2015
// @noCheck: true
// @emitDeclarationOnly: true
// @declaration: true

const k = "bar";
export function foo() {}
foo[k] = 1;