Skip to content
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

ES6 modules default exported function/class/generator name is not declared #5447

Closed
falsandtru opened this issue Oct 29, 2015 · 8 comments · Fixed by #5588
Closed

ES6 modules default exported function/class/generator name is not declared #5447

falsandtru opened this issue Oct 29, 2015 · 8 comments · Fixed by #5588
Assignees
Labels
Bug A bug in TypeScript ES6 Relates to the ES6 Spec Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

// function
export default function foo() {
}
export {foo}; // hello.ts(3,9): error TS2304: Cannot find name 'foo'.

// generator
export default function *foo() {
}
export {foo}; // hello.ts(3,9): error TS2304: Cannot find name 'foo'.

// class
export default class Foo {
}
export {Foo}; // hello.ts(3,9): error TS2304: Cannot find name 'Foo'.
// hoistable
export {foo}; // hello.ts(1,9): error TS2304: Cannot find name 'foo'.
export default function foo() {
}

http://www.ecma-international.org/ecma-262/6.0/#sec-source-text-module-records
http://www.ecma-international.org/ecma-262/6.0/#table-42

@falsandtru falsandtru changed the title ES6 modules default exported function/class identity is not declared ES6 modules default exported function/class/generator identity is not declared Oct 29, 2015
@mhegazy mhegazy added Bug A bug in TypeScript ES6 Relates to the ES6 Spec labels Oct 29, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Oct 29, 2015
@falsandtru falsandtru changed the title ES6 modules default exported function/class/generator identity is not declared ES6 modules default exported function/class/generator name is not declared Nov 3, 2015
@WangJi
Copy link

WangJi commented Nov 9, 2015

is this fixed in 1.8?

@sandersn
Copy link
Member

sandersn commented Nov 9, 2015

Not yet. I haven't had a chance to look at it.

@sandersn
Copy link
Member

It looks like an earlier fix (41e3973) prevents exported identifiers from being available to namespaces that have merged with the module in question. It doesn't take into account that default actually does introduce a local name.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 11, 2015

@WangJi and @falsandtru can you give tonight's typescript@next a try.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 11, 2015
@WangJi
Copy link

WangJi commented Nov 12, 2015

Tried on Version 1.8.0-dev.20151112, still got the same warning.
And

export default class Foo{
}

is complied into

exports.Foo = Foo; //instead of default

@sandersn
Copy link
Member

This bug fix indeed only fixes the name resolution, not the emit. Although the emit is wrong for classes but not functions. I'll open a separate bug for the incorrect emit.

@sandersn
Copy link
Member

And it only happens when the target is ES6, not ES5.

@sandersn
Copy link
Member

Turns out the bug is already known: #5594

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript ES6 Relates to the ES6 Spec Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants