@tinacms/app 1.0.2 → 1.0.4
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 +24 -24
- package/appFiles/node_modules/@babel/generator/lib/node/parentheses.js +5 -1
- package/appFiles/node_modules/@babel/generator/lib/node/parentheses.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/lib/printer.js +3 -2
- package/appFiles/node_modules/@babel/generator/lib/printer.js.map +1 -1
- package/appFiles/node_modules/@babel/generator/package.json +3 -3
- package/appFiles/node_modules/@babel/parser/lib/index.js +22 -11
- 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 +3 -9
- 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 +3 -9
- 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 +10 -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/path/conversion.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/introspection.js +7 -2
- package/appFiles/node_modules/@babel/traverse/lib/path/introspection.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/path/modification.js +9 -4
- package/appFiles/node_modules/@babel/traverse/lib/path/modification.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/scope/index.js +20 -11
- package/appFiles/node_modules/@babel/traverse/lib/scope/index.js.map +1 -1
- package/appFiles/node_modules/@babel/traverse/lib/scope/lib/renamer.js +6 -8
- package/appFiles/node_modules/@babel/traverse/lib/scope/lib/renamer.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/src/preview.tsx +7 -7
- package/dist/index.js +3 -1
- package/package.json +3 -3
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = literalTemplate;
|
|
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 literalTemplate(formatter, tpl, opts) {
|
|
15
11
|
const {
|
|
16
12
|
metadata,
|
|
@@ -23,7 +19,6 @@ function literalTemplate(formatter, tpl, opts) {
|
|
|
23
19
|
});
|
|
24
20
|
return arg => {
|
|
25
21
|
const replacements = (0, _options.normalizeReplacements)(arg);
|
|
26
|
-
|
|
27
22
|
if (replacements) {
|
|
28
23
|
Object.keys(replacements).forEach(key => {
|
|
29
24
|
if (Object.prototype.hasOwnProperty.call(defaultReplacements, key)) {
|
|
@@ -31,18 +26,15 @@ function literalTemplate(formatter, tpl, opts) {
|
|
|
31
26
|
}
|
|
32
27
|
});
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
return formatter.unwrap((0, _populate.default)(metadata, replacements ? Object.assign(replacements, defaultReplacements) : defaultReplacements));
|
|
36
30
|
};
|
|
37
31
|
};
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
function buildLiteralData(formatter, tpl, opts) {
|
|
41
34
|
let names;
|
|
42
35
|
let nameSet;
|
|
43
36
|
let metadata;
|
|
44
37
|
let prefix = "";
|
|
45
|
-
|
|
46
38
|
do {
|
|
47
39
|
prefix += "$";
|
|
48
40
|
const result = buildTemplateCode(tpl, prefix);
|
|
@@ -56,25 +48,23 @@ function buildLiteralData(formatter, tpl, opts) {
|
|
|
56
48
|
syntacticPlaceholders: opts.syntacticPlaceholders
|
|
57
49
|
});
|
|
58
50
|
} while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name)));
|
|
59
|
-
|
|
60
51
|
return {
|
|
61
52
|
metadata,
|
|
62
53
|
names
|
|
63
54
|
};
|
|
64
55
|
}
|
|
65
|
-
|
|
66
56
|
function buildTemplateCode(tpl, prefix) {
|
|
67
57
|
const names = [];
|
|
68
58
|
let code = tpl[0];
|
|
69
|
-
|
|
70
59
|
for (let i = 1; i < tpl.length; i++) {
|
|
71
60
|
const value = `${prefix}${i - 1}`;
|
|
72
61
|
names.push(value);
|
|
73
62
|
code += value + tpl[i];
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
return {
|
|
77
65
|
names,
|
|
78
66
|
code
|
|
79
67
|
};
|
|
80
|
-
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["literalTemplate","formatter","tpl","opts","metadata","names","buildLiteralData","arg","defaultReplacements","forEach","replacement","i","replacements","normalizeReplacements","Object","keys","key","prototype","hasOwnProperty","call","Error","unwrap","populatePlaceholders","assign","nameSet","prefix","result","buildTemplateCode","Set","parseAndBuildMetadata","code","parser","placeholderWhitelist","concat","Array","from","placeholderPattern","preserveComments","syntacticPlaceholders","placeholders","some","placeholder","isDuplicate","has","name","length","value","push"],"sources":["../src/literal.ts"],"sourcesContent":["import type { Formatter } from \"./formatters\";\nimport type { TemplateReplacements, TemplateOpts } from \"./options\";\nimport { normalizeReplacements } from \"./options\";\nimport parseAndBuildMetadata from \"./parse\";\nimport populatePlaceholders from \"./populate\";\n\nexport default function literalTemplate<T>(\n formatter: Formatter<T>,\n tpl: Array<string>,\n opts: TemplateOpts,\n): (_: Array<unknown>) => (_: unknown) => T {\n const { metadata, names } = buildLiteralData(formatter, tpl, opts);\n\n return arg => {\n const defaultReplacements: TemplateReplacements = {};\n arg.forEach((replacement, i) => {\n defaultReplacements[names[i]] = replacement;\n });\n\n return (arg: unknown) => {\n const replacements = normalizeReplacements(arg);\n\n if (replacements) {\n Object.keys(replacements).forEach(key => {\n if (Object.prototype.hasOwnProperty.call(defaultReplacements, key)) {\n throw new Error(\"Unexpected replacement overlap.\");\n }\n });\n }\n\n return formatter.unwrap(\n populatePlaceholders(\n metadata,\n replacements\n ? Object.assign(replacements, defaultReplacements)\n : defaultReplacements,\n ),\n );\n };\n };\n}\n\nfunction buildLiteralData<T>(\n formatter: Formatter<T>,\n tpl: Array<string>,\n opts: TemplateOpts,\n) {\n let names;\n let nameSet: Set<string>;\n let metadata;\n let prefix = \"\";\n\n do {\n // If there are cases where the template already contains $0 or any other\n // matching pattern, we keep adding \"$\" characters until a unique prefix\n // is found.\n prefix += \"$\";\n const result = buildTemplateCode(tpl, prefix);\n\n names = result.names;\n nameSet = new Set(names);\n metadata = parseAndBuildMetadata(formatter, formatter.code(result.code), {\n parser: opts.parser,\n\n // Explicitly include our generated names in the whitelist so users never\n // have to think about whether their placeholder pattern will match.\n placeholderWhitelist: new Set(\n result.names.concat(\n opts.placeholderWhitelist\n ? Array.from(opts.placeholderWhitelist)\n : [],\n ),\n ),\n placeholderPattern: opts.placeholderPattern,\n preserveComments: opts.preserveComments,\n syntacticPlaceholders: opts.syntacticPlaceholders,\n });\n } while (\n metadata.placeholders.some(\n placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name),\n )\n );\n\n return { metadata, names };\n}\n\nfunction buildTemplateCode(\n tpl: Array<string>,\n prefix: string,\n): { names: Array<string>; code: string } {\n const names = [];\n\n let code = tpl[0];\n\n for (let i = 1; i < tpl.length; i++) {\n const value = `${prefix}${i - 1}`;\n names.push(value);\n\n code += value + tpl[i];\n }\n\n return { names, code };\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AAEe,SAASA,eAAe,CACrCC,SAAuB,EACvBC,GAAkB,EAClBC,IAAkB,EACwB;EAC1C,MAAM;IAAEC,QAAQ;IAAEC;EAAM,CAAC,GAAGC,gBAAgB,CAACL,SAAS,EAAEC,GAAG,EAAEC,IAAI,CAAC;EAElE,OAAOI,GAAG,IAAI;IACZ,MAAMC,mBAAyC,GAAG,CAAC,CAAC;IACpDD,GAAG,CAACE,OAAO,CAAC,CAACC,WAAW,EAAEC,CAAC,KAAK;MAC9BH,mBAAmB,CAACH,KAAK,CAACM,CAAC,CAAC,CAAC,GAAGD,WAAW;IAC7C,CAAC,CAAC;IAEF,OAAQH,GAAY,IAAK;MACvB,MAAMK,YAAY,GAAG,IAAAC,8BAAqB,EAACN,GAAG,CAAC;MAE/C,IAAIK,YAAY,EAAE;QAChBE,MAAM,CAACC,IAAI,CAACH,YAAY,CAAC,CAACH,OAAO,CAACO,GAAG,IAAI;UACvC,IAAIF,MAAM,CAACG,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,mBAAmB,EAAEQ,GAAG,CAAC,EAAE;YAClE,MAAM,IAAII,KAAK,CAAC,iCAAiC,CAAC;UACpD;QACF,CAAC,CAAC;MACJ;MAEA,OAAOnB,SAAS,CAACoB,MAAM,CACrB,IAAAC,iBAAoB,EAClBlB,QAAQ,EACRQ,YAAY,GACRE,MAAM,CAACS,MAAM,CAACX,YAAY,EAAEJ,mBAAmB,CAAC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AAG5B,GAAG,CAAC,CAAC,CAAC;EAEjB,KAAK,IAAIS,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGT,GAAG,CAAC2C,MAAM,EAAElC,CAAC,EAAE,EAAE;IACnC,MAAMmC,KAAK,GAAI,GAAErB,MAAO,GAAEd,CAAC,GAAG,CAAE,EAAC;IACjCN,KAAK,CAAC0C,IAAI,CAACD,KAAK,CAAC;IAEjBhB,IAAI,IAAIgB,KAAK,GAAG5C,GAAG,CAACS,CAAC,CAAC;EACxB;EAEA,OAAO;IAAEN,KAAK;IAAEyB;EAAK,CAAC;AACxB"}
|
|
@@ -7,7 +7,6 @@ exports.merge = merge;
|
|
|
7
7
|
exports.normalizeReplacements = normalizeReplacements;
|
|
8
8
|
exports.validate = validate;
|
|
9
9
|
const _excluded = ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"];
|
|
10
|
-
|
|
11
10
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
11
|
|
|
13
12
|
function merge(a, b) {
|
|
@@ -25,41 +24,33 @@ function merge(a, b) {
|
|
|
25
24
|
syntacticPlaceholders
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
function validate(opts) {
|
|
30
28
|
if (opts != null && typeof opts !== "object") {
|
|
31
29
|
throw new Error("Unknown template options.");
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
const _ref = opts || {},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
{
|
|
33
|
+
placeholderWhitelist,
|
|
34
|
+
placeholderPattern,
|
|
35
|
+
preserveComments,
|
|
36
|
+
syntacticPlaceholders
|
|
37
|
+
} = _ref,
|
|
38
|
+
parser = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
43
39
|
if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
|
|
44
40
|
throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
|
|
45
41
|
}
|
|
46
|
-
|
|
47
42
|
if (placeholderPattern != null && !(placeholderPattern instanceof RegExp) && placeholderPattern !== false) {
|
|
48
43
|
throw new Error("'.placeholderPattern' must be a RegExp, false, null, or undefined");
|
|
49
44
|
}
|
|
50
|
-
|
|
51
45
|
if (preserveComments != null && typeof preserveComments !== "boolean") {
|
|
52
46
|
throw new Error("'.preserveComments' must be a boolean, null, or undefined");
|
|
53
47
|
}
|
|
54
|
-
|
|
55
48
|
if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
|
|
56
49
|
throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
|
|
60
52
|
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
return {
|
|
64
55
|
parser,
|
|
65
56
|
placeholderWhitelist: placeholderWhitelist || undefined,
|
|
@@ -68,7 +59,6 @@ function validate(opts) {
|
|
|
68
59
|
syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders
|
|
69
60
|
};
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
function normalizeReplacements(replacements) {
|
|
73
63
|
if (Array.isArray(replacements)) {
|
|
74
64
|
return replacements.reduce((acc, replacement, i) => {
|
|
@@ -78,6 +68,7 @@ function normalizeReplacements(replacements) {
|
|
|
78
68
|
} else if (typeof replacements === "object" || replacements == null) {
|
|
79
69
|
return replacements || undefined;
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
throw new Error("Template replacements must be an array, object, null, or undefined");
|
|
83
|
-
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["merge","a","b","placeholderWhitelist","placeholderPattern","preserveComments","syntacticPlaceholders","parser","validate","opts","Error","Set","RegExp","undefined","normalizeReplacements","replacements","Array","isArray","reduce","acc","replacement","i"],"sources":["../src/options.ts"],"sourcesContent":["import type { ParserOptions as ParserOpts } from \"@babel/parser\";\n\nexport type { ParserOpts };\n\n/**\n * These are the options that 'babel-template' actually accepts and typechecks\n * when called. All other options are passed through to the parser.\n */\nexport type PublicOpts = {\n /**\n * A set of placeholder names to automatically accept, ignoring the given\n * pattern entirely.\n *\n * This option can be used when using %%foo%% style placeholders.\n */\n placeholderWhitelist?: Set<string>;\n /**\n * A pattern to search for when looking for Identifier and StringLiteral\n * nodes that can be replaced.\n *\n * 'false' will disable placeholder searching entirely, leaving only the\n * 'placeholderWhitelist' value to find replacements.\n *\n * Defaults to /^[_$A-Z0-9]+$/.\n *\n * This option can be used when using %%foo%% style placeholders.\n */\n placeholderPattern?: RegExp | false;\n /**\n * 'true' to pass through comments from the template into the resulting AST,\n * or 'false' to automatically discard comments. Defaults to 'false'.\n */\n preserveComments?: boolean;\n /**\n * 'true' to use %%foo%% style placeholders, 'false' to use legacy placeholders\n * described by placeholderPattern or placeholderWhitelist.\n * When it is not set, it behaves as 'true' if there are syntactic placeholders,\n * otherwise as 'false'.\n */\n syntacticPlaceholders?: boolean | null;\n};\n\nexport type TemplateOpts = {\n parser: ParserOpts;\n placeholderWhitelist?: Set<string>;\n placeholderPattern?: RegExp | false;\n preserveComments?: boolean;\n syntacticPlaceholders?: boolean;\n};\n\nexport function merge(a: TemplateOpts, b: TemplateOpts): TemplateOpts {\n const {\n placeholderWhitelist = a.placeholderWhitelist,\n placeholderPattern = a.placeholderPattern,\n preserveComments = a.preserveComments,\n syntacticPlaceholders = a.syntacticPlaceholders,\n } = b;\n\n return {\n parser: {\n ...a.parser,\n ...b.parser,\n },\n placeholderWhitelist,\n placeholderPattern,\n preserveComments,\n syntacticPlaceholders,\n };\n}\n\nexport function validate(opts: unknown): TemplateOpts {\n if (opts != null && typeof opts !== \"object\") {\n throw new Error(\"Unknown template options.\");\n }\n\n const {\n placeholderWhitelist,\n placeholderPattern,\n preserveComments,\n syntacticPlaceholders,\n ...parser\n } = opts || ({} as any);\n\n if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {\n throw new Error(\n \"'.placeholderWhitelist' must be a Set, null, or undefined\",\n );\n }\n\n if (\n placeholderPattern != null &&\n !(placeholderPattern instanceof RegExp) &&\n placeholderPattern !== false\n ) {\n throw new Error(\n \"'.placeholderPattern' must be a RegExp, false, null, or undefined\",\n );\n }\n\n if (preserveComments != null && typeof preserveComments !== \"boolean\") {\n throw new Error(\n \"'.preserveComments' must be a boolean, null, or undefined\",\n );\n }\n\n if (\n syntacticPlaceholders != null &&\n typeof syntacticPlaceholders !== \"boolean\"\n ) {\n throw new Error(\n \"'.syntacticPlaceholders' must be a boolean, null, or undefined\",\n );\n }\n if (\n syntacticPlaceholders === true &&\n (placeholderWhitelist != null || placeholderPattern != null)\n ) {\n throw new Error(\n \"'.placeholderWhitelist' and '.placeholderPattern' aren't compatible\" +\n \" with '.syntacticPlaceholders: true'\",\n );\n }\n\n return {\n parser,\n placeholderWhitelist: placeholderWhitelist || undefined,\n placeholderPattern:\n placeholderPattern == null ? undefined : placeholderPattern,\n preserveComments: preserveComments == null ? undefined : preserveComments,\n syntacticPlaceholders:\n syntacticPlaceholders == null ? undefined : syntacticPlaceholders,\n };\n}\n\nexport type PublicReplacements = { [x: string]: unknown } | Array<unknown>;\nexport type TemplateReplacements = { [x: string]: unknown } | void;\n\nexport function normalizeReplacements(\n replacements: unknown,\n): TemplateReplacements {\n if (Array.isArray(replacements)) {\n return replacements.reduce((acc, replacement, i) => {\n acc[\"$\" + i] = replacement;\n return acc;\n }, {});\n } else if (typeof replacements === \"object\" || replacements == null) {\n return (replacements as any) || undefined;\n }\n\n throw new Error(\n \"Template replacements must be an array, object, null, or undefined\",\n );\n}\n"],"mappings":";;;;;;;;;;;AAkDO,SAASA,KAAK,CAACC,CAAe,EAAEC,CAAe,EAAgB;EACpE,MAAM;IACJC,oBAAoB,GAAGF,CAAC,CAACE,oBAAoB;IAC7CC,kBAAkB,GAAGH,CAAC,CAACG,kBAAkB;IACzCC,gBAAgB,GAAGJ,CAAC,CAACI,gBAAgB;IACrCC,qBAAqB,GAAGL,CAAC,CAACK;EAC5B,CAAC,GAAGJ,CAAC;EAEL,OAAO;IACLK,MAAM,oBACDN,CAAC,CAACM,MAAM,EACRL,CAAC,CAACK,MAAM,CACZ;IACDJ,oBAAoB;IACpBC,kBAAkB;IAClBC,gBAAgB;IAChBC;EACF,CAAC;AACH;AAEO,SAASE,QAAQ,CAACC,IAAa,EAAgB;EACpD,IAAIA,IAAI,IAAI,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC5C,MAAM,IAAIC,KAAK,CAAC,2BAA2B,CAAC;EAC9C;EAEA,aAMID,IAAI,IAAK,CAAC,CAAS;IANjB;MACJN,oBAAoB;MACpBC,kBAAkB;MAClBC,gBAAgB;MAChBC;IAEF,CAAC;IADIC,MAAM;EAGX,IAAIJ,oBAAoB,IAAI,IAAI,IAAI,EAAEA,oBAAoB,YAAYQ,GAAG,CAAC,EAAE;IAC1E,MAAM,IAAID,KAAK,CACb,2DAA2D,CAC5D;EACH;EAEA,IACEN,kBAAkB,IAAI,IAAI,IAC1B,EAAEA,kBAAkB,YAAYQ,MAAM,CAAC,IACvCR,kBAAkB,KAAK,KAAK,EAC5B;IACA,MAAM,IAAIM,KAAK,CACb,mEAAmE,CACpE;EACH;EAEA,IAAIL,gBAAgB,IAAI,IAAI,IAAI,OAAOA,gBAAgB,KAAK,SAAS,EAAE;IACrE,MAAM,IAAIK,KAAK,CACb,2DAA2D,CAC5D;EACH;EAEA,IACEJ,qBAAqB,IAAI,IAAI,IAC7B,OAAOA,qBAAqB,KAAK,SAAS,EAC1C;IACA,MAAM,IAAII,KAAK,CACb,gEAAgE,CACjE;EACH;EACA,IACEJ,qBAAqB,KAAK,IAAI,KAC7BH,oBAAoB,IAAI,IAAI,IAAIC,kBAAkB,IAAI,IAAI,CAAC,EAC5D;IACA,MAAM,IAAIM,KAAK,CACb,qEAAqE,GACnE,sCAAsC,CACzC;EACH;EAEA,OAAO;IACLH,MAAM;IACNJ,oBAAoB,EAAEA,oBAAoB,IAAIU,SAAS;IACvDT,kBAAkB,EAChBA,kBAAkB,IAAI,IAAI,GAAGS,SAAS,GAAGT,kBAAkB;IAC7DC,gBAAgB,EAAEA,gBAAgB,IAAI,IAAI,GAAGQ,SAAS,GAAGR,gBAAgB;IACzEC,qBAAqB,EACnBA,qBAAqB,IAAI,IAAI,GAAGO,SAAS,GAAGP;EAChD,CAAC;AACH;AAKO,SAASQ,qBAAqB,CACnCC,YAAqB,EACC;EACtB,IAAIC,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,EAAE;IAC/B,OAAOA,YAAY,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,WAAW,EAAEC,CAAC,KAAK;MAClDF,GAAG,CAAC,GAAG,GAAGE,CAAC,CAAC,GAAGD,WAAW;MAC1B,OAAOD,GAAG;IACZ,CAAC,EAAE,CAAC,CAAC,CAAC;EACR,CAAC,MAAM,IAAI,OAAOJ,YAAY,KAAK,QAAQ,IAAIA,YAAY,IAAI,IAAI,EAAE;IACnE,OAAQA,YAAY,IAAYF,SAAS;EAC3C;EAEA,MAAM,IAAIH,KAAK,CACb,oEAAoE,CACrE;AACH"}
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = parseAndBuildMetadata;
|
|
7
|
-
|
|
8
7
|
var _t = require("@babel/types");
|
|
9
|
-
|
|
10
8
|
var _parser = require("@babel/parser");
|
|
11
|
-
|
|
12
9
|
var _codeFrame = require("@babel/code-frame");
|
|
13
|
-
|
|
14
10
|
const {
|
|
15
11
|
isCallExpression,
|
|
16
12
|
isExpressionStatement,
|
|
@@ -25,7 +21,6 @@ const {
|
|
|
25
21
|
traverse
|
|
26
22
|
} = _t;
|
|
27
23
|
const PATTERN = /^[_$A-Z0-9]+$/;
|
|
28
|
-
|
|
29
24
|
function parseAndBuildMetadata(formatter, code, opts) {
|
|
30
25
|
const {
|
|
31
26
|
placeholderWhitelist,
|
|
@@ -61,12 +56,9 @@ function parseAndBuildMetadata(formatter, code, opts) {
|
|
|
61
56
|
ast
|
|
62
57
|
}, isLegacyRef.value ? legacy : syntactic);
|
|
63
58
|
}
|
|
64
|
-
|
|
65
59
|
function placeholderVisitorHandler(node, ancestors, state) {
|
|
66
60
|
var _state$placeholderWhi;
|
|
67
|
-
|
|
68
61
|
let name;
|
|
69
|
-
|
|
70
62
|
if (isPlaceholder(node)) {
|
|
71
63
|
if (state.syntacticPlaceholders === false) {
|
|
72
64
|
throw new Error("%%foo%%-style placeholders can't be used when " + "'.syntacticPlaceholders' is false.");
|
|
@@ -85,11 +77,9 @@ function placeholderVisitorHandler(node, ancestors, state) {
|
|
|
85
77
|
} else {
|
|
86
78
|
return;
|
|
87
79
|
}
|
|
88
|
-
|
|
89
80
|
if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) {
|
|
90
81
|
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
|
|
91
82
|
}
|
|
92
|
-
|
|
93
83
|
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) != null && _state$placeholderWhi.has(name))) {
|
|
94
84
|
return;
|
|
95
85
|
}
|
|
@@ -100,7 +90,6 @@ function placeholderVisitorHandler(node, ancestors, state) {
|
|
|
100
90
|
key
|
|
101
91
|
} = ancestors[ancestors.length - 1];
|
|
102
92
|
let type;
|
|
103
|
-
|
|
104
93
|
if (isStringLiteral(node) || isPlaceholder(node, {
|
|
105
94
|
expectedNode: "StringLiteral"
|
|
106
95
|
})) {
|
|
@@ -115,7 +104,6 @@ function placeholderVisitorHandler(node, ancestors, state) {
|
|
|
115
104
|
} else {
|
|
116
105
|
type = "other";
|
|
117
106
|
}
|
|
118
|
-
|
|
119
107
|
const {
|
|
120
108
|
placeholders,
|
|
121
109
|
placeholderNames
|
|
@@ -128,23 +116,19 @@ function placeholderVisitorHandler(node, ancestors, state) {
|
|
|
128
116
|
});
|
|
129
117
|
placeholderNames.add(name);
|
|
130
118
|
}
|
|
131
|
-
|
|
132
119
|
function resolveAncestors(ast, ancestors) {
|
|
133
120
|
let parent = ast;
|
|
134
|
-
|
|
135
121
|
for (let i = 0; i < ancestors.length - 1; i++) {
|
|
136
122
|
const {
|
|
137
123
|
key,
|
|
138
124
|
index
|
|
139
125
|
} = ancestors[i];
|
|
140
|
-
|
|
141
126
|
if (index === undefined) {
|
|
142
127
|
parent = parent[key];
|
|
143
128
|
} else {
|
|
144
129
|
parent = parent[key][index];
|
|
145
130
|
}
|
|
146
131
|
}
|
|
147
|
-
|
|
148
132
|
const {
|
|
149
133
|
key,
|
|
150
134
|
index
|
|
@@ -155,14 +139,11 @@ function resolveAncestors(ast, ancestors) {
|
|
|
155
139
|
index
|
|
156
140
|
};
|
|
157
141
|
}
|
|
158
|
-
|
|
159
142
|
function parseWithCodeFrame(code, parserOpts, syntacticPlaceholders) {
|
|
160
143
|
const plugins = (parserOpts.plugins || []).slice();
|
|
161
|
-
|
|
162
144
|
if (syntacticPlaceholders !== false) {
|
|
163
145
|
plugins.push("placeholders");
|
|
164
146
|
}
|
|
165
|
-
|
|
166
147
|
parserOpts = Object.assign({
|
|
167
148
|
allowReturnOutsideFunction: true,
|
|
168
149
|
allowSuperOutsideMethod: true,
|
|
@@ -170,19 +151,18 @@ function parseWithCodeFrame(code, parserOpts, syntacticPlaceholders) {
|
|
|
170
151
|
}, parserOpts, {
|
|
171
152
|
plugins
|
|
172
153
|
});
|
|
173
|
-
|
|
174
154
|
try {
|
|
175
155
|
return (0, _parser.parse)(code, parserOpts);
|
|
176
156
|
} catch (err) {
|
|
177
157
|
const loc = err.loc;
|
|
178
|
-
|
|
179
158
|
if (loc) {
|
|
180
159
|
err.message += "\n" + (0, _codeFrame.codeFrameColumns)(code, {
|
|
181
160
|
start: loc
|
|
182
161
|
});
|
|
183
162
|
err.code = "BABEL_TEMPLATE_PARSE_ERROR";
|
|
184
163
|
}
|
|
185
|
-
|
|
186
164
|
throw err;
|
|
187
165
|
}
|
|
188
|
-
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -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,I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ACZuC,UAAsB,EACtBlC,qBAA+B,EACvB;EACR,MAAMmC,OAAO,GAAG,CAACD,UAAU,CAACC,OAAO,IAAI,EAAE,EAAEd,KAAK,EAAE;EAClD,IAAIrB,qBAAqB,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,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MAC9B,MAAM,IAAIV,KAAK,CAAC,iDAAiD,CAAC;IACpE;EACF;EAEA,IAAIiB,KAAK,KAAKG,SAAS,EAAE;IACvBlC,QAAQ,CAAC8B,MAAM,EAAEd,GAAG,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"
|