@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
|
@@ -16,9 +16,7 @@ export default function _wrapRegExp() {
|
|
|
16
16
|
return Object.keys(g).reduce(function (groups, name) {
|
|
17
17
|
var i = g[name];
|
|
18
18
|
if ("number" == typeof i) groups[name] = result[i];else {
|
|
19
|
-
for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;)
|
|
20
|
-
k++;
|
|
21
|
-
}
|
|
19
|
+
for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++;
|
|
22
20
|
groups[name] = result[i[k]];
|
|
23
21
|
}
|
|
24
22
|
return groups;
|
|
@@ -12,9 +12,7 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
12
12
|
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
13
13
|
if (Object(_i) !== _i) return;
|
|
14
14
|
_n = !1;
|
|
15
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0)
|
|
16
|
-
;
|
|
17
|
-
}
|
|
15
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
18
16
|
} catch (err) {
|
|
19
17
|
_d = !0, _e = err;
|
|
20
18
|
} finally {
|
|
@@ -3,9 +3,7 @@ function _iterableToArrayLimitLoose(arr, i) {
|
|
|
3
3
|
if (null != _i) {
|
|
4
4
|
var _s,
|
|
5
5
|
_arr = [];
|
|
6
|
-
for (_i = _i.call(arr); arr.length < i && !(_s = _i.next()).done;)
|
|
7
|
-
_arr.push(_s.value);
|
|
8
|
-
}
|
|
6
|
+
for (_i = _i.call(arr); arr.length < i && !(_s = _i.next()).done;) _arr.push(_s.value);
|
|
9
7
|
return _arr;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
@@ -6,14 +6,10 @@ function _createRawReactElement(type, props, key, children) {
|
|
|
6
6
|
if (props || 0 === childrenLength || (props = {
|
|
7
7
|
children: void 0
|
|
8
8
|
}), 1 === childrenLength) props.children = children;else if (childrenLength > 1) {
|
|
9
|
-
for (var childArray = new Array(childrenLength), i = 0; i < childrenLength; i++)
|
|
10
|
-
childArray[i] = arguments[i + 3];
|
|
11
|
-
}
|
|
9
|
+
for (var childArray = new Array(childrenLength), i = 0; i < childrenLength; i++) childArray[i] = arguments[i + 3];
|
|
12
10
|
props.children = childArray;
|
|
13
11
|
}
|
|
14
|
-
if (props && defaultProps) for (var propName in defaultProps) {
|
|
15
|
-
void 0 === props[propName] && (props[propName] = defaultProps[propName]);
|
|
16
|
-
} else props || (props = defaultProps || {});
|
|
12
|
+
if (props && defaultProps) for (var propName in defaultProps) void 0 === props[propName] && (props[propName] = defaultProps[propName]);else props || (props = defaultProps || {});
|
|
17
13
|
return {
|
|
18
14
|
$$typeof: REACT_ELEMENT_TYPE,
|
|
19
15
|
type: type,
|
|
@@ -166,9 +166,7 @@ function _regeneratorRuntime() {
|
|
|
166
166
|
if (!isNaN(iterable.length)) {
|
|
167
167
|
var i = -1,
|
|
168
168
|
next = function next() {
|
|
169
|
-
for (; ++i < iterable.length;)
|
|
170
|
-
if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
171
|
-
}
|
|
169
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
172
170
|
return next.value = undefined, next.done = !0, next;
|
|
173
171
|
};
|
|
174
172
|
return next.next = next;
|
|
@@ -214,9 +212,7 @@ function _regeneratorRuntime() {
|
|
|
214
212
|
}), exports.keys = function (val) {
|
|
215
213
|
var object = Object(val),
|
|
216
214
|
keys = [];
|
|
217
|
-
for (var key in object)
|
|
218
|
-
keys.push(key);
|
|
219
|
-
}
|
|
215
|
+
for (var key in object) keys.push(key);
|
|
220
216
|
return keys.reverse(), function next() {
|
|
221
217
|
for (; keys.length;) {
|
|
222
218
|
var key = keys.pop();
|
|
@@ -227,9 +223,7 @@ function _regeneratorRuntime() {
|
|
|
227
223
|
}, exports.values = values, Context.prototype = {
|
|
228
224
|
constructor: Context,
|
|
229
225
|
reset: function reset(skipTempReset) {
|
|
230
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this)
|
|
231
|
-
"t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
232
|
-
}
|
|
226
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
233
227
|
},
|
|
234
228
|
stop: function stop() {
|
|
235
229
|
this.done = !0;
|
|
@@ -34,7 +34,7 @@ function set(target, property, value, receiver) {
|
|
|
34
34
|
function _set(target, property, value, receiver, isStrict) {
|
|
35
35
|
var s = set(target, property, value, receiver || target);
|
|
36
36
|
if (!s && isStrict) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new TypeError('failed to set property');
|
|
38
38
|
}
|
|
39
39
|
return value;
|
|
40
40
|
}
|
|
@@ -16,9 +16,7 @@ function _wrapRegExp() {
|
|
|
16
16
|
return Object.keys(g).reduce(function (groups, name) {
|
|
17
17
|
var i = g[name];
|
|
18
18
|
if ("number" == typeof i) groups[name] = result[i];else {
|
|
19
|
-
for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;)
|
|
20
|
-
k++;
|
|
21
|
-
}
|
|
19
|
+
for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++;
|
|
22
20
|
groups[name] = result[i[k]];
|
|
23
21
|
}
|
|
24
22
|
return groups;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babel/runtime",
|
|
3
|
-
"version": "7.20.
|
|
3
|
+
"version": "7.20.13",
|
|
4
4
|
"description": "babel's modular runtime helpers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -53,6 +53,15 @@
|
|
|
53
53
|
"./helpers/applyDecs2203.js"
|
|
54
54
|
],
|
|
55
55
|
"./helpers/esm/applyDecs2203": "./helpers/esm/applyDecs2203.js",
|
|
56
|
+
"./helpers/applyDecs2203R": [
|
|
57
|
+
{
|
|
58
|
+
"node": "./helpers/applyDecs2203R.js",
|
|
59
|
+
"import": "./helpers/esm/applyDecs2203R.js",
|
|
60
|
+
"default": "./helpers/applyDecs2203R.js"
|
|
61
|
+
},
|
|
62
|
+
"./helpers/applyDecs2203R.js"
|
|
63
|
+
],
|
|
64
|
+
"./helpers/esm/applyDecs2203R": "./helpers/esm/applyDecs2203R.js",
|
|
56
65
|
"./helpers/asyncGeneratorDelegate": [
|
|
57
66
|
{
|
|
58
67
|
"node": "./helpers/asyncGeneratorDelegate.js",
|
|
@@ -89,6 +98,15 @@
|
|
|
89
98
|
"./helpers/checkInRHS.js"
|
|
90
99
|
],
|
|
91
100
|
"./helpers/esm/checkInRHS": "./helpers/esm/checkInRHS.js",
|
|
101
|
+
"./helpers/defineAccessor": [
|
|
102
|
+
{
|
|
103
|
+
"node": "./helpers/defineAccessor.js",
|
|
104
|
+
"import": "./helpers/esm/defineAccessor.js",
|
|
105
|
+
"default": "./helpers/defineAccessor.js"
|
|
106
|
+
},
|
|
107
|
+
"./helpers/defineAccessor.js"
|
|
108
|
+
],
|
|
109
|
+
"./helpers/esm/defineAccessor": "./helpers/esm/defineAccessor.js",
|
|
92
110
|
"./helpers/iterableToArrayLimit": [
|
|
93
111
|
{
|
|
94
112
|
"node": "./helpers/iterableToArrayLimit.js",
|
|
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = createTemplateBuilder;
|
|
7
|
-
|
|
8
7
|
var _options = require("./options");
|
|
9
|
-
|
|
10
8
|
var _string = require("./string");
|
|
11
|
-
|
|
12
9
|
var _literal = require("./literal");
|
|
13
|
-
|
|
14
10
|
const NO_PLACEHOLDER = (0, _options.validate)({
|
|
15
11
|
placeholderPattern: false
|
|
16
12
|
});
|
|
17
|
-
|
|
18
13
|
function createTemplateBuilder(formatter, defaultOpts) {
|
|
19
14
|
const templateFnCache = new WeakMap();
|
|
20
15
|
const templateAstCache = new WeakMap();
|
|
@@ -25,18 +20,15 @@ function createTemplateBuilder(formatter, defaultOpts) {
|
|
|
25
20
|
return extendedTrace((0, _string.default)(formatter, tpl, (0, _options.merge)(cachedOpts, (0, _options.validate)(args[0]))));
|
|
26
21
|
} else if (Array.isArray(tpl)) {
|
|
27
22
|
let builder = templateFnCache.get(tpl);
|
|
28
|
-
|
|
29
23
|
if (!builder) {
|
|
30
24
|
builder = (0, _literal.default)(formatter, tpl, cachedOpts);
|
|
31
25
|
templateFnCache.set(tpl, builder);
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
return extendedTrace(builder(args));
|
|
35
28
|
} else if (typeof tpl === "object" && tpl) {
|
|
36
29
|
if (args.length > 0) throw new Error("Unexpected extra params.");
|
|
37
30
|
return createTemplateBuilder(formatter, (0, _options.merge)(cachedOpts, (0, _options.validate)(tpl)));
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
throw new Error(`Unexpected template param ${typeof tpl}`);
|
|
41
33
|
}, {
|
|
42
34
|
ast: (tpl, ...args) => {
|
|
@@ -45,23 +37,18 @@ function createTemplateBuilder(formatter, defaultOpts) {
|
|
|
45
37
|
return (0, _string.default)(formatter, tpl, (0, _options.merge)((0, _options.merge)(cachedOpts, (0, _options.validate)(args[0])), NO_PLACEHOLDER))();
|
|
46
38
|
} else if (Array.isArray(tpl)) {
|
|
47
39
|
let builder = templateAstCache.get(tpl);
|
|
48
|
-
|
|
49
40
|
if (!builder) {
|
|
50
41
|
builder = (0, _literal.default)(formatter, tpl, (0, _options.merge)(cachedOpts, NO_PLACEHOLDER));
|
|
51
42
|
templateAstCache.set(tpl, builder);
|
|
52
43
|
}
|
|
53
|
-
|
|
54
44
|
return builder(args)();
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
throw new Error(`Unexpected template param ${typeof tpl}`);
|
|
58
47
|
}
|
|
59
48
|
});
|
|
60
49
|
}
|
|
61
|
-
|
|
62
50
|
function extendedTrace(fn) {
|
|
63
51
|
let rootStack = "";
|
|
64
|
-
|
|
65
52
|
try {
|
|
66
53
|
throw new Error();
|
|
67
54
|
} catch (error) {
|
|
@@ -69,7 +56,6 @@ function extendedTrace(fn) {
|
|
|
69
56
|
rootStack = error.stack.split("\n").slice(3).join("\n");
|
|
70
57
|
}
|
|
71
58
|
}
|
|
72
|
-
|
|
73
59
|
return arg => {
|
|
74
60
|
try {
|
|
75
61
|
return fn(arg);
|
|
@@ -78,4 +64,6 @@ function extendedTrace(fn) {
|
|
|
78
64
|
throw err;
|
|
79
65
|
}
|
|
80
66
|
};
|
|
81
|
-
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NO_PLACEHOLDER","validate","placeholderPattern","createTemplateBuilder","formatter","defaultOpts","templateFnCache","WeakMap","templateAstCache","cachedOpts","Object","assign","tpl","args","length","Error","extendedTrace","stringTemplate","merge","Array","isArray","builder","get","literalTemplate","set","ast","fn","rootStack","error","stack","split","slice","join","arg","err"],"sources":["../src/builder.ts"],"sourcesContent":["import { merge, validate } from \"./options\";\nimport type { TemplateOpts, PublicOpts, PublicReplacements } from \"./options\";\nimport type { Formatter } from \"./formatters\";\n\nimport stringTemplate from \"./string\";\nimport literalTemplate from \"./literal\";\n\nexport type TemplateBuilder<T> = {\n // Build a new builder, merging the given options with the previous ones.\n (opts: PublicOpts): TemplateBuilder<T>;\n\n // Building from a string produces an AST builder function by default.\n (tpl: string, opts?: PublicOpts): (replacements?: PublicReplacements) => T;\n\n // Building from a template literal produces an AST builder function by default.\n (tpl: TemplateStringsArray, ...args: Array<unknown>): (\n replacements?: PublicReplacements,\n ) => T;\n\n // Allow users to explicitly create templates that produce ASTs, skipping\n // the need for an intermediate function.\n ast: {\n (tpl: string, opts?: PublicOpts): T;\n (tpl: TemplateStringsArray, ...args: Array<unknown>): T;\n };\n};\n\n// Prebuild the options that will be used when parsing a `.ast` template.\n// These do not use a pattern because there is no way for users to pass in\n// replacement patterns to begin with, and disabling pattern matching means\n// users have more flexibility in what type of content they have in their\n// template JS.\nconst NO_PLACEHOLDER: TemplateOpts = validate({\n placeholderPattern: false,\n});\n\nexport default function createTemplateBuilder<T>(\n formatter: Formatter<T>,\n defaultOpts?: TemplateOpts,\n): TemplateBuilder<T> {\n const templateFnCache = new WeakMap();\n const templateAstCache = new WeakMap();\n const cachedOpts = defaultOpts || validate(null);\n\n return Object.assign(\n ((tpl, ...args) => {\n if (typeof tpl === \"string\") {\n if (args.length > 1) throw new Error(\"Unexpected extra params.\");\n return extendedTrace(\n stringTemplate(formatter, tpl, merge(cachedOpts, validate(args[0]))),\n );\n } else if (Array.isArray(tpl)) {\n let builder = templateFnCache.get(tpl);\n if (!builder) {\n builder = literalTemplate(formatter, tpl, cachedOpts);\n templateFnCache.set(tpl, builder);\n }\n return extendedTrace(builder(args));\n } else if (typeof tpl === \"object\" && tpl) {\n if (args.length > 0) throw new Error(\"Unexpected extra params.\");\n return createTemplateBuilder(\n formatter,\n merge(cachedOpts, validate(tpl)),\n );\n }\n throw new Error(`Unexpected template param ${typeof tpl}`);\n }) as TemplateBuilder<T>,\n {\n ast: (tpl: string | Array<string>, ...args: Array<unknown>) => {\n if (typeof tpl === \"string\") {\n if (args.length > 1) throw new Error(\"Unexpected extra params.\");\n return stringTemplate(\n formatter,\n tpl,\n merge(merge(cachedOpts, validate(args[0])), NO_PLACEHOLDER),\n )();\n } else if (Array.isArray(tpl)) {\n let builder = templateAstCache.get(tpl);\n if (!builder) {\n builder = literalTemplate(\n formatter,\n tpl,\n merge(cachedOpts, NO_PLACEHOLDER),\n );\n templateAstCache.set(tpl, builder);\n }\n return builder(args)();\n }\n\n throw new Error(`Unexpected template param ${typeof tpl}`);\n },\n },\n );\n}\n\nfunction extendedTrace<Arg, Result>(\n fn: (_: Arg) => Result,\n): (_: Arg) => Result {\n // Since we lazy parse the template, we get the current stack so we have the\n // original stack to append if it errors when parsing\n let rootStack = \"\";\n try {\n // error stack gets populated in IE only on throw\n // (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx)\n throw new Error();\n } catch (error) {\n if (error.stack) {\n // error.stack does not exists in IE <= 9\n // We slice off the top 3 items in the stack to remove the call to\n // 'extendedTrace', and the anonymous builder function, with the final\n // stripped line being the error message itself since we threw it\n // in the first place and it doesn't matter.\n rootStack = error.stack.split(\"\\n\").slice(3).join(\"\\n\");\n }\n }\n\n return (arg: Arg) => {\n try {\n return fn(arg);\n } catch (err) {\n err.stack += `\\n =============\\n${rootStack}`;\n throw err;\n }\n };\n}\n"],"mappings":";;;;;;AAAA;AAIA;AACA;AA2BA,MAAMA,cAA4B,GAAG,IAAAC,iBAAQ,EAAC;EAC5CC,kBAAkB,EAAE;AACtB,CAAC,CAAC;AAEa,SAASC,qBAAqB,CAC3CC,SAAuB,EACvBC,WAA0B,EACN;EACpB,MAAMC,eAAe,GAAG,IAAIC,OAAO,EAAE;EACrC,MAAMC,gBAAgB,GAAG,IAAID,OAAO,EAAE;EACtC,MAAME,UAAU,GAAGJ,WAAW,IA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GAAG,CAACL,KAAK,IAAK,wBAAuBF,SAAU,EAAC;MAChD,MAAMO,GAAG;IACX;EACF,CAAC;AACH"}
|
|
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.statements = exports.statement = exports.smart = exports.program = exports.expression = void 0;
|
|
7
|
-
|
|
8
7
|
var _t = require("@babel/types");
|
|
9
|
-
|
|
10
8
|
const {
|
|
11
9
|
assertExpressionStatement
|
|
12
10
|
} = _t;
|
|
13
|
-
|
|
14
11
|
function makeStatementFormatter(fn) {
|
|
15
12
|
return {
|
|
16
13
|
code: str => `/* @babel/template */;\n${str}`,
|
|
@@ -20,7 +17,6 @@ function makeStatementFormatter(fn) {
|
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
const smart = makeStatementFormatter(body => {
|
|
25
21
|
if (body.length > 1) {
|
|
26
22
|
return body;
|
|
@@ -35,11 +31,9 @@ const statement = makeStatementFormatter(body => {
|
|
|
35
31
|
if (body.length === 0) {
|
|
36
32
|
throw new Error("Found nothing to return.");
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
if (body.length > 1) {
|
|
40
35
|
throw new Error("Found multiple statements but wanted one");
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
return body[0];
|
|
44
38
|
});
|
|
45
39
|
exports.statement = statement;
|
|
@@ -49,7 +43,6 @@ const expression = {
|
|
|
49
43
|
if (ast.program.body.length > 1) {
|
|
50
44
|
throw new Error("Found multiple statements but wanted one");
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
if (expression.unwrap(ast).start === 0) {
|
|
54
47
|
throw new Error("Parse result included parens.");
|
|
55
48
|
}
|
|
@@ -68,4 +61,6 @@ const program = {
|
|
|
68
61
|
validate: () => {},
|
|
69
62
|
unwrap: ast => ast.program
|
|
70
63
|
};
|
|
71
|
-
exports.program = program;
|
|
64
|
+
exports.program = program;
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["assertExpressionStatement","makeStatementFormatter","fn","code","str","validate","unwrap","ast","program","body","slice","smart","length","statements","statement","Error","expression","start","stmt"],"sources":["../src/formatters.ts"],"sourcesContent":["import { assertExpressionStatement } from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\nexport type Formatter<T> = {\n code: (source: string) => string;\n validate: (ast: t.File) => void;\n unwrap: (ast: t.File) => T;\n};\n\nfunction makeStatementFormatter<T>(\n fn: (statements: Array<t.Statement>) => T,\n): Formatter<T> {\n return {\n // We need to prepend a \";\" to force statement parsing so that\n // ExpressionStatement strings won't be parsed as directives.\n // Alongside that, we also prepend a comment so that when a syntax error\n // is encountered, the user will be less likely to get confused about\n // where the random semicolon came from.\n code: str => `/* @babel/template */;\\n${str}`,\n validate: () => {},\n unwrap: (ast: t.File): T => {\n return fn(ast.program.body.slice(1));\n },\n };\n}\n\nexport const smart = makeStatementFormatter(body => {\n if (body.length > 1) {\n return body;\n } else {\n return body[0];\n }\n});\n\nexport const statements = makeStatementFormatter(body => body);\n\nexport const statement = makeStatementFormatter(body => {\n // We do this validation when unwrapping since the replacement process\n // could have added or removed statements.\n if (body.length === 0) {\n throw new Error(\"Found nothing to return.\");\n }\n if (body.length > 1) {\n throw new Error(\"Found multiple statements but wanted one\");\n }\n\n return body[0];\n});\n\nexport const expression: Formatter<t.Expression> = {\n code: str => `(\\n${str}\\n)`,\n validate: ast => {\n if (ast.program.body.length > 1) {\n throw new Error(\"Found multiple statements but wanted one\");\n }\n if (expression.unwrap(ast).start === 0) {\n throw new Error(\"Parse result included parens.\");\n }\n },\n unwrap: ({ program }) => {\n const [stmt] = program.body;\n assertExpressionStatement(stmt);\n return stmt.expression;\n },\n};\n\nexport const program: Formatter<t.Program> = {\n code: str => str,\n validate: () => {},\n unwrap: ast => ast.program,\n};\n"],"mappings":";;;;;;AAAA;AAAy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tC,MAAM,IAAIF,KAAK,CAAC,+BAA+B,CAAC;IAClD;EACF,CAAC;EACDT,MAAM,EAAE,CAAC;IAAEE;EAAQ,CAAC,KAAK;IACvB,MAAM,CAACU,IAAI,CAAC,GAAGV,OAAO,CAACC,IAAI;IAC3BT,yBAAyB,CAACkB,IAAI,CAAC;IAC/B,OAAOA,IAAI,CAACF,UAAU;EACxB;AACF,CAAC;AAAC;AAEK,MAAMR,OAA6B,GAAG;EAC3CL,IAAI,EAAEC,GAAG,IAAIA,GAAG;EAChBC,QAAQ,EAAE,MAAM,CAAC,CAAC;EAClBC,MAAM,EAAEC,GAAG,IAAIA,GAAG,CAACC;AACrB,CAAC;AAAC"}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.statements = exports.statement = exports.smart = exports.program = exports.expression = exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var formatters = require("./formatters");
|
|
9
|
-
|
|
10
8
|
var _builder = require("./builder");
|
|
11
|
-
|
|
12
9
|
const smart = (0, _builder.default)(formatters.smart);
|
|
13
10
|
exports.smart = smart;
|
|
14
11
|
const statement = (0, _builder.default)(formatters.statement);
|
|
@@ -19,7 +16,6 @@ const expression = (0, _builder.default)(formatters.expression);
|
|
|
19
16
|
exports.expression = expression;
|
|
20
17
|
const program = (0, _builder.default)(formatters.program);
|
|
21
18
|
exports.program = program;
|
|
22
|
-
|
|
23
19
|
var _default = Object.assign(smart.bind(undefined), {
|
|
24
20
|
smart,
|
|
25
21
|
statement,
|
|
@@ -28,5 +24,6 @@ var _default = Object.assign(smart.bind(undefined), {
|
|
|
28
24
|
program,
|
|
29
25
|
ast: smart.ast
|
|
30
26
|
});
|
|
27
|
+
exports.default = _default;
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["smart","createTemplateBuilder","formatters","statement","statements","expression","program","Object","assign","bind","undefined","ast"],"sources":["../src/index.ts"],"sourcesContent":["import * as formatters from \"./formatters\";\nimport createTemplateBuilder from \"./builder\";\n\nexport const smart = createTemplateBuilder(formatters.smart);\nexport const statement = createTemplateBuilder(formatters.statement);\nexport const statements = createTemplateBuilder(formatters.statements);\nexport const expression = createTemplateBuilder(formatters.expression);\nexport const program = createTemplateBuilder(formatters.program);\n\ntype DefaultTemplateBuilder = typeof smart & {\n smart: typeof smart;\n statement: typeof statement;\n statements: typeof statements;\n expression: typeof expression;\n program: typeof program;\n};\n\nexport default Object.assign(smart.bind(undefined) as DefaultTemplateBuilder, {\n smart,\n statement,\n statements,\n expression,\n program,\n ast: smart.ast,\n});\n"],"mappings":";;;;;;AAAA;AACA;AAEO,MAAMA,KAAK,GAAG,IAAAC,gBAAqB,EAACC,UAAU,CAACF,KAAK,CAAC;AAAC;AACtD,MAAMG,SAAS,GAAG,IAAAF,gBAAqB,EAACC,UAAU,CAACC,SAAS,CAAC;AAAC;AAC9D,MAAMC,UAAU,GAAG,IAAAH,gBAAqB,EAACC,UAAU,CAACE,UAAU,CAAC;AAAC;AAChE,MAAMC,UAAU,GAAG,IAAAJ,gBAAqB,EAACC,UAAU,CAACG,UAAU,CAAC;AAAC;AAChE,MAAMC,OAAO,GAAG,IAAAL,gBAAqB,EAACC,UAAU,CAACI,OAAO,CAAC;AAAC;AAAA,eAUlDC,MAAM,CAACC,MAAM,CAACR,KAAK,CAACS,IAAI,CAACC,SAAS,CAAC,EAA4B;EAC5EV,KAAK;EACLG,SAAS;EACTC,UAAU;EACVC,UAAU;EACVC,OAAO;EACPK,GAAG,EAAEX,KAAK,CAACW;AACb,CAAC,CAAC;AAAA"}
|
|
@@ -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,M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I,kBAAkB,EAAEjC,IAAI,CAACiC,kBAAkB;MAC3CC,gBAAgB,EAAElC,IAAI,CAACkC,gBAAgB;MACvCC,qBAAqB,EAAEnC,IAAI,CAACmC;IAC9B,CAAC,CAAC;EACJ,CAAC,QACClC,QAAQ,CAACmC,YAAY,CAACC,IAAI,CACxBC,WAAW,IAAIA,WAAW,CAACC,WAAW,IAAIlB,OAAO,CAACmB,GAAG,CAACF,WAAW,CAACG,IAAI,CAAC,CACxE;EAGH,OAAO;IAAExC,QAAQ;IAAEC;EAAM,CAAC;AAC5B;AAEA,SAASsB,iBAAiB,CACxBzB,GAAkB,EAClBuB,MAAc,EAC0B;EACxC,MAAMpB,KAAK,GAAG,EAAE;EAEhB,IAAIyB,IAAI,GAAG5B,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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AAG,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
|