diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index aebbb7b3ca5..27b3067278c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2403,7 +2403,7 @@ namespace ts { } function lookupSymbolForName(name: string) { - return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name); + return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name)); } function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) { diff --git a/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols new file mode 100644 index 00000000000..6cb2e235ce2 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/foo.js === +module.exports = function () { +>module : Symbol(export=, Decl(foo.js, 0, 0)) +>exports : Symbol(export=, Decl(foo.js, 0, 0)) + + class A { } +>A : Symbol(A, Decl(foo.js, 0, 30)) + + return { + c: A.b = 1, +>c : Symbol(c, Decl(foo.js, 2, 10)) +>A : Symbol(A, Decl(foo.js, 0, 30)) + } +}; + diff --git a/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types new file mode 100644 index 00000000000..fc1fad7f861 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/foo.js === +module.exports = function () { +>module.exports = function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; } +>module.exports : any +>module : any +>exports : any +>function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; } + + class A { } +>A : A + + return { +>{ c: A.b = 1, } : { [x: string]: any; c: number; } + + c: A.b = 1, +>c : number +>A.b = 1 : 1 +>A.b : any +>A : typeof A +>b : any +>1 : 1 + } +}; + diff --git a/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts b/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts new file mode 100644 index 00000000000..d8908740fd4 --- /dev/null +++ b/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @noEmit: true + +// @filename: foo.js +module.exports = function () { + class A { } + return { + c: A.b = 1, + } +};