{"version":3,"names":["ESLINT_VERSION","require","it","children","Array","isArray","traverse","node","visitorKeys","visitor","type","keys","key","child","enter","exit","convertNodesVisitor","innerComments","trailingComments","leadingComments","extra","loc","identifierName","typeAnnotation","bound","id","name","isType","i","quasis","length","q","range","tail","start","column","end","convertNodes","ast","convertProgramNode","sourceType","program","body","errors","comments","lastComment","tokens","lastToken","line","module","exports","convertAST"],"sources":["../../src/convert/convertAST.cjs"],"sourcesContent":["const ESLINT_VERSION = require(\"../utils/eslint-version.cjs\");\n\nfunction* it(children) {\n if (Array.isArray(children)) yield* children;\n else yield children;\n}\n\nfunction traverse(node, visitorKeys, visitor) {\n const { type } = node;\n if (!type) return;\n const keys = visitorKeys[type];\n if (!keys) return;\n\n for (const key of keys) {\n for (const child of it(node[key])) {\n if (child && typeof child === \"object\") {\n visitor.enter(child);\n traverse(child, visitorKeys, visitor);\n visitor.exit(child);\n }\n }\n }\n}\n\nconst convertNodesVisitor = {\n enter(node) {\n if (node.innerComments) {\n delete node.innerComments;\n }\n\n if (node.trailingComments) {\n delete node.trailingComments;\n }\n\n if (node.leadingComments) {\n delete node.leadingComments;\n }\n },\n exit(node) {\n // Used internally by @babel/parser.\n if (node.extra) {\n delete node.extra;\n }\n\n if (node.loc.identifierName) {\n delete node.loc.identifierName;\n }\n\n if (node.type === \"TypeParameter\") {\n node.type = \"Identifier\";\n node.typeAnnotation = node.bound;\n delete node.bound;\n }\n\n // flow: prevent \"no-undef\"\n // for \"Component\" in: \"let x: React.Component\"\n if (node.type === \"QualifiedTypeIdentifier\") {\n delete node.id;\n }\n // for \"b\" in: \"var a: { b: Foo }\"\n if (node.type === \"ObjectTypeProperty\") {\n delete node.key;\n }\n // for \"indexer\" in: \"var a: {[indexer: string]: number}\"\n if (node.type === \"ObjectTypeIndexer\") {\n delete node.id;\n }\n // for \"param\" in: \"var a: { func(param: Foo): Bar };\"\n if (node.type === \"FunctionTypeParam\") {\n delete node.name;\n }\n\n // modules\n if (node.type === \"ImportDeclaration\") {\n delete node.isType;\n }\n\n // template string range fixes\n if (node.type === \"TemplateLiteral\") {\n for (let i = 0; i < node.quasis.length; i++) {\n const q = node.quasis[i];\n q.range[0] -= 1;\n if (q.tail) {\n q.range[1] += 1;\n } else {\n q.range[1] += 2;\n }\n q.loc.start.column -= 1;\n if (q.tail) {\n q.loc.end.column += 1;\n } else {\n q.loc.end.column += 2;\n }\n\n if (ESLINT_VERSION >= 8) {\n q.start -= 1;\n if (q.tail) {\n q.end += 1;\n } else {\n q.end += 2;\n }\n }\n }\n }\n },\n};\n\nfunction convertNodes(ast, visitorKeys) {\n traverse(ast, visitorKeys, convertNodesVisitor);\n}\n\nfunction convertProgramNode(ast) {\n ast.type = \"Program\";\n ast.sourceType = ast.program.sourceType;\n ast.body = ast.program.body;\n delete ast.program;\n delete ast.errors;\n\n if (ast.comments.length) {\n const lastComment = ast.comments[ast.comments.length - 1];\n\n if (ast.tokens.length) {\n const lastToken = ast.tokens[ast.tokens.length - 1];\n\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.range[1] = lastToken.end;\n ast.loc.end.line = lastToken.loc.end.line;\n ast.loc.end.column = lastToken.loc.end.column;\n\n if (ESLINT_VERSION >= 8) {\n ast.end = lastToken.end;\n }\n }\n }\n } else {\n if (!ast.tokens.length) {\n ast.loc.start.line = 1;\n ast.loc.end.line = 1;\n }\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 if (ESLINT_VERSION >= 8) {\n ast.start = ast.body[0].start;\n }\n }\n}\n\nmodule.exports = function convertAST(ast, visitorKeys) {\n convertNodes(ast, visitorKeys);\n convertProgramNode(ast);\n};\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGC,OAAO,CAAC,6BAA6B,CAAC;AAE7D,UAAUC,EAAEA,CAACC,QAAQ,EAAE;EACrB,IAAIC,KAAK,CAACC,OAAO,CAACF,QAAQ,CAAC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