Skip to content

Blocks with locals should be added to the container chain. #2856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2015
Merged
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
15 changes: 10 additions & 5 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ module ts {
if (symbolKind & SymbolFlags.IsContainer) {
container = node;

if (lastContainer) {
lastContainer.nextContainer = container;
}

lastContainer = container;
addToContainerChain(container);
}

if (isBlockScopeContainer) {
Expand All @@ -262,6 +258,14 @@ module ts {
blockScopeContainer = savedBlockScopeContainer;
}

function addToContainerChain(node: Node) {
if (lastContainer) {
lastContainer.nextContainer = node;
}

lastContainer = node;
}

function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) {
switch (container.kind) {
case SyntaxKind.ModuleDeclaration:
Expand Down Expand Up @@ -403,6 +407,7 @@ module ts {
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = {};
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ module ts {
export function isLineBreak(ch: number): boolean {
// ES5 7.3:
// The ECMAScript line terminator characters are listed in Table 3.
// Table 3 Line Terminator Characters
// Table 3: Line Terminator Characters
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an errant extended character in the file, breaking cscript.

// Code Unit Value Name Formal Name
// \u000A Line Feed <LF>
// \u000D Carriage Return <CR>
Expand Down
25 changes: 25 additions & 0 deletions tests/baselines/reference/nameCollisionWithBlockScopedVariable1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [nameCollisionWithBlockScopedVariable1.ts]
module M {
export class C { }
}
module M {
{
let M = 0;
new C();
}
}

//// [nameCollisionWithBlockScopedVariable1.js]
var M;
(function (M) {
class C {
}
M.C = C;
})(M || (M = {}));
var M;
(function (M_1) {
{
let M = 0;
new M_1.C();
}
})(M || (M = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts ===
module M {
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1))

export class C { }
>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10))
}
module M {
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1))
{
let M = 0;
>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 5, 11))

new C();
>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts ===
module M {
>M : typeof M

export class C { }
>C : C
}
module M {
>M : typeof M
{
let M = 0;
>M : number
>0 : number

new C();
>new C() : C
>C : typeof C
}
}
10 changes: 10 additions & 0 deletions tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @target: es6
module M {
export class C { }
}
module M {
{
let M = 0;
new C();
}
}