-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
outdatedA 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: template
Description
Bug Report
Current Behavior
A @babel/template template with placeholders and a type annotation generates code without the annotation. A template without placeholders works as expected.
Input Code
const template = require('@babel/template').default
const generate = require('@babel/generator').default
const t = require('@babel/types')
const withType = template({plugins:['typescript']}).ast`
const greeting: string = 'Hello';
`
console.log(generate(withType).code)
// => "const greeting: string = 'Hello';"
const typeDisappears = template({plugins:['typescript']}).ast`
const ${t.identifier('greeting')}: string = 'Hello';
`
console.log(generate(typeDisappears).code)
// => "const greeting = 'Hello';"Expected behavior/code
I expect both templates above to keep the : string type in the generated code.
Babel Configuration (.babelrc, package.json, cli command)
No configuration, used from code, see above.
Environment
- Babel version(s): 7.6.4
- Node/npm version: Node 12.9.1 / yarn 1.17.3
- Monorepo: no
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
outdatedA 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: template