{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-portal/src/external/eslint/babylon-to-espree7/attachComments.js"],"names":["attachComments","ast","comments","tokens","length","firstComment","lastComment","start","end","loc","line","column","leadingComments","innerComments","token","body","node","firstTokenStart","len","i","push","lastToken","range"],"mappings":";;;AAAA;AACO,WAASA,cAAT,CAAwBC,GAAxB,EAA6BC,QAA7B,EAAuCC,MAAvC,EAA+C;AACpD,QAAID,SAASE,MAAb,EAAqB;AACnB,UAAIC,eAAeH,SAAS,CAAT,CAAnB;AACA,UAAII,cAAcJ,SAASA,SAASE,MAAT,GAAkB,CAA3B,CAAlB;AACA;AACA,UAAI,CAACD,OAAOC,MAAZ,EAAoB;AAClB;AACAH,YAAIM,KAAJ,GAAYD,YAAYE,GAAxB;AACAP,YAAIQ,GAAJ,CAAQF,KAAR,CAAcG,IAAd,GAAqBJ,YAAYG,GAAZ,CAAgBD,GAAhB,CAAoBE,IAAzC;AACAT,YAAIQ,GAAJ,CAAQF,KAAR,CAAcI,MAAd,GAAuBL,YAAYG,GAAZ,CAAgBD,GAAhB,CAAoBG,MAA3C;;AAEA,YAAIV,IAAIW,eAAJ,KAAwB,IAAxB,IAAgCX,IAAIY,aAAJ,CAAkBT,MAAtD,EAA8D;AAC5DH,cAAIW,eAAJ,GAAsBX,IAAIY,aAA1B;AACD;AACF,OATD,MASO,IAAIR,aAAaE,KAAb,GAAqBJ,OAAO,CAAP,EAAUI,KAAnC,EAA0C;AAC/C;AACA,YAAIO,QAAQX,OAAO,CAAP,CAAZ;AACA;AACA;AACA;;AAEA;AACA;AACA,YAAIF,IAAIc,IAAJ,CAASX,MAAb,EAAqB;AACnB,cAAIY,OAAOf,IAAIc,IAAJ,CAAS,CAAT,CAAX;AACAC,eAAKJ,eAAL,GAAuB,EAAvB;AACA,cAAIK,kBAAkBH,MAAMP,KAA5B;AACA,cAAIW,MAAMhB,SAASE,MAAnB;AACA,eAAK,IAAIe,IAAI,CAAb,EAAgBA,IAAID,GAAJ,IAAWhB,SAASiB,CAAT,EAAYZ,KAAZ,GAAoBU,eAA/C,EAAgEE,GAAhE,EAAqE;AACnEH,iBAAKJ,eAAL,CAAqBQ,IAArB,CAA0BlB,SAASiB,CAAT,CAA1B;AACD;AACF;AACF;AACD;AACA,UAAIhB,OAAOC,MAAX,EAAmB;AACjB,YAAIiB,YAAYlB,OAAOA,OAAOC,MAAP,GAAgB,CAAvB,CAAhB;AACA,YAAIE,YAAYE,GAAZ,GAAkBa,UAAUb,GAAhC,EAAqC;AACnC;AACA;AACA;AACAP,cAAIqB,KAAJ,CAAU,CAAV,IAAeD,UAAUb,GAAzB;AACAP,cAAIQ,GAAJ,CAAQD,GAAR,CAAYE,IAAZ,GAAmBW,UAAUZ,GAAV,CAAcD,GAAd,CAAkBE,IAArC;AACAT,cAAIQ,GAAJ,CAAQD,GAAR,CAAYG,MAAZ,GAAqBU,UAAUZ,GAAV,CAAcD,GAAd,CAAkBG,MAAvC;AACD;AACF;AACF,KA5CD,MA4CO;AACL,UAAI,CAACR,OAAOC,MAAZ,EAAoB;AAClBH,YAAIQ,GAAJ,CAAQF,KAAR,CAAcG,IAAd,GAAqB,CAArB;AACAT,YAAIQ,GAAJ,CAAQD,GAAR,CAAYE,IAAZ,GAAmB,CAAnB;AACD;AACF;AACD,QAAIT,IAAIc,IAAJ,IAAYd,IAAIc,IAAJ,CAASX,MAAT,GAAkB,CAAlC,EAAqC;AACnCH,UAAIQ,GAAJ,CAAQF,KAAR,CAAcG,IAAd,GAAqBT,IAAIc,IAAJ,CAAS,CAAT,EAAYN,GAAZ,CAAgBF,KAAhB,CAAsBG,IAA3C;AACAT,UAAIqB,KAAJ,CAAU,CAAV,IAAerB,IAAIc,IAAJ,CAAS,CAAT,EAAYR,KAA3B;AACD;AACF;;4BAvDeP,c","file":"attachComments.js","sourcesContent":["// comment fixes\nexport function attachComments(ast, comments, tokens) {\n  if (comments.length) {\n    var firstComment = comments[0];\n    var lastComment = comments[comments.length - 1];\n    // fixup program start\n    if (!tokens.length) {\n      // if no tokens, the program starts at the end of the last comment\n      ast.start = lastComment.end;\n      ast.loc.start.line = lastComment.loc.end.line;\n      ast.loc.start.column = lastComment.loc.end.column;\n\n      if (ast.leadingComments === null && ast.innerComments.length) {\n        ast.leadingComments = ast.innerComments;\n      }\n    } else if (firstComment.start < tokens[0].start) {\n      // if there are comments before the first token, the program starts at the first token\n      var token = tokens[0];\n      // ast.start = token.start;\n      // ast.loc.start.line = token.loc.start.line;\n      // ast.loc.start.column = token.loc.start.column;\n\n      // estraverse do not put leading comments on first node when the comment\n      // appear before the first token\n      if (ast.body.length) {\n        var node = ast.body[0];\n        node.leadingComments = [];\n        var firstTokenStart = token.start;\n        var len = comments.length;\n        for (var i = 0; i < len && comments[i].start < firstTokenStart; i++) {\n          node.leadingComments.push(comments[i]);\n        }\n      }\n    }\n    // fixup program end\n    if (tokens.length) {\n      var lastToken = tokens[tokens.length - 1];\n      if (lastComment.end > lastToken.end) {\n        // If there is a comment after the last token, the program ends at the\n        // last token and not the comment\n        // ast.end = lastToken.end;\n        ast.range[1] = lastToken.end;\n        ast.loc.end.line = lastToken.loc.end.line;\n        ast.loc.end.column = lastToken.loc.end.column;\n      }\n    }\n  } else {\n    if (!tokens.length) {\n      ast.loc.start.line = 1;\n      ast.loc.end.line = 1;\n    }\n  }\n  if (ast.body && ast.body.length > 0) {\n    ast.loc.start.line = ast.body[0].loc.start.line;\n    ast.range[0] = ast.body[0].start;\n  }\n}\n"]}