-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support “Arbitrary module namespace identifier names” #40594
Comments
Note that Babel now has support for this: babel/babel#12091 |
import { "😊" as yay } from "...";
yay();
export { yay as "🦈" }; The above code should be supported. The minimum viable product should have tests for:
It is likely that we would never try to emit our own |
Is it planned for this to work with TypeScript types as well as values? For example, I'd expect the following to be valid as well: import type { 'a' as b } from 'foo'
import { type 'a' as b } from 'foo'
export type { a as 'b' }
export { type a as 'b' }
export { type 'a' } from 'foo'
export { type 'a' as b } from 'foo'
export { type a as 'b' } from 'foo'
export { type 'a' as 'b' } from 'foo' I'm wondering because esbuild supports both TypeScript and arbitrary module namespace identifier names, so it has to deal with this somehow. Right now I'm moving forward assuming that it will eventually be supported for types as well but it would be good to clarify this. |
@evanw I’m pretty sure your examples above will “just work” unless we explicitly disallow them, and I don’t see an immediate reason to do that. The syntax above would certainly parse. Just out of curiosity, what’s the impact of this on esbuild? |
@DanielRosenwasser should this actually be milestoned right now? It’s a bit hard to tell the status of the spec change, but it looks kinda stuck. |
Good call, I assumed it would be an open-and-shut normative PR but it looks like it hasn't been updated for a while; let's hold off until tc39/ecma262#2154 is actually merged. |
This prepares the ground for when TypeScript will have support for "Arbitrary module namespace identifier names": microsoft/TypeScript#40594
* fix: invalid names in import object This prepares the ground for when TypeScript will have support for "Arbitrary module namespace identifier names": microsoft/TypeScript#40594 * chore: define import object as interface and not namespace --------- Co-authored-by: Eduardo Rodrigues <eduardomourar@users.noreply.github.com> Co-authored-by: Guy Bedford <gbedford@fastly.com>
Some progress: I recently rewrite PR for this issue. I also plan to include full support (checker, transpiler, and language service). I'm still working on it. |
BREAKING CHANGE: Updates the declaration template. This is a followup on seek-oss#38 The `exports =` declaration was added in e7342df but removed in 908d491 due some issue in babel which I can't reproduce. Maybe that has been fixed downstream in the meantime. Due to microsoft/TypeScript#40594 we cannot export these names directly since class names might not be valid JavaScript identifiers, even though they are valid exported names. When that TypeScript bug is resolved this can be changed to export the names directly instead of using `export =`. The problem with `export =` is that it will let you do `import * as css from ...` in addition to `import css from ...` even though only `import *` will work.
(For those on this thread) I gave fixing this a try: #58640 |
I'm happy to see you pick this up! My mental health does not support me finishing my PR for now but I still want to see this happen |
Thanks @evanw! |
Thank you for accepting this PR. I'm looking forward to using this feature in VSCode! One potential remaining task is syntax highlighting. I have another PR ready to go that adds support for this feature to the TypeScript language syntax definition: microsoft/TypeScript-TmLanguage#1030. Would it be possible to add that or a similar change (doesn't have to be mine) so that syntax highlighting works too? |
Search Terms
Suggestion
Implement support for tc39/ecma262#2154.
Use Cases
This is necessary for WASM module integration.
This would also allow typing
@types/webidl‑conversions
without needing to useexport =
.For transpiled modules, this can already be supported, since it’s just creation of arbitrary properties on the CommonJS
exports
object, but native modules will requiremodule: "ESNext"
.Examples
See tc39/ecma262#2154
Workbench Repro
Checklist
My suggestion meets these guidelines:
Related issues
The text was updated successfully, but these errors were encountered: