Merge pull request #3288 from Microsoft/fixResolutionForFuncExprsClassExprsAndArguments

Fix resolution of named function & class expressions as well as 'arguments'
This commit is contained in:
Daniel Rosenwasser 2015-06-02 12:57:05 -07:00
commit d1b3ac7c12
24 changed files with 276 additions and 10 deletions

View File

@ -422,27 +422,32 @@ module ts {
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
if (name === "arguments") {
if (meaning & SymbolFlags.Variable && name === "arguments") {
result = argumentsSymbol;
break loop;
}
break;
case SyntaxKind.FunctionExpression:
if (name === "arguments") {
if (meaning & SymbolFlags.Variable && name === "arguments") {
result = argumentsSymbol;
break loop;
}
let functionName = (<FunctionExpression>location).name;
if (functionName && name === functionName.text) {
result = location.symbol;
break loop;
if (meaning & SymbolFlags.Function) {
let functionName = (<FunctionExpression>location).name;
if (functionName && name === functionName.text) {
result = location.symbol;
break loop;
}
}
break;
case SyntaxKind.ClassExpression:
let className = (<ClassExpression>location).name;
if (className && name === className.text) {
result = location.symbol;
break loop;
if (meaning & SymbolFlags.Class) {
let className = (<ClassExpression>location).name;
if (className && name === className.text) {
result = location.symbol;
break loop;
}
}
break;
case SyntaxKind.Decorator:

View File

@ -0,0 +1,14 @@
tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts(6,15): error TS9003: 'class' expressions are not currently supported.
==== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts (1 errors) ====
namespace C {
export interface type {
}
}
var x = class C {
~
!!! error TS9003: 'class' expressions are not currently supported.
prop: C.type;
}

View File

@ -0,0 +1,16 @@
//// [classExpressionWithResolutionOfNamespaceOfSameName01.ts]
namespace C {
export interface type {
}
}
var x = class C {
prop: C.type;
}
//// [classExpressionWithResolutionOfNamespaceOfSameName01.js]
var x = (function () {
function C() {
}
return C;
})();

View File

@ -0,0 +1,12 @@
//// [functionDeclarationWithResolutionOfTypeNamedArguments01.ts]
interface arguments {
}
function f() {
<arguments>arguments;
}
//// [functionDeclarationWithResolutionOfTypeNamedArguments01.js]
function f() {
arguments;
}

View File

@ -0,0 +1,12 @@
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts ===
interface arguments {
>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0))
}
function f() {
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 1, 1))
<arguments>arguments;
>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0))
>arguments : Symbol(arguments)
}

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts ===
interface arguments {
>arguments : arguments
}
function f() {
>f : () => void
<arguments>arguments;
><arguments>arguments : arguments
>arguments : arguments
>arguments : IArguments
}

View File

@ -0,0 +1,12 @@
//// [functionDeclarationWithResolutionOfTypeOfSameName01.ts]
interface f {
}
function f() {
<f>f;
}
//// [functionDeclarationWithResolutionOfTypeOfSameName01.js]
function f() {
f;
}

View File

@ -0,0 +1,12 @@
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts ===
interface f {
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
}
function f() {
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
<f>f;
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
}

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts ===
interface f {
>f : f
}
function f() {
>f : () => void
<f>f;
><f>f : f
>f : f
>f : () => void
}

View File

@ -0,0 +1,12 @@
//// [functionExpressionWithResolutionOfTypeNamedArguments01.ts]
interface arguments {
}
var x = function f() {
<arguments>arguments;
}
//// [functionExpressionWithResolutionOfTypeNamedArguments01.js]
var x = function f() {
arguments;
};

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts ===
interface arguments {
>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0))
}
var x = function f() {
>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 3))
>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 7))
<arguments>arguments;
>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0))
>arguments : Symbol(arguments)
}

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts ===
interface arguments {
>arguments : arguments
}
var x = function f() {
>x : () => void
>function f() { <arguments>arguments;} : () => void
>f : () => void
<arguments>arguments;
><arguments>arguments : arguments
>arguments : arguments
>arguments : IArguments
}

View File

@ -0,0 +1,12 @@
//// [functionExpressionWithResolutionOfTypeOfSameName01.ts]
interface f {
}
var x = function f() {
<f>f;
}
//// [functionExpressionWithResolutionOfTypeOfSameName01.js]
var x = function f() {
f;
};

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts ===
interface f {
>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0))
}
var x = function f() {
>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 3))
>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7))
<f>f;
>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0))
>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7))
}

View File

@ -0,0 +1,15 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts ===
interface f {
>f : f
}
var x = function f() {
>x : () => void
>function f() { <f>f;} : () => void
>f : () => void
<f>f;
><f>f : f
>f : f
>f : () => void
}

View File

@ -0,0 +1,12 @@
//// [functionExpressionWithResolutionOfTypeOfSameName02.ts]
interface Foo {
}
var x = function Foo() {
var x: Foo;
}
//// [functionExpressionWithResolutionOfTypeOfSameName02.js]
var x = function Foo() {
var x;
};

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts ===
interface Foo {
>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0))
}
var x = function Foo() {
>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 3))
>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 7))
var x: Foo;
>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 4, 7))
>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0))
}

View File

@ -0,0 +1,14 @@
=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts ===
interface Foo {
>Foo : Foo
}
var x = function Foo() {
>x : () => void
>function Foo() { var x: Foo;} : () => void
>Foo : () => void
var x: Foo;
>x : Foo
>Foo : Foo
}

View File

@ -0,0 +1,8 @@
namespace C {
export interface type {
}
}
var x = class C {
prop: C.type;
}

View File

@ -0,0 +1,6 @@
interface arguments {
}
function f() {
<arguments>arguments;
}

View File

@ -0,0 +1,6 @@
interface f {
}
function f() {
<f>f;
}

View File

@ -0,0 +1,6 @@
interface arguments {
}
var x = function f() {
<arguments>arguments;
}

View File

@ -0,0 +1,6 @@
interface f {
}
var x = function f() {
<f>f;
}

View File

@ -0,0 +1,6 @@
interface Foo {
}
var x = function Foo() {
var x: Foo;
}