@@ -78,15 +78,16 @@ export function genEffects(
78
78
) : CodeFragment [ ] {
79
79
const { helper } = context
80
80
const [ frag , push , unshift ] = buildCodeFragment ( )
81
- const declareNames = new Set < string > ( )
82
81
let operationsCount = 0
83
82
for ( let i = 0 ; i < effects . length ; i ++ ) {
84
- const effect = ( context . processingRenderEffect = effects [ i ] )
83
+ const effect = effects [ i ]
85
84
operationsCount += effect . operations . length
86
- const frags = genEffect ( effect , context , declareNames )
87
- const needSemi = frag [ frag . length - 1 ] === ')' && frags [ 0 ] === '('
85
+ const frags = genEffect ( effect , context )
88
86
i > 0 && push ( NEWLINE )
89
- push ( needSemi ? ';' : undefined , ...frags )
87
+ if ( frag [ frag . length - 1 ] === ')' && frags [ 0 ] === '(' ) {
88
+ push ( ';' )
89
+ }
90
+ push ( ...frags )
90
91
}
91
92
92
93
const newLineCount = frag . filter ( frag => frag === NEWLINE ) . length
@@ -100,60 +101,21 @@ export function genEffects(
100
101
push ( `)` )
101
102
}
102
103
103
- // declare variables: let _foo, _bar
104
- if ( declareNames . size ) {
105
- frag . splice ( 1 , 0 , `let ${ [ ...declareNames ] . join ( ', ' ) } ` , NEWLINE )
106
- }
107
104
return frag
108
105
}
109
106
110
107
export function genEffect (
111
108
{ operations } : IREffect ,
112
109
context : CodegenContext ,
113
- allDeclareNames : Set < string > ,
114
110
) : CodeFragment [ ] {
115
- const { processingRenderEffect } = context
116
111
const [ frag , push ] = buildCodeFragment ( )
117
- const { declareNames, earlyCheckExps } = processingRenderEffect !
118
112
const operationsExps = genOperations ( operations , context )
119
-
120
- if ( declareNames . size ) {
121
- allDeclareNames . add ( [ ...declareNames ] . join ( ', ' ) )
122
- }
123
-
124
113
const newlineCount = operationsExps . filter ( frag => frag === NEWLINE ) . length
114
+
125
115
if ( newlineCount > 1 ) {
126
- // multiline check expression: if (_foo !== _ctx.foo || _bar !== _ctx.bar) {
127
- const checkExpsStart : CodeFragment [ ] =
128
- earlyCheckExps . length > 0
129
- ? [ `if(` , ...earlyCheckExps . join ( ' || ' ) , `) {` , INDENT_START ]
130
- : [ ]
131
- const checkExpsEnd : CodeFragment [ ] =
132
- earlyCheckExps . length > 0 ? [ INDENT_END , NEWLINE , '}' ] : [ ]
133
- // assignment: _foo = _ctx.foo; _bar = _ctx.bar
134
- const assignmentExps : CodeFragment [ ] =
135
- earlyCheckExps . length > 0
136
- ? [ NEWLINE , ...earlyCheckExps . map ( c => c . replace ( '!==' , '=' ) ) . join ( ';' ) ]
137
- : [ ]
138
- push (
139
- ...checkExpsStart ,
140
- ...operationsExps ,
141
- ...assignmentExps ,
142
- ...checkExpsEnd ,
143
- )
116
+ push ( ...operationsExps )
144
117
} else {
145
- // single line check expression: (_foo !== _ctx.foo || _bar !== _ctx.bar) &&
146
- const multiple = earlyCheckExps . length > 1
147
- const checkExps : CodeFragment [ ] =
148
- earlyCheckExps . length > 0
149
- ? [
150
- multiple ? `(` : undefined ,
151
- ...earlyCheckExps . join ( ' || ' ) ,
152
- multiple ? `)` : undefined ,
153
- ' && ' ,
154
- ]
155
- : [ ]
156
- push ( ...checkExps , ...operationsExps . filter ( frag => frag !== NEWLINE ) )
118
+ push ( ...operationsExps . filter ( frag => frag !== NEWLINE ) )
157
119
}
158
120
159
121
return frag
0 commit comments