exported name should be defined on the source file level

This commit is contained in:
Vladimir Matveev 2016-10-06 21:28:50 -07:00
parent 90b81858af
commit a31c8d5861
5 changed files with 160 additions and 1 deletions

View File

@ -2651,7 +2651,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
return false;
}
return !exportEquals && exportSpecifiers && (<Identifier>node).text in exportSpecifiers;
if (exportEquals || !exportSpecifiers || !((<Identifier>node).text in exportSpecifiers)) {
return false;
}
// check that referenced declaration is declared on source file level
const declaration = resolver.getReferencedValueDeclaration(<Identifier>node);
return declaration && getEnclosingBlockScopeContainer(declaration).kind === SyntaxKind.SourceFile;
}
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {

View File

@ -0,0 +1,40 @@
//// [localNameThatMatchExportedNameViaExportDeclaration.ts]
export { my }
var my: any;
my += my;
function doSome1(my: any) {
my = +my;
return my;
}
function doSome2() {
const internal = (my: any) => {
my = +my;
return my;
};
return internal("1");
}
//// [localNameThatMatchExportedNameViaExportDeclaration.js]
define(["require", "exports"], function (require, exports) {
"use strict";
var my;
exports.my = my;
exports.my = my += my;
function doSome1(my) {
my = +my;
return my;
}
function doSome2() {
var internal = function (my) {
my = +my;
return my;
};
return internal("1");
}
});

View File

@ -0,0 +1,43 @@
=== tests/cases/compiler/localNameThatMatchExportedNameViaExportDeclaration.ts ===
export { my }
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 1, 8))
var my: any;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
my += my;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 3, 3))
function doSome1(my: any) {
>doSome1 : Symbol(doSome1, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 5, 9))
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
my = +my;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
return my;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 7, 17))
}
function doSome2() {
>doSome2 : Symbol(doSome2, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 10, 1))
const internal = (my: any) => {
>internal : Symbol(internal, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 9))
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
my = +my;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
return my;
>my : Symbol(my, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 22))
};
return internal("1");
>internal : Symbol(internal, Decl(localNameThatMatchExportedNameViaExportDeclaration.ts, 13, 9))
}

View File

@ -0,0 +1,51 @@
=== tests/cases/compiler/localNameThatMatchExportedNameViaExportDeclaration.ts ===
export { my }
>my : any
var my: any;
>my : any
my += my;
>my += my : any
>my : any
>my : any
function doSome1(my: any) {
>doSome1 : (my: any) => any
>my : any
my = +my;
>my = +my : number
>my : any
>+my : number
>my : any
return my;
>my : any
}
function doSome2() {
>doSome2 : () => any
const internal = (my: any) => {
>internal : (my: any) => any
>(my: any) => { my = +my; return my; } : (my: any) => any
>my : any
my = +my;
>my = +my : number
>my : any
>+my : number
>my : any
return my;
>my : any
};
return internal("1");
>internal("1") : any
>internal : (my: any) => any
>"1" : string
}

View File

@ -0,0 +1,20 @@
// @module: amd
export { my }
var my: any;
my += my;
function doSome1(my: any) {
my = +my;
return my;
}
function doSome2() {
const internal = (my: any) => {
my = +my;
return my;
};
return internal("1");
}