Skip to content

Commit b7c416c

Browse files
committed
Check if container has locals before looking up properties
1 parent 4e29b18 commit b7c416c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ namespace ts {
24012401
}
24022402

24032403
function lookupSymbolForName(name: string) {
2404-
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name);
2404+
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name));
24052405
}
24062406

24072407
function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/foo.js ===
2+
module.exports = function () {
3+
>module : Symbol(export=, Decl(foo.js, 0, 0))
4+
>exports : Symbol(export=, Decl(foo.js, 0, 0))
5+
6+
class A { }
7+
>A : Symbol(A, Decl(foo.js, 0, 30))
8+
9+
return {
10+
c: A.b = 1,
11+
>c : Symbol(c, Decl(foo.js, 2, 10))
12+
>A : Symbol(A, Decl(foo.js, 0, 30))
13+
}
14+
};
15+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/foo.js ===
2+
module.exports = function () {
3+
>module.exports = function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; }
4+
>module.exports : any
5+
>module : any
6+
>exports : any
7+
>function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; }
8+
9+
class A { }
10+
>A : A
11+
12+
return {
13+
>{ c: A.b = 1, } : { [x: string]: any; c: number; }
14+
15+
c: A.b = 1,
16+
>c : number
17+
>A.b = 1 : 1
18+
>A.b : any
19+
>A : typeof A
20+
>b : any
21+
>1 : 1
22+
}
23+
};
24+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowJs: true
2+
// @noEmit: true
3+
4+
// @filename: foo.js
5+
module.exports = function () {
6+
class A { }
7+
return {
8+
c: A.b = 1,
9+
}
10+
};

0 commit comments

Comments
 (0)