google_forms/node_modules/@babel/eslint-parser/lib/convert/convertAST.cjs.map

1 line
9.1 KiB
Plaintext
Raw Permalink Normal View History

2024-08-09 12:04:48 +00:00
{"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","body","program","Object","assign","sourceType","errors","comments","lastComment","tokens","lastToken","line","module","exports","convertAST"],"sources":["../../src/convert/convertAST.cts"],"sourcesContent":["import type * as t from \"@babel/types\";\nimport ESLINT_VERSION = require(\"../utils/eslint-version.cts\");\nimport type { ParseResult } from \"../types.d.cts\";\n\nfunction* it<T>(children: T | T[]) {\n if (Array.isArray(children)) yield* children;\n else yield children;\n}\n\nfunction traverse(\n node: t.Node,\n visitorKeys: Record<string, string[]>,\n visitor: typeof convertNodesVisitor,\n) {\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(\n node[key as keyof t.Node] as unknown as t.Node | t.Node[],\n )) {\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: t.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: t.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 // @ts-expect-error eslint\n node.type = \"Identifier\";\n // @ts-expect-error eslint\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 // @ts-expect-error legacy?\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: ParseResult, visitorKeys: Record<string, string[]>) {\n traverse(ast as unknown as t.Program, visitorKeys, convertNodesVisitor);\n}\n\nfunction convertProgramNode(ast: ParseResult) {\n const body = ast.program.body;\n Object.assign(ast, {\n type: \"Program\",\n sourceType: ast.program.sourceType,\n body,\n });\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.t