-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Props are lost when the template replaces the node #15286
fix: Props are lost when the template replaces the node #15286
Conversation
liuxingbaoyu
commented
Dec 16, 2022
•
edited by gitpod-io
bot
Loading
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #10636 |
Patch: Bug Fix? | √ |
Major: Breaking Change? | ? |
Minor: New Feature? | |
Tests Added + Pass? | √ |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
items[index] = replacement; | ||
assignOrSet(items, index, replacement); | ||
} | ||
} else { | ||
items[index] = replacement; | ||
assignOrSet(items, index, replacement); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |