@marko/compiler 5.39.50 → 5.39.52
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/dist/babel-plugin/file.js +2 -2
- package/dist/babel-plugin/index.js +14 -12
- package/dist/babel-plugin/parser.js +39 -39
- package/dist/babel-plugin/plugins/migrate.js +4 -4
- package/dist/babel-plugin/plugins/transform.js +4 -4
- package/dist/babel-utils/imports.js +2 -2
- package/dist/babel-utils/parse.js +12 -9
- package/dist/babel-utils/tags.js +2 -2
- package/dist/babel-utils/template-string.js +2 -2
- package/dist/babel.js +65127 -0
- package/dist/config.js +2 -2
- package/dist/index.js +18 -10
- package/dist/taglib/index.js +2 -2
- package/dist/types.d.ts +5 -5
- package/dist/util/build-code-frame.js +3 -3
- package/dist/util/try-load-translator.js +2 -2
- package/internal/babel/index.ts +22 -0
- package/internal/babel/modules.d.ts +9 -0
- package/internal/babel/package.json +5 -0
- package/package.json +7 -14
- package/dist/babel-types/generator/patch.js +0 -358
- package/dist/babel-types/index.js +0 -5
- package/dist/babel-types/traverse/patch.js +0 -133
- package/dist/babel-types/types/definitions.js +0 -254
- package/dist/babel-types/types/patch.js +0 -124
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";require("../types/patch");
|
|
2
|
-
|
|
3
|
-
var _traverse = _interopRequireWildcard(require("@babel/traverse"));
|
|
4
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
|
5
|
-
|
|
6
|
-
var _definitions = require("../types/definitions");function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}
|
|
7
|
-
|
|
8
|
-
_definitions.MARKO_TYPES.forEach((typeName) => {
|
|
9
|
-
const checkKey = `is${typeName}`;
|
|
10
|
-
const assertKey = `assert${typeName}`;
|
|
11
|
-
const checkFn = t[checkKey];
|
|
12
|
-
const assertFn = t[assertKey];
|
|
13
|
-
_traverse.NodePath.prototype[checkKey] = function (opts) {
|
|
14
|
-
return checkFn(this.node, opts);
|
|
15
|
-
};
|
|
16
|
-
_traverse.NodePath.prototype[assertKey] = function (opts) {
|
|
17
|
-
assertFn(this.node, opts);
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
_definitions.MARKO_ALIAS_TYPES.forEach((aliasName) => {
|
|
22
|
-
const checkKey = `is${aliasName}`;
|
|
23
|
-
const originalProtoCheck = _traverse.NodePath.prototype[checkKey];
|
|
24
|
-
_traverse.NodePath.prototype[checkKey] = function (opts) {
|
|
25
|
-
return (
|
|
26
|
-
t.is(aliasName, this.node, opts) ||
|
|
27
|
-
originalProtoCheck.call(this, this.node, opts));
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Adds a one time patch to the scope collector visitors to include
|
|
33
|
-
// Marko bindings for params and tag vars.
|
|
34
|
-
const originalCrawl = _traverse.Scope.prototype.crawl;
|
|
35
|
-
const patchedVisitors = new WeakSet();
|
|
36
|
-
|
|
37
|
-
_traverse.Scope.prototype.crawl = function () {
|
|
38
|
-
const path = this.path;
|
|
39
|
-
const originalTraverse = path.traverse;
|
|
40
|
-
path.traverse = function (visitor, state) {
|
|
41
|
-
state.hoistableTagVarsByScope = new Map();
|
|
42
|
-
path.traverse = originalTraverse;
|
|
43
|
-
|
|
44
|
-
if (!patchedVisitors.has(visitor)) {
|
|
45
|
-
patchedVisitors.add(visitor);
|
|
46
|
-
Object.assign(
|
|
47
|
-
_traverse.default.explode(visitor),
|
|
48
|
-
_traverse.default.explode({
|
|
49
|
-
MarkoTagBody(body) {
|
|
50
|
-
for (const param of body.get("params")) {
|
|
51
|
-
body.scope.registerBinding("param", param);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
MarkoTag(tag, state) {
|
|
55
|
-
const tagVar = tag.get("var");
|
|
56
|
-
if (tagVar.node) {
|
|
57
|
-
tag.scope.registerBinding("local", tagVar, tag);
|
|
58
|
-
for (const name in tagVar.getBindingIdentifiers()) {
|
|
59
|
-
let curScope = tag.scope;
|
|
60
|
-
const binding = curScope.getBinding(name);
|
|
61
|
-
|
|
62
|
-
while (curScope = curScope.parent) {
|
|
63
|
-
const hoistableTagVars =
|
|
64
|
-
state.hoistableTagVarsByScope.get(curScope);
|
|
65
|
-
|
|
66
|
-
if (hoistableTagVars) {
|
|
67
|
-
hoistableTagVars[name] = hoistableTagVars[name] ?
|
|
68
|
-
true :
|
|
69
|
-
binding;
|
|
70
|
-
} else {
|
|
71
|
-
state.hoistableTagVarsByScope.set(curScope, {
|
|
72
|
-
[name]: binding
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (this.type === "Program" && this.node.params?.length) {
|
|
84
|
-
this.scope.registerBinding("params", this);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.traverse(visitor, state);
|
|
88
|
-
|
|
89
|
-
if (state.references.length) {
|
|
90
|
-
const movedBindings = new Map();
|
|
91
|
-
for (const ref of state.references) {
|
|
92
|
-
const { name } = ref.node;
|
|
93
|
-
let curScope = ref.scope;
|
|
94
|
-
if (curScope.hasBinding(name)) continue;
|
|
95
|
-
|
|
96
|
-
do {
|
|
97
|
-
const hoistableBinding =
|
|
98
|
-
state.hoistableTagVarsByScope.get(curScope)?.[name];
|
|
99
|
-
|
|
100
|
-
if (hoistableBinding) {
|
|
101
|
-
if (hoistableBinding === true) {
|
|
102
|
-
throw ref.buildCodeFrameError(
|
|
103
|
-
"Ambiguous reference, variable was defined in multiple places and was not shadowed."
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const movedBinding = movedBindings.get(hoistableBinding);
|
|
108
|
-
if (
|
|
109
|
-
!movedBinding ||
|
|
110
|
-
getScopeDepth(movedBinding) > getScopeDepth(curScope))
|
|
111
|
-
{
|
|
112
|
-
movedBindings.set(hoistableBinding, curScope);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} while (curScope = curScope.parent);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
for (const [binding, scope] of movedBindings) {
|
|
119
|
-
binding.scope.moveBindingTo(binding.identifier.name, scope);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
originalCrawl.call(this);
|
|
125
|
-
path.traverse = originalTraverse;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
function getScopeDepth(scope) {
|
|
129
|
-
let depth = 0;
|
|
130
|
-
let cur = scope;
|
|
131
|
-
while (cur = cur.parent) depth++;
|
|
132
|
-
return depth;
|
|
133
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";exports.__esModule = true;exports.default = exports.MARKO_TYPES = exports.MARKO_ALIAS_TYPES = void 0;var _utils = require("@babel/types/lib/definitions/utils");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const valueFieldCommon = {
|
|
10
|
-
value: {
|
|
11
|
-
validate: (0, _utils.assertValueType)("string")
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const MarkoDefinitions = {
|
|
16
|
-
MarkoParseError: {
|
|
17
|
-
aliases: ["Marko", "Expression", "Statement"],
|
|
18
|
-
builder: ["source", "label", "errorLoc"],
|
|
19
|
-
fields: {
|
|
20
|
-
source: {
|
|
21
|
-
validate: (0, _utils.assertValueType)("string")
|
|
22
|
-
},
|
|
23
|
-
label: {
|
|
24
|
-
validate: (0, _utils.assertValueType)("string")
|
|
25
|
-
},
|
|
26
|
-
errorLoc: {
|
|
27
|
-
optional: true,
|
|
28
|
-
validate: (0, _utils.assertValueType)("object")
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
MarkoDocumentType: {
|
|
33
|
-
aliases: ["Marko", "Statement"],
|
|
34
|
-
builder: ["value"],
|
|
35
|
-
fields: { ...valueFieldCommon }
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
MarkoDeclaration: {
|
|
39
|
-
aliases: ["Marko", "Statement"],
|
|
40
|
-
builder: ["value"],
|
|
41
|
-
fields: { ...valueFieldCommon }
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
MarkoCDATA: {
|
|
45
|
-
aliases: ["Marko", "Statement"],
|
|
46
|
-
builder: ["value"],
|
|
47
|
-
fields: { ...valueFieldCommon }
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
MarkoComment: {
|
|
51
|
-
aliases: ["Marko", "Statement"],
|
|
52
|
-
builder: ["value"],
|
|
53
|
-
fields: { ...valueFieldCommon }
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
MarkoText: {
|
|
57
|
-
aliases: ["Marko", "Statement"],
|
|
58
|
-
builder: ["value"],
|
|
59
|
-
fields: { ...valueFieldCommon }
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
MarkoPlaceholder: {
|
|
63
|
-
aliases: ["Marko", "Statement"],
|
|
64
|
-
builder: ["value", "escape"],
|
|
65
|
-
visitor: ["value"],
|
|
66
|
-
fields: {
|
|
67
|
-
value: {
|
|
68
|
-
validate: (0, _utils.assertNodeType)("Expression")
|
|
69
|
-
},
|
|
70
|
-
escape: {
|
|
71
|
-
validate: (0, _utils.assertValueType)("boolean"),
|
|
72
|
-
default: true
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
MarkoScriptlet: {
|
|
78
|
-
aliases: ["Marko", "Statement"],
|
|
79
|
-
builder: ["body", "static", "target"],
|
|
80
|
-
visitor: ["body"],
|
|
81
|
-
fields: {
|
|
82
|
-
body: {
|
|
83
|
-
validate: arrayOfType(["Statement"])
|
|
84
|
-
},
|
|
85
|
-
static: {
|
|
86
|
-
validate: (0, _utils.assertValueType)("boolean"),
|
|
87
|
-
default: false
|
|
88
|
-
},
|
|
89
|
-
target: {
|
|
90
|
-
validate: (0, _utils.assertOneOf)("server", "client"),
|
|
91
|
-
optional: true
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
MarkoClass: {
|
|
97
|
-
aliases: ["Marko", "Statement", "Class"],
|
|
98
|
-
builder: ["body"],
|
|
99
|
-
visitor: ["body"],
|
|
100
|
-
fields: {
|
|
101
|
-
body: {
|
|
102
|
-
validate: (0, _utils.assertNodeType)("ClassBody")
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
MarkoAttribute: {
|
|
108
|
-
aliases: ["Marko"],
|
|
109
|
-
builder: ["name", "value", "modifier", "arguments", "default", "bound"],
|
|
110
|
-
visitor: ["value", "arguments"],
|
|
111
|
-
fields: {
|
|
112
|
-
name: {
|
|
113
|
-
validate: (0, _utils.assertValueType)("string")
|
|
114
|
-
},
|
|
115
|
-
value: {
|
|
116
|
-
validate: (0, _utils.assertNodeType)("Expression")
|
|
117
|
-
},
|
|
118
|
-
modifier: {
|
|
119
|
-
validate: (0, _utils.assertValueType)("string"),
|
|
120
|
-
optional: true
|
|
121
|
-
},
|
|
122
|
-
arguments: {
|
|
123
|
-
validate: (0, _utils.chain)(
|
|
124
|
-
(0, _utils.assertValueType)("array"),
|
|
125
|
-
(0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement"))
|
|
126
|
-
),
|
|
127
|
-
optional: true
|
|
128
|
-
},
|
|
129
|
-
default: {
|
|
130
|
-
validate: (0, _utils.assertValueType)("boolean"),
|
|
131
|
-
optional: true
|
|
132
|
-
},
|
|
133
|
-
bound: {
|
|
134
|
-
validate: (0, _utils.assertValueType)("boolean"),
|
|
135
|
-
optional: true
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
MarkoSpreadAttribute: {
|
|
141
|
-
aliases: ["Marko"],
|
|
142
|
-
builder: ["value"],
|
|
143
|
-
visitor: ["value"],
|
|
144
|
-
fields: {
|
|
145
|
-
value: {
|
|
146
|
-
validate: (0, _utils.assertNodeType)("Expression")
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
MarkoTagBody: {
|
|
152
|
-
aliases: ["Marko", "BlockParent", "FunctionParent", "Scope"],
|
|
153
|
-
builder: ["body", "params"],
|
|
154
|
-
visitor: ["typeParameters", "params", "body"],
|
|
155
|
-
fields: {
|
|
156
|
-
params: {
|
|
157
|
-
validate: (0, _utils.chain)(
|
|
158
|
-
(0, _utils.assertValueType)("array"),
|
|
159
|
-
(0, _utils.assertEach)((0, _utils.assertNodeType)("Identifier", "Pattern", "RestElement"))
|
|
160
|
-
),
|
|
161
|
-
default: []
|
|
162
|
-
},
|
|
163
|
-
typeParameters: {
|
|
164
|
-
validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration"),
|
|
165
|
-
optional: true
|
|
166
|
-
},
|
|
167
|
-
body: {
|
|
168
|
-
validate: arrayOfType([
|
|
169
|
-
"MarkoTag",
|
|
170
|
-
"MarkoCDATA",
|
|
171
|
-
"MarkoText",
|
|
172
|
-
"MarkoPlaceholder",
|
|
173
|
-
"MarkoScriptlet",
|
|
174
|
-
"MarkoComment"]
|
|
175
|
-
),
|
|
176
|
-
default: []
|
|
177
|
-
},
|
|
178
|
-
attributeTags: {
|
|
179
|
-
validate: (0, _utils.assertValueType)("boolean"),
|
|
180
|
-
default: false
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
MarkoTag: {
|
|
186
|
-
aliases: ["Marko", "Statement"],
|
|
187
|
-
builder: [
|
|
188
|
-
"name",
|
|
189
|
-
"attributes",
|
|
190
|
-
"body",
|
|
191
|
-
"arguments",
|
|
192
|
-
"var",
|
|
193
|
-
"attributeTags"],
|
|
194
|
-
|
|
195
|
-
visitor: [
|
|
196
|
-
"name",
|
|
197
|
-
"typeArguments",
|
|
198
|
-
"arguments",
|
|
199
|
-
"attributes",
|
|
200
|
-
"attributeTags",
|
|
201
|
-
"var",
|
|
202
|
-
"body"],
|
|
203
|
-
|
|
204
|
-
fields: {
|
|
205
|
-
name: {
|
|
206
|
-
validate: (0, _utils.assertNodeType)("Expression")
|
|
207
|
-
},
|
|
208
|
-
attributes: {
|
|
209
|
-
validate: arrayOfType(["MarkoAttribute", "MarkoSpreadAttribute"]),
|
|
210
|
-
default: []
|
|
211
|
-
},
|
|
212
|
-
body: {
|
|
213
|
-
validate: (0, _utils.assertNodeType)("MarkoTagBody")
|
|
214
|
-
},
|
|
215
|
-
arguments: {
|
|
216
|
-
validate: (0, _utils.chain)(
|
|
217
|
-
(0, _utils.assertValueType)("array"),
|
|
218
|
-
(0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement"))
|
|
219
|
-
),
|
|
220
|
-
optional: true
|
|
221
|
-
},
|
|
222
|
-
typeArguments: {
|
|
223
|
-
validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"),
|
|
224
|
-
optional: true
|
|
225
|
-
},
|
|
226
|
-
rawValue: {
|
|
227
|
-
validate: (0, _utils.assertValueType)("string"),
|
|
228
|
-
optional: true
|
|
229
|
-
},
|
|
230
|
-
var: {
|
|
231
|
-
validate: (0, _utils.assertNodeType)("LVal"),
|
|
232
|
-
optional: true
|
|
233
|
-
},
|
|
234
|
-
attributeTags: {
|
|
235
|
-
validate: arrayOfType(["MarkoTag", "MarkoScriptlet", "MarkoComment"]),
|
|
236
|
-
default: []
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};var _default = exports.default =
|
|
241
|
-
|
|
242
|
-
MarkoDefinitions;
|
|
243
|
-
const MARKO_TYPES = exports.MARKO_TYPES = Object.keys(MarkoDefinitions);
|
|
244
|
-
const MARKO_ALIAS_TYPES = exports.MARKO_ALIAS_TYPES = Array.from(
|
|
245
|
-
new Set(
|
|
246
|
-
MARKO_TYPES.reduce((all, t) => all.concat(MarkoDefinitions[t].aliases), [])
|
|
247
|
-
)
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
// Note this is inline because a change in babel caused a regression with this api.
|
|
251
|
-
// TODO: we should not rely on babels validators or builders.
|
|
252
|
-
function arrayOfType(types) {
|
|
253
|
-
return (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)(...types)));
|
|
254
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
2
|
-
require("../generator/patch");
|
|
3
|
-
|
|
4
|
-
var babelTypes = _interopRequireWildcard(require("@babel/types"));
|
|
5
|
-
var definitionUtils = _interopRequireWildcard(require("@babel/types/lib/definitions/utils"));
|
|
6
|
-
var generatedValidators = _interopRequireWildcard(require("@babel/types/lib/validators/generated"));
|
|
7
|
-
var referencedValidators = _interopRequireWildcard(require("@babel/types/lib/validators/isReferenced"));
|
|
8
|
-
var _validate = _interopRequireDefault(require("@babel/types/lib/validators/validate"));
|
|
9
|
-
|
|
10
|
-
var _definitions = _interopRequireWildcard(require("./definitions"));function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);} /* eslint-disable no-import-assign */
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
TYPES,
|
|
14
|
-
VISITOR_KEYS,
|
|
15
|
-
FLIPPED_ALIAS_KEYS,
|
|
16
|
-
DEPRECATED_KEYS,
|
|
17
|
-
is,
|
|
18
|
-
getBindingIdentifiers
|
|
19
|
-
} = babelTypes;
|
|
20
|
-
|
|
21
|
-
getBindingIdentifiers.keys.Program = ["params"];
|
|
22
|
-
getBindingIdentifiers.keys.MarkoTag = ["var"];
|
|
23
|
-
getBindingIdentifiers.keys.MarkoTagBody = ["params"];
|
|
24
|
-
getBindingIdentifiers.keys.MarkoScriptlet = ["body"];
|
|
25
|
-
|
|
26
|
-
_definitions.MARKO_TYPES.forEach((typeName) => {
|
|
27
|
-
definitionUtils.default(typeName, _definitions.default[typeName]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
babelTypes.NODE_FIELDS.Program.params =
|
|
31
|
-
babelTypes.NODE_FIELDS.MarkoTagBody.params;
|
|
32
|
-
|
|
33
|
-
for (const type of [
|
|
34
|
-
...Object.keys(VISITOR_KEYS),
|
|
35
|
-
...Object.keys(FLIPPED_ALIAS_KEYS),
|
|
36
|
-
...Object.keys(DEPRECATED_KEYS)])
|
|
37
|
-
{
|
|
38
|
-
if (!TYPES.includes(type)) TYPES.push(type);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_definitions.MARKO_TYPES.forEach((typeName) => {
|
|
42
|
-
const lowerName = typeName[0].toLowerCase() + typeName.slice(1);
|
|
43
|
-
const checkKey = `is${typeName}`;
|
|
44
|
-
const assertKey = `assert${typeName}`;
|
|
45
|
-
babelTypes[checkKey] = (node, opts) => is(typeName, node, opts);
|
|
46
|
-
babelTypes[assertKey] = (node, opts) => assert(typeName, node, opts);
|
|
47
|
-
babelTypes[typeName] = babelTypes[lowerName] = function () {
|
|
48
|
-
return builder(typeName, arguments);
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
_definitions.MARKO_ALIAS_TYPES.forEach((aliasName) => {
|
|
53
|
-
const checkKey = `is${aliasName}`;
|
|
54
|
-
const originalCheck = generatedValidators[checkKey];
|
|
55
|
-
generatedValidators[checkKey] = (node, opts) =>
|
|
56
|
-
is(aliasName, node, opts) || originalCheck(node, opts);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const originalIsReferenced = referencedValidators.default;
|
|
60
|
-
referencedValidators.default = (node, parent, grandparent) => {
|
|
61
|
-
switch (parent.type) {
|
|
62
|
-
case "MarkoTag":
|
|
63
|
-
return parent.var !== node;
|
|
64
|
-
case "MarkoTagBody":
|
|
65
|
-
return false;
|
|
66
|
-
default:
|
|
67
|
-
return originalIsReferenced(node, parent, grandparent);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
for (const { types, set } of definitionUtils.allExpandedTypes || []) {
|
|
72
|
-
for (const type of types) {
|
|
73
|
-
const aliases = FLIPPED_ALIAS_KEYS[type];
|
|
74
|
-
if (aliases) {
|
|
75
|
-
aliases.forEach(set.add, set);
|
|
76
|
-
} else {
|
|
77
|
-
set.add(type);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function assert(typeName, node, opts) {
|
|
83
|
-
if (!is(typeName, node, opts)) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
`Expected type "${typeName}" with option ${JSON.stringify(
|
|
86
|
-
opts
|
|
87
|
-
)}, but instead got "${node.type}".`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function builder(type, args) {
|
|
93
|
-
const definition = _definitions.default[type];
|
|
94
|
-
const keys = definition.builder;
|
|
95
|
-
const countArgs = args.length;
|
|
96
|
-
if (countArgs > keys.length) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`${type}: Too many arguments passed. Received ${countArgs} but can receive no more than ${keys.length}`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const node = { type };
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < keys.length; ++i) {
|
|
105
|
-
const key = keys[i];
|
|
106
|
-
const field = definition.fields[key];
|
|
107
|
-
|
|
108
|
-
let arg;
|
|
109
|
-
if (i < countArgs) arg = args[i];
|
|
110
|
-
if (arg === undefined) {
|
|
111
|
-
arg = Array.isArray(field.default) ? [] : field.default;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
node[key] = arg;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// (assume all enumerable properties are own)
|
|
118
|
-
|
|
119
|
-
for (const key in node) {
|
|
120
|
-
(0, _validate.default)(node, key, node[key]);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return node;
|
|
124
|
-
}
|