1
- /** @import { AssignmentExpression, BinaryOperator, BlockStatement, CallExpression, Expression, ExpressionStatement, Identifier, MethodDefinition, Node , Pattern, Program, Property, PropertyDefinition, Statement, VariableDeclarator } from 'estree' */
1
+ /** @import { AssignmentExpression, BinaryOperator, CallExpression, Expression, ExpressionStatement, MethodDefinition, Pattern, Program, Property, PropertyDefinition, Statement, VariableDeclarator } from 'estree' */
2
2
/** @import { Binding, Namespace, SvelteNode, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
3
3
/** @import { ComponentServerTransformState, ComponentVisitors, ServerTransformState, Visitors } from './types.js' */
4
4
/** @import { Analysis, ComponentAnalysis } from '../../types.js' */
@@ -8,10 +8,10 @@ import { walk } from 'zimmerframe';
8
8
import { set_scope , get_rune } from '../../scope.js' ;
9
9
import { extract_identifiers , extract_paths , is_expression_async } from '../../../utils/ast.js' ;
10
10
import * as b from '../../../utils/builders.js' ;
11
- import is_reference from 'is-reference' ;
12
11
import { transform_inspect_rune } from '../utils.js' ;
13
12
import { filename } from '../../../state.js' ;
14
13
import { render_stylesheet } from '../css/index.js' ;
14
+ import { Identifier } from './visitors/javascript/Identifier.js' ;
15
15
import { AwaitBlock } from './visitors/template/AwaitBlock.js' ;
16
16
import { Component } from './visitors/template/Component.js' ;
17
17
import { ConstTag } from './visitors/template/ConstTag.js' ;
@@ -33,6 +33,7 @@ import { SvelteFragment } from './visitors/template/SvelteFragment.js';
33
33
import { SvelteHead } from './visitors/template/SvelteHead.js' ;
34
34
import { SvelteSelf } from './visitors/template/SvelteSelf.js' ;
35
35
import { TitleElement } from './visitors/template/TitleElement.js' ;
36
+ import { serialize_get_binding } from './visitors/javascript/shared/utils.js' ;
36
37
37
38
/**
38
39
* @param {VariableDeclarator } declarator
@@ -56,37 +57,6 @@ function create_state_declarators(declarator, scope, value) {
56
57
] ;
57
58
}
58
59
59
- /**
60
- * @param {Identifier } node
61
- * @param {ServerTransformState } state
62
- * @returns {Expression }
63
- */
64
- function serialize_get_binding ( node , state ) {
65
- const binding = state . scope . get ( node . name ) ;
66
-
67
- if ( binding === null || node === binding . node ) {
68
- // No associated binding or the declaration itself which shouldn't be transformed
69
- return node ;
70
- }
71
-
72
- if ( binding . kind === 'store_sub' ) {
73
- const store_id = b . id ( node . name . slice ( 1 ) ) ;
74
- return b . call (
75
- '$.store_get' ,
76
- b . assignment ( '??=' , b . id ( '$$store_subs' ) , b . object ( [ ] ) ) ,
77
- b . literal ( node . name ) ,
78
- serialize_get_binding ( store_id , state )
79
- ) ;
80
- }
81
-
82
- if ( Object . hasOwn ( state . getters , node . name ) ) {
83
- const getter = state . getters [ node . name ] ;
84
- return typeof getter === 'function' ? getter ( node ) : getter ;
85
- }
86
-
87
- return node ;
88
- }
89
-
90
60
/**
91
61
* @param {AssignmentExpression } node
92
62
* @param {Pick<import('zimmerframe').Context<SvelteNode, ServerTransformState>, 'visit' | 'state'> } context
@@ -220,14 +190,7 @@ function serialize_set_binding(node, context, fallback) {
220
190
221
191
/** @type {Visitors } */
222
192
const global_visitors = {
223
- Identifier ( node , { path, state } ) {
224
- if ( is_reference ( node , /** @type {Node } */ ( path . at ( - 1 ) ) ) ) {
225
- if ( node . name === '$$props' ) {
226
- return b . id ( '$$sanitized_props' ) ;
227
- }
228
- return serialize_get_binding ( node , state ) ;
229
- }
230
- } ,
193
+ Identifier,
231
194
AssignmentExpression ( node , context ) {
232
195
return serialize_set_binding ( node , context , context . next ) ;
233
196
} ,
0 commit comments