convertAST.cjs.map
8.63 KB
{"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,6BAAD,CAA9B;;AAEA,UAAUC,EAAV,CAAaC,QAAb,EAAuB;EACrB,IAAIC,KAAK,CAACC,OA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