Skip to content

Commit d1b3ac7

Browse files
Merge pull request #3288 from Microsoft/fixResolutionForFuncExprsClassExprsAndArguments
Fix resolution of named function & class expressions as well as 'arguments'
2 parents 5b94e40 + acbff90 commit d1b3ac7

24 files changed

+276
-10
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,32 @@ module ts {
422422
case SyntaxKind.SetAccessor:
423423
case SyntaxKind.FunctionDeclaration:
424424
case SyntaxKind.ArrowFunction:
425-
if (name === "arguments") {
425+
if (meaning & SymbolFlags.Variable && name === "arguments") {
426426
result = argumentsSymbol;
427427
break loop;
428428
}
429429
break;
430430
case SyntaxKind.FunctionExpression:
431-
if (name === "arguments") {
431+
if (meaning & SymbolFlags.Variable && name === "arguments") {
432432
result = argumentsSymbol;
433433
break loop;
434434
}
435-
let functionName = (<FunctionExpression>location).name;
436-
if (functionName && name === functionName.text) {
437-
result = location.symbol;
438-
break loop;
435+
436+
if (meaning & SymbolFlags.Function) {
437+
let functionName = (<FunctionExpression>location).name;
438+
if (functionName && name === functionName.text) {
439+
result = location.symbol;
440+
break loop;
441+
}
439442
}
440443
break;
441444
case SyntaxKind.ClassExpression:
442-
let className = (<ClassExpression>location).name;
443-
if (className && name === className.text) {
444-
result = location.symbol;
445-
break loop;
445+
if (meaning & SymbolFlags.Class) {
446+
let className = (<ClassExpression>location).name;
447+
if (className && name === className.text) {
448+
result = location.symbol;
449+
break loop;
450+
}
446451
}
447452
break;
448453
case SyntaxKind.Decorator:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts(6,15): error TS9003: 'class' expressions are not currently supported.
2+
3+
4+
==== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts (1 errors) ====
5+
namespace C {
6+
export interface type {
7+
}
8+
}
9+
10+
var x = class C {
11+
~
12+
!!! error TS9003: 'class' expressions are not currently supported.
13+
prop: C.type;
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [classExpressionWithResolutionOfNamespaceOfSameName01.ts]
2+
namespace C {
3+
export interface type {
4+
}
5+
}
6+
7+
var x = class C {
8+
prop: C.type;
9+
}
10+
11+
//// [classExpressionWithResolutionOfNamespaceOfSameName01.js]
12+
var x = (function () {
13+
function C() {
14+
}
15+
return C;
16+
})();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [functionDeclarationWithResolutionOfTypeNamedArguments01.ts]
2+
interface arguments {
3+
}
4+
5+
function f() {
6+
<arguments>arguments;
7+
}
8+
9+
//// [functionDeclarationWithResolutionOfTypeNamedArguments01.js]
10+
function f() {
11+
arguments;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts ===
2+
interface arguments {
3+
>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0))
4+
}
5+
6+
function f() {
7+
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 1, 1))
8+
9+
<arguments>arguments;
10+
>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0))
11+
>arguments : Symbol(arguments)
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts ===
2+
interface arguments {
3+
>arguments : arguments
4+
}
5+
6+
function f() {
7+
>f : () => void
8+
9+
<arguments>arguments;
10+
><arguments>arguments : arguments
11+
>arguments : arguments
12+
>arguments : IArguments
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [functionDeclarationWithResolutionOfTypeOfSameName01.ts]
2+
interface f {
3+
}
4+
5+
function f() {
6+
<f>f;
7+
}
8+
9+
//// [functionDeclarationWithResolutionOfTypeOfSameName01.js]
10+
function f() {
11+
f;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts ===
2+
interface f {
3+
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
4+
}
5+
6+
function f() {
7+
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
8+
9+
<f>f;
10+
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
11+
>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1))
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts ===
2+
interface f {
3+
>f : f
4+
}
5+
6+
function f() {
7+
>f : () => void
8+
9+
<f>f;
10+
><f>f : f
11+
>f : f
12+
>f : () => void
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [functionExpressionWithResolutionOfTypeNamedArguments01.ts]
2+
interface arguments {
3+
}
4+
5+
var x = function f() {
6+
<arguments>arguments;
7+
}
8+
9+
//// [functionExpressionWithResolutionOfTypeNamedArguments01.js]
10+
var x = function f() {
11+
arguments;
12+
};

0 commit comments

Comments
 (0)