Skip to content

Commit 8a8d175

Browse files
Merge pull request #2856 from Microsoft/blockLocals
Blocks with locals should be added to the container chain.
2 parents 8c1a652 + 92756e1 commit 8a8d175

6 files changed

+82
-6
lines changed

src/compiler/binder.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,7 @@ module ts {
239239
if (symbolKind & SymbolFlags.IsContainer) {
240240
container = node;
241241

242-
if (lastContainer) {
243-
lastContainer.nextContainer = container;
244-
}
245-
246-
lastContainer = container;
242+
addToContainerChain(container);
247243
}
248244

249245
if (isBlockScopeContainer) {
@@ -262,6 +258,14 @@ module ts {
262258
blockScopeContainer = savedBlockScopeContainer;
263259
}
264260

261+
function addToContainerChain(node: Node) {
262+
if (lastContainer) {
263+
lastContainer.nextContainer = node;
264+
}
265+
266+
lastContainer = node;
267+
}
268+
265269
function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) {
266270
switch (container.kind) {
267271
case SyntaxKind.ModuleDeclaration:
@@ -403,6 +407,7 @@ module ts {
403407
default:
404408
if (!blockScopeContainer.locals) {
405409
blockScopeContainer.locals = {};
410+
addToContainerChain(blockScopeContainer);
406411
}
407412
declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes);
408413
}

src/compiler/scanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ module ts {
352352
export function isLineBreak(ch: number): boolean {
353353
// ES5 7.3:
354354
// The ECMAScript line terminator characters are listed in Table 3.
355-
// Table 3 — Line Terminator Characters
355+
// Table 3: Line Terminator Characters
356356
// Code Unit Value Name Formal Name
357357
// \u000A Line Feed <LF>
358358
// \u000D Carriage Return <CR>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [nameCollisionWithBlockScopedVariable1.ts]
2+
module M {
3+
export class C { }
4+
}
5+
module M {
6+
{
7+
let M = 0;
8+
new C();
9+
}
10+
}
11+
12+
//// [nameCollisionWithBlockScopedVariable1.js]
13+
var M;
14+
(function (M) {
15+
class C {
16+
}
17+
M.C = C;
18+
})(M || (M = {}));
19+
var M;
20+
(function (M_1) {
21+
{
22+
let M = 0;
23+
new M_1.C();
24+
}
25+
})(M || (M = {}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts ===
2+
module M {
3+
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1))
4+
5+
export class C { }
6+
>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10))
7+
}
8+
module M {
9+
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1))
10+
{
11+
let M = 0;
12+
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 5, 11))
13+
14+
new C();
15+
>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10))
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts ===
2+
module M {
3+
>M : typeof M
4+
5+
export class C { }
6+
>C : C
7+
}
8+
module M {
9+
>M : typeof M
10+
{
11+
let M = 0;
12+
>M : number
13+
>0 : number
14+
15+
new C();
16+
>new C() : C
17+
>C : typeof C
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: es6
2+
module M {
3+
export class C { }
4+
}
5+
module M {
6+
{
7+
let M = 0;
8+
new C();
9+
}
10+
}

0 commit comments

Comments
 (0)