-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Bug]: Babel produces invalid TypeScript code if comment follows type annotation and is not stripped #14751
Copy link
Copy link
Labels
area: typescripti: discussionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
export default (): void /* hi! */ => {};Configuration file name
babel.config.json
Configuration
{}Current and expected behavior
Using this test harness:
const babel = require('@babel/core');
const result = babel.transformSync("export default (): void /* hi! */ => {};", {
filename: './source.ts',
parserOpts: {
plugins: ["typescript"],
},
});
console.log(result.code);The resulting code produced by Babel looks like this:
export default ((): void
/* hi! */
=> {});This is invalid TypeScript/JavaScript as the arrow function is not allowed to have a line terminator preceding it.
Removing the comment from the source produces working output:
export default ((): void => {});Environment
System:
OS: macOS 11.6.7
Binaries:
Node: 16.15.1
Yarn: 1.22.10
npm: 8.11.0
npmPackages:
@babel/core: ^7.18.6 => 7.18.6
Possible solution
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: typescripti: discussionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: generator