@@ -3987,6 +3987,31 @@ const lambdaModifiers = (func) =>
39873987 */
39883988const staticSize = (isStatic) => (isStatic ? 7 : 0);
39893989
3990+ /**
3991+ * Whether a destructuring pattern writes an expression: its element,
3992+ * property value, rest or defaulted target.
3993+ * @param {Node} self the expression
3994+ * @param {Compressor} compressor the compressor, `self`'s parent first
3995+ * @param {TerserAst} ast the node kinds
3996+ * @returns {boolean} true when a pattern writes it
3997+ */
3998+ const isPatternTarget = (self, compressor, ast) => {
3999+ /** @type {Node | NodeShape} */
4000+ let node = self;
4001+ let level = 0;
4002+ let parent = compressor.parent(level);
4003+ while (
4004+ parent &&
4005+ ((ast.isObjectPropertyNode(parent) && parent.value === node) ||
4006+ ast.isExpansionNode(parent) ||
4007+ (ast.isDefaultAssignNode(parent) && parent.left === node))
4008+ ) {
4009+ node = parent;
4010+ parent = compressor.parent(++level);
4011+ }
4012+ return Boolean(parent) && ast.isDestructuringNode(parent);
4013+ };
4014+
39904015/**
39914016 * terser's `first_in_statement`: whether the node a walk is at is the first
39924017 * thing its statement prints, so an object or function there needs parentheses.
@@ -24090,7 +24115,8 @@ const installImprove = (modules) => {
2409024115 node.optional ||
2409124116 node.property.name !== "source" ||
2409224117 !A.isRegExpNode(node.object) ||
24093- isLhs(node, compressor.parent()) ||
24118+ isLhs(compressor.self(), compressor.parent()) ||
24119+ isPatternTarget(compressor.self(), compressor, A) ||
2409424120 !compressor.option("evaluate")
2409524121 ) {
2409624122 return undefined;
@@ -31349,16 +31375,12 @@ const installImprove = (modules) => {
3134931375 !Number.isInteger(index) ||
3135031376 index < 0 ||
3135131377 index >= object.elements.length ||
31352- isLhs(self, parent) ||
31378+ isLhs(compressor.self(), parent) ||
31379+ isPatternTarget(compressor.self(), compressor, A) ||
3135331380 (A.isUnaryPrefixNode(parent) && parent.operator === "delete") ||
3135431381 // Called, it reads the array as its `this`.
3135531382 (A.isCallNode(parent) && parent.callee === self) ||
31356- A.isPrefixedTemplateStringNode(parent) ||
31357- (A.isForInNode(parent) && parent.left === self) ||
31358- A.isDestructuringNode(parent) ||
31359- A.isDefaultAssignNode(parent) ||
31360- (A.isObjectKeyValNode(parent) &&
31361- A.isDestructuringNode(compressor.parent(1)))
31383+ A.isPrefixedTemplateStringNode(parent)
3136231384 ) {
3136331385 return undefined;
3136431386 }
@@ -43547,30 +43569,6 @@ const installValueOptimizers = (modules, helpers) => {
4354743569 );
4354843570 };
4354943571
43550- /**
43551- * Whether a destructuring pattern writes a name: its element, property
43552- * value, rest or defaulted target, which `void 0` cannot stand for.
43553- * @param {Node} self the name
43554- * @param {Compressor} compressor the compressor, `self`'s parent first
43555- * @returns {boolean} true when a pattern writes it
43556- */
43557- const isPatternTarget = (self, compressor) => {
43558- /** @type {Node | NodeShape} */
43559- let node = self;
43560- let level = 0;
43561- let parent = compressor.parent(level);
43562- while (
43563- parent &&
43564- ((A.isObjectPropertyNode(parent) && parent.value === node) ||
43565- A.isExpansionNode(parent) ||
43566- (A.isDefaultAssignNode(parent) && parent.left === node))
43567- ) {
43568- node = parent;
43569- parent = compressor.parent(++level);
43570- }
43571- return Boolean(parent) && A.isDestructuringNode(parent);
43572- };
43573-
4357443572 defineOptimizer("SymbolRef", (self, compressor) => {
4357543573 if (
4357643574 !compressor.option("ie8") &&
@@ -43579,7 +43577,7 @@ const installValueOptimizers = (modules, helpers) => {
4357943577 !(
4358043578 modules.corrections !== undefined &&
4358143579 modules.corrections.enabled &&
43582- isPatternTarget(self, compressor)
43580+ isPatternTarget(self, compressor, A )
4358343581 )
4358443582 ) {
4358543583 switch (self.name) {
0 commit comments