File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -950,9 +950,9 @@ class Printer {
950950 for ( let i = 0 ; i < len ; i ++ ) {
951951 const comment = comments [ i ] ;
952952
953- if ( hasLoc && "loc" in comment && ! this . _printedComments . has ( comment ) ) {
954- const commentStartLine = comment . loc ? .start . line ;
955- const commentEndLine = comment . loc ? .end . line ;
953+ if ( hasLoc && comment . loc && ! this . _printedComments . has ( comment ) ) {
954+ const commentStartLine = comment . loc . start . line ;
955+ const commentEndLine = comment . loc . end . line ;
956956 if ( type === COMMENT_TYPE . LEADING ) {
957957 let offset = 0 ;
958958 if ( i === 0 ) {
Original file line number Diff line number Diff line change @@ -472,6 +472,17 @@ describe("generation", function () {
472472
473473 expect ( generate ( ast ) . code ) . toBe ( "/*#__PURE__*/a();\n/*#__PURE__*/b();" ) ;
474474 } ) ;
475+
476+ it ( "comments with null or undefined loc" , ( ) => {
477+ const code = "/*#__PURE__*/ /*#__PURE__*/" ;
478+
479+ const ast = parse ( code ) ;
480+
481+ ast . comments [ 0 ] . loc = null ;
482+ ast . comments [ 1 ] . loc = undefined ;
483+
484+ expect ( generate ( ast ) . code ) . toBe ( "/*#__PURE__*/\n/*#__PURE__*/" ) ;
485+ } ) ;
475486} ) ;
476487
477488describe ( "programmatic generation" , function ( ) {
You can’t perform that action at this time.
0 commit comments