Skip to content

Commit dc321df

Browse files
committed
fix: bind snapshot patterns for defaulted destructured params and add useLinkedState shape support
- strong-mode: call bindSnapshotPattern in the AssignmentPattern branch so destructured updater/reducer parameters with defaults get snapshot bindings - strong-state: extend initialShape to handle useLinkedState (argument index 1) so .push/.set/.add on linked state report OCTANE_STRONG_SNAPSHOT_MUTATION
1 parent 9c49f52 commit dc321df

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,14 @@ export function analyzeStrongMode(ast, source, filename, options = {}) {
23252325
bindStateGetterPattern(parameter.left, value, parameterScope, bindGetter);
23262326
bindAmbientPattern(parameter.left, value, parameterScope, bindGetter);
23272327
if (value?.kind === 'prop') bindPropPattern(parameter.left, bindGetter);
2328+
if (value?.kind === 'snapshot' && parameter.left.type !== 'Identifier') {
2329+
bindSnapshotPattern(
2330+
parameter.left,
2331+
value,
2332+
bindGetter,
2333+
snapshotPatternProperty(parameterScope),
2334+
);
2335+
}
23282336
parameter = parameter.left;
23292337
} else {
23302338
visitPatternExpressions(parameter, parameterScope, phase, value?.kind === 'ref', value);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function createStrongStatePolicy(api) {
231231
* proof for known mutator methods, including nested literal properties.
232232
*/
233233
initialShape(hook, node, scope) {
234-
if (hook === 'useState') {
235-
const initial = unwrap(node.arguments?.[0]);
234+
if (hook === 'useState' || hook === 'useLinkedState') {
235+
const initial = unwrap(node.arguments?.[hook === 'useLinkedState' ? 1 : 0]);
236236
if (!FUNCTIONS.has(initial?.type)) return literalShape(initial, scope);
237237
const body = initial.body;
238238
if (body?.type !== 'BlockStatement') return literalShape(body, scope);

0 commit comments

Comments
 (0)