From b7c416cdeb093a6dfbc00ed807d839d849e6c9de Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 17 Apr 2017 16:26:49 -0700 Subject: [PATCH] Check if container has locals before looking up properties --- src/compiler/binder.ts | 2 +- ...opertyInitalizationInObjectLiteral.symbols | 15 ++++++++++++ ...PropertyInitalizationInObjectLiteral.types | 24 +++++++++++++++++++ ...assPropertyInitalizationInObjectLiteral.ts | 10 ++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols create mode 100644 tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types create mode 100644 tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b2ad2151bb6..ec29edfe217 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2401,7 +2401,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, + } +};