Skip to content

exported name should be defined on the source file level #11438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
});
Original file line number Diff line number Diff line change
@@ -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))
}

Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
@@ -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");
}