💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
import { transformFromAstSync } from '@babel/core';
import * as t from '@babel/types';
const { code } = transformFromAstSync(
t.program([
t.expressionStatement(
t.templateLiteral(
[t.templateElement({ raw: 'leading' }), t.templateElement({ raw: 'trailing' }, true)],
[t.identifier('identifier')]
)
),
]),
'',
{ plugins: ['@babel/plugin-transform-template-literals'] }
);
console.log(code);
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current output:
Expected output:
"leading".concat(identifier, "trailing");
Environment
- Babel
7.18.5
- Node
16.15.1
Possible solution
No response
Additional context
- The
cooked property is marked as optional, so I would expect it not to matter (e.g. match raw) if omitted.
- With
@babel/plugin-transform-template-literals disabled, I get the expected result `leading${identifier}trailing`.
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current output:
Expected output:
Environment
7.18.516.15.1Possible solution
No response
Additional context
cookedproperty is marked as optional, so I would expect it not to matter (e.g. matchraw) if omitted.@babel/plugin-transform-template-literalsdisabled, I get the expected result`leading${identifier}trailing`.