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

export { a as "hello world" } is valid JavaScript but invalid TypeScript #54584

Closed
jcbhmr opened this issue Jun 9, 2023 · 2 comments Β· Fixed by #58640
Closed

export { a as "hello world" } is valid JavaScript but invalid TypeScript #54584

jcbhmr opened this issue Jun 9, 2023 · 2 comments Β· Fixed by #58640
Labels
Fix Available A PR has been opened for this issue

Comments

@jcbhmr
Copy link

jcbhmr commented Jun 9, 2023

Bug Report

πŸ”Ž Search Terms

"es2020"
"export as string"
"import as string export as string"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "exports"

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// This typescript code...
const a = 34;
export { a as "hello world" };

πŸ™ Actual behavior

// ...generates this invalid JavaScript code.
const a = 34;
export { a as  } from "hello world";
;

The input was valid JavaScript so I would expect (intuitively) for it to be valid TypeScript. This is currently not the case.

πŸ™‚ Expected behavior

// I expected this JavaScript code to be generted:
const a = 34;
export { a as "hello world" };

Current behavior in browsers and Node.js works with this syntax!

// But running this in the DevTools or Node.js REPL works just fine.
await import("data:text/javascript," + encodeURIComponent(`
const a = 34;
export { a as "hello world" };
`))

image
image

JavaScript seems to allow strings as import/export names:

import { "hello world" as a } from "./hello.js"
export { a as "hello world" };

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#syntax
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#syntax

@Josh-Cena
Copy link
Contributor

Duplicate of #40594

@jcbhmr
Copy link
Author

jcbhmr commented Jun 9, 2023

Oops! I didn't search thoroughly enough. πŸ€¦β€β™‚οΈ

@jcbhmr jcbhmr closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants