Closed
Description
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" };
`))
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