fix: Props are lost when the template replaces the node#15286
fix: Props are lost when the template replaces the node#15286nicolo-ribaudo merged 3 commits intobabel:mainfrom
Conversation
| items[index] = replacement; | ||
| assignOrSet(items, index, replacement); | ||
| } | ||
| } else { | ||
| items[index] = replacement; | ||
| assignOrSet(items, index, replacement); |
There was a problem hiding this comment.
I didn't find a test example for these two cases.😞
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57432 |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
I would prefer to explicitly special-case identifiers: if parent[key].type === "Identifier" && parent[key].typeAnnotation && !replacement.typeAnnotation, we clone replacement and set its .typeAnnotation to parent[key].typeAnnotation.
|
I'm a little concerned that there will be cases other than the example. |
|
The replaced node is always an identifier, because it's what we use as placeholder in templates. However you are right, there are multiple possible properties:
Some tests cases: template.statement.ast`
var ${t.objectPattern([])}: string = x;
`
template.statement.ast`
class X {
f(@dec ${t.identifier("x")}) {}
}
`;
template.statement.ast`
function f(${t.identifier("x")}?) {}
`
template.statement.ast`
function f(${ Object.assign(t.identifier("x"), { optional: true }) }: string) {}
`
template.statement.ast`
class X {
f(@dec ${ Object.assign(t.identifier("x"), { optional: true }) }) {}
}
`
// This should probably throw?
const typeAnotation = t.tsTypeAnnotation(t.tsStringKeyword());
template.statement.ast`
function f(${ Object.assign(t.identifier("x"), { typeAnnotation }) }: number) {}
` |
245a51e to
f53b8e7
Compare
|
Sorry forgot about this! Updated. |
Uh oh!
There was an error while loading. Please reload this page.