Skip to content

Commit ca8057e

Browse files
authored
Merge pull request #11438 from Microsoft/vladima/fix-11204
exported name should be defined on the source file level
2 parents 90b8185 + a31c8d5 commit ca8057e

5 files changed

+160
-1
lines changed

src/compiler/emitter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26512651
return false;
26522652
}
26532653

2654-
return !exportEquals && exportSpecifiers && (<Identifier>node).text in exportSpecifiers;
2654+
if (exportEquals || !exportSpecifiers || !((<Identifier>node).text in exportSpecifiers)) {
2655+
return false;
2656+
}
2657+
// check that referenced declaration is declared on source file level
2658+
const declaration = resolver.getReferencedValueDeclaration(<Identifier>node);
2659+
return declaration && getEnclosingBlockScopeContainer(declaration).kind === SyntaxKind.SourceFile;
26552660
}
26562661

26572662
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//// [localNameThatMatchExportedNameViaExportDeclaration.ts]
2+
3+
export { my }
4+
5+
var my: any;
6+
7+
my += my;
8+
9+
function doSome1(my: any) {
10+
my = +my;
11+
return my;
12+
}
13+
14+
function doSome2() {
15+
const internal = (my: any) => {
16+
my = +my;
17+
return my;
18+
};
19+
return internal("1");
20+
}
21+
22+
23+
//// [localNameThatMatchExportedNameViaExportDeclaration.js]
24+
define(["require", "exports"], function (require, exports) {
25+
"use strict";
26+
var my;
27+
exports.my = my;
28+
exports.my = my += my;
29+
function doSome1(my) {
30+
my = +my;
31+
return my;
32+
}
33+
function doSome2() {
34+
var internal = function (my) {
35+
my = +my;
36+
return my;
37+
};
38+
return internal("1");
39+
}
40+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== tests/cases/compiler/localNameThatMatchExportedNameViaExportDeclaration.ts ===
2+
3+
export { my }
4+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 1, 8))
5+
6+
var my: any;
7+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
8+
9+
my += my;
10+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
11+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
12+
13+
function doSome1(my: any) {
14+
>doSome1 : Symbol(doSome1, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 5, 9))
15+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
16+
17+
my = +my;
18+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
19+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
20+
21+
return my;
22+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
23+
}
24+
25+
function doSome2() {
26+
>doSome2 : Symbol(doSome2, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 10, 1))
27+
28+
const internal = (my: any) => {
29+
>internal : Symbol(internal, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 9))
30+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
31+
32+
my = +my;
33+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
34+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
35+
36+
return my;
37+
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
38+
39+
};
40+
return internal("1");
41+
>internal : Symbol(internal, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 9))
42+
}
43+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/compiler/localNameThatMatchExportedNameViaExportDeclaration.ts ===
2+
3+
export { my }
4+
>my : any
5+
6+
var my: any;
7+
>my : any
8+
9+
my += my;
10+
>my += my : any
11+
>my : any
12+
>my : any
13+
14+
function doSome1(my: any) {
15+
>doSome1 : (my: any) => any
16+
>my : any
17+
18+
my = +my;
19+
>my = +my : number
20+
>my : any
21+
>+my : number
22+
>my : any
23+
24+
return my;
25+
>my : any
26+
}
27+
28+
function doSome2() {
29+
>doSome2 : () => any
30+
31+
const internal = (my: any) => {
32+
>internal : (my: any) => any
33+
>(my: any) => { my = +my; return my; } : (my: any) => any
34+
>my : any
35+
36+
my = +my;
37+
>my = +my : number
38+
>my : any
39+
>+my : number
40+
>my : any
41+
42+
return my;
43+
>my : any
44+
45+
};
46+
return internal("1");
47+
>internal("1") : any
48+
>internal : (my: any) => any
49+
>"1" : string
50+
}
51+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @module: amd
2+
3+
export { my }
4+
5+
var my: any;
6+
7+
my += my;
8+
9+
function doSome1(my: any) {
10+
my = +my;
11+
return my;
12+
}
13+
14+
function doSome2() {
15+
const internal = (my: any) => {
16+
my = +my;
17+
return my;
18+
};
19+
return internal("1");
20+
}

0 commit comments

Comments
 (0)