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
Update pathCache in NodePath#_replaceWith
#12391
Changes from 3 commits
8d8782a
3949b40
04d106c
9b91f0f
307b003
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const a = 1; | ||
const b = () => a?.b?.c!.d; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["transform-typescript", "proposal-optional-chaining"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const a = 1; | ||
|
||
const b = () => { | ||
var _a$b; | ||
|
||
return a === null || a === void 0 ? void 0 : (_a$b = a.b) === null || _a$b === void 0 ? void 0 : _a$b.c.d; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,14 @@ describe("conversion", function () { | |
expect(generateCode(rootPath)).toBe("() => {\n return false;\n};"); | ||
}); | ||
|
||
it("preserves arrow function body's context", function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need another test, or is this enough? (Since there is the to-do item in the PR description) I can work on it if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is copied from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Appreciated. Feel free to push 😄. I am still trying to figure out how we should test the |
||
const rootPath = getPath("() => true").get("expression"); | ||
const body = rootPath.get("body"); | ||
rootPath.ensureBlock(); | ||
body.replaceWithMultiple([t.booleanLiteral(false), t.emptyStatement()]); | ||
expect(generateCode(rootPath)).toBe("() => {\n return false;\n};"); | ||
}); | ||
|
||
it("converts for loop with statement body to block", function () { | ||
const rootPath = getPath("for (;;) true;"); | ||
rootPath.ensureBlock(); | ||
|
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.
This fix is inspired from ancestry commit that in some user cases the
pathCache
is nullish inNodePath#_replaceWith
.