@@ -219,16 +219,16 @@ export default class TransformedModule {
219
219
220
220
/**
221
221
* Converts the mappings in this transformed module to the format expected by Volar.
222
- *
222
+ *
223
223
* The main difference between the two formats is that while the classic Glint transformation
224
224
* mappings support mapping a differently sized source region to a differently sized target region
225
225
* (e.g. `{{expectsAtLeastOneArg}}` in an .hbs file to `χ.emitContent(χ.resolveOrReturn(expectsAtLeastOneArg)());`
226
226
* in a generated TS file, in Volar you can only map regions of the same size.
227
- *
227
+ *
228
228
* In the case that you need to map regions of different sizes in Volar, you need to also using
229
229
* zero-length mappings to delineate regions/boundaries that should map to each other, otherwise there will
230
230
* be cases where TS diagnostics will fail to transform/map back to the original source. Example:
231
- *
231
+ *
232
232
* - `{{[[ZEROLEN-A]][[expectsAtLeastOneArg]][[ZEROLEN-B]]}}`
233
233
* - to
234
234
* - `[[ZEROLEN-A]]χ.emitContent(χ.resolveOrReturn([[expectsAtLeastOneArg]])());[[ZEROLEN-B]]`
@@ -248,46 +248,37 @@ export default class TransformedModule {
248
248
249
249
if ( children . length === 0 ) {
250
250
// leaf node
251
-
252
- const length = hbsEnd - hbsStart ;
253
-
254
- if ( length === tsEnd - tsStart ) {
251
+ const hbsLength = hbsEnd - hbsStart ;
252
+ const tsLength = tsEnd - tsStart ;
253
+ if ( hbsLength === tsLength ) {
255
254
// (Hacky?) assumption: because TS and HBS span lengths are equivalent,
256
255
// then this is a simple leafmost mapping, e.g. `{{this.[foo]}}` -> `this.[foo]`
257
256
sourceOffsets . push ( hbsStart ) ;
258
257
generatedOffsets . push ( tsStart ) ;
259
- lengths . push ( length ) ;
258
+ lengths . push ( hbsLength ) ;
260
259
} else {
261
- // This isn't common but there are a few cases where we are not currently going as
262
- // "deep" as we good into the mapping tree to produce equal-size leaf nodes; here
263
- // is one example (using `toDebugString()`)
264
- //
265
- // | | | Mapping: MustacheStatement
266
- // | | | hbs(686:723): {{yield to="expectsAtLeastOneParam"}}
267
- // | | | ts(1025:1073):χ.yieldToBlock(𝚪, "expectsAtLeastOneParam")()
268
-
269
- // It may make sense to rework the mappings for yields and other cases so that
270
- // the leaf nodes are equal-sized identifiers
271
- // (e.g. expectsAtLeastOneParam (hbs) -> expectsAtLeastOneParam(ts) ), but
272
- // in the mean time we will just produce zero-length boundary markers for Volar.
260
+ // Disregard the "null zone" mappings, i.e. cases where TS code maps to empty HBS code
261
+ if ( hbsLength > 0 && tsLength > 0 ) {
262
+ sourceOffsets . push ( hbsStart ) ;
263
+ generatedOffsets . push ( tsStart ) ;
264
+ lengths . push ( 0 ) ;
265
+ sourceOffsets . push ( hbsEnd ) ;
266
+ generatedOffsets . push ( tsEnd ) ;
267
+ lengths . push ( 0 ) ;
268
+ }
273
269
}
274
270
} else {
275
- // here we want to install zero-length mappings on the boundaries
276
-
277
- // TODO: consider re-enabling these zero-length boundary mappings, but for now
278
- // they don't solve the problem of lack of granularity
279
- // sourceOffsets.push(hbsStart);
280
- // generatedOffsets.push(tsStart);
281
- // lengths.push(0);
271
+ sourceOffsets . push ( hbsStart ) ;
272
+ generatedOffsets . push ( tsStart ) ;
273
+ lengths . push ( 0 ) ;
282
274
283
275
mapping . children . forEach ( ( child ) => {
284
276
recurse ( span , child ) ;
285
277
} ) ;
286
278
287
- // TODO: see above
288
- // sourceOffsets.push(hbsEnd);
289
- // generatedOffsets.push(tsEnd);
290
- // lengths.push(0);
279
+ sourceOffsets . push ( hbsEnd ) ;
280
+ generatedOffsets . push ( tsEnd ) ;
281
+ lengths . push ( 0 ) ;
291
282
}
292
283
} ;
293
284
@@ -301,7 +292,6 @@ export default class TransformedModule {
301
292
// transformation, we expect these to be the same length (in fact, they
302
293
// should be the same string entirely)
303
294
304
-
305
295
// This assertion seemed valid when parsing .gts files with extracted hbs in <template> tags,
306
296
// but when parsing solo .hbs files in loose mode there were cases where, e.g.,
307
297
// originalLength == 0 and transformLength == 1;
0 commit comments