@@ -390,17 +390,55 @@ class StatementNormalizer {
390
390
391
391
MustacheCommentStatement ( node : ASTv1 . MustacheCommentStatement ) : ASTv2 . GlimmerComment {
392
392
let loc = this . block . loc ( node . loc ) ;
393
- let textLoc : SourceSpan ;
394
393
395
- if ( loc . asString ( ) . slice ( 0 , 5 ) === '{{!--' ) {
396
- textLoc = loc . slice ( { skipStart : 5 , skipEnd : 4 } ) ;
394
+ // If someone cares for these cases to have the right loc, feel free to attempt:
395
+ // {{!}} {{~!}} {{!~}} {{~!~}}
396
+ // {{!-}} {{~!-}} {{!-~}} {{~!-~}}
397
+ // {{!--}} {{~!--}} {{!--~}} {{~!--~}}
398
+ // {{!---}} {{~!---}} {{!---~}} {{~!---~}}
399
+ // {{!----}} {{~!----}} {{!----~}} {{~!----~}}
400
+ if ( node . value === '' ) {
401
+ return new ASTv2 . GlimmerComment ( {
402
+ loc,
403
+ text : SourceSlice . synthetic ( '' ) ,
404
+ } ) ;
405
+ }
406
+
407
+ let source = loc . asString ( ) ;
408
+ let span = loc ;
409
+
410
+ if ( node . value . startsWith ( '-' ) ) {
411
+ localAssert (
412
+ / ^ \{ \{ ~ ? ! - - - / u. test ( source ) ,
413
+ `to start a comment's content with a '-', it must have started with {{!--`
414
+ ) ;
415
+ span = span . sliceStartChars ( {
416
+ skipStart : source . startsWith ( '{{~' ) ? 6 : 5 ,
417
+ chars : node . value . length ,
418
+ } ) ;
419
+ } else if ( node . value . endsWith ( '-' ) ) {
420
+ localAssert (
421
+ / - - ~ ? \} \} / u. test ( source ) ,
422
+ `to end a comment's content with a '-', it must have ended with --}}`
423
+ ) ;
424
+
425
+ const skipEnd = source . endsWith ( '~}}' ) ? 5 : 4 ;
426
+ const skipStart = source . length - node . value . length - skipEnd ;
427
+
428
+ span = span . slice ( {
429
+ skipStart,
430
+ skipEnd,
431
+ } ) ;
397
432
} else {
398
- textLoc = loc . slice ( { skipStart : 3 , skipEnd : 2 } ) ;
433
+ span = span . sliceStartChars ( {
434
+ skipStart : source . lastIndexOf ( node . value ) ,
435
+ chars : node . value . length ,
436
+ } ) ;
399
437
}
400
438
401
439
return new ASTv2 . GlimmerComment ( {
402
440
loc,
403
- text : textLoc . toSlice ( node . value ) ,
441
+ text : span . toSlice ( node . value ) ,
404
442
} ) ;
405
443
}
406
444
0 commit comments