-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Bug]: parse return type with comments fail with @babel/generator #14809
Copy link
Copy link
Closed
Labels
area: typescripti: regressionoutdatedA 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?
Vite
Input code
const test = (): {
// test
foo: string;
} => {
return {
foo: "bar",
};
};
export default test;Configuration file name
.babelrc
Configuration
{
"parserOpts": {
"plugins": ["typescript"]
}
}Current and expected behavior
Throw error with @babel/generator@7.18.9(latest):
TypeError: /tmp/reproduce/test.ts: Cannot read properties of undefined (reading 'charCodeAt')
at Generator._append (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:210:27)
at Buffer.withSource (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/buffer.js:291:28)
at Generator.withSource (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:196:15)
at Generator._printComment (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:566:10)
at Generator._printComments (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:577:14)
at Generator._printLeadingComments (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:473:10)
at Generator.print (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/printer.js:369:10)
at tsPrintBraced (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/generators/typescript.js:386:15)
at Generator.tsPrintTypeLiteralOrInterfaceBody (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/generators/typescript.js:375:3)
at Generator.TSTypeLiteral (/tmp/reproduce/node_modules/.pnpm/@babel+generator@7.18.9/node_modules/@babel/generator/lib/generators/typescript.js:371:8) {
code: 'BABEL_GENERATE_ERROR'
}
Works with @babel/generator@7.18.7:
const test = (): {
// test
foo: string;
} => {
return {
foo: "bar"
};
};
export default test;
Environment
System:
OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
Binaries:
Node: 18.4.0 - ~/.nvm/versions/node/v18.4.0/bin/node
npm: 8.13.2 - ~/.nvm/versions/node/v18.4.0/bin/npm
npmPackages:
@babel/cli: ^7.18.9 => 7.18.9
@babel/core: ^7.18.9 => 7.18.9
Possible solution
No response
Additional context
I found this issue from @vitejs/plugin-react and I used npm pnpm overrides / yarn resolutions as workaround:
{
"pnpm": {
"overrides": {
"@babel/generator": "7.18.7"
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: typescripti: regressionoutdatedA 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