[Babel 8] Create TSTemplateLiteralType#17066
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58621 |
| rm tests/format/typescript/typeparams/consistent/format.test.js | ||
| rm tests/format/typescript/template-literal-types/format.test.js | ||
| rm tests/format/typescript/method/format.test.js | ||
| rm tests/format/typescript/argument-expansion/format.test.js |
There was a problem hiding this comment.
/cc @fisker These tests are affected by this breaking change.
877427a to
5400a2d
Compare
| export interface TsTemplateLiteralType extends TsTypeBase { | ||
| type: "TSTemplateLiteralType"; | ||
| quasis: TemplateElement[]; | ||
| expressions: TsType[]; |
There was a problem hiding this comment.
I overlooked that TSTemplateLiteralType uses types here. I will update the AST and the generator methods.
a5010ee to
cd7b11e
Compare
Since the generator requires the types information
| export function TSTemplateLiteralType( | ||
| this: Printer, | ||
| node: t.TSTemplateLiteralType, | ||
| ) { | ||
| const quasis = node.quasis; | ||
|
|
||
| let partRaw = "`"; | ||
|
|
||
| for (let i = 0; i < quasis.length; i++) { | ||
| partRaw += quasis[i].value.raw; | ||
|
|
||
| if (i + 1 < quasis.length) { | ||
| this.token(partRaw + "${", true); | ||
| this.print(node.types[i]); | ||
| partRaw = "}"; | ||
| } | ||
| } | ||
|
|
||
| this.token(partRaw + "`", true); | ||
| } |
There was a problem hiding this comment.
We can extract this to a function _printTemplate(quasis, substitutions), so that we don't have to keep the same logic in two different printers.
|
Pushed a ranges fix in the |
|
Good question. Yes it can still contain a |
* breaking: create TSTemplateLiteralType * update test fixtures * ignore TSTemplateLiteralType in printer test * purge failing prettier tests * rename expressions to types * fix: generate TSLiteralType when the template does not contain types * restore template literals transform * update test fixtures * define TSTemplateLiteralType for Babel 7 Since the generator requires the types information * refactor: extract _printTemplate helper * Apply template literal range fixes to TSTemplateLiteralType


In this PR, we generate the
TSTemplateLiteralTypeAST node when there is at least onetypeelement (${...}) within the template.