hexo/node_modules/@babel/generator/lib/node/index.js.map

1 line
5.7 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"names":["whitespace","require","parens","_t","FLIPPED_ALIAS_KEYS","isCallExpression","isExpressionStatement","isMemberExpression","isNewExpression","expandAliases","obj","newObj","add","type","func","fn","node","parent","stack","result","Object","keys","aliases","alias","expandedParens","expandedWhitespaceNodes","nodes","find","printStack","isOrHasCallExpression","object","needsWhitespace","expression","flag","needsWhitespaceBefore","needsWhitespaceAfter","needsParens","callee"],"sources":["../../src/node/index.ts"],"sourcesContent":["import * as whitespace from \"./whitespace\";\nimport * as parens from \"./parentheses\";\nimport {\n FLIPPED_ALIAS_KEYS,\n isCallExpression,\n isExpressionStatement,\n isMemberExpression,\n isNewExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nimport type { WhitespaceFlag } from \"./whitespace\";\n\nexport type NodeHandlers<R> = {\n [K in string]?: (\n node: K extends t.Node[\"type\"] ? Extract<t.Node, { type: K }> : t.Node,\n // todo:\n // node: K extends keyof typeof t\n // ? Extract<typeof t[K], { type: \"string\" }>\n // : t.Node,\n parent: t.Node,\n stack: t.Node[],\n ) => R;\n};\n\nfunction expandAliases<R>(obj: NodeHandlers<R>) {\n const newObj: NodeHandlers<R> = {};\n\n function add(\n type: string,\n func: (node: t.Node, parent: t.Node, stack: t.Node[]) => R,\n ) {\n const fn = newObj[type];\n newObj[type] = fn\n ? function (node, parent, stack) {\n const result = fn(node, parent, stack);\n\n return result == null ? func(node, parent, stack) : result;\n }\n : func;\n }\n\n for (const type of Object.keys(obj)) {\n const aliases = FLIPPED_ALIAS_KEYS[type];\n if (aliases) {\n for (const alias of aliases) {\n add(alias, obj[type]);\n }\n } else {\n add(type, obj[type]);\n }\n }\n\n return newObj;\n}\n\n// Rather than using `t.is` on each object property, we pre-expand any type aliases\n// into concrete types so that the 'find' call below can be as fast as possible.\nconst expandedParens = expandAliases(parens);\nconst expandedWhitespaceNodes = expandAliases(whitespace.nodes);\n\nfunction find<R>(\n obj: NodeHandlers<R>,\n node: t.Node,\n parent: t.Node,\n printStack?: t.Node[],\n): R | null {\n const fn = obj[node.type];\n return fn ? fn(node, parent, printStack) : null;\n}\n\nfunction isOrHasCallExpression(node: t.Node): boolean {\n if (isCallExpression(node)) {\n return true;\n }\n\n return isMemberExpression(node) && isOrHasCallExpression(node.object);\n}\n\nexport function needsWhitespace(\n node: t.Node,\n parent: t.Node,\n type: WhitespaceFlag,\n): boolean {\n if (!node) return false;\n\n if (isExpressionStatement(node)) {\n node = node.expression;\n }\n\n const flag = find(expandedWhitespaceNodes, node, parent);\n\n if (typeof flag === \"number\") {\n return (flag & type) !== 0;\n }\n\n return false;\n}\n\nexport function needsWhitespaceBefore(node: t.Node, parent: t.Node) {\n return needsWhitespace(node, parent, 1);\n}\n\nexport function needsWhitespaceAfter(node: t.Node, parent: t.Node) {\n return needsWhitespace(node, parent, 2);\n}\n\nexport function needsParens(\n node: t.Node,\n parent: t.Node,\n printStack?: t.Node[],\n) {\n if (!parent) return false;\n\n if (isNewExpression(parent) && parent.callee === node) {\n if (isOrHasCallExpression(node)) return true;\n }\n\n return find(expandedParens, node, parent, printStack);\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,EAAA,GAAAF,OAAA;AAMsB;EALpBG,kBAAkB;EAClBC,gBAAgB;EAChBC,qBAAqB;EACrBC,kBAAkB;EAClBC;AAAe,IAAAL,EAAA;AAkBjB,SAASM,aAAaA,CAAIC,GAAoB,EAAE;EAC9C,MAAMC,MAAuB,GAAG,CAAC,CAAC;EAElC,SAASC,GAAGA,CACVC,IAAY,EACZC,IAA0D,EAC1D;IACA,MAAMC,EAAE,GAAGJ,MAAM,CAACE,IAAI,CAAC;IACvBF,MAAM,CAACE,IAAI,CAAC,GAAGE,EAAE,GACb,UAAUC,IAAI,EAAEC,MAAM,EAAEC,KAAK,EAAE;MAC7B,MAAMC,MAAM,GAAGJ,EAAE,CAACC,IAAI,EAAEC,MAAM,EAAEC,KAAK,CAAC;MAEtC,OAAOC,MAAM,IAAI,IAAI,GAAGL,IAAI,CAACE,IAAI,EAAEC