Skip to content

Commit

Permalink
Avoid terser workaround in firefox bugfix for computed keys (#16401)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 3, 2024
1 parent af4f9cd commit 0cfe039
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,8 @@ export default declare(({ types: t, traverse, assertVersion }) => {
} else {
const fn = t.arrowFunctionExpression([], path.node, context.await);

if (context.await) {
replacement = t.awaitExpression(t.callExpression(fn, []));
} else {
replacement = t.callExpression(
// We need to use fn.call() instead of just fn() because
// terser transforms (() => class {})() to class {}, effectively
// undoing the wrapping introduced by this plugin.
// https://github.com/terser/terser/issues/1514
// TODO(Babel 8): Remove .call if Terser stops inlining this case.
t.memberExpression(fn, t.identifier("call")),
[],
);
}
replacement = t.callExpression(fn, []);
if (context.await) replacement = t.awaitExpression(replacement);
}

path.replaceWith(replacement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class A {
#x = 1;
[(() => useIt([1 + class {}])).call()];
[(() => useIt([1 + class {}]))()];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class A {
#x = 1;
[(() => class {}).call()];
[(() => class {})()];
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class A {
#x;
[(() => class {}).call()];
[(() => class {})()];
[await (async () => await class {})()];
}
async function* f() {
class A {
#x;
[(() => class {}).call()];
[(() => class {})()];
[await (async () => await class {})()];
[yield* function* () {
return yield class {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new class extends babelHelpers.identity {
[_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c;
}
#x = 1;
}).call()];
})()];
#y = 2;
constructor() {
super(_A), _initClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new class extends babelHelpers.identity {
[_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c;
}
#x = 1;
}).call()];
})()];
#y = 2;
constructor() {
super(_A), _initClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new class extends babelHelpers.identity {
[_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c;
}
#x = 1;
}).call()];
})()];
#y = 2;
constructor() {
super(_A), _initClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class A {
#x;
[(() => class {}).call()];
[(() => class {})()];
}

0 comments on commit 0cfe039

Please sign in to comment.