mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 10:29:36 -06:00
Merge pull request #2856 from Microsoft/blockLocals
Blocks with locals should be added to the container chain.
This commit is contained in:
commit
8a8d175f79
@ -239,11 +239,7 @@ module ts {
|
||||
if (symbolKind & SymbolFlags.IsContainer) {
|
||||
container = node;
|
||||
|
||||
if (lastContainer) {
|
||||
lastContainer.nextContainer = container;
|
||||
}
|
||||
|
||||
lastContainer = container;
|
||||
addToContainerChain(container);
|
||||
}
|
||||
|
||||
if (isBlockScopeContainer) {
|
||||
@ -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:
|
||||
@ -403,6 +407,7 @@ module ts {
|
||||
default:
|
||||
if (!blockScopeContainer.locals) {
|
||||
blockScopeContainer.locals = {};
|
||||
addToContainerChain(blockScopeContainer);
|
||||
}
|
||||
declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes);
|
||||
}
|
||||
|
||||
@ -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
|
||||
// Code Unit Value Name Formal Name
|
||||
// \u000A Line Feed <LF>
|
||||
// \u000D Carriage Return <CR>
|
||||
|
||||
@ -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 = {}));
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
// @target: es6
|
||||
module M {
|
||||
export class C { }
|
||||
}
|
||||
module M {
|
||||
{
|
||||
let M = 0;
|
||||
new C();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user