@marko/compiler 5.38.4 → 5.39.0
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/babel-utils.d.ts +419 -0
- package/dist/babel-plugin/index.js +12 -16
- package/dist/babel-plugin/parser.js +1 -1
- package/dist/babel-plugin/plugins/migrate.js +1 -1
- package/dist/babel-plugin/plugins/transform.js +1 -1
- package/dist/babel-types/generator/patch.js +3 -5
- package/dist/babel-utils/assert.js +98 -0
- package/dist/babel-utils/compute.js +194 -0
- package/dist/babel-utils/diagnostics.js +63 -0
- package/dist/babel-utils/imports.js +136 -0
- package/dist/babel-utils/index.js +63 -0
- package/dist/babel-utils/loc.js +107 -0
- package/dist/babel-utils/parse.js +199 -0
- package/dist/babel-utils/taglib.js +27 -0
- package/dist/babel-utils/tags.js +430 -0
- package/dist/babel-utils/template-string.js +56 -0
- package/dist/config.js +6 -2
- package/dist/index.js +1 -1
- package/dist/util/try-load-translator.js +2 -21
- package/index.d.ts +1 -1
- package/package.json +20 -11
package/babel-utils.d.ts
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import type { Config, types as t } from "@marko/compiler";
|
|
2
|
+
|
|
3
|
+
export interface AttributeDefinition {
|
|
4
|
+
allowExpressions: boolean;
|
|
5
|
+
filePath: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
html?: boolean;
|
|
9
|
+
enum?: string[];
|
|
10
|
+
pattern?: RegExp;
|
|
11
|
+
required: boolean;
|
|
12
|
+
defaultValue: unknown;
|
|
13
|
+
description?: string;
|
|
14
|
+
deprecated: boolean;
|
|
15
|
+
autocomplete: Array<{
|
|
16
|
+
displayText: string;
|
|
17
|
+
snippet: string;
|
|
18
|
+
description: string;
|
|
19
|
+
descriptionMoreURL?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
export interface PluginDefinition<T = any> {
|
|
23
|
+
path?: string;
|
|
24
|
+
hook: Plugin<T>;
|
|
25
|
+
}
|
|
26
|
+
export interface TagDefinition {
|
|
27
|
+
dir: string;
|
|
28
|
+
filePath: string;
|
|
29
|
+
attributeGroups?: string[];
|
|
30
|
+
patternAttributes?: AttributeDefinition[];
|
|
31
|
+
attributes: { [x: string]: AttributeDefinition };
|
|
32
|
+
description?: string;
|
|
33
|
+
nestedTags?: {
|
|
34
|
+
[x: string]: TagDefinition & {
|
|
35
|
+
isNestedTag: true;
|
|
36
|
+
isRepeated: boolean;
|
|
37
|
+
targetProperty: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
autocomplete?: Array<{
|
|
41
|
+
displayText: string;
|
|
42
|
+
snippet: string;
|
|
43
|
+
description: string;
|
|
44
|
+
descriptionMoreURL?: string;
|
|
45
|
+
}>;
|
|
46
|
+
htmlType?: "html" | "svg" | "math";
|
|
47
|
+
html: boolean;
|
|
48
|
+
name: string;
|
|
49
|
+
isNestedTag?: boolean;
|
|
50
|
+
isRepeated?: boolean;
|
|
51
|
+
targetProperty?: string;
|
|
52
|
+
taglibId: string;
|
|
53
|
+
types?: string;
|
|
54
|
+
template?: string;
|
|
55
|
+
renderer?: string;
|
|
56
|
+
deprecated: boolean;
|
|
57
|
+
openTagOnly: boolean;
|
|
58
|
+
analyzer?: PluginDefinition<t.MarkoTag>;
|
|
59
|
+
translator?: PluginDefinition<t.MarkoTag>;
|
|
60
|
+
parser?: PluginDefinition<t.MarkoTag>;
|
|
61
|
+
transformers?: PluginDefinition<t.MarkoTag>[];
|
|
62
|
+
migrators?: PluginDefinition<t.MarkoTag>[];
|
|
63
|
+
parseOptions?: {
|
|
64
|
+
text?: boolean;
|
|
65
|
+
statement?: boolean;
|
|
66
|
+
controlFlow?: boolean;
|
|
67
|
+
openTagOnly?: boolean;
|
|
68
|
+
rawOpenTag?: boolean;
|
|
69
|
+
preserveWhitespace?: boolean;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface TaglibLookup {
|
|
74
|
+
getTagsSorted(): TagDefinition[];
|
|
75
|
+
getTag(tagName: string): undefined | TagDefinition;
|
|
76
|
+
getAttribute(
|
|
77
|
+
tagName: string,
|
|
78
|
+
attrName: string,
|
|
79
|
+
): undefined | AttributeDefinition;
|
|
80
|
+
forEachAttribute(
|
|
81
|
+
tagName: string,
|
|
82
|
+
callback: (attr: AttributeDefinition, tag: TagDefinition) => void,
|
|
83
|
+
): void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface Attribute {
|
|
87
|
+
allowExpressions?: boolean;
|
|
88
|
+
type?: string;
|
|
89
|
+
html?: boolean;
|
|
90
|
+
enum?: string[];
|
|
91
|
+
pattern?: RegExp;
|
|
92
|
+
required?: boolean;
|
|
93
|
+
defaultValue?: unknown;
|
|
94
|
+
description?: string;
|
|
95
|
+
deprecated?: boolean;
|
|
96
|
+
autocomplete?: Array<{
|
|
97
|
+
displayText?: string;
|
|
98
|
+
snippet?: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
descriptionMoreURL?: string;
|
|
101
|
+
}>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface Tag {
|
|
105
|
+
attributeGroups?: string[];
|
|
106
|
+
patternAttributes?: Attribute[];
|
|
107
|
+
attributes?: { [x: string]: Attribute };
|
|
108
|
+
description?: string;
|
|
109
|
+
nestedTags?: {
|
|
110
|
+
[x: string]: Tag & {
|
|
111
|
+
isRepeated?: boolean;
|
|
112
|
+
targetProperty?: string;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
autocomplete?: Array<{
|
|
116
|
+
displayText?: string;
|
|
117
|
+
snippet?: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
descriptionMoreURL?: string;
|
|
120
|
+
}>;
|
|
121
|
+
htmlType?: "html" | "svg" | "math";
|
|
122
|
+
html?: boolean;
|
|
123
|
+
types?: string;
|
|
124
|
+
template?: string;
|
|
125
|
+
renderer?: string;
|
|
126
|
+
deprecated?: boolean;
|
|
127
|
+
openTagOnly?: boolean;
|
|
128
|
+
analyze?: Plugin<t.MarkoTag>;
|
|
129
|
+
translate?: Plugin<t.MarkoTag>;
|
|
130
|
+
parse?: Plugin<t.MarkoTag>;
|
|
131
|
+
transform?: Plugin<t.MarkoTag>[];
|
|
132
|
+
migrate?: Plugin<t.MarkoTag>[];
|
|
133
|
+
parseOptions?: {
|
|
134
|
+
rootOnly?: boolean;
|
|
135
|
+
rawOpenTag?: boolean;
|
|
136
|
+
openTagOnly?: boolean;
|
|
137
|
+
controlFlow?: boolean;
|
|
138
|
+
ignoreAttributes?: boolean;
|
|
139
|
+
relaxRequireCommas?: boolean;
|
|
140
|
+
text?: boolean;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function defineTag<T extends Tag>(tag: T): T;
|
|
145
|
+
|
|
146
|
+
export type FunctionPlugin<T = any> = (
|
|
147
|
+
path: t.NodePath<T>,
|
|
148
|
+
types: typeof t,
|
|
149
|
+
) => void;
|
|
150
|
+
export type EnterExitPlugin<T = any> = {
|
|
151
|
+
enter?(path: t.NodePath<T>, types: typeof t): void;
|
|
152
|
+
exit?(path: t.NodePath<T>, types: typeof t): void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type ModulePlugin<T = any> = {
|
|
156
|
+
default: EnterExitPlugin<T> | FunctionPlugin<T>;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export type Plugin<T = any> =
|
|
160
|
+
| ModulePlugin<T>
|
|
161
|
+
| EnterExitPlugin<T>
|
|
162
|
+
| FunctionPlugin<T>;
|
|
163
|
+
|
|
164
|
+
export function assertAllowedAttributes(
|
|
165
|
+
path: t.NodePath<t.MarkoTag>,
|
|
166
|
+
allowed: string[],
|
|
167
|
+
): void;
|
|
168
|
+
export function assertNoArgs(path: t.NodePath<t.MarkoTag>): void;
|
|
169
|
+
export function assertNoVar(path: t.NodePath<t.MarkoTag>): void;
|
|
170
|
+
export function assertNoAttributes(path: t.NodePath<t.MarkoTag>): void;
|
|
171
|
+
export function assertNoParams(path: t.NodePath<t.MarkoTag>): void;
|
|
172
|
+
export function assertNoAttributeTags(path: t.NodePath<t.MarkoTag>): void;
|
|
173
|
+
export function assertAttributesOrArgs(path: t.NodePath<t.MarkoTag>): void;
|
|
174
|
+
export function assertAttributesOrSingleArg(path: t.NodePath<t.MarkoTag>): void;
|
|
175
|
+
|
|
176
|
+
export function isNativeTag(path: t.NodePath<t.MarkoTag>): boolean;
|
|
177
|
+
export function isMacroTag(path: t.NodePath<t.MarkoTag>): boolean;
|
|
178
|
+
export function isDynamicTag(path: t.NodePath<t.MarkoTag>): boolean;
|
|
179
|
+
export function isAttributeTag(
|
|
180
|
+
path: t.NodePath<t.MarkoTag>,
|
|
181
|
+
): path is t.NodePath<t.MarkoTag & { name: t.StringLiteral }>;
|
|
182
|
+
export function isTransparentTag(
|
|
183
|
+
path: t.NodePath<t.MarkoTag>,
|
|
184
|
+
): path is t.NodePath<t.MarkoTag & { name: t.StringLiteral }>;
|
|
185
|
+
export function isLoopTag(
|
|
186
|
+
path: t.NodePath<t.MarkoTag>,
|
|
187
|
+
): path is t.NodePath<t.MarkoTag & { name: t.StringLiteral }>;
|
|
188
|
+
|
|
189
|
+
export function registerMacro(path: t.NodePath<any>, name: string): void;
|
|
190
|
+
export function hasMacro(path: t.NodePath<any>, name: string): boolean;
|
|
191
|
+
export function getMacroIdentifierForName(
|
|
192
|
+
path: t.NodePath<any>,
|
|
193
|
+
name: string,
|
|
194
|
+
): t.Identifier;
|
|
195
|
+
export function getMacroIdentifier(path: t.NodePath<t.MarkoTag>): t.Identifier;
|
|
196
|
+
export function getTagTemplate(
|
|
197
|
+
path: t.NodePath<t.MarkoTag>,
|
|
198
|
+
): string | undefined;
|
|
199
|
+
export function getTagDef(
|
|
200
|
+
path: t.NodePath<t.MarkoTag>,
|
|
201
|
+
): TagDefinition | undefined;
|
|
202
|
+
export function getFullyResolvedTagName(path: t.NodePath<t.MarkoTag>): string;
|
|
203
|
+
|
|
204
|
+
export function findParentTag(
|
|
205
|
+
path: t.NodePath<t.MarkoTag>,
|
|
206
|
+
): t.NodePath<t.MarkoTag> | undefined;
|
|
207
|
+
export function findAttributeTags(
|
|
208
|
+
path: t.NodePath<t.MarkoTag>,
|
|
209
|
+
): Array<t.NodePath<t.MarkoTag>>;
|
|
210
|
+
|
|
211
|
+
export function getArgOrSequence(
|
|
212
|
+
path: t.NodePath<t.MarkoTag | t.MarkoAttribute>,
|
|
213
|
+
): t.Expression;
|
|
214
|
+
|
|
215
|
+
export function loadFileForTag(
|
|
216
|
+
path: t.NodePath<t.MarkoTag>,
|
|
217
|
+
): t.BabelFile | undefined;
|
|
218
|
+
export function loadFileForImport(
|
|
219
|
+
file: t.BabelFile,
|
|
220
|
+
template: string,
|
|
221
|
+
): t.BabelFile | undefined;
|
|
222
|
+
|
|
223
|
+
export function normalizeTemplateString(
|
|
224
|
+
quasis: Array<string | t.TemplateElement>,
|
|
225
|
+
...expressions: t.Expression[]
|
|
226
|
+
): t.TemplateLiteral;
|
|
227
|
+
|
|
228
|
+
type Loc = { line: number; column: number; index?: number };
|
|
229
|
+
type LocRange = { start: Loc; end: Loc };
|
|
230
|
+
|
|
231
|
+
export function getStart(file: t.BabelFile, node: t.Node): number | null;
|
|
232
|
+
export function getEnd(file: t.BabelFile, node: t.Node): number | null;
|
|
233
|
+
export function getLoc(file: t.BabelFile, pos: number): Loc;
|
|
234
|
+
export function getLocRange(
|
|
235
|
+
file: t.BabelFile,
|
|
236
|
+
start: number,
|
|
237
|
+
end: number,
|
|
238
|
+
): LocRange;
|
|
239
|
+
export function withLoc<T extends t.Node>(
|
|
240
|
+
file: t.BabelFile,
|
|
241
|
+
node: T,
|
|
242
|
+
start: number,
|
|
243
|
+
end: number,
|
|
244
|
+
): T;
|
|
245
|
+
|
|
246
|
+
export function parseStatements<T extends t.Statement[]>(
|
|
247
|
+
file: t.BabelFile,
|
|
248
|
+
str: string,
|
|
249
|
+
): T;
|
|
250
|
+
export function parseStatements<T extends t.Statement[]>(
|
|
251
|
+
file: t.BabelFile,
|
|
252
|
+
str: string,
|
|
253
|
+
sourceStart: number,
|
|
254
|
+
sourceEnd: number,
|
|
255
|
+
sourceOffset?: number,
|
|
256
|
+
): T;
|
|
257
|
+
|
|
258
|
+
export function parseExpression<T extends t.Expression>(
|
|
259
|
+
file: t.BabelFile,
|
|
260
|
+
str: string,
|
|
261
|
+
): T;
|
|
262
|
+
export function parseExpression<T extends t.Expression>(
|
|
263
|
+
file: t.BabelFile,
|
|
264
|
+
str: string,
|
|
265
|
+
sourceStart: number,
|
|
266
|
+
sourceEnd: number,
|
|
267
|
+
sourceOffset?: number,
|
|
268
|
+
): T;
|
|
269
|
+
|
|
270
|
+
export function parseParams(
|
|
271
|
+
file: t.BabelFile,
|
|
272
|
+
str: string,
|
|
273
|
+
): t.Function["params"];
|
|
274
|
+
export function parseParams(
|
|
275
|
+
file: t.BabelFile,
|
|
276
|
+
str: string,
|
|
277
|
+
sourceStart: number,
|
|
278
|
+
sourceEnd: number,
|
|
279
|
+
): t.Function["params"];
|
|
280
|
+
|
|
281
|
+
export function parseArgs(
|
|
282
|
+
file: t.BabelFile,
|
|
283
|
+
str: string,
|
|
284
|
+
): t.CallExpression["arguments"];
|
|
285
|
+
export function parseArgs(
|
|
286
|
+
file: t.BabelFile,
|
|
287
|
+
str: string,
|
|
288
|
+
sourceStart: number,
|
|
289
|
+
sourceEnd: number,
|
|
290
|
+
): t.CallExpression["arguments"];
|
|
291
|
+
|
|
292
|
+
export function parseVar(
|
|
293
|
+
file: t.BabelFile,
|
|
294
|
+
str: string,
|
|
295
|
+
): t.VariableDeclarator["id"];
|
|
296
|
+
export function parseVar(
|
|
297
|
+
file: t.BabelFile,
|
|
298
|
+
str: string,
|
|
299
|
+
sourceStart: number,
|
|
300
|
+
sourceEnd: number,
|
|
301
|
+
): t.VariableDeclarator["id"];
|
|
302
|
+
|
|
303
|
+
export function parseTemplateLiteral(
|
|
304
|
+
file: t.BabelFile,
|
|
305
|
+
str: string,
|
|
306
|
+
): t.TemplateLiteral;
|
|
307
|
+
export function parseTemplateLiteral(
|
|
308
|
+
file: t.BabelFile,
|
|
309
|
+
str: string,
|
|
310
|
+
sourceStart: number,
|
|
311
|
+
sourceEnd: number,
|
|
312
|
+
): t.TemplateLiteral;
|
|
313
|
+
|
|
314
|
+
export function resolveRelativePath(file: t.BabelFile, request: string): string;
|
|
315
|
+
export function importDefault(
|
|
316
|
+
file: t.BabelFile,
|
|
317
|
+
request: string,
|
|
318
|
+
nameHint?: string,
|
|
319
|
+
): t.Identifier;
|
|
320
|
+
export function importStar(
|
|
321
|
+
file: t.BabelFile,
|
|
322
|
+
request: string,
|
|
323
|
+
nameHint?: string,
|
|
324
|
+
): t.Identifier;
|
|
325
|
+
export function importNamed(
|
|
326
|
+
file: t.BabelFile,
|
|
327
|
+
request: string,
|
|
328
|
+
name: string,
|
|
329
|
+
nameHint?: string,
|
|
330
|
+
): t.Identifier;
|
|
331
|
+
|
|
332
|
+
export function getTaglibLookup(file: t.BabelFile): TaglibLookup;
|
|
333
|
+
export function getTagDefForTagName(
|
|
334
|
+
file: t.BabelFile,
|
|
335
|
+
tagName: string,
|
|
336
|
+
): TagDefinition | undefined;
|
|
337
|
+
|
|
338
|
+
export function getTemplateId(
|
|
339
|
+
optimize: boolean | Config,
|
|
340
|
+
request: string,
|
|
341
|
+
child?: string,
|
|
342
|
+
): string;
|
|
343
|
+
export function resolveTagImport(
|
|
344
|
+
path: t.NodePath<any>,
|
|
345
|
+
request: string,
|
|
346
|
+
): string | undefined;
|
|
347
|
+
|
|
348
|
+
export enum DiagnosticType {
|
|
349
|
+
Error = "error",
|
|
350
|
+
Warning = "warning",
|
|
351
|
+
Deprecation = "deprecation",
|
|
352
|
+
Suggestion = "suggestion",
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface Diagnostic {
|
|
356
|
+
type: DiagnosticType;
|
|
357
|
+
label: string;
|
|
358
|
+
loc: undefined | false | LocRange;
|
|
359
|
+
fix: boolean | ConfirmFix | SelectFix;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface DiagnosticOptions {
|
|
363
|
+
label: string;
|
|
364
|
+
loc?: undefined | false | LocRange;
|
|
365
|
+
fix?:
|
|
366
|
+
| undefined
|
|
367
|
+
| (() => void)
|
|
368
|
+
| (ConfirmFix & {
|
|
369
|
+
apply(confirmed: boolean | undefined): void;
|
|
370
|
+
})
|
|
371
|
+
| (SelectFix & {
|
|
372
|
+
apply(selected: string | undefined): void;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export function diagnosticError(
|
|
377
|
+
path: t.NodePath<any>,
|
|
378
|
+
options: DiagnosticOptions,
|
|
379
|
+
): void;
|
|
380
|
+
export function diagnosticWarn(
|
|
381
|
+
path: t.NodePath<any>,
|
|
382
|
+
options: DiagnosticOptions,
|
|
383
|
+
): void;
|
|
384
|
+
export function diagnosticDeprecate(
|
|
385
|
+
path: t.NodePath<any>,
|
|
386
|
+
options: DiagnosticOptions,
|
|
387
|
+
): void;
|
|
388
|
+
export function diagnosticSuggest(
|
|
389
|
+
path: t.NodePath<any>,
|
|
390
|
+
options: DiagnosticOptions,
|
|
391
|
+
): void;
|
|
392
|
+
|
|
393
|
+
interface ConfirmFix {
|
|
394
|
+
type: "confirm";
|
|
395
|
+
message: string;
|
|
396
|
+
initialValue?: boolean;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface SelectFix {
|
|
400
|
+
type: "select";
|
|
401
|
+
message: string;
|
|
402
|
+
options: {
|
|
403
|
+
value: string;
|
|
404
|
+
label?: string;
|
|
405
|
+
}[];
|
|
406
|
+
initialValue?: string;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
type Computed =
|
|
410
|
+
| undefined
|
|
411
|
+
| number
|
|
412
|
+
| string
|
|
413
|
+
| boolean
|
|
414
|
+
| RegExp
|
|
415
|
+
| bigint
|
|
416
|
+
| null
|
|
417
|
+
| { [x: string]: Computed }
|
|
418
|
+
| Computed[];
|
|
419
|
+
export function computeNode(node: t.Node): undefined | { value: Computed };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;exports.getMarkoFile = getMarkoFile;var _traverse = require("@babel/traverse");
|
|
2
|
-
var _babelUtils = require("@marko/babel-utils");
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;exports.getMarkoFile = getMarkoFile;var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
2
|
+
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
3
3
|
var _crypto = require("crypto");
|
|
4
4
|
var _path = _interopRequireDefault(require("path"));
|
|
5
5
|
|
|
@@ -358,27 +358,23 @@ function mergeVisitors(all) {
|
|
|
358
358
|
if (all.length === 1) {
|
|
359
359
|
all = all[0];
|
|
360
360
|
} else {
|
|
361
|
-
return _traverse.visitors.merge(all);
|
|
361
|
+
return _traverse.default.visitors.merge(all);
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
return _traverse.visitors.explode(all);
|
|
365
|
+
return _traverse.default.visitors.explode(all);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
function traverseAll(file, visitors) {
|
|
369
369
|
const program = file.path;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (Program && Program.exit) {
|
|
379
|
-
program._call(Program.exit);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
370
|
+
(0, _traverse.default)(
|
|
371
|
+
program.node,
|
|
372
|
+
mergeVisitors(visitors),
|
|
373
|
+
program.scope,
|
|
374
|
+
program.state = {},
|
|
375
|
+
program,
|
|
376
|
+
true
|
|
377
|
+
);
|
|
382
378
|
}
|
|
383
379
|
|
|
384
380
|
function addPlugin(meta, arr, plugin) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";exports.__esModule = true;exports.visitor = void 0;var _babelUtils = require("@marko/babel-utils");
|
|
1
|
+
"use strict";exports.__esModule = true;exports.visitor = void 0;var _babelUtils = require("@marko/compiler/babel-utils");
|
|
2
2
|
|
|
3
3
|
var t = _interopRequireWildcard(require("../../babel-types"));
|
|
4
4
|
var _pluginHooks = require("../util/plugin-hooks");function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";exports.__esModule = true;exports.visitor = void 0;var _babelUtils = require("@marko/babel-utils");
|
|
1
|
+
"use strict";exports.__esModule = true;exports.visitor = void 0;var _babelUtils = require("@marko/compiler/babel-utils");
|
|
2
2
|
|
|
3
3
|
var t = _interopRequireWildcard(require("../../babel-types"));
|
|
4
4
|
var _pluginHooks = require("../util/plugin-hooks");function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}
|
|
@@ -136,7 +136,7 @@ Object.assign(_printer.default.prototype, {
|
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
138
|
MarkoTagBody(node) {
|
|
139
|
-
this.printSequence(node.body,
|
|
139
|
+
this.printSequence(node.body, true);
|
|
140
140
|
},
|
|
141
141
|
MarkoTag(node) {
|
|
142
142
|
const isDynamicTag = !t.isStringLiteral(node.name);
|
|
@@ -216,7 +216,7 @@ Object.assign(_printer.default.prototype, {
|
|
|
216
216
|
this.token(" ");
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
this.printJoin(attributes,
|
|
219
|
+
this.printJoin(attributes, undefined, undefined, spaceSeparator);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -230,9 +230,7 @@ Object.assign(_printer.default.prototype, {
|
|
|
230
230
|
} else {
|
|
231
231
|
this.token(">");
|
|
232
232
|
this.newline();
|
|
233
|
-
this.printSequence(bodyOverride || zipAttributeTagsAndBody(node),
|
|
234
|
-
indent: true
|
|
235
|
-
});
|
|
233
|
+
this.printSequence(bodyOverride || zipAttributeTagsAndBody(node), true);
|
|
236
234
|
this.token("</");
|
|
237
235
|
if (!isDynamicTag) {
|
|
238
236
|
this.token(tagName);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.assertAllowedAttributes = assertAllowedAttributes;exports.assertAttributesOrArgs = assertAttributesOrArgs;exports.assertAttributesOrSingleArg = assertAttributesOrSingleArg;exports.assertNoArgs = assertNoArgs;exports.assertNoAttributeTags = assertNoAttributeTags;exports.assertNoAttributes = assertNoAttributes;exports.assertNoParams = assertNoParams;exports.assertNoVar = assertNoVar;function assertAllowedAttributes(path, allowed) {
|
|
2
|
+
let i = 0;
|
|
3
|
+
for (const attr of path.node.attributes) {
|
|
4
|
+
if (attr.type === "MarkoSpreadAttribute") {
|
|
5
|
+
throw path.hub.buildError(
|
|
6
|
+
attr,
|
|
7
|
+
`Tag does not support spread attributes.`
|
|
8
|
+
);
|
|
9
|
+
} else if (!allowed.includes(attr.name)) {
|
|
10
|
+
throw path.hub.buildError(
|
|
11
|
+
attr,
|
|
12
|
+
`Tag does not support the \`${attr.name}\` attribute.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
i++;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function assertNoAttributes(path) {
|
|
21
|
+
const { attributes } = path.node;
|
|
22
|
+
if (attributes.length) {
|
|
23
|
+
const start = attributes[0].loc.start;
|
|
24
|
+
const end = attributes[attributes.length - 1].loc.end;
|
|
25
|
+
throw path.hub.buildError(
|
|
26
|
+
{ loc: { start, end } },
|
|
27
|
+
"Tag does not support attributes."
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function assertNoParams(path) {
|
|
33
|
+
const { params } = path.node.body;
|
|
34
|
+
if (params.length) {
|
|
35
|
+
const start = params[0].loc.start;
|
|
36
|
+
const end = params[params.length - 1].loc.end;
|
|
37
|
+
throw path.hub.buildError(
|
|
38
|
+
{ loc: { start, end } },
|
|
39
|
+
"Tag does not support parameters."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function assertNoAttributeTags(path) {
|
|
45
|
+
if (path.node.attributeTags.length) {
|
|
46
|
+
throw path.hub.buildError(
|
|
47
|
+
path.node.attributeTags[0],
|
|
48
|
+
"Tag not support nested attribute tags."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function assertNoArgs(path) {
|
|
54
|
+
const args = path.node.arguments;
|
|
55
|
+
if (args && args.length) {
|
|
56
|
+
const start = args[0].loc.start;
|
|
57
|
+
const end = args[args.length - 1].loc.end;
|
|
58
|
+
throw path.hub.buildError(
|
|
59
|
+
{ loc: { start, end } },
|
|
60
|
+
"Tag does not support arguments."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function assertNoVar(path) {
|
|
66
|
+
if (path.node.var) {
|
|
67
|
+
throw path.hub.buildError(
|
|
68
|
+
path.node.var,
|
|
69
|
+
"Tag does not support a variable."
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function assertAttributesOrArgs(path) {
|
|
75
|
+
const { node } = path;
|
|
76
|
+
const args = node.arguments;
|
|
77
|
+
if (args && args.length && (node.attributes.length > 0 || node.body.length)) {
|
|
78
|
+
const start = args[0].loc.start;
|
|
79
|
+
const end = args[args.length - 1].loc.end;
|
|
80
|
+
throw path.hub.buildError(
|
|
81
|
+
{ loc: { start, end } },
|
|
82
|
+
"Tag does not support arguments when attributes or body present."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function assertAttributesOrSingleArg(path) {
|
|
88
|
+
assertAttributesOrArgs(path);
|
|
89
|
+
const args = path.node.arguments;
|
|
90
|
+
if (args && args.length > 1) {
|
|
91
|
+
const start = args[1].loc.start;
|
|
92
|
+
const end = args[args.length - 1].loc.end;
|
|
93
|
+
throw path.hub.buildError(
|
|
94
|
+
{ loc: { start, end } },
|
|
95
|
+
"Tag does not support multiple arguments."
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|