mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
addressed PR feedback
This commit is contained in:
+13
-2
@@ -412,7 +412,7 @@ namespace ts {
|
||||
return origin.pos > target.pos ? RelativeLocation.SameFileLocatedBefore : RelativeLocation.SameFileLocatedAfter;
|
||||
}
|
||||
|
||||
if (!compilerOptions.outFile && !compilerOptions.out) {
|
||||
if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) {
|
||||
// nodes are in different files and order cannot be determines
|
||||
return RelativeLocation.Unknown;
|
||||
}
|
||||
@@ -666,7 +666,18 @@ namespace ts {
|
||||
isUsedBeforeDeclaration = true;
|
||||
break;
|
||||
}
|
||||
else if (isFunctionLike(current)) {
|
||||
|
||||
if (isFunctionLike(current)) {
|
||||
break;
|
||||
}
|
||||
|
||||
const isInitializerOfNonStaticProperty =
|
||||
current.parent &&
|
||||
current.parent.kind === SyntaxKind.PropertyDeclaration &&
|
||||
(current.parent.flags & NodeFlags.Static) === 0 &&
|
||||
(<PropertyDeclaration>current.parent).initializer === current;
|
||||
|
||||
if (isInitializerOfNonStaticProperty) {
|
||||
break;
|
||||
}
|
||||
current = current.parent;
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(53,20): error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(60,20): error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts (2 errors) ====
|
||||
function foo1() {
|
||||
let a = () => x;
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo2() {
|
||||
let a = function () { return x; }
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo3() {
|
||||
class X {
|
||||
m() { return x;}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo4() {
|
||||
let y = class {
|
||||
m() { return x; }
|
||||
};
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo5() {
|
||||
let x = () => y;
|
||||
let y = () => x;
|
||||
}
|
||||
|
||||
function foo6() {
|
||||
function f() {
|
||||
return x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo7() {
|
||||
class A {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo8() {
|
||||
let y = class {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo9() {
|
||||
let y = class {
|
||||
static a = x;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo10() {
|
||||
class A {
|
||||
static a = x;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo11() {
|
||||
function f () {
|
||||
let y = class {
|
||||
static a = x;
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo12() {
|
||||
function f () {
|
||||
let y = class {
|
||||
a;
|
||||
constructor() {
|
||||
this.a = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
@@ -1,38 +1,87 @@
|
||||
//// [blockScopedVariablesUseBeforeDef.ts]
|
||||
function foo1() {
|
||||
let a = () => x;
|
||||
let x;
|
||||
let a = () => x;
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo2() {
|
||||
let a = function () { return x; }
|
||||
let x;
|
||||
let a = function () { return x; }
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo3() {
|
||||
class X {
|
||||
m() { return x;}
|
||||
}
|
||||
let x;
|
||||
class X {
|
||||
m() { return x;}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo4() {
|
||||
let y = class {
|
||||
m() { return x; }
|
||||
};
|
||||
let x;
|
||||
let y = class {
|
||||
m() { return x; }
|
||||
};
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo5() {
|
||||
let x = () => y;
|
||||
let y = () => x;
|
||||
let x = () => y;
|
||||
let y = () => x;
|
||||
}
|
||||
|
||||
function foo6() {
|
||||
function f() {
|
||||
return x;
|
||||
}
|
||||
let x;
|
||||
function f() {
|
||||
return x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo7() {
|
||||
class A {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo8() {
|
||||
let y = class {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo9() {
|
||||
let y = class {
|
||||
static a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo10() {
|
||||
class A {
|
||||
static a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo11() {
|
||||
function f () {
|
||||
let y = class {
|
||||
static a = x;
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo12() {
|
||||
function f () {
|
||||
let y = class {
|
||||
a;
|
||||
constructor() {
|
||||
this.a = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
//// [blockScopedVariablesUseBeforeDef.js]
|
||||
@@ -72,3 +121,61 @@ function foo6() {
|
||||
}
|
||||
var x;
|
||||
}
|
||||
function foo7() {
|
||||
var A = (function () {
|
||||
function A() {
|
||||
this.a = x;
|
||||
}
|
||||
return A;
|
||||
})();
|
||||
var x;
|
||||
}
|
||||
function foo8() {
|
||||
var y = (function () {
|
||||
function class_2() {
|
||||
this.a = x;
|
||||
}
|
||||
return class_2;
|
||||
})();
|
||||
var x;
|
||||
}
|
||||
function foo9() {
|
||||
var y = (function () {
|
||||
function class_3() {
|
||||
}
|
||||
class_3.a = x;
|
||||
return class_3;
|
||||
})();
|
||||
var x;
|
||||
}
|
||||
function foo10() {
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
A.a = x;
|
||||
return A;
|
||||
})();
|
||||
var x;
|
||||
}
|
||||
function foo11() {
|
||||
function f() {
|
||||
var y = (function () {
|
||||
function class_4() {
|
||||
}
|
||||
class_4.a = x;
|
||||
return class_4;
|
||||
})();
|
||||
}
|
||||
var x;
|
||||
}
|
||||
function foo12() {
|
||||
function f() {
|
||||
var y = (function () {
|
||||
function class_5() {
|
||||
this.a = x;
|
||||
}
|
||||
return class_5;
|
||||
})();
|
||||
}
|
||||
var x;
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
=== tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts ===
|
||||
function foo1() {
|
||||
>foo1 : Symbol(foo1, Decl(blockScopedVariablesUseBeforeDef.ts, 0, 0))
|
||||
|
||||
let a = () => x;
|
||||
>a : Symbol(a, Decl(blockScopedVariablesUseBeforeDef.ts, 1, 4))
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 2, 4))
|
||||
|
||||
let x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 2, 4))
|
||||
}
|
||||
|
||||
function foo2() {
|
||||
>foo2 : Symbol(foo2, Decl(blockScopedVariablesUseBeforeDef.ts, 3, 1))
|
||||
|
||||
let a = function () { return x; }
|
||||
>a : Symbol(a, Decl(blockScopedVariablesUseBeforeDef.ts, 6, 4))
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 7, 4))
|
||||
|
||||
let x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 7, 4))
|
||||
}
|
||||
|
||||
function foo3() {
|
||||
>foo3 : Symbol(foo3, Decl(blockScopedVariablesUseBeforeDef.ts, 8, 1))
|
||||
|
||||
class X {
|
||||
>X : Symbol(X, Decl(blockScopedVariablesUseBeforeDef.ts, 10, 17))
|
||||
|
||||
m() { return x;}
|
||||
>m : Symbol(m, Decl(blockScopedVariablesUseBeforeDef.ts, 11, 10))
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 14, 4))
|
||||
}
|
||||
let x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 14, 4))
|
||||
}
|
||||
|
||||
function foo4() {
|
||||
>foo4 : Symbol(foo4, Decl(blockScopedVariablesUseBeforeDef.ts, 15, 1))
|
||||
|
||||
let y = class {
|
||||
>y : Symbol(y, Decl(blockScopedVariablesUseBeforeDef.ts, 18, 4))
|
||||
|
||||
m() { return x; }
|
||||
>m : Symbol((Anonymous class).m, Decl(blockScopedVariablesUseBeforeDef.ts, 18, 16))
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 21, 4))
|
||||
|
||||
};
|
||||
let x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 21, 4))
|
||||
}
|
||||
|
||||
function foo5() {
|
||||
>foo5 : Symbol(foo5, Decl(blockScopedVariablesUseBeforeDef.ts, 22, 1))
|
||||
|
||||
let x = () => y;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 25, 4))
|
||||
>y : Symbol(y, Decl(blockScopedVariablesUseBeforeDef.ts, 26, 4))
|
||||
|
||||
let y = () => x;
|
||||
>y : Symbol(y, Decl(blockScopedVariablesUseBeforeDef.ts, 26, 4))
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 25, 4))
|
||||
}
|
||||
|
||||
function foo6() {
|
||||
>foo6 : Symbol(foo6, Decl(blockScopedVariablesUseBeforeDef.ts, 27, 1))
|
||||
|
||||
function f() {
|
||||
>f : Symbol(f, Decl(blockScopedVariablesUseBeforeDef.ts, 29, 17))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 33, 4))
|
||||
}
|
||||
let x;
|
||||
>x : Symbol(x, Decl(blockScopedVariablesUseBeforeDef.ts, 33, 4))
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
=== tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts ===
|
||||
function foo1() {
|
||||
>foo1 : () => void
|
||||
|
||||
let a = () => x;
|
||||
>a : () => any
|
||||
>() => x : () => any
|
||||
>x : any
|
||||
|
||||
let x;
|
||||
>x : any
|
||||
}
|
||||
|
||||
function foo2() {
|
||||
>foo2 : () => void
|
||||
|
||||
let a = function () { return x; }
|
||||
>a : () => any
|
||||
>function () { return x; } : () => any
|
||||
>x : any
|
||||
|
||||
let x;
|
||||
>x : any
|
||||
}
|
||||
|
||||
function foo3() {
|
||||
>foo3 : () => void
|
||||
|
||||
class X {
|
||||
>X : X
|
||||
|
||||
m() { return x;}
|
||||
>m : () => any
|
||||
>x : any
|
||||
}
|
||||
let x;
|
||||
>x : any
|
||||
}
|
||||
|
||||
function foo4() {
|
||||
>foo4 : () => void
|
||||
|
||||
let y = class {
|
||||
>y : typeof (Anonymous class)
|
||||
>class { m() { return x; } } : typeof (Anonymous class)
|
||||
|
||||
m() { return x; }
|
||||
>m : () => any
|
||||
>x : any
|
||||
|
||||
};
|
||||
let x;
|
||||
>x : any
|
||||
}
|
||||
|
||||
function foo5() {
|
||||
>foo5 : () => void
|
||||
|
||||
let x = () => y;
|
||||
>x : () => () => any
|
||||
>() => y : () => () => any
|
||||
>y : () => () => any
|
||||
|
||||
let y = () => x;
|
||||
>y : () => () => any
|
||||
>() => x : () => () => any
|
||||
>x : () => () => any
|
||||
}
|
||||
|
||||
function foo6() {
|
||||
>foo6 : () => void
|
||||
|
||||
function f() {
|
||||
>f : () => any
|
||||
|
||||
return x;
|
||||
>x : any
|
||||
}
|
||||
let x;
|
||||
>x : any
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'c' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (1 errors) ====
|
||||
|
||||
c;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'c' used before its declaration.
|
||||
|
||||
==== tests/cases/compiler/file2.ts (0 errors) ====
|
||||
const c = 0;
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
c;
|
||||
>c : Symbol(c, Decl(file2.ts, 0, 5))
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
const c = 0;
|
||||
>c : Symbol(c, Decl(file2.ts, 0, 5))
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
c;
|
||||
>c : number
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
const c = 0;
|
||||
>c : number
|
||||
>0 : number
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
tests/cases/compiler/file1.ts(2,1): error TS2448: Block-scoped variable 'l' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (1 errors) ====
|
||||
|
||||
l;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'l' used before its declaration.
|
||||
|
||||
==== tests/cases/compiler/file2.ts (0 errors) ====
|
||||
const l = 0;
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
l;
|
||||
>l : Symbol(l, Decl(file2.ts, 0, 5))
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
const l = 0;
|
||||
>l : Symbol(l, Decl(file2.ts, 0, 5))
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/file1.ts ===
|
||||
|
||||
l;
|
||||
>l : number
|
||||
|
||||
=== tests/cases/compiler/file2.ts ===
|
||||
const l = 0;
|
||||
>l : number
|
||||
>0 : number
|
||||
|
||||
@@ -1,35 +1,84 @@
|
||||
function foo1() {
|
||||
let a = () => x;
|
||||
let x;
|
||||
let a = () => x;
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo2() {
|
||||
let a = function () { return x; }
|
||||
let x;
|
||||
let a = function () { return x; }
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo3() {
|
||||
class X {
|
||||
m() { return x;}
|
||||
}
|
||||
let x;
|
||||
class X {
|
||||
m() { return x;}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo4() {
|
||||
let y = class {
|
||||
m() { return x; }
|
||||
};
|
||||
let x;
|
||||
let y = class {
|
||||
m() { return x; }
|
||||
};
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo5() {
|
||||
let x = () => y;
|
||||
let y = () => x;
|
||||
let x = () => y;
|
||||
let y = () => x;
|
||||
}
|
||||
|
||||
function foo6() {
|
||||
function f() {
|
||||
return x;
|
||||
}
|
||||
let x;
|
||||
function f() {
|
||||
return x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo7() {
|
||||
class A {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo8() {
|
||||
let y = class {
|
||||
a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo9() {
|
||||
let y = class {
|
||||
static a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo10() {
|
||||
class A {
|
||||
static a = x;
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo11() {
|
||||
function f () {
|
||||
let y = class {
|
||||
static a = x;
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
|
||||
function foo12() {
|
||||
function f () {
|
||||
let y = class {
|
||||
a;
|
||||
constructor() {
|
||||
this.a = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
let x;
|
||||
}
|
||||
Reference in New Issue
Block a user