polish: skip creating extra reference for safely re-used node (#10720)
* polish: skip creating extra reference for safely re-used node * reimplement using scope.maybeGenerateMemoised
This commit is contained in:
parent
d56911b88d
commit
6c7f8291d4
@ -16,14 +16,15 @@ export default declare((api, { loose = false }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ref = scope.generateUidIdentifierBasedOnNode(node.left);
|
let ref = scope.maybeGenerateMemoised(node.left);
|
||||||
scope.push({ id: ref });
|
let assignment;
|
||||||
|
// skip creating extra reference when `left` is static
|
||||||
const assignment = t.assignmentExpression(
|
if (ref === null) {
|
||||||
"=",
|
ref = node.left;
|
||||||
t.cloneNode(ref),
|
assignment = t.cloneNode(node.left);
|
||||||
node.left,
|
} else {
|
||||||
);
|
assignment = t.assignmentExpression("=", ref, node.left);
|
||||||
|
}
|
||||||
|
|
||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
t.conditionalExpression(
|
t.conditionalExpression(
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
function foo(foo, bar = foo ?? "bar") {}
|
function foo(foo, qux = foo.bar ?? "qux") {}
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
function foo(foo, bar = (_foo = foo) !== null && _foo !== void 0 ? _foo : "bar") {
|
function foo(foo, qux = (_foo$bar = foo.bar) !== null && _foo$bar !== void 0 ? _foo$bar : "qux") {
|
||||||
var _foo;
|
var _foo$bar;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
function foo(foo, bar = foo ?? "bar") {}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["proposal-nullish-coalescing-operator"]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
function foo(foo, bar = foo !== null && foo !== void 0 ? foo : "bar") {}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
function foo() {
|
||||||
|
var foo = this ?? {};
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["proposal-nullish-coalescing-operator"]
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
function foo() {
|
||||||
|
var foo = this !== null && this !== void 0 ? this : {};
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user