Innovenergy_trunk/frontend/node_modules/@babel/template/lib/parse.js.map

1 line
11 KiB
Plaintext
Raw Normal View History

{"version":3,"names":["isCallExpression","isExpressionStatement","isFunction","isIdentifier","isJSXIdentifier","isNewExpression","isPlaceholder","isStatement","isStringLiteral","removePropertiesDeep","traverse","PATTERN","parseAndBuildMetadata","formatter","code","opts","placeholderWhitelist","placeholderPattern","preserveComments","syntacticPlaceholders","ast","parseWithCodeFrame","parser","validate","syntactic","placeholders","placeholderNames","Set","legacy","isLegacyRef","value","undefined","placeholderVisitorHandler","node","ancestors","state","name","Error","test","has","slice","parent","key","length","type","expectedNode","push","resolve","resolveAncestors","isDuplicate","add","i","index","parserOpts","plugins","allowReturnOutsideFunction","allowSuperOutsideMethod","sourceType","parse","err","loc","message","codeFrameColumns","start"],"sources":["../src/parse.ts"],"sourcesContent":["import {\n isCallExpression,\n isExpressionStatement,\n isFunction,\n isIdentifier,\n isJSXIdentifier,\n isNewExpression,\n isPlaceholder,\n isStatement,\n isStringLiteral,\n removePropertiesDeep,\n traverse,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type { TraversalAncestors, TraversalHandler } from \"@babel/types\";\nimport { parse } from \"@babel/parser\";\nimport { codeFrameColumns } from \"@babel/code-frame\";\nimport type { TemplateOpts, ParserOpts } from \"./options\";\nimport type { Formatter } from \"./formatters\";\n\nexport type Metadata = {\n ast: t.File;\n placeholders: Array<Placeholder>;\n placeholderNames: Set<string>;\n};\n\ntype PlaceholderType = \"string\" | \"param\" | \"statement\" | \"other\";\nexport type Placeholder = {\n name: string;\n resolve: (a: t.File) => { parent: t.Node; key: string; index?: number };\n type: PlaceholderType;\n isDuplicate: boolean;\n};\n\nconst PATTERN = /^[_$A-Z0-9]+$/;\n\nexport default function parseAndBuildMetadata<T>(\n formatter: Formatter<T>,\n code: string,\n opts: TemplateOpts,\n): Metadata {\n const {\n placeholderWhitelist,\n placeholderPattern,\n preserveComments,\n syntacticPlaceholders,\n } = opts;\n\n const ast = parseWithCodeFrame(code, opts.parser, syntacticPlaceholders);\n\n removePropertiesDeep(ast, {\n preserveComments,\n });\n\n formatter.validate(ast);\n\n const syntactic: MetadataState[\"syntactic\"] = {\n placeholders: [],\n placeholderNames: new Set(),\n };\n const legacy: MetadataState[\"legacy\"] = {\n placeholders: [],\n placeholderNames: new Set(),\n };\n const isLegacyRef: MetadataState[\"isLegacyRef\"] = { value: undefined };\n\n traverse(ast, placeholderVisitorHandler as TraversalHandler<any>, {\n syntactic,\n legacy,\n isLegacyRef,\n placeholderWhitelist,\n placeholderPattern,\n syntacticPlaceholders,\n });\n\n return {\n ast,\n ...(isLegacyRef.value ? legacy : syntactic),\n };\n}\n\nfunction placeholderVisitorHandler(\n node: t.Node,\n ancestors: TraversalAncestors,\n state: MetadataState,\n) {\n let name: string;\n\n if (isPlaceholder(node)) {\n if (state.syntacticPlaceholders === false) {\n throw new Error(\n \"%%foo%%-style placeholders can't be used when \" +\n \"'.syntacticPlaceholders' is false.\",\n );\n } else {\n name = node.name.name;\n state.isLegacyRef.value = false;\n }\n } else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) {\n return;\n } else if (isIdentifier(node) || isJSXIdentifier(node)) {\n name = node.name;\n state.isLegacyRef.value = true;\n } else if (isStringLiteral(node)) {\n name = node.value;\n state.isLegacyRef.value = true;\n } else {\n return;\n }\n\n if (\n !state.isLegacyRef.value &&\n (state.placeholderPattern != null || state.placeholderWhitelist != null)\n ) {\n // This check is also in options.js. We need it there to handle the default\n // .syntacticPlaceholders behavior.\n throw new Error(\n \"'.placeholderWhitelist' and '.placeholderPattern' aren't compatible\" +\n \" wit