@@ -156,6 +156,52 @@ test('should work w/ AST from descriptor', () => {
156
156
expect (
157
157
consumer . originalPositionFor ( getPositionInCode ( code , 'foobar' ) )
158
158
) . toMatchObject ( getPositionInCode ( source , `foobar` ) )
159
+
160
+ expect ( code ) . toBe (
161
+ compile ( {
162
+ filename : 'example.vue' ,
163
+ source : template . content
164
+ } ) . code
165
+ )
166
+ } )
167
+
168
+ test ( 'should work w/ AST from descriptor in SSR mode' , ( ) => {
169
+ const source = `
170
+ <template>
171
+ <div><p>{{ foobar }}</p></div>
172
+ </template>
173
+ `
174
+ const template = parse ( source , {
175
+ filename : 'example.vue' ,
176
+ sourceMap : true
177
+ } ) . descriptor . template !
178
+
179
+ expect ( template . ast ! . source ) . toBe ( source )
180
+
181
+ const { code, map } = compile ( {
182
+ filename : 'example.vue' ,
183
+ source : '' , // make sure it's actually using the AST instead of source
184
+ ast : template . ast ,
185
+ ssr : true
186
+ } )
187
+
188
+ expect ( map ! . sources ) . toEqual ( [ `example.vue` ] )
189
+ // when reusing AST from SFC parse for template compile,
190
+ // the source corresponds to the entire SFC
191
+ expect ( map ! . sourcesContent ) . toEqual ( [ source ] )
192
+
193
+ const consumer = new SourceMapConsumer ( map as RawSourceMap )
194
+ expect (
195
+ consumer . originalPositionFor ( getPositionInCode ( code , 'foobar' ) )
196
+ ) . toMatchObject ( getPositionInCode ( source , `foobar` ) )
197
+
198
+ expect ( code ) . toBe (
199
+ compile ( {
200
+ filename : 'example.vue' ,
201
+ source : template . content ,
202
+ ssr : true
203
+ } ) . code
204
+ )
159
205
} )
160
206
161
207
test ( 'should not reuse AST if using custom compiler' , ( ) => {
@@ -185,6 +231,66 @@ test('should not reuse AST if using custom compiler', () => {
185
231
expect ( code ) . toBe ( template . content )
186
232
} )
187
233
234
+ test ( 'should force re-parse on already transformed AST' , ( ) => {
235
+ const source = `
236
+ <template>
237
+ <div><p>{{ foobar }}</p></div>
238
+ </template>
239
+ `
240
+ const template = parse ( source , {
241
+ filename : 'example.vue' ,
242
+ sourceMap : true
243
+ } ) . descriptor . template !
244
+
245
+ // force set to empty, if this is reused then it won't generate proper code
246
+ template . ast ! . children = [ ]
247
+ template . ast ! . transformed = true
248
+
249
+ const { code } = compile ( {
250
+ filename : 'example.vue' ,
251
+ source : '' ,
252
+ ast : template . ast
253
+ } )
254
+
255
+ expect ( code ) . toBe (
256
+ compile ( {
257
+ filename : 'example.vue' ,
258
+ source : template . content
259
+ } ) . code
260
+ )
261
+ } )
262
+
263
+ test ( 'should force re-parse with correct compiler in SSR mode' , ( ) => {
264
+ const source = `
265
+ <template>
266
+ <div><p>{{ foobar }}</p></div>
267
+ </template>
268
+ `
269
+ const template = parse ( source , {
270
+ filename : 'example.vue' ,
271
+ sourceMap : true
272
+ } ) . descriptor . template !
273
+
274
+ // force set to empty, if this is reused then it won't generate proper code
275
+ template . ast ! . children = [ ]
276
+ template . ast ! . transformed = true
277
+
278
+ const { code } = compile ( {
279
+ filename : 'example.vue' ,
280
+ source : '' ,
281
+ ast : template . ast ,
282
+ ssr : true
283
+ } )
284
+
285
+ expect ( code ) . toBe (
286
+ compile ( {
287
+ filename : 'example.vue' ,
288
+ source : template . content ,
289
+ ssr : true
290
+ } ) . code
291
+ )
292
+ } )
293
+
188
294
test ( 'template errors' , ( ) => {
189
295
const result = compile ( {
190
296
filename : 'example.vue' ,
0 commit comments