1- /** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, Pattern, PrivateIdentifier, Statement } from 'estree' */
2- /** @import { AST, Binding } from '#compiler' */
1+ /** @import { ArrowFunctionExpression, AssignmentExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, Node, Pattern, UpdateExpression } from 'estree' */
2+ /** @import { Binding } from '#compiler' */
33/** @import { ClientTransformState, ComponentClientTransformState, ComponentContext } from './types.js' */
44/** @import { Analysis } from '../../types.js' */
55/** @import { Scope } from '../../scope.js' */
66import * as b from '../../../utils/builders.js' ;
7- import { extract_identifiers , is_simple_expression } from '../../../utils/ast.js' ;
7+ import { is_simple_expression } from '../../../utils/ast.js' ;
88import {
99 PROPS_IS_LAZY_INITIAL ,
1010 PROPS_IS_IMMUTABLE ,
@@ -13,7 +13,8 @@ import {
1313 PROPS_IS_BINDABLE
1414} from '../../../../constants.js' ;
1515import { dev } from '../../../state.js' ;
16- import { get_value } from './visitors/shared/declarations.js' ;
16+ import { walk } from 'zimmerframe' ;
17+ import { validate_mutation } from './visitors/shared/utils.js' ;
1718
1819/**
1920 * @param {Binding } binding
@@ -110,6 +111,30 @@ function get_hoisted_params(node, context) {
110111 }
111112 }
112113 }
114+
115+ if ( dev ) {
116+ // this is a little hacky, but necessary for ownership validation
117+ // to work inside hoisted event handlers
118+
119+ /**
120+ * @param {AssignmentExpression | UpdateExpression } node
121+ * @param {{ next: () => void, stop: () => void } } context
122+ */
123+ function visit ( node , { next, stop } ) {
124+ if ( validate_mutation ( node , /** @type {any } */ ( context ) , node ) !== node ) {
125+ params . push ( b . id ( '$$ownership_validator' ) ) ;
126+ stop ( ) ;
127+ } else {
128+ next ( ) ;
129+ }
130+ }
131+
132+ walk ( /** @type {Node } */ ( node ) , null , {
133+ AssignmentExpression : visit ,
134+ UpdateExpression : visit
135+ } ) ;
136+ }
137+
113138 return params ;
114139}
115140
0 commit comments