Skip to content

Commit 31062ab

Browse files
fix(javascript): still flatten a constant read off an object literal and called in the minifier
Claude-Session: https://claude.ai/code/session_01UgQAw35dRJd9GKMF9p5CcQ
1 parent 9337971 commit 31062ab

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16866,9 +16866,11 @@ const installCorrect = (modules) => {
1686616866
}
1686716867
const value = flattened.object.elements[flattened.property.value];
1686816868
const fixed = A.isSymbolRefNode(value) ? ast.fixedValue(value) : value;
16869+
// Calling a constant throws whatever `this` is.
1686916870
return fixed &&
16870-
A.isLambdaNode(fixed) &&
16871-
(A.isArrowNode(fixed) || !ast.containsThis(fixed))
16871+
(A.isConstantNode(fixed) ||
16872+
(A.isLambdaNode(fixed) &&
16873+
(A.isArrowNode(fixed) || !ast.containsThis(fixed))))
1687216874
? flattened
1687316875
: undefined;
1687416876
};

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,10 @@ const RESERVED_NAME_CASES = [
25872587
// that would write it where it is a keyword.
25882588
/** @type {[string, string][]} */
25892589
const STILL_INLINED_CASES = [
2590+
[
2591+
"a constant read off an object literal and called, which throws whatever `this` is",
2592+
"try { ({ x: null }).x(); } catch (e) { sink(e.name); } try { ({ x: 1 })['x'](); } catch (e) { sink(e.name); }"
2593+
],
25902594
[
25912595
"a nested function keeping its own context",
25922596
"var await; async function f() { function g() { sink(function () { await = 1; }); } g(); } f();"

0 commit comments

Comments
 (0)