Skip to content

Commit f634529

Browse files
fix(javascript): annotate a chain's member link only where the chain ends there
Marking every link, as the commit before this did, mangles a property terser keeps: `/*@__MANGLE_PROP__*/ this.keepthis.manglethis` is one mark on the last link, because terser's parser annotates a `.` or `[…]` link by annotating whatever the rest of the chain returns. A call annotates itself, so it keeps its own mark, and a link built over a member takes that member's. terser also marks the chain wrapper of `this.a?.b.c`, which is left as it is: nothing reads an annotation there, and the output of each optional-chain shape is byte for byte terser's either way.
1 parent 0e7aaf3 commit f634529

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14647,6 +14647,13 @@ const installEstree = (modules) => {
1464714647
for (const [pattern, annotation] of ANNOTATIONS) {
1464814648
if (!pattern.test(value)) continue;
1464914649
node._annotations |= annotation;
14650+
// WHY: terser's parser annotates a `.` or `[…]` link by annotating
14651+
// whatever the rest of the chain returns, so such a link holds the mark
14652+
// only where the chain ends there, while every call annotates itself.
14653+
const inner = node.expression;
14654+
if (inner instanceof AST_PropAccess && inner.start === token) {
14655+
inner._annotations &= ~annotation;
14656+
}
1465014657
return;
1465114658
}
1465214659
}

0 commit comments

Comments
 (0)