💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
See REPL: https://runkit.com/alexandre-cai/60a2ae9feaab4400130133c8
transform(`
type Test = 1 | -1;
`, {
parserOpts: {
plugins: ["typescript"],
},
plugins: [
({ types: t }) => ({
visitor: {
TSLiteralType(path) {
path.node = t.tsLiteralType(path.node.literal)
}
}
}),
],
})
Configuration file name
No response
Configuration
No response
Current and expected behavior
Babel currently accepts UnaryExpression while parsing TSLiteralType, but can’t generate one. Output:
TypeError: unknown: Property literal of TSLiteralType expected node to be of a type
["NumericLiteral","StringLiteral","BooleanLiteral","BigIntLiteral"] but instead got "UnaryExpression"
Environment
Possible solution
https://github.com/babel/babel/blob/main/packages/babel-types/src/definitions/typescript.ts#L342
Add UnaryExpression.
Additional context
No response
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
See REPL: https://runkit.com/alexandre-cai/60a2ae9feaab4400130133c8
Configuration file name
No response
Configuration
No response
Current and expected behavior
Babel currently accepts UnaryExpression while parsing TSLiteralType, but can’t generate one. Output:
Environment
Possible solution
https://github.com/babel/babel/blob/main/packages/babel-types/src/definitions/typescript.ts#L342
Add
UnaryExpression.Additional context
No response