Skip to content

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

Closed
@jcbhmr

Description

@jcbhmr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions