@tinacms/app 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appFiles/node_modules/.package-lock.json +27 -27
- package/appFiles/node_modules/@babel/generator/lib/buffer.js +1 -16
- package/appFiles/node_modules/@babel/generator/lib/buffer.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/base.js +0 -2
- package/appFiles/node_modules/@babel/generator/lib/generators/base.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/classes.js +0 -6
- package/appFiles/node_modules/@babel/generator/lib/generators/classes.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/expressions.js +1 -6
- package/appFiles/node_modules/@babel/generator/lib/generators/expressions.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/flow.js +0 -2
- package/appFiles/node_modules/@babel/generator/lib/generators/flow.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/methods.js +4 -11
- package/appFiles/node_modules/@babel/generator/lib/generators/methods.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/modules.js +0 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/modules.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/statements.js +0 -3
- package/appFiles/node_modules/@babel/generator/lib/generators/statements.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/types.js +1 -5
- package/appFiles/node_modules/@babel/generator/lib/generators/types.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/generators/typescript.js +2 -4
- package/appFiles/node_modules/@babel/generator/lib/generators/typescript.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/index.js +0 -6
- package/appFiles/node_modules/@babel/generator/lib/index.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/node/index.js +0 -1
- package/appFiles/node_modules/@babel/generator/lib/node/index.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/node/parentheses.js +8 -15
- package/appFiles/node_modules/@babel/generator/lib/node/parentheses.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/node/whitespace.js +1 -15
- package/appFiles/node_modules/@babel/generator/lib/node/whitespace.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/printer.js +8 -47
- package/appFiles/node_modules/@babel/generator/lib/printer.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/source-map.js +0 -4
- package/appFiles/node_modules/@babel/generator/lib/source-map.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/package.json +3 -3
- package/appFiles/node_modules/@babel/parser/lib/index.js +169 -684
- package/appFiles/node_modules/@babel/parser/lib/index.js.map +1 -1
- package/appFiles/node_modules/@babel/parser/package.json +1 -1
- package/appFiles/node_modules/@babel/runtime/helpers/applyDecs.js +3 -9
- package/appFiles/node_modules/@babel/runtime/helpers/applyDecs2203.js +169 -172
- package/appFiles/node_modules/@babel/runtime/helpers/applyDecs2203R.js +188 -0
- package/appFiles/node_modules/@babel/runtime/helpers/arrayLikeToArray.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/classNameTDZError.js +1 -1
- package/appFiles/node_modules/@babel/runtime/helpers/defineAccessor.js +8 -0
- package/appFiles/node_modules/@babel/runtime/helpers/esm/applyDecs.js +3 -9
- package/appFiles/node_modules/@babel/runtime/helpers/esm/applyDecs2203.js +169 -172
- package/appFiles/node_modules/@babel/runtime/helpers/esm/applyDecs2203R.js +187 -0
- package/appFiles/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/esm/classNameTDZError.js +1 -1
- package/appFiles/node_modules/@babel/runtime/helpers/esm/defineAccessor.js +7 -0
- package/appFiles/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimitLoose.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/esm/jsx.js +2 -6
- package/appFiles/node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js +3 -9
- package/appFiles/node_modules/@babel/runtime/helpers/esm/set.js +1 -1
- package/appFiles/node_modules/@babel/runtime/helpers/esm/wrapRegExp.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/iterableToArrayLimit.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/iterableToArrayLimitLoose.js +1 -3
- package/appFiles/node_modules/@babel/runtime/helpers/jsx.js +2 -6
- package/appFiles/node_modules/@babel/runtime/helpers/regeneratorRuntime.js +3 -9
- package/appFiles/node_modules/@babel/runtime/helpers/set.js +1 -1
- package/appFiles/node_modules/@babel/runtime/helpers/wrapRegExp.js +1 -3
- package/appFiles/node_modules/@babel/runtime/package.json +19 -1
- package/appFiles/node_modules/@babel/template/lib/builder.js +3 -15
- package/appFiles/node_modules/@babel/template/lib/builder.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/formatters.js +3 -8
- package/appFiles/node_modules/@babel/template/lib/formatters.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/index.js +2 -5
- package/appFiles/node_modules/@babel/template/lib/index.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/literal.js +3 -13
- package/appFiles/node_modules/@babel/template/lib/literal.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/options.js +10 -19
- package/appFiles/node_modules/@babel/template/lib/options.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/parse.js +3 -23
- package/appFiles/node_modules/@babel/template/lib/parse.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/populate.js +3 -15
- package/appFiles/node_modules/@babel/template/lib/populate.js.map +1 -0
- package/appFiles/node_modules/@babel/template/lib/string.js +3 -5
- package/appFiles/node_modules/@babel/template/lib/string.js.map +1 -0
- package/appFiles/node_modules/@babel/template/package.json +3 -3
- package/appFiles/node_modules/@babel/traverse/lib/context.js +2 -14
- package/appFiles/node_modules/@babel/traverse/lib/context.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/index.js +1 -4
- package/appFiles/node_modules/@babel/traverse/lib/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/ancestry.js +0 -19
- package/appFiles/node_modules/@babel/traverse/lib/path/ancestry.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/comments.js +0 -2
- package/appFiles/node_modules/@babel/traverse/lib/path/comments.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/context.js +5 -21
- package/appFiles/node_modules/@babel/traverse/lib/path/context.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/conversion.js +6 -30
- package/appFiles/node_modules/@babel/traverse/lib/path/conversion.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/evaluation.js +14 -20
- package/appFiles/node_modules/@babel/traverse/lib/path/evaluation.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/family.js +3 -9
- package/appFiles/node_modules/@babel/traverse/lib/path/family.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/index.js +1 -6
- package/appFiles/node_modules/@babel/traverse/lib/path/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/index.js +1 -9
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js +1 -13
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/inferers.js +2 -5
- package/appFiles/node_modules/@babel/traverse/lib/path/inference/inferers.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/introspection.js +21 -62
- package/appFiles/node_modules/@babel/traverse/lib/path/introspection.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/hoister.js +1 -22
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/hoister.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js +1 -7
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js +0 -2
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/virtual-types.js +0 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/lib/virtual-types.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/modification.js +12 -24
- package/appFiles/node_modules/@babel/traverse/lib/path/modification.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/removal.js +0 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/removal.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/replacement.js +2 -16
- package/appFiles/node_modules/@babel/traverse/lib/path/replacement.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/scope/binding.js +1 -6
- package/appFiles/node_modules/@babel/traverse/lib/scope/binding.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/scope/index.js +28 -63
- package/appFiles/node_modules/@babel/traverse/lib/scope/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/scope/lib/renamer.js +8 -14
- package/appFiles/node_modules/@babel/traverse/lib/scope/lib/renamer.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/visitors.js +2 -23
- package/appFiles/node_modules/@babel/traverse/lib/visitors.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/package.json +4 -4
- package/appFiles/node_modules/@babel/types/lib/asserts/assertNode.js.map +1 -1
- package/appFiles/node_modules/@babel/types/lib/traverse/traverse.js.map +1 -1
- package/appFiles/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js +2 -1
- package/appFiles/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js.map +1 -1
- package/appFiles/node_modules/@babel/types/package.json +3 -3
- package/appFiles/node_modules/css-to-react-native/README.md +4 -2
- package/appFiles/node_modules/css-to-react-native/index.js +13 -6
- package/appFiles/node_modules/css-to-react-native/package.json +2 -1
- package/appFiles/node_modules/css-to-react-native/src/__tests__/fontVariant.js +8 -0
- package/appFiles/node_modules/css-to-react-native/src/transforms/fontVariant.js +14 -0
- package/appFiles/node_modules/css-to-react-native/src/transforms/index.js +5 -7
- package/appFiles/src/fields/rich-text/monaco/index.tsx +12 -10
- package/appFiles/src/fields/rich-text/monaco/mdx.js +41 -35
- package/appFiles/src/lib/machines/document-machine.ts +1 -1
- package/dist/index.js +4 -2
- package/package.json +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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 \" with '.syntacticPlaceholders: true'\",\n );\n }\n\n if (\n state.isLegacyRef.value &&\n (state.placeholderPattern === false ||\n !(state.placeholderPattern || PATTERN).test(name)) &&\n !state.placeholderWhitelist?.has(name)\n ) {\n return;\n }\n\n // Keep our own copy of the ancestors so we can use it in .resolve().\n ancestors = ancestors.slice();\n\n const { node: parent, key } = ancestors[ancestors.length - 1];\n\n let type: PlaceholderType;\n if (\n isStringLiteral(node) ||\n isPlaceholder(node, { expectedNode: \"StringLiteral\" })\n ) {\n type = \"string\";\n } else if (\n (isNewExpression(parent) && key === \"arguments\") ||\n (isCallExpression(parent) && key === \"arguments\") ||\n (isFunction(parent) && key === \"params\")\n ) {\n type = \"param\";\n } else if (isExpressionStatement(parent) && !isPlaceholder(node)) {\n type = \"statement\";\n ancestors = ancestors.slice(0, -1);\n } else if (isStatement(node) && isPlaceholder(node)) {\n type = \"statement\";\n } else {\n type = \"other\";\n }\n\n const { placeholders, placeholderNames } = state.isLegacyRef.value\n ? state.legacy\n : state.syntactic;\n\n placeholders.push({\n name,\n type,\n resolve: ast => resolveAncestors(ast, ancestors),\n isDuplicate: placeholderNames.has(name),\n });\n placeholderNames.add(name);\n}\n\nfunction resolveAncestors(ast: t.File, ancestors: TraversalAncestors) {\n let parent: t.Node = ast;\n for (let i = 0; i < ancestors.length - 1; i++) {\n const { key, index } = ancestors[i];\n\n if (index === undefined) {\n parent = (parent as any)[key];\n } else {\n parent = (parent as any)[key][index];\n }\n }\n\n const { key, index } = ancestors[ancestors.length - 1];\n\n return { parent, key, index };\n}\n\ntype MetadataState = {\n syntactic: {\n placeholders: Array<Placeholder>;\n placeholderNames: Set<string>;\n };\n legacy: {\n placeholders: Array<Placeholder>;\n placeholderNames: Set<string>;\n };\n isLegacyRef: {\n value?: boolean;\n };\n placeholderWhitelist?: Set<string>;\n placeholderPattern?: RegExp | false;\n syntacticPlaceholders?: boolean;\n};\n\nfunction parseWithCodeFrame(\n code: string,\n parserOpts: ParserOpts,\n syntacticPlaceholders?: boolean,\n): t.File {\n const plugins = (parserOpts.plugins || []).slice();\n if (syntacticPlaceholders !== false) {\n plugins.push(\"placeholders\");\n }\n\n parserOpts = {\n allowReturnOutsideFunction: true,\n allowSuperOutsideMethod: true,\n sourceType: \"module\",\n ...parserOpts,\n plugins,\n };\n\n try {\n // @ts-expect-error todo: use babel-types ast typings in Babel parser\n return parse(code, parserOpts);\n } catch (err) {\n const loc = err.loc;\n if (loc) {\n err.message += \"\\n\" + codeFrameColumns(code, { start: loc });\n err.code = \"BABEL_TEMPLATE_PARSE_ERROR\";\n }\n throw err;\n }\n}\n"],"mappings":";;;;;;AAAA;AAeA;AACA;AAAqD;EAfnDA,gBAAgB;EAChBC,qBAAqB;EACrBC,UAAU;EACVC,YAAY;EACZC,eAAe;EACfC,eAAe;EACfC,aAAa;EACbC,WAAW;EACXC,eAAe;EACfC,oBAAoB;EACpBC;AAAQ;AAuBV,MAAMC,OAAO,GAAG,eAAe;AAEhB,SAASC,qBAAqB,CAC3CC,SAAuB,EACvBC,IAAY,EACZC,IAAkB,EACR;EACV,MAAM;IACJC,oBAAoB;IACpBC,kBAAkB;IAClBC,gBAAgB;IAChBC;EACF,CAAC,GAAGJ,IAAI;EAER,MAAMK,GAAG,GAAGC,kBAAkB,CAACP,IAAI,EAAEC,IAAI,CAACO,MAAM,EAAEH,qBAAqB,CAAC;EAExEV,oBAAoB,CAACW,GAAG,EAAE;IACxBF;EACF,CAAC,CAAC;EAEFL,SAAS,CAACU,QAAQ,CAACH,GAAG,CAAC;EAEvB,MAAMI,SAAqC,GAAG;IAC5CC,YAAY,EAAE,EAAE;IAChBC,gBAAgB,EAAE,IAAIC,GAAG;EAC3B,CAAC;EACD,MAAMC,MAA+B,GAAG;IACtCH,YAAY,EAAE,EAAE;IAChBC,gBAAgB,EAAE,IAAIC,GAAG;EAC3B,CAAC;EACD,MAAME,W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qB,KAAK,KAAK,EAAE;IACnCmC,OAAO,CAACR,IAAI,CAAC,cAAc,CAAC;EAC9B;EAEAO,UAAU;IACRE,0BAA0B,EAAE,IAAI;IAChCC,uBAAuB,EAAE,IAAI;IAC7BC,UAAU,EAAE;EAAQ,GACjBJ,UAAU;IACbC;EAAO,EACR;EAED,IAAI;IAEF,OAAO,IAAAI,aAAK,EAAC5C,IAAI,EAAEuC,UAAU,CAAC;EAChC,CAAC,CAAC,OAAOM,GAAG,EAAE;IACZ,MAAMC,GAAG,GAAGD,GAAG,CAACC,GAAG;IACnB,IAAIA,GAAG,EAAE;MACPD,GAAG,CAACE,OAAO,IAAI,IAAI,GAAG,IAAAC,2BAAgB,EAAChD,IAAI,EAAE;QAAEiD,KAAK,EAAEH;MAAI,CAAC,CAAC;MAC5DD,GAAG,CAAC7C,IAAI,GAAG,4BAA4B;IACzC;IACA,MAAM6C,GAAG;EACX;AACF"}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = populatePlaceholders;
|
|
7
|
-
|
|
8
7
|
var _t = require("@babel/types");
|
|
9
|
-
|
|
10
8
|
const {
|
|
11
9
|
blockStatement,
|
|
12
10
|
cloneNode,
|
|
@@ -18,10 +16,8 @@ const {
|
|
|
18
16
|
stringLiteral,
|
|
19
17
|
validate
|
|
20
18
|
} = _t;
|
|
21
|
-
|
|
22
19
|
function populatePlaceholders(metadata, replacements) {
|
|
23
20
|
const ast = cloneNode(metadata.ast);
|
|
24
|
-
|
|
25
21
|
if (replacements) {
|
|
26
22
|
metadata.placeholders.forEach(placeholder => {
|
|
27
23
|
if (!Object.prototype.hasOwnProperty.call(replacements, placeholder.name)) {
|
|
@@ -49,7 +45,6 @@ function populatePlaceholders(metadata, replacements) {
|
|
|
49
45
|
});
|
|
50
46
|
return ast;
|
|
51
47
|
}
|
|
52
|
-
|
|
53
48
|
function applyReplacement(placeholder, ast, replacement) {
|
|
54
49
|
if (placeholder.isDuplicate) {
|
|
55
50
|
if (Array.isArray(replacement)) {
|
|
@@ -58,18 +53,15 @@ function applyReplacement(placeholder, ast, replacement) {
|
|
|
58
53
|
replacement = cloneNode(replacement);
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
|
-
|
|
62
56
|
const {
|
|
63
57
|
parent,
|
|
64
58
|
key,
|
|
65
59
|
index
|
|
66
60
|
} = placeholder.resolve(ast);
|
|
67
|
-
|
|
68
61
|
if (placeholder.type === "string") {
|
|
69
62
|
if (typeof replacement === "string") {
|
|
70
63
|
replacement = stringLiteral(replacement);
|
|
71
64
|
}
|
|
72
|
-
|
|
73
65
|
if (!replacement || !isStringLiteral(replacement)) {
|
|
74
66
|
throw new Error("Expected string substitution");
|
|
75
67
|
}
|
|
@@ -89,7 +81,6 @@ function applyReplacement(placeholder, ast, replacement) {
|
|
|
89
81
|
if (typeof replacement === "string") {
|
|
90
82
|
replacement = identifier(replacement);
|
|
91
83
|
}
|
|
92
|
-
|
|
93
84
|
if (!isStatement(replacement)) {
|
|
94
85
|
replacement = expressionStatement(replacement);
|
|
95
86
|
}
|
|
@@ -99,24 +90,20 @@ function applyReplacement(placeholder, ast, replacement) {
|
|
|
99
90
|
if (typeof replacement === "string") {
|
|
100
91
|
replacement = identifier(replacement);
|
|
101
92
|
}
|
|
102
|
-
|
|
103
93
|
if (index === undefined) throw new Error("Assertion failure.");
|
|
104
94
|
} else {
|
|
105
95
|
if (typeof replacement === "string") {
|
|
106
96
|
replacement = identifier(replacement);
|
|
107
97
|
}
|
|
108
|
-
|
|
109
98
|
if (Array.isArray(replacement)) {
|
|
110
99
|
throw new Error("Cannot replace single expression with an array.");
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
|
-
|
|
114
102
|
if (index === undefined) {
|
|
115
103
|
validate(parent, key, replacement);
|
|
116
104
|
parent[key] = replacement;
|
|
117
105
|
} else {
|
|
118
106
|
const items = parent[key].slice();
|
|
119
|
-
|
|
120
107
|
if (placeholder.type === "statement" || placeholder.type === "param") {
|
|
121
108
|
if (replacement == null) {
|
|
122
109
|
items.splice(index, 1);
|
|
@@ -128,8 +115,9 @@ function applyReplacement(placeholder, ast, replacement) {
|
|
|
128
115
|
} else {
|
|
129
116
|
items[index] = replacement;
|
|
130
117
|
}
|
|
131
|
-
|
|
132
118
|
validate(parent, key, items);
|
|
133
119
|
parent[key] = items;
|
|
134
120
|
}
|
|
135
|
-
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=populate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["blockStatement","cloneNode","emptyStatement","expressionStatement","identifier","isStatement","isStringLiteral","stringLiteral","validate","populatePlaceholders","metadata","replacements","ast","placeholders","forEach","placeholder","Object","prototype","hasOwnProperty","call","name","placeholderName","Error","keys","key","placeholderNames","has","slice","reverse","applyReplacement","e","message","replacement","isDuplicate","Array","isArray","map","node","parent","index","resolve","type","undefined","items","splice"],"sources":["../src/populate.ts"],"sourcesContent":["import {\n blockStatement,\n cloneNode,\n emptyStatement,\n expressionStatement,\n identifier,\n isStatement,\n isStringLiteral,\n stringLiteral,\n validate,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nimport type { TemplateReplacements } from \"./options\";\nimport type { Metadata, Placeholder } from \"./parse\";\n\nexport default function populatePlaceholders(\n metadata: Metadata,\n replacements: TemplateReplacements,\n): t.File {\n const ast = cloneNode(metadata.ast);\n\n if (replacements) {\n metadata.placeholders.forEach(placeholder => {\n if (\n !Object.prototype.hasOwnProperty.call(replacements, placeholder.name)\n ) {\n const placeholderName = placeholder.name;\n\n throw new Error(\n `Error: No substitution given for \"${placeholderName}\". If this is not meant to be a\n placeholder you may want to consider passing one of the following options to @babel/template:\n - { placeholderPattern: false, placeholderWhitelist: new Set(['${placeholderName}'])}\n - { placeholderPattern: /^${placeholderName}$/ }`,\n );\n }\n });\n Object.keys(replacements).forEach(key => {\n if (!metadata.placeholderNames.has(key)) {\n throw new Error(`Unknown substitution \"${key}\" given`);\n }\n });\n }\n\n // Process in reverse order so AST mutation doesn't change indices that\n // will be needed for later calls to `placeholder.resolve()`.\n metadata.placeholders\n .slice()\n .reverse()\n .forEach(placeholder => {\n try {\n applyReplacement(\n placeholder,\n ast,\n (replacements && replacements[placeholder.name]) || null,\n );\n } catch (e) {\n e.message = `@babel/template placeholder \"${placeholder.name}\": ${e.message}`;\n throw e;\n }\n });\n\n return ast;\n}\n\nfunction applyReplacement(\n placeholder: Placeholder,\n ast: t.File,\n replacement: any,\n) {\n // Track inserted nodes and clone them if they are inserted more than\n // once to avoid injecting the same node multiple times.\n if (placeholder.isDuplicate) {\n if (Array.isArray(replacement)) {\n replacement = replacement.map(node => cloneNode(node));\n } else if (typeof replacement === \"object\") {\n replacement = cloneNode(replacement);\n }\n }\n\n const { parent, key, index } = placeholder.resolve(ast);\n\n if (placeholder.type === \"string\") {\n if (typeof replacement === \"string\") {\n replacement = stringLiteral(replacement);\n }\n if (!replacement || !isStringLiteral(replacement)) {\n throw new Error(\"Expected string substitution\");\n }\n } else if (placeholder.type === \"statement\") {\n if (index === undefined) {\n if (!replacement) {\n replacement = emptyStatement();\n } else if (Array.isArray(replacement)) {\n replacement = blockStatement(replacement);\n } else if (typeof replacement === \"string\") {\n replacement = expressionStatement(identifier(replacement));\n } else if (!isStatement(replacement)) {\n replacement = expressionStatement(replacement);\n }\n } else {\n if (replacement && !Array.isArray(replacement)) {\n if (typeof replacement === \"string\") {\n replacement = identifier(replacement);\n }\n if (!isStatement(replacement)) {\n replacement = expressionStatement(replacement);\n }\n }\n }\n } else if (placeholder.type === \"param\") {\n if (typeof replacement === \"string\") {\n replacement = identifier(replacement);\n }\n\n if (index === undefined) throw new Error(\"Assertion failure.\");\n } else {\n if (typeof replacement === \"string\") {\n replacement = identifier(replacement);\n }\n if (Array.isArray(replacement)) {\n throw new Error(\"Cannot replace single expression with an array.\");\n }\n }\n\n if (index === undefined) {\n validate(parent, key, replacement);\n\n (parent as any)[key] = replacement;\n } else {\n const items: Array<t.Node> = (parent as any)[key].slice();\n\n if (placeholder.type === \"statement\" || placeholder.type === \"param\") {\n if (replacement == null) {\n items.splice(index, 1);\n } else if (Array.isArray(replacement)) {\n items.splice(index, 1, ...replacement);\n } else {\n items[index] = replacement;\n }\n } else {\n items[index] = replacement;\n }\n\n validate(parent, key, items);\n (parent as any)[key] = items;\n }\n}\n"],"mappings":";;;;;;AAAA;AAUsB;EATpBA,cAAc;EACdC,SAAS;EACTC,cAAc;EACdC,mBAAmB;EACnBC,UAAU;EACVC,WAAW;EACXC,eAAe;EACfC,aAAa;EACbC;AAAQ;AAOK,SAASC,oBAAoB,CAC1CC,QAAkB,EAClBC,YAAkC,EAC1B;EACR,MAAMC,GAAG,GAAGX,SAAS,CAACS,QAAQ,CAACE,GAAG,CAAC;EAEnC,IAAID,YAAY,EAAE;IAChBD,QAAQ,CAACG,YAAY,CAACC,OAAO,CAACC,WAAW,IAAI;MAC3C,IACE,CAACC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACR,YAAY,EAAEI,WAAW,CAACK,IAAI,CAAC,EACrE;QACA,MAAMC,eAAe,GAAGN,WAAW,CAACK,IAAI;QAExC,MAAM,IAAIE,KAAK,CACZ,qCAAoCD,eAAgB;AAC/D;AACA,6EAA6EA,eAAgB;AAC7F,wCAAwCA,eAAgB,MAAK,CACpD;MACH;IACF,CAAC,CAAC;IACFL,MAAM,CAACO,IAAI,CAACZ,YAAY,CAAC,CAACG,OAAO,CAACU,GAAG,IAAI;MACvC,IAAI,CAACd,QAAQ,CAACe,gBAAgB,CAACC,GAAG,CAACF,GAAG,CAAC,EAAE;QACvC,MAAM,IAAIF,KAAK,CAAE,yBAAwBE,GAAI,SAAQ,CAAC;MACxD;IACF,CAAC,CAAC;EACJ;;EAIAd,QAAQ,CAACG,YAAY,CAClBc,KAAK,EAAE,CACPC,OAAO,EAAE,CACTd,OAAO,CAACC,WAAW,IAAI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AAG,EAAEQ,WAAW,CAAC;IAEjCM,MAAM,CAASd,GAAG,CAAC,GAAGQ,WAAW;EACpC,CAAC,MAAM;IACL,MAAMW,KAAoB,GAAIL,MAAM,CAASd,GAAG,CAAC,CAACG,KAAK,EAAE;IAEzD,IAAIZ,WAAW,CAAC0B,IAAI,KAAK,WAAW,IAAI1B,WAAW,CAAC0B,IAAI,KAAK,OAAO,EAAE;MACpE,IAAIT,WAAW,IAAI,IAAI,EAAE;QACvBW,KAAK,CAACC,MAAM,CAACL,KAAK,EAAE,CAAC,CAAC;MACxB,CAAC,MAAM,IAAIL,KAAK,CAACC,OAAO,CAACH,WAAW,CAAC,EAAE;QACrCW,KAAK,CAACC,MAAM,CAACL,KAAK,EAAE,CAAC,EAAE,GAAGP,WAAW,CAAC;MACxC,CAAC,MAAM;QACLW,KAAK,CAACJ,KAAK,CAAC,GAAGP,WAAW;MAC5B;IACF,CAAC,MAAM;MACLW,KAAK,CAACJ,KAAK,CAAC,GAAGP,WAAW;IAC5B;IAEAxB,QAAQ,CAAC8B,MAAM,EAAEd,GAAG,EAAEmB,KAAK,CAAC;IAC3BL,MAAM,CAASd,GAAG,CAAC,GAAGmB,KAAK;EAC9B;AACF"}
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = stringTemplate;
|
|
7
|
-
|
|
8
7
|
var _options = require("./options");
|
|
9
|
-
|
|
10
8
|
var _parse = require("./parse");
|
|
11
|
-
|
|
12
9
|
var _populate = require("./populate");
|
|
13
|
-
|
|
14
10
|
function stringTemplate(formatter, code, opts) {
|
|
15
11
|
code = formatter.code(code);
|
|
16
12
|
let metadata;
|
|
@@ -19,4 +15,6 @@ function stringTemplate(formatter, code, opts) {
|
|
|
19
15
|
if (!metadata) metadata = (0, _parse.default)(formatter, code, opts);
|
|
20
16
|
return formatter.unwrap((0, _populate.default)(metadata, replacements));
|
|
21
17
|
};
|
|
22
|
-
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["stringTemplate","formatter","code","opts","metadata","arg","replacements","normalizeReplacements","parseAndBuildMetadata","unwrap","populatePlaceholders"],"sources":["../src/string.ts"],"sourcesContent":["import type { Formatter } from \"./formatters\";\nimport type { TemplateOpts } from \"./options\";\nimport type { Metadata } from \"./parse\";\nimport { normalizeReplacements } from \"./options\";\nimport parseAndBuildMetadata from \"./parse\";\nimport populatePlaceholders from \"./populate\";\n\nexport default function stringTemplate<T>(\n formatter: Formatter<T>,\n code: string,\n opts: TemplateOpts,\n): (arg?: unknown) => T {\n code = formatter.code(code);\n\n let metadata: Metadata;\n\n return (arg?: unknown) => {\n const replacements = normalizeReplacements(arg);\n\n if (!metadata) metadata = parseAndBuildMetadata(formatter, code, opts);\n\n return formatter.unwrap(populatePlaceholders(metadata, replacements));\n };\n}\n"],"mappings":";;;;;;AAGA;AACA;AACA;AAEe,SAASA,cAAc,CACpCC,SAAuB,EACvBC,IAAY,EACZC,IAAkB,EACI;EACtBD,IAAI,GAAGD,SAAS,CAACC,IAAI,CAACA,IAAI,CAAC;EAE3B,IAAIE,QAAkB;EAEtB,OAAQC,GAAa,IAAK;IACxB,MAAMC,YAAY,GAAG,IAAAC,8BAAqB,EAACF,GAAG,CAAC;IAE/C,IAAI,CAACD,QAAQ,EAAEA,QAAQ,GAAG,IAAAI,cAAqB,EAACP,SAAS,EAAEC,IAAI,EAAEC,IAAI,CAAC;IAEtE,OAAOF,SAAS,CAACQ,MAAM,CAAC,IAAAC,iBAAoB,EAACN,QAAQ,EAAEE,YAAY,CAAC,CAAC;EACvE,CAAC;AACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babel/template",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.20.7",
|
|
4
4
|
"description": "Generate an AST from a string template.",
|
|
5
5
|
"author": "The Babel Team (https://babel.dev/team)",
|
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-template",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"main": "./lib/index.js",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/code-frame": "^7.18.6",
|
|
20
|
-
"@babel/parser": "^7.
|
|
21
|
-
"@babel/types": "^7.
|
|
20
|
+
"@babel/parser": "^7.20.7",
|
|
21
|
+
"@babel/types": "^7.20.7"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=6.9.0"
|
|
@@ -18,19 +18,14 @@ class TraversalContext {
|
|
|
18
18
|
this.state = state;
|
|
19
19
|
this.opts = opts;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
shouldVisit(node) {
|
|
23
22
|
const opts = this.opts;
|
|
24
23
|
if (opts.enter || opts.exit) return true;
|
|
25
|
-
|
|
26
24
|
if (opts[node.type]) return true;
|
|
27
|
-
|
|
28
25
|
const keys = VISITOR_KEYS[node.type];
|
|
29
26
|
if (!(keys != null && keys.length)) return false;
|
|
30
|
-
|
|
31
27
|
for (const key of keys) {
|
|
32
|
-
if (
|
|
33
|
-
node[key]) {
|
|
28
|
+
if (node[key]) {
|
|
34
29
|
return true;
|
|
35
30
|
}
|
|
36
31
|
}
|
|
@@ -57,7 +52,6 @@ class TraversalContext {
|
|
|
57
52
|
visitMultiple(container, parent, listKey) {
|
|
58
53
|
if (container.length === 0) return false;
|
|
59
54
|
const queue = [];
|
|
60
|
-
|
|
61
55
|
for (let key = 0; key < container.length; key++) {
|
|
62
56
|
const node = container[key];
|
|
63
57
|
if (node && this.shouldVisit(node)) {
|
|
@@ -67,8 +61,7 @@ class TraversalContext {
|
|
|
67
61
|
return this.visitQueue(queue);
|
|
68
62
|
}
|
|
69
63
|
visitSingle(node, key) {
|
|
70
|
-
if (this.shouldVisit(
|
|
71
|
-
node[key])) {
|
|
64
|
+
if (this.shouldVisit(node[key])) {
|
|
72
65
|
return this.visitQueue([this.create(node, node, key)]);
|
|
73
66
|
} else {
|
|
74
67
|
return false;
|
|
@@ -79,15 +72,12 @@ class TraversalContext {
|
|
|
79
72
|
this.priorityQueue = [];
|
|
80
73
|
const visited = new WeakSet();
|
|
81
74
|
let stop = false;
|
|
82
|
-
|
|
83
75
|
for (const path of queue) {
|
|
84
76
|
path.resync();
|
|
85
77
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
|
86
78
|
path.pushContext(this);
|
|
87
79
|
}
|
|
88
|
-
|
|
89
80
|
if (path.key === null) continue;
|
|
90
|
-
|
|
91
81
|
const {
|
|
92
82
|
node
|
|
93
83
|
} = path;
|
|
@@ -104,11 +94,9 @@ class TraversalContext {
|
|
|
104
94
|
if (stop) break;
|
|
105
95
|
}
|
|
106
96
|
}
|
|
107
|
-
|
|
108
97
|
for (const path of queue) {
|
|
109
98
|
path.popContext();
|
|
110
99
|
}
|
|
111
|
-
|
|
112
100
|
this.queue = null;
|
|
113
101
|
return stop;
|
|
114
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VISITOR_KEYS","TraversalContext","constructor","scope","opts","state","parentPath","queue","priorityQueue","shouldVisit","node","enter","exit","type","keys","length","key","create","container","listKey","NodePath","get","parent","maybeQueue","path","notPriority","push","visitMultiple","visitQueue","visitSingle","visited","WeakSet","stop","resync","contexts","pushContext","has","add","visit","popContext","nodes","Array","isArray"],"sources":["../src/context.ts"],"sourcesContent":["import NodePath from \"./path\";\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type Scope from \"./scope\";\nimport type { TraverseOptions } from \".\";\nimport type * as t from \"@babel/types\";\nimport type { Visitor } from \"./types\";\n\nexport default class TraversalContext<S = unknown> {\n constructor(\n scope: Scope,\n opts: TraverseOptions,\n state: S,\n parentPath: NodePath,\n ) {\n this.parentPath = parentPath;\n this.scope = scope;\n this.state = state;\n this.opts = opts;\n }\n\n declare parentPath: NodePath;\n declare scope: Scope;\n declare state: S;\n declare opts: TraverseOptions;\n queue: Array<NodePath> | null = null;\n priorityQueue: Array<NodePath> | null = null;\n\n /**\n * This method does a simple check to determine whether or not we really need to attempt\n * visit a node. This will prevent us from constructing a NodePath.\n */\n\n shouldVisit(node: t.Node): boolean {\n const opts = this.opts as Visitor;\n if (opts.enter || opts.exit) return true;\n\n // check if we have a visitor for this node\n if (opts[node.type]) return true;\n\n // check if we're going to traverse into this node\n const keys: Array<string> | undefined = VISITOR_KEYS[node.type];\n if (!keys?.length) return false;\n\n // we need to traverse into this node so ensure that it has children to traverse into!\n for (const key of keys) {\n if (\n // @ts-expect-error key is from visitor keys\n node[key]\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n create(\n node: t.Node,\n container: t.Node | t.Node[],\n key: string | number,\n listKey?: string,\n ): NodePath {\n // We don't need to `.setContext()` here, since `.visitQueue()` already\n // calls `.pushContext`.\n return NodePath.get({\n parentPath: this.parentPath,\n parent: node,\n container,\n key: key,\n listKey,\n });\n }\n\n maybeQueue(path: NodePath, notPriority?: boolean) {\n if (this.queue) {\n if (notPriority) {\n this.queue.push(path);\n } else {\n this.priorityQueue.push(path);\n }\n }\n }\n\n visitMultiple(container: t.Node[], parent: t.Node, listKey: string) {\n // nothing to traverse!\n if (container.length === 0) return false;\n\n const queue = [];\n\n // build up initial queue\n for (let key = 0; key < container.length; key++) {\n const node = container[key];\n if (node && this.shouldVisit(node)) {\n queue.push(this.create(parent, container, key, listKey));\n }\n }\n\n return this.visitQueue(queue);\n }\n\n visitSingle(node: t.Node, key: string): boolean {\n if (\n this.shouldVisit(\n // @ts-expect-error key may not index node\n node[key],\n )\n ) {\n return this.visitQueue([this.create(node, node, key)]);\n } else {\n return false;\n }\n }\n\n visitQueue(queue: Array<NodePath>): boolean {\n // set queue\n this.queue = queue;\n this.priorityQueue = [];\n\n const visited = new WeakSet();\n let stop = false;\n\n // visit the queue\n for (const path of queue) {\n path.resync();\n\n if (\n path.contexts.length === 0 ||\n path.contexts[path.contexts.length - 1] !== this\n ) {\n // The context might already have been pushed when this path was inserted and queued.\n // If we always re-pushed here, we could get duplicates and risk leaving contexts\n // on the stack after the traversal has completed, which could break things.\n path.pushContext(this);\n }\n\n // this path no longer belongs to the tree\n if (path.key === null) continue;\n\n // ensure we don't visit the same node twice\n const { node } = path;\n if (visited.has(node)) continue;\n if (node) visited.add(node);\n\n if (path.visit()) {\n stop = true;\n break;\n }\n\n if (this.priorityQueue.length) {\n stop = this.visitQueue(this.priorityQueue);\n this.priorityQueue = [];\n this.queue = queue;\n if (stop) break;\n }\n }\n\n // clear queue\n for (const path of queue) {\n path.popContext();\n }\n\n // clear queue\n this.queue = null;\n\n return stop;\n }\n\n visit(node: t.Node, key: string) {\n // @ts-expect-error key may not index node\n const nodes = node[key] as t.Node | t.Node[] | null;\n if (!nodes) return false;\n\n if (Array.isArray(nodes)) {\n return this.visitMultiple(nodes, node, key);\n } else {\n return this.visitSingle(node, key);\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AAA4C;EAAnCA;AAAY;AAMN,MAAMC,gBAAgB,CAAc;EACjDC,WAAW,CACTC,KAAY,EACZC,IAAqB,EACrBC,KAAQ,EACRC,UAAoB,EACpB;IAAA,KAWFC,KAAK,GAA2B,IAAI;IAAA,KACpCC,aAAa,GAA2B,IAAI;IAX1C,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","TraversalContext","constructor","scope","opts","state","parentPath","queue","priorityQueue","shouldVisit","node","enter","exit","type","keys","length","key","create","container","listKey","NodePath","get","parent","maybeQueue","path","notPriority","push","visitMultiple","visitQueue","visitSingle","visited","WeakSet","stop","resync","contexts","pushContext","has","add","visit","popContext","nodes","Array","isArray"],"sources":["../src/context.ts"],"sourcesContent":["import NodePath from \"./path\";\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type Scope from \"./scope\";\nimport type { TraverseOptions } from \".\";\nimport type * as t from \"@babel/types\";\nimport type { Visitor } from \"./types\";\n\nexport default class TraversalContext<S = unknown> {\n constructor(\n scope: Scope,\n opts: TraverseOptions,\n state: S,\n parentPath: NodePath,\n ) {\n this.parentPath = parentPath;\n this.scope = scope;\n this.state = state;\n this.opts = opts;\n }\n\n declare parentPath: NodePath;\n declare scope: Scope;\n declare state: S;\n declare opts: TraverseOptions;\n queue: Array<NodePath> | null = null;\n priorityQueue: Array<NodePath> | null = null;\n\n /**\n * This method does a simple check to determine whether or not we really need to attempt\n * visit a node. This will prevent us from constructing a NodePath.\n */\n\n shouldVisit(node: t.Node): boolean {\n const opts = this.opts as Visitor;\n if (opts.enter || opts.exit) return true;\n\n // check if we have a visitor for this node\n if (opts[node.type]) return true;\n\n // check if we're going to traverse into this node\n const keys: Array<string> | undefined = VISITOR_KEYS[node.type];\n if (!keys?.length) return false;\n\n // we need to traverse into this node so ensure that it has children to traverse into!\n for (const key of keys) {\n if (\n // @ts-expect-error key is from visitor keys\n node[key]\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n create(\n node: t.Node,\n container: t.Node | t.Node[],\n key: string | number,\n listKey?: string,\n ): NodePath {\n // We don't need to `.setContext()` here, since `.visitQueue()` already\n // calls `.pushContext`.\n return NodePath.get({\n parentPath: this.parentPath,\n parent: node,\n container,\n key: key,\n listKey,\n });\n }\n\n maybeQueue(path: NodePath, notPriority?: boolean) {\n if (this.queue) {\n if (notPriority) {\n this.queue.push(path);\n } else {\n this.priorityQueue.push(path);\n }\n }\n }\n\n visitMultiple(container: t.Node[], parent: t.Node, listKey: string) {\n // nothing to traverse!\n if (container.length === 0) return false;\n\n const queue = [];\n\n // build up initial queue\n for (let key = 0; key < container.length; key++) {\n const node = container[key];\n if (node && this.shouldVisit(node)) {\n queue.push(this.create(parent, container, key, listKey));\n }\n }\n\n return this.visitQueue(queue);\n }\n\n visitSingle(node: t.Node, key: string): boolean {\n if (\n this.shouldVisit(\n // @ts-expect-error key may not index node\n node[key],\n )\n ) {\n return this.visitQueue([this.create(node, node, key)]);\n } else {\n return false;\n }\n }\n\n visitQueue(queue: Array<NodePath>): boolean {\n // set queue\n this.queue = queue;\n this.priorityQueue = [];\n\n const visited = new WeakSet();\n let stop = false;\n\n // visit the queue\n for (const path of queue) {\n path.resync();\n\n if (\n path.contexts.length === 0 ||\n path.contexts[path.contexts.length - 1] !== this\n ) {\n // The context might already have been pushed when this path was inserted and queued.\n // If we always re-pushed here, we could get duplicates and risk leaving contexts\n // on the stack after the traversal has completed, which could break things.\n path.pushContext(this);\n }\n\n // this path no longer belongs to the tree\n if (path.key === null) continue;\n\n // ensure we don't visit the same node twice\n const { node } = path;\n if (visited.has(node)) continue;\n if (node) visited.add(node);\n\n if (path.visit()) {\n stop = true;\n break;\n }\n\n if (this.priorityQueue.length) {\n stop = this.visitQueue(this.priorityQueue);\n this.priorityQueue = [];\n this.queue = queue;\n if (stop) break;\n }\n }\n\n // clear queue\n for (const path of queue) {\n path.popContext();\n }\n\n // clear queue\n this.queue = null;\n\n return stop;\n }\n\n visit(node: t.Node, key: string) {\n // @ts-expect-error key may not index node\n const nodes = node[key] as t.Node | t.Node[] | null;\n if (!nodes) return false;\n\n if (Array.isArray(nodes)) {\n return this.visitMultiple(nodes, node, key);\n } else {\n return this.visitSingle(node, key);\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AAA4C;EAAnCA;AAAY;AAMN,MAAMC,gBAAgB,CAAc;EACjDC,WAAW,CACTC,KAAY,EACZC,IAAqB,EACrBC,KAAQ,EACRC,UAAoB,EACpB;IAAA,KAWFC,KAAK,GAA2B,IAAI;IAAA,KACpCC,aAAa,GAA2B,IAAI;IAX1C,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACE,KAAK,GAAGA,KAAK;I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M,GAAG,CAAC1B,IAAI,CAAC,EAAE;MACvB,IAAIA,IAAI,EAAEoB,OAAO,CAACO,GAAG,CAAC3B,IAAI,CAAC;MAE3B,IAAIc,IAAI,CAACc,KAAK,EAAE,EAAE;QAChBN,IAAI,GAAG,IAAI;QACX;MACF;MAEA,IAAI,IAAI,CAACxB,aAAa,CAACO,MAAM,EAAE;QAC7BiB,IAAI,GAAG,IAAI,CAACJ,UAAU,CAAC,IAAI,CAACpB,aAAa,CAAC;QAC1C,IAAI,CAACA,aAAa,GAAG,EAAE;QACvB,IAAI,CAACD,KAAK,GAAGA,KAAK;QAClB,IAAIyB,IAAI,EAAE;MACZ;IACF;IAGA,KAAK,MAAMR,IAAI,IAAIjB,KAAK,EAAE;MACxBiB,IAAI,CAACe,UAAU,EAAE;IACnB;IAGA,IAAI,CAAChC,KAAK,GAAG,IAAI;IAEjB,OAAOyB,IAAI;EACb;EAEAM,KAAK,CAAC5B,IAAY,EAAEM,GAAW,EAAE;IAE/B,MAAMwB,KAAK,GAAG9B,IAAI,CAACM,GAAG,CAA6B;IACnD,IAAI,CAACwB,KAAK,EAAE,OAAO,KAAK;IAExB,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACxB,OAAO,IAAI,CAACb,aAAa,CAACa,KAAK,EAAE9B,IAAI,EAAEM,GAAG,CAAC;IAC7C,CAAC,MAAM;MACL,OAAO,IAAI,CAACa,WAAW,CAACnB,IAAI,EAAEM,GAAG,CAAC;IACpC;EACF;AACF;AAAC"}
|
|
@@ -35,8 +35,7 @@ const {
|
|
|
35
35
|
removeProperties,
|
|
36
36
|
traverseFast
|
|
37
37
|
} = _t;
|
|
38
|
-
function traverse(parent,
|
|
39
|
-
opts = {}, scope, state, parentPath) {
|
|
38
|
+
function traverse(parent, opts = {}, scope, state, parentPath) {
|
|
40
39
|
if (!parent) return;
|
|
41
40
|
if (!opts.noScope && !scope) {
|
|
42
41
|
if (parent.type !== "Program" && parent.type !== "File") {
|
|
@@ -60,7 +59,6 @@ traverse.cheap = function (node, enter) {
|
|
|
60
59
|
traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
|
61
60
|
(0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys);
|
|
62
61
|
};
|
|
63
|
-
|
|
64
62
|
traverse.clearNode = function (node, opts) {
|
|
65
63
|
removeProperties(node, opts);
|
|
66
64
|
cache.path.delete(node);
|
|
@@ -77,7 +75,6 @@ function hasDenylistedType(path, state) {
|
|
|
77
75
|
}
|
|
78
76
|
traverse.hasType = function (tree, type, denylistTypes) {
|
|
79
77
|
if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
|
|
80
|
-
|
|
81
78
|
if (tree.type === type) return true;
|
|
82
79
|
const state = {
|
|
83
80
|
has: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VISITOR_KEYS","removeProperties","traverseFast","traverse","parent","opts","scope","state","parentPath","noScope","type","Error","visitors","explode","traverseNode","verify","cheap","node","enter","path","skipKeys","clearNode","cache","delete","tree","hasDenylistedType","has","stop","hasType","denylistTypes","includes","denylist"],"sources":["../src/index.ts"],"sourcesContent":["import * as visitors from \"./visitors\";\nimport {\n VISITOR_KEYS,\n removeProperties,\n type RemovePropertiesOptions,\n traverseFast,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport * as cache from \"./cache\";\nimport type NodePath from \"./path\";\nimport type { default as Scope, Binding } from \"./scope\";\nimport type { Visitor } from \"./types\";\nimport { traverseNode } from \"./traverse-node\";\n\nexport type { Visitor, Binding };\nexport { default as NodePath } from \"./path\";\nexport { default as Scope } from \"./scope\";\nexport { default as Hub } from \"./hub\";\nexport type { HubInterface } from \"./hub\";\n\nexport { visitors };\n\nexport type TraverseOptions<S = t.Node> = {\n scope?: Scope;\n noScope?: boolean;\n denylist?: string[];\n} & Visitor<S>;\n\nfunction traverse<S>(\n parent: t.Node,\n opts: TraverseOptions<S>,\n scope: Scope | undefined,\n state: S,\n parentPath?: NodePath,\n): void;\n\nfunction traverse(\n parent: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n): void;\n\nfunction traverse<Options extends TraverseOptions>(\n parent: t.Node,\n // @ts-expect-error provide {} as default value for Options\n opts: Options = {},\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n) {\n if (!parent) return;\n\n if (!opts.noScope && !scope) {\n if (parent.type !== \"Program\" && parent.type !== \"File\") {\n throw new Error(\n \"You must pass a scope and parentPath unless traversing a Program/File. \" +\n `Instead of that you tried to traverse a ${parent.type} node without ` +\n \"passing scope and parentPath.\",\n );\n }\n }\n\n if (!VISITOR_KEYS[parent.type]) {\n return;\n }\n\n visitors.explode(opts as Visitor);\n\n traverseNode(parent, opts, scope, state, parentPath);\n}\n\nexport default traverse;\n\ntraverse.visitors = visitors;\ntraverse.verify = visitors.verify;\ntraverse.explode = visitors.explode;\n\ntraverse.cheap = function (node: t.Node, enter: (node: t.Node) => void) {\n return traverseFast(node, enter);\n};\n\ntraverse.node = function (\n node: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n path?: NodePath,\n skipKeys?: Record<string, boolean>,\n) {\n traverseNode(node, opts, scope, state, path, skipKeys);\n // traverse.node always returns undefined\n};\n\ntraverse.clearNode = function (node: t.Node, opts?: RemovePropertiesOptions) {\n removeProperties(node, opts);\n\n cache.path.delete(node);\n};\n\ntraverse.removeProperties = function (\n tree: t.Node,\n opts?: RemovePropertiesOptions,\n) {\n traverseFast(tree, traverse.clearNode, opts);\n return tree;\n};\n\ntype HasDenylistedTypeState = {\n has: boolean;\n type: t.Node[\"type\"];\n};\nfunction hasDenylistedType(path: NodePath, state: HasDenylistedTypeState) {\n if (path.node.type === state.type) {\n state.has = true;\n path.stop();\n }\n}\n\ntraverse.hasType = function (\n tree: t.Node,\n type: t.Node[\"type\"],\n denylistTypes?: Array<string>,\n): boolean {\n // the node we're searching in is denylisted\n if (denylistTypes?.includes(tree.type)) return false;\n\n // the type we're looking for is the same as the passed node\n if (tree.type === type) return true;\n\n const state: HasDenylistedTypeState = {\n has: false,\n type: type,\n };\n\n traverse(\n tree,\n {\n noScope: true,\n denylist: denylistTypes,\n enter: hasDenylistedType,\n },\n null,\n state,\n );\n\n return state.has;\n};\n\ntraverse.cache = cache;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAuC;AACvC;AAOA;AAIA;AAGA;AACA;AACA;AAAuC;EAfrCA,YAAY;EACZC,gBAAgB;EAEhBC;AAAY;AAuCd,SAASC,QAAQ,CACfC,MAAc
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","removeProperties","traverseFast","traverse","parent","opts","scope","state","parentPath","noScope","type","Error","visitors","explode","traverseNode","verify","cheap","node","enter","path","skipKeys","clearNode","cache","delete","tree","hasDenylistedType","has","stop","hasType","denylistTypes","includes","denylist"],"sources":["../src/index.ts"],"sourcesContent":["import * as visitors from \"./visitors\";\nimport {\n VISITOR_KEYS,\n removeProperties,\n type RemovePropertiesOptions,\n traverseFast,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport * as cache from \"./cache\";\nimport type NodePath from \"./path\";\nimport type { default as Scope, Binding } from \"./scope\";\nimport type { Visitor } from \"./types\";\nimport { traverseNode } from \"./traverse-node\";\n\nexport type { Visitor, Binding };\nexport { default as NodePath } from \"./path\";\nexport { default as Scope } from \"./scope\";\nexport { default as Hub } from \"./hub\";\nexport type { HubInterface } from \"./hub\";\n\nexport { visitors };\n\nexport type TraverseOptions<S = t.Node> = {\n scope?: Scope;\n noScope?: boolean;\n denylist?: string[];\n} & Visitor<S>;\n\nfunction traverse<S>(\n parent: t.Node,\n opts: TraverseOptions<S>,\n scope: Scope | undefined,\n state: S,\n parentPath?: NodePath,\n): void;\n\nfunction traverse(\n parent: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n): void;\n\nfunction traverse<Options extends TraverseOptions>(\n parent: t.Node,\n // @ts-expect-error provide {} as default value for Options\n opts: Options = {},\n scope?: Scope,\n state?: any,\n parentPath?: NodePath,\n) {\n if (!parent) return;\n\n if (!opts.noScope && !scope) {\n if (parent.type !== \"Program\" && parent.type !== \"File\") {\n throw new Error(\n \"You must pass a scope and parentPath unless traversing a Program/File. \" +\n `Instead of that you tried to traverse a ${parent.type} node without ` +\n \"passing scope and parentPath.\",\n );\n }\n }\n\n if (!VISITOR_KEYS[parent.type]) {\n return;\n }\n\n visitors.explode(opts as Visitor);\n\n traverseNode(parent, opts, scope, state, parentPath);\n}\n\nexport default traverse;\n\ntraverse.visitors = visitors;\ntraverse.verify = visitors.verify;\ntraverse.explode = visitors.explode;\n\ntraverse.cheap = function (node: t.Node, enter: (node: t.Node) => void) {\n return traverseFast(node, enter);\n};\n\ntraverse.node = function (\n node: t.Node,\n opts: TraverseOptions,\n scope?: Scope,\n state?: any,\n path?: NodePath,\n skipKeys?: Record<string, boolean>,\n) {\n traverseNode(node, opts, scope, state, path, skipKeys);\n // traverse.node always returns undefined\n};\n\ntraverse.clearNode = function (node: t.Node, opts?: RemovePropertiesOptions) {\n removeProperties(node, opts);\n\n cache.path.delete(node);\n};\n\ntraverse.removeProperties = function (\n tree: t.Node,\n opts?: RemovePropertiesOptions,\n) {\n traverseFast(tree, traverse.clearNode, opts);\n return tree;\n};\n\ntype HasDenylistedTypeState = {\n has: boolean;\n type: t.Node[\"type\"];\n};\nfunction hasDenylistedType(path: NodePath, state: HasDenylistedTypeState) {\n if (path.node.type === state.type) {\n state.has = true;\n path.stop();\n }\n}\n\ntraverse.hasType = function (\n tree: t.Node,\n type: t.Node[\"type\"],\n denylistTypes?: Array<string>,\n): boolean {\n // the node we're searching in is denylisted\n if (denylistTypes?.includes(tree.type)) return false;\n\n // the type we're looking for is the same as the passed node\n if (tree.type === type) return true;\n\n const state: HasDenylistedTypeState = {\n has: false,\n type: type,\n };\n\n traverse(\n tree,\n {\n noScope: true,\n denylist: denylistTypes,\n enter: hasDenylistedType,\n },\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GA,KAAK"}
|
|
@@ -17,7 +17,6 @@ var _t = require("@babel/types");
|
|
|
17
17
|
const {
|
|
18
18
|
VISITOR_KEYS
|
|
19
19
|
} = _t;
|
|
20
|
-
|
|
21
20
|
function findParent(callback) {
|
|
22
21
|
let path = this;
|
|
23
22
|
while (path = path.parentPath) {
|
|
@@ -25,7 +24,6 @@ function findParent(callback) {
|
|
|
25
24
|
}
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
function find(callback) {
|
|
30
28
|
let path = this;
|
|
31
29
|
do {
|
|
@@ -33,11 +31,9 @@ function find(callback) {
|
|
|
33
31
|
} while (path = path.parentPath);
|
|
34
32
|
return null;
|
|
35
33
|
}
|
|
36
|
-
|
|
37
34
|
function getFunctionParent() {
|
|
38
35
|
return this.findParent(p => p.isFunction());
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
function getStatementParent() {
|
|
42
38
|
let path = this;
|
|
43
39
|
do {
|
|
@@ -52,26 +48,22 @@ function getStatementParent() {
|
|
|
52
48
|
}
|
|
53
49
|
return path;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
51
|
function getEarliestCommonAncestorFrom(paths) {
|
|
57
52
|
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
|
58
53
|
let earliest;
|
|
59
54
|
const keys = VISITOR_KEYS[deepest.type];
|
|
60
55
|
for (const ancestry of ancestries) {
|
|
61
56
|
const path = ancestry[i + 1];
|
|
62
|
-
|
|
63
57
|
if (!earliest) {
|
|
64
58
|
earliest = path;
|
|
65
59
|
continue;
|
|
66
60
|
}
|
|
67
|
-
|
|
68
61
|
if (path.listKey && earliest.listKey === path.listKey) {
|
|
69
62
|
if (path.key < earliest.key) {
|
|
70
63
|
earliest = path;
|
|
71
64
|
continue;
|
|
72
65
|
}
|
|
73
66
|
}
|
|
74
|
-
|
|
75
67
|
const earliestKeyIndex = keys.indexOf(earliest.parentKey);
|
|
76
68
|
const currentKeyIndex = keys.indexOf(path.parentKey);
|
|
77
69
|
if (earliestKeyIndex > currentKeyIndex) {
|
|
@@ -81,7 +73,6 @@ function getEarliestCommonAncestorFrom(paths) {
|
|
|
81
73
|
return earliest;
|
|
82
74
|
});
|
|
83
75
|
}
|
|
84
|
-
|
|
85
76
|
function getDeepestCommonAncestorFrom(paths, filter) {
|
|
86
77
|
if (!paths.length) {
|
|
87
78
|
return this;
|
|
@@ -89,25 +80,19 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
|
89
80
|
if (paths.length === 1) {
|
|
90
81
|
return paths[0];
|
|
91
82
|
}
|
|
92
|
-
|
|
93
83
|
let minDepth = Infinity;
|
|
94
|
-
|
|
95
84
|
let lastCommonIndex, lastCommon;
|
|
96
|
-
|
|
97
85
|
const ancestries = paths.map(path => {
|
|
98
86
|
const ancestry = [];
|
|
99
87
|
do {
|
|
100
88
|
ancestry.unshift(path);
|
|
101
89
|
} while ((path = path.parentPath) && path !== this);
|
|
102
|
-
|
|
103
90
|
if (ancestry.length < minDepth) {
|
|
104
91
|
minDepth = ancestry.length;
|
|
105
92
|
}
|
|
106
93
|
return ancestry;
|
|
107
94
|
});
|
|
108
|
-
|
|
109
95
|
const first = ancestries[0];
|
|
110
|
-
|
|
111
96
|
depthLoop: for (let i = 0; i < minDepth; i++) {
|
|
112
97
|
const shouldMatch = first[i];
|
|
113
98
|
for (const ancestry of ancestries) {
|
|
@@ -115,7 +100,6 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
|
115
100
|
break depthLoop;
|
|
116
101
|
}
|
|
117
102
|
}
|
|
118
|
-
|
|
119
103
|
lastCommonIndex = i;
|
|
120
104
|
lastCommon = shouldMatch;
|
|
121
105
|
}
|
|
@@ -129,7 +113,6 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
|
129
113
|
throw new Error("Couldn't find intersection");
|
|
130
114
|
}
|
|
131
115
|
}
|
|
132
|
-
|
|
133
116
|
function getAncestry() {
|
|
134
117
|
let path = this;
|
|
135
118
|
const paths = [];
|
|
@@ -138,11 +121,9 @@ function getAncestry() {
|
|
|
138
121
|
} while (path = path.parentPath);
|
|
139
122
|
return paths;
|
|
140
123
|
}
|
|
141
|
-
|
|
142
124
|
function isAncestor(maybeDescendant) {
|
|
143
125
|
return maybeDescendant.isDescendant(this);
|
|
144
126
|
}
|
|
145
|
-
|
|
146
127
|
function isDescendant(maybeAncestor) {
|
|
147
128
|
return !!this.findParent(parent => parent === maybeAncestor);
|
|
148
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VISITOR_KEYS","findParent","callback","path","parentPath","find","getFunctionParent","p","isFunction","getStatementParent","Array","isArray","container","isStatement","isProgram","isFile","Error","getEarliestCommonAncestorFrom","paths","getDeepestCommonAncestorFrom","deepest","i","ancestries","earliest","keys","type","ancestry","listKey","key","earliestKeyIndex","indexOf","parentKey","currentKeyIndex","filter","length","minDepth","Infinity","lastCommonIndex","lastCommon","map","unshift","first","depthLoop","shouldMatch","getAncestry","push","isAncestor","maybeDescendant","isDescendant","maybeAncestor","parent","inType","candidateTypes","node"],"sources":["../../src/path/ancestry.ts"],"sourcesContent":["// This file contains that retrieve or validate anything related to the current paths ancestry.\n\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\n\n/**\n * Starting at the parent path of the current `NodePath` and going up the\n * tree, return the first `NodePath` that causes the provided `callback`\n * to return a truthy value, or `null` if the `callback` never returns a\n * truthy value.\n */\n\nexport function findParent(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n while ((path = path.parentPath)) {\n if (callback(path)) return path;\n }\n return null;\n}\n\n/**\n * Starting at current `NodePath` and going up the tree, return the first\n * `NodePath` that causes the provided `callback` to return a truthy value,\n * or `null` if the `callback` never returns a truthy value.\n */\n\nexport function find(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n do {\n if (callback(path)) return path;\n } while ((path = path.parentPath));\n return null;\n}\n\n/**\n * Get the parent function of the current path.\n */\n\nexport function getFunctionParent(this: NodePath): NodePath<t.Function> | null {\n return this.findParent(p => p.isFunction()) as NodePath<t.Function> | null;\n}\n\n/**\n * Walk up the tree until we hit a parent node path in a list.\n */\n\nexport function getStatementParent(this: NodePath): NodePath<t.Statement> {\n let path = this;\n\n do {\n if (\n !path.parentPath ||\n (Array.isArray(path.container) && path.isStatement())\n ) {\n break;\n } else {\n path = path.parentPath;\n }\n } while (path);\n\n if (path && (path.isProgram() || path.isFile())) {\n throw new Error(\n \"File/Program node, we can't possibly find a statement parent to this\",\n );\n }\n\n return path as NodePath<t.Statement>;\n}\n\n/**\n * Get the deepest common ancestor and then from it, get the earliest relationship path\n * to that ancestor.\n *\n * Earliest is defined as being \"before\" all the other nodes in terms of list container\n * position and visiting key.\n */\n\nexport function getEarliestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n): NodePath {\n return this.getDeepestCommonAncestorFrom(\n paths,\n function (deepest, i, ancestries) {\n let earliest;\n const keys = VISITOR_KEYS[deepest.type];\n\n for (const ancestry of ancestries) {\n const path = ancestry[i + 1];\n\n // first path\n if (!earliest) {\n earliest = path;\n continue;\n }\n\n // handle containers\n if (path.listKey && earliest.listKey === path.listKey) {\n // we're in the same container so check if we're earlier\n if (path.key < earliest.key) {\n earliest = path;\n continue;\n }\n }\n\n // handle keys\n const earliestKeyIndex = keys.indexOf(earliest.parentKey);\n const currentKeyIndex = keys.indexOf(path.parentKey as string);\n if (earliestKeyIndex > currentKeyIndex) {\n // key appears before so it's earlier\n earliest = path;\n }\n }\n\n return earliest;\n },\n );\n}\n\n/**\n * Get the earliest path in the tree where the provided `paths` intersect.\n *\n * TODO: Possible optimisation target.\n */\n\nexport function getDeepestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n filter?: (deepest: NodePath, i: number, ancestries: NodePath[][]) => NodePath,\n): NodePath {\n if (!paths.length) {\n return this;\n }\n\n if (paths.length === 1) {\n return paths[0];\n }\n\n // minimum depth of the tree so we know the highest node\n let minDepth = Infinity;\n\n // last common ancestor\n let lastCommonIndex, lastCommon;\n\n // get the ancestors of the path, breaking when the parent exceeds ourselves\n const ancestries = paths.map(path => {\n const ancestry: NodePath[] = [];\n\n do {\n ancestry.unshift(path);\n } while ((path = path.parentPath) && path !== this);\n\n // save min depth to avoid going too far in\n if (ancestry.length < minDepth) {\n minDepth = ancestry.length;\n }\n\n return ancestry;\n });\n\n // get the first ancestry so we have a seed to assess all other ancestries with\n const first = ancestries[0];\n\n // check ancestor equality\n depthLoop: for (let i = 0; i < minDepth; i++) {\n const shouldMatch = first[i];\n\n for (const ancestry of ancestries) {\n if (ancestry[i] !== shouldMatch) {\n // we've hit a snag\n break depthLoop;\n }\n }\n\n // next iteration may break so store these so they can be returned\n lastCommonIndex = i;\n lastCommon = shouldMatch;\n }\n\n if (lastCommon) {\n if (filter) {\n return filter(lastCommon, lastCommonIndex, ancestries);\n } else {\n return lastCommon;\n }\n } else {\n throw new Error(\"Couldn't find intersection\");\n }\n}\n\n/**\n * Build an array of node paths containing the entire ancestry of the current node path.\n *\n * NOTE: The current node path is included in this.\n */\n\nexport function getAncestry(this: NodePath): Array<NodePath> {\n let path = this;\n const paths = [];\n do {\n paths.push(path);\n } while ((path = path.parentPath));\n return paths;\n}\n\n/**\n * A helper to find if `this` path is an ancestor of @param maybeDescendant\n */\nexport function isAncestor(this: NodePath, maybeDescendant: NodePath): boolean {\n return maybeDescendant.isDescendant(this);\n}\n\n/**\n * A helper to find if `this` path is a descendant of @param maybeAncestor\n */\nexport function isDescendant(this: NodePath, maybeAncestor: NodePath): boolean {\n return !!this.findParent(parent => parent === maybeAncestor);\n}\n\nexport function inType(this: NodePath, ...candidateTypes: string[]): boolean {\n let path = this;\n while (path) {\n for (const type of candidateTypes) {\n if (path.node.type === type) return true;\n }\n path = path.parentPath;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAEA;AAA4C;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AEO,SAASE,MAAM,CAAiB,GAAGC,cAAwB,EAAW;EAC3E,IAAIjD,IAAI,GAAG,IAAI;EACf,OAAOA,IAAI,EAAE;IACX,KAAK,MAAMsB,IAAI,IAAI2B,cAAc,EAAE;MACjC,IAAIjD,IAAI,CAACkD,IAAI,CAAC5B,IAAI,KAAKA,IAAI,EAAE,OAAO,IAAI;IAC1C;IACAtB,IAAI,GAAGA,IAAI,CAACC,UAAU;EACxB;EAEA,OAAO,KAAK;AACd"}
|
|
1
|
+
{"version":3,"names":["VISITOR_KEYS","findParent","callback","path","parentPath","find","getFunctionParent","p","isFunction","getStatementParent","Array","isArray","container","isStatement","isProgram","isFile","Error","getEarliestCommonAncestorFrom","paths","getDeepestCommonAncestorFrom","deepest","i","ancestries","earliest","keys","type","ancestry","listKey","key","earliestKeyIndex","indexOf","parentKey","currentKeyIndex","filter","length","minDepth","Infinity","lastCommonIndex","lastCommon","map","unshift","first","depthLoop","shouldMatch","getAncestry","push","isAncestor","maybeDescendant","isDescendant","maybeAncestor","parent","inType","candidateTypes","node"],"sources":["../../src/path/ancestry.ts"],"sourcesContent":["// This file contains that retrieve or validate anything related to the current paths ancestry.\n\nimport { VISITOR_KEYS } from \"@babel/types\";\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\n\n/**\n * Starting at the parent path of the current `NodePath` and going up the\n * tree, return the first `NodePath` that causes the provided `callback`\n * to return a truthy value, or `null` if the `callback` never returns a\n * truthy value.\n */\n\nexport function findParent(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n while ((path = path.parentPath)) {\n if (callback(path)) return path;\n }\n return null;\n}\n\n/**\n * Starting at current `NodePath` and going up the tree, return the first\n * `NodePath` that causes the provided `callback` to return a truthy value,\n * or `null` if the `callback` never returns a truthy value.\n */\n\nexport function find(\n this: NodePath,\n callback: (path: NodePath) => boolean,\n): NodePath | null {\n let path = this;\n do {\n if (callback(path)) return path;\n } while ((path = path.parentPath));\n return null;\n}\n\n/**\n * Get the parent function of the current path.\n */\n\nexport function getFunctionParent(this: NodePath): NodePath<t.Function> | null {\n return this.findParent(p => p.isFunction()) as NodePath<t.Function> | null;\n}\n\n/**\n * Walk up the tree until we hit a parent node path in a list.\n */\n\nexport function getStatementParent(this: NodePath): NodePath<t.Statement> {\n let path = this;\n\n do {\n if (\n !path.parentPath ||\n (Array.isArray(path.container) && path.isStatement())\n ) {\n break;\n } else {\n path = path.parentPath;\n }\n } while (path);\n\n if (path && (path.isProgram() || path.isFile())) {\n throw new Error(\n \"File/Program node, we can't possibly find a statement parent to this\",\n );\n }\n\n return path as NodePath<t.Statement>;\n}\n\n/**\n * Get the deepest common ancestor and then from it, get the earliest relationship path\n * to that ancestor.\n *\n * Earliest is defined as being \"before\" all the other nodes in terms of list container\n * position and visiting key.\n */\n\nexport function getEarliestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n): NodePath {\n return this.getDeepestCommonAncestorFrom(\n paths,\n function (deepest, i, ancestries) {\n let earliest;\n const keys = VISITOR_KEYS[deepest.type];\n\n for (const ancestry of ancestries) {\n const path = ancestry[i + 1];\n\n // first path\n if (!earliest) {\n earliest = path;\n continue;\n }\n\n // handle containers\n if (path.listKey && earliest.listKey === path.listKey) {\n // we're in the same container so check if we're earlier\n if (path.key < earliest.key) {\n earliest = path;\n continue;\n }\n }\n\n // handle keys\n const earliestKeyIndex = keys.indexOf(earliest.parentKey);\n const currentKeyIndex = keys.indexOf(path.parentKey as string);\n if (earliestKeyIndex > currentKeyIndex) {\n // key appears before so it's earlier\n earliest = path;\n }\n }\n\n return earliest;\n },\n );\n}\n\n/**\n * Get the earliest path in the tree where the provided `paths` intersect.\n *\n * TODO: Possible optimisation target.\n */\n\nexport function getDeepestCommonAncestorFrom(\n this: NodePath,\n paths: Array<NodePath>,\n filter?: (deepest: NodePath, i: number, ancestries: NodePath[][]) => NodePath,\n): NodePath {\n if (!paths.length) {\n return this;\n }\n\n if (paths.length === 1) {\n return paths[0];\n }\n\n // minimum depth of the tree so we know the highest node\n let minDepth = Infinity;\n\n // last common ancestor\n let lastCommonIndex, lastCommon;\n\n // get the ancestors of the path, breaking when the parent exceeds ourselves\n const ancestries = paths.map(path => {\n const ancestry: NodePath[] = [];\n\n do {\n ancestry.unshift(path);\n } while ((path = path.parentPath) && path !== this);\n\n // save min depth to avoid going too far in\n if (ancestry.length < minDepth) {\n minDepth = ancestry.length;\n }\n\n return ancestry;\n });\n\n // get the first ancestry so we have a seed to assess all other ancestries with\n const first = ancestries[0];\n\n // check ancestor equality\n depthLoop: for (let i = 0; i < minDepth; i++) {\n const shouldMatch = first[i];\n\n for (const ancestry of ancestries) {\n if (ancestry[i] !== shouldMatch) {\n // we've hit a snag\n break depthLoop;\n }\n }\n\n // next iteration may break so store these so they can be returned\n lastCommonIndex = i;\n lastCommon = shouldMatch;\n }\n\n if (lastCommon) {\n if (filter) {\n return filter(lastCommon, lastCommonIndex, ancestries);\n } else {\n return lastCommon;\n }\n } else {\n throw new Error(\"Couldn't find intersection\");\n }\n}\n\n/**\n * Build an array of node paths containing the entire ancestry of the current node path.\n *\n * NOTE: The current node path is included in this.\n */\n\nexport function getAncestry(this: NodePath): Array<NodePath> {\n let path = this;\n const paths = [];\n do {\n paths.push(path);\n } while ((path = path.parentPath));\n return paths;\n}\n\n/**\n * A helper to find if `this` path is an ancestor of @param maybeDescendant\n */\nexport function isAncestor(this: NodePath, maybeDescendant: NodePath): boolean {\n return maybeDescendant.isDescendant(this);\n}\n\n/**\n * A helper to find if `this` path is a descendant of @param maybeAncestor\n */\nexport function isDescendant(this: NodePath, maybeAncestor: NodePath): boolean {\n return !!this.findParent(parent => parent === maybeAncestor);\n}\n\nexport function inType(this: NodePath, ...candidateTypes: string[]): boolean {\n let path = this;\n while (path) {\n for (const type of candidateTypes) {\n if (path.node.type === type) return true;\n }\n path = path.parentPath;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAEA;AAA4C;EAAnCA;AAAY;AAWd,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;EAC3E,IAAIjD,IAAI,GAAG,IAAI;EACf,OAAOA,IAAI,EAAE;IACX,KAAK,MAAMsB,IAAI,IAAI2B,cAAc,EAAE;MACjC,IAAIjD,IAAI,CAACkD,IAAI,CAAC5B,IAAI,KAAKA,IAAI,EAAE,OAAO,IAAI;IAC1C;IACAtB,IAAI,GAAGA,IAAI,CAACC,UAAU;EACxB;EAEA,OAAO,KAAK;AACd"}
|
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
addComment: _addComment,
|
|
12
12
|
addComments: _addComments
|
|
13
13
|
} = _t;
|
|
14
|
-
|
|
15
14
|
function shareCommentsWithSiblings() {
|
|
16
15
|
if (typeof this.key === "string") return;
|
|
17
16
|
const node = this.node;
|
|
@@ -32,7 +31,6 @@ function shareCommentsWithSiblings() {
|
|
|
32
31
|
function addComment(type, content, line) {
|
|
33
32
|
_addComment(this.node, type, content, line);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
function addComments(type, comments) {
|
|
37
35
|
_addComments(this.node, type, comments);
|
|
38
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","type","content","line","comments"],"sources":["../../src/path/comments.ts"],"sourcesContent":["// This file contains methods responsible for dealing with comments.\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\nimport {\n addComment as _addComment,\n addComments as _addComments,\n} from \"@babel/types\";\n\n/**\n * Share comments amongst siblings.\n */\n\nexport function shareCommentsWithSiblings(this: NodePath) {\n // NOTE: this assumes numbered keys\n if (typeof this.key === \"string\") return;\n\n const node = this.node;\n if (!node) return;\n\n const trailing = node.trailingComments;\n const leading = node.leadingComments;\n if (!trailing && !leading) return;\n\n const prev = this.getSibling(this.key - 1);\n const next = this.getSibling(this.key + 1);\n const hasPrev = Boolean(prev.node);\n const hasNext = Boolean(next.node);\n if (hasPrev && !hasNext) {\n prev.addComments(\"trailing\", trailing);\n } else if (hasNext && !hasPrev) {\n next.addComments(\"leading\", leading);\n }\n}\n\nexport function addComment(\n this: NodePath,\n type: t.CommentTypeShorthand,\n content: string,\n line?: boolean,\n) {\n _addComment(this.node, type, content, line);\n}\n\n/**\n * Give node `comments` of the specified `type`.\n */\n\nexport function addComments(\n this: NodePath,\n type: t.CommentTypeShorthand,\n comments: t.Comment[],\n) {\n _addComments(this.node, type, comments);\n}\n"],"mappings":";;;;;;;;AAGA;AAGsB;EAFpBA,UAAU,EAAIC,WAAW;EACzBC,WAAW,EAAIC;AAAY
|
|
1
|
+
{"version":3,"names":["addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","type","content","line","comments"],"sources":["../../src/path/comments.ts"],"sourcesContent":["// This file contains methods responsible for dealing with comments.\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index\";\nimport {\n addComment as _addComment,\n addComments as _addComments,\n} from \"@babel/types\";\n\n/**\n * Share comments amongst siblings.\n */\n\nexport function shareCommentsWithSiblings(this: NodePath) {\n // NOTE: this assumes numbered keys\n if (typeof this.key === \"string\") return;\n\n const node = this.node;\n if (!node) return;\n\n const trailing = node.trailingComments;\n const leading = node.leadingComments;\n if (!trailing && !leading) return;\n\n const prev = this.getSibling(this.key - 1);\n const next = this.getSibling(this.key + 1);\n const hasPrev = Boolean(prev.node);\n const hasNext = Boolean(next.node);\n if (hasPrev && !hasNext) {\n prev.addComments(\"trailing\", trailing);\n } else if (hasNext && !hasPrev) {\n next.addComments(\"leading\", leading);\n }\n}\n\nexport function addComment(\n this: NodePath,\n type: t.CommentTypeShorthand,\n content: string,\n line?: boolean,\n) {\n _addComment(this.node, type, content, line);\n}\n\n/**\n * Give node `comments` of the specified `type`.\n */\n\nexport function addComments(\n this: NodePath,\n type: t.CommentTypeShorthand,\n comments: t.Comment[],\n) {\n _addComments(this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