11import { processOpcodes } from "./utils" ;
2- import { string , array } from "../htmlbars-util/quoting" ;
2+ import { array } from "../htmlbars-util/quoting" ;
33
44function HydrationJavaScriptCompiler ( ) {
55 this . stack = [ ] ;
@@ -86,106 +86,50 @@ prototype.compile = function(opcodes, options) {
8686
8787prototype . prepareArray = function ( length ) {
8888 var values = [ ] ;
89- var expressionValues = [ ] ;
9089
9190 for ( var i = 0 ; i < length ; i ++ ) {
92- values . push ( this . stack . pop ( ) ) ;
93- expressionValues . push ( this . expressionStack . pop ( ) ) ;
91+ values . push ( this . expressionStack . pop ( ) ) ;
9492 }
9593
96- this . expressionStack . push ( expressionValues ) ;
97- this . stack . push ( '[' + values . join ( ', ' ) + ']' ) ;
94+ this . expressionStack . push ( values ) ;
9895} ;
9996
10097prototype . prepareObject = function ( size ) {
10198 var pairs = [ ] ;
102- var expressionPairs = [ ] ;
10399
104100 for ( var i = 0 ; i < size ; i ++ ) {
105- pairs . push ( this . stack . pop ( ) + ': ' + this . stack . pop ( ) ) ;
106- expressionPairs . push ( this . expressionStack . pop ( ) , this . expressionStack . pop ( ) ) ;
101+ pairs . push ( this . expressionStack . pop ( ) , this . expressionStack . pop ( ) ) ;
107102 }
108103
109- this . expressionStack . push ( expressionPairs ) ;
110- this . stack . push ( '{' + pairs . join ( ', ' ) + '}' ) ;
111- } ;
112-
113- prototype . pushRaw = function ( value ) {
114- this . expressionStack . push ( value ) ;
115- this . stack . push ( value ) ;
104+ this . expressionStack . push ( pairs ) ;
116105} ;
117106
118107prototype . pushLiteral = function ( value ) {
119108 this . expressionStack . push ( value ) ;
120-
121- if ( typeof value === 'string' ) {
122- this . stack . push ( string ( value ) ) ;
123- } else {
124- this . stack . push ( value . toString ( ) ) ;
125- }
126- } ;
127-
128- prototype . pushHook = function ( name , args ) {
129- this . hooks [ name ] = true ;
130- this . stack . push ( name + '(' + args . join ( ', ' ) + ')' ) ;
131109} ;
132110
133- prototype . pushGetHook = function ( path , morphNum ) {
111+ prototype . pushGetHook = function ( path ) {
134112 this . expressionStack . push ( [ 'get' , path ] ) ;
135-
136- this . pushHook ( 'get' , [
137- 'env' ,
138- 'morphs[' + morphNum + ']' ,
139- 'context' ,
140- string ( path )
141- ] ) ;
142113} ;
143114
144- prototype . pushSexprHook = function ( morphNum ) {
115+ prototype . pushSexprHook = function ( ) {
145116 this . expressionStack . push ( [
146117 'subexpr' ,
147118 this . expressionStack . pop ( ) ,
148119 this . expressionStack . pop ( ) ,
149120 this . expressionStack . pop ( )
150121 ] ) ;
151-
152- this . pushHook ( 'subexpr' , [
153- 'env' ,
154- 'morphs[' + morphNum + ']' ,
155- 'context' ,
156- this . stack . pop ( ) , // path
157- this . stack . pop ( ) , // params
158- this . stack . pop ( ) // hash
159- ] ) ;
160122} ;
161123
162- prototype . pushConcatHook = function ( morphNum ) {
124+ prototype . pushConcatHook = function ( ) {
163125 this . expressionStack . push ( [ 'concat' , this . expressionStack . pop ( ) ] ) ;
164-
165- this . pushHook ( 'concat' , [
166- 'env' ,
167- 'morphs[' + morphNum + ']' ,
168- this . stack . pop ( ) // parts
169- ] ) ;
170- } ;
171-
172- prototype . printHook = function ( name , args ) {
173- this . hooks [ name ] = true ;
174- this . source . push ( this . indent + ' ' + name + '(' + args . join ( ', ' ) + ');\n' ) ;
175126} ;
176127
177- prototype . printSetHook = function ( name , index ) {
128+ prototype . printSetHook = function ( name ) {
178129 this . augmentContext . push ( name ) ;
179-
180- this . printHook ( 'set' , [
181- 'env' ,
182- 'context' ,
183- string ( name ) ,
184- 'blockArguments[' + index + ']'
185- ] ) ;
186130} ;
187131
188- prototype . printBlockHook = function ( morphNum , templateId , inverseId ) {
132+ prototype . printBlockHook = function ( templateId , inverseId ) {
189133 this . statements . push ( [
190134 'block' ,
191135 this . expressionStack . pop ( ) , // path
@@ -194,100 +138,44 @@ prototype.printBlockHook = function(morphNum, templateId, inverseId) {
194138 templateId ,
195139 inverseId
196140 ] ) ;
197-
198- this . printHook ( 'block' , [
199- 'env' ,
200- 'morphs[' + morphNum + ']' ,
201- 'context' ,
202- this . stack . pop ( ) , // path
203- this . stack . pop ( ) , // params
204- this . stack . pop ( ) , // hash
205- templateId === null ? 'null' : 'child' + templateId ,
206- inverseId === null ? 'null' : 'child' + inverseId
207- ] ) ;
208141} ;
209142
210- prototype . printInlineHook = function ( morphNum ) {
211- var path = this . stack . pop ( ) ;
212- var params = this . stack . pop ( ) ;
213- var hash = this . stack . pop ( ) ;
143+ prototype . printInlineHook = function ( ) {
144+ var path = this . expressionStack . pop ( ) ;
145+ var params = this . expressionStack . pop ( ) ;
146+ var hash = this . expressionStack . pop ( ) ;
214147
215- var exprPath = this . expressionStack . pop ( ) ;
216- var exprParams = this . expressionStack . pop ( ) ;
217- var exprHash = this . expressionStack . pop ( ) ;
218-
219- this . statements . push ( [ 'inline' , exprPath , exprParams , exprHash ] ) ;
220-
221- this . printHook ( 'inline' , [
222- 'env' ,
223- 'morphs[' + morphNum + ']' ,
224- 'context' ,
225- path ,
226- params ,
227- hash
228- ] ) ;
148+ this . statements . push ( [ 'inline' , path , params , hash ] ) ;
229149} ;
230150
231- prototype . printContentHook = function ( morphNum ) {
151+ prototype . printContentHook = function ( ) {
232152 this . statements . push ( [ 'content' , this . expressionStack . pop ( ) ] ) ;
233-
234- this . printHook ( 'content' , [
235- 'env' ,
236- 'morphs[' + morphNum + ']' ,
237- 'context' ,
238- this . stack . pop ( ) // path
239- ] ) ;
240153} ;
241154
242- prototype . printComponentHook = function ( morphNum , templateId ) {
155+ prototype . printComponentHook = function ( templateId ) {
243156 this . statements . push ( [
244157 'component' ,
245158 this . expressionStack . pop ( ) , // path
246159 this . expressionStack . pop ( ) , // attrs
247160 templateId
248161 ] ) ;
249-
250- this . printHook ( 'component' , [
251- 'env' ,
252- 'morphs[' + morphNum + ']' ,
253- 'context' ,
254- this . stack . pop ( ) , // path
255- this . stack . pop ( ) , // attrs
256- templateId === null ? 'null' : 'child' + templateId
257- ] ) ;
258162} ;
259163
260- prototype . printAttributeHook = function ( attrMorphNum ) {
164+ prototype . printAttributeHook = function ( ) {
261165 this . statements . push ( [
262166 'attribute' ,
263167 this . expressionStack . pop ( ) , // name
264168 this . expressionStack . pop ( ) // value;
265169 ] ) ;
266-
267- this . printHook ( 'attribute' , [
268- 'env' ,
269- 'morphs[' + attrMorphNum + ']' ,
270- this . stack . pop ( ) , // name
271- this . stack . pop ( ) // value
272- ] ) ;
273170} ;
274171
275- prototype . printElementHook = function ( morphNum ) {
172+ prototype . printElementHook = function ( ) {
276173 this . statements . push ( [
277174 'element' ,
278175 this . expressionStack . pop ( ) , // path
279176 this . expressionStack . pop ( ) , // params
280177 this . expressionStack . pop ( ) // hash
281178 ] ) ;
282-
283- this . printHook ( 'element' , [
284- 'env' ,
285- 'morphs[' + morphNum + ']' ,
286- 'context' ,
287- this . stack . pop ( ) , // path
288- this . stack . pop ( ) , // params
289- this . stack . pop ( ) // hash
290- ] ) ;
291179} ;
292180
293181prototype . createMorph = function ( morphNum , parentPath , startIndex , endIndex , escaped ) {
0 commit comments