Skip to content

Commit af380a4

Browse files
committed
fix(compiler): detect hidden ref dependency in assignment destructuring
Assignment destructuring like `({ current } = ref)` was not detected as a hidden dependency in effect setup, unlike the equivalent variable declarator `const { current } = ref`. Two gaps: 1. In classify (strong-effects.js), AssignmentExpression with an ObjectPattern left side fell through to escaped, making isValueRef return false. 2. In the AssignmentExpression visitor (strong-mode.js), the ObjectPattern branch did not check for hidden ref dependencies the way bindDeclaration does for VariableDeclarator. Add an AssignmentExpression case to classify that returns early (no escape) when the left side is an ObjectPattern, and mirror bindDeclaration's hiddenDependency check in the AssignmentExpression handler.
1 parent af3044c commit af380a4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎packages/octane/src/compiler/strong-effects.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
802802
if (parent.id === child || parent.id?.type === 'ObjectPattern') return;
803803
if (references.declarations.has(parent.id)) return;
804804
break;
805+
case 'AssignmentExpression':
806+
if (parent.left?.type === 'ObjectPattern') return;
807+
break;
805808
case 'LabeledStatement':
806809
case 'BreakStatement':
807810
case 'ContinueStatement':

‎packages/octane/src/compiler/strong-mode.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,6 +5218,20 @@ export function analyzeStrongMode(ast, source, filename, options = {}) {
52185218
case 'AssignmentExpression': {
52195219
if (node.left?.type === 'ArrayPattern' || node.left?.type === 'ObjectPattern') {
52205220
visit(node.right, scope, phase);
5221+
if (
5222+
hiddenEffectRead(phase) &&
5223+
node.left.type === 'ObjectPattern' &&
5224+
node.left.properties?.some(
5225+
(property) =>
5226+
property.type === 'RestElement' ||
5227+
(property.computed
5228+
? staticPrimitiveValue(property.key, scope)
5229+
: (property.key?.name ?? property.key?.value)) === 'current',
5230+
) &&
5231+
valueRefRead(node.right, scope)
5232+
) {
5233+
effectPolicy.hiddenDependency(unwrap(node.right), 'ref');
5234+
}
52215235
visitPatternExpressions(
52225236
node.left,
52235237
scope,

0 commit comments

Comments
 (0)