@marko/translator-default 5.21.0 → 5.21.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/dist/index.js +37 -37
  2. package/package.json +5 -5
  3. package/src/index.js +0 -516
package/dist/index.js CHANGED
@@ -457,49 +457,49 @@ function getRuntimeEntryFiles(output, optimize) {
457
457
  const base = `marko/${optimize ? "dist" : "src"}/`;
458
458
 
459
459
  return [
460
- `${base}runtime/components`,
461
- `${base}runtime/components/defineComponent`,
462
- `${base}runtime/components/renderer`,
460
+ `${base}runtime/components/index.js`,
461
+ `${base}runtime/components/defineComponent.js`,
462
+ `${base}runtime/components/renderer.js`,
463
463
  `${base}runtime/components/registry`,
464
- `${base}runtime/components/attach-detach`,
465
- `${base}runtime/helpers/assign`,
466
- `${base}runtime/helpers/class-value`,
467
- `${base}runtime/helpers/dynamic-tag`,
468
- `${base}runtime/helpers/load-nested-tag`,
469
- `${base}runtime/helpers/merge`,
470
- `${base}runtime/helpers/render-tag`,
471
- `${base}runtime/helpers/style-value`,
472
- `${base}runtime/helpers/to-string`,
464
+ `${base}runtime/components/attach-detach.js`,
465
+ `${base}runtime/helpers/assign.js`,
466
+ `${base}runtime/helpers/class-value.js`,
467
+ `${base}runtime/helpers/dynamic-tag.js`,
468
+ `${base}runtime/helpers/load-nested-tag.js`,
469
+ `${base}runtime/helpers/merge.js`,
470
+ `${base}runtime/helpers/render-tag.js`,
471
+ `${base}runtime/helpers/style-value.js`,
472
+ `${base}runtime/helpers/to-string.js`,
473
473
  `${base}core-tags/components/preserve-tag`,
474
- `${base}core-tags/components/init-components-tag`,
475
- `${base}core-tags/components/preferred-script-location-tag`,
476
- `${base}core-tags/core/__flush_here_and_after__`,
477
- `${base}core-tags/core/await/renderer`,
478
- `${base}core-tags/core/await/reorderer-renderer`,
479
474
  ...(output === "html" ?
480
475
  [
481
- `${base}runtime/html`,
482
- `${base}runtime/html/hot-reload`,
483
- `${base}runtime/html/helpers/attr`,
484
- `${base}runtime/html/helpers/attrs`,
485
- `${base}runtime/html/helpers/class-attr`,
486
- `${base}runtime/html/helpers/data-marko`,
487
- `${base}runtime/html/helpers/escape-quotes`,
488
- `${base}runtime/html/helpers/escape-script-placeholder`,
489
- `${base}runtime/html/helpers/escape-style-placeholder`,
490
- `${base}runtime/html/helpers/escape-xml`,
491
- `${base}runtime/html/helpers/merge-attrs`,
492
- `${base}runtime/html/helpers/props-script`,
493
- `${base}runtime/html/helpers/style-attr`] :
476
+ `${base}runtime/html/index.js`,
477
+ `${base}runtime/html/hot-reload.js`,
478
+ `${base}runtime/html/helpers/attr.js`,
479
+ `${base}runtime/html/helpers/attrs.js`,
480
+ `${base}runtime/html/helpers/class-attr.js`,
481
+ `${base}runtime/html/helpers/data-marko.js`,
482
+ `${base}runtime/html/helpers/escape-quotes.js`,
483
+ `${base}runtime/html/helpers/escape-script-placeholder.js`,
484
+ `${base}runtime/html/helpers/escape-style-placeholder.js`,
485
+ `${base}runtime/html/helpers/escape-xml.js`,
486
+ `${base}runtime/html/helpers/merge-attrs.js`,
487
+ `${base}runtime/html/helpers/props-script.js`,
488
+ `${base}runtime/html/helpers/style-attr.js`,
489
+ `${base}core-tags/components/init-components-tag.js`,
490
+ `${base}core-tags/components/preferred-script-location-tag.js`,
491
+ `${base}core-tags/core/__flush_here_and_after__.js`,
492
+ `${base}core-tags/core/await/renderer.js`,
493
+ `${base}core-tags/core/await/reorderer-renderer.js`] :
494
494
 
495
495
  [
496
- `${base}runtime/vdom`,
497
- `${base}runtime/vdom/hot-reload`,
498
- `${base}runtime/vdom/helpers/attrs`,
499
- `${base}runtime/vdom/helpers/const`,
500
- `${base}runtime/vdom/helpers/v-element`,
501
- `${base}runtime/vdom/helpers/v-text`,
502
- `${base}runtime/vdom/preserve-attrs`])];
496
+ `${base}runtime/vdom/index.js`,
497
+ `${base}runtime/vdom/hot-reload.js`,
498
+ `${base}runtime/vdom/helpers/attrs.js`,
499
+ `${base}runtime/vdom/helpers/const.js`,
500
+ `${base}runtime/vdom/helpers/v-element.js`,
501
+ `${base}runtime/vdom/helpers/v-text.js`,
502
+ `${base}runtime/vdom/preserve-attrs.js`])];
503
503
 
504
504
 
505
505
  }
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@marko/translator-default",
3
3
  "description": "Translates Marko templates to the default Marko runtime.",
4
- "version": "5.21.0",
4
+ "version": "5.21.3",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.16.0",
9
- "@marko/babel-utils": "^5.21.0",
9
+ "@marko/babel-utils": "^5.21.1",
10
10
  "escape-string-regexp": "^4.0.0",
11
11
  "magic-string": "^0.25.7",
12
12
  "self-closing-tags": "^1.0.1"
13
13
  },
14
14
  "devDependencies": {
15
- "@marko/compiler": "^5.21.0",
16
- "marko": "^5.21.0"
15
+ "@marko/compiler": "^5.21.7",
16
+ "marko": "^5.21.3"
17
17
  },
18
18
  "files": [
19
19
  "dist"
@@ -28,7 +28,7 @@
28
28
  "plugin"
29
29
  ],
30
30
  "license": "MIT",
31
- "main": "src/index.js",
31
+ "main": "dist/index.js",
32
32
  "main:dev": "src/index.js",
33
33
  "main:npm": "dist/index.js",
34
34
  "peerDependencies": {
package/src/index.js DELETED
@@ -1,516 +0,0 @@
1
- import { resolve } from "path";
2
- import { types as t } from "@marko/compiler";
3
- import {
4
- parseExpression,
5
- resolveTagImport,
6
- resolveRelativePath,
7
- importNamed,
8
- importDefault,
9
- parseScript,
10
- isNativeTag,
11
- isMacroTag,
12
- isDynamicTag,
13
- isAttributeTag,
14
- loadFileForTag,
15
- findParentTag,
16
- getTagDef
17
- } from "@marko/babel-utils";
18
- import { version } from "marko/package.json";
19
- import MarkoDocumentType from "./document-type";
20
- import MarkoDeclaration from "./declaration";
21
- import MarkoCDATA from "./cdata";
22
- import MarkoTag from "./tag";
23
- import MarkoText from "./text";
24
- import MarkoPlaceholder from "./placeholder";
25
- import MarkoComment from "./comment";
26
- import MarkoScriptlet from "./scriptlet";
27
- import MarkoClass from "./class";
28
- import { analyzeStaticVDOM } from "./util/optimize-vdom-create";
29
- import { optimizeHTMLWrites } from "./util/optimize-html-writes";
30
- import getComponentFiles from "./util/get-component-files";
31
- import addDependencies from "./util/add-dependencies";
32
-
33
- export { default as taglibs } from "./taglib";
34
-
35
- export const analyze = {
36
- Program: {
37
- enter(program) {
38
- // Pre populate metadata for component files.
39
- const meta = program.hub.file.metadata.marko;
40
- getComponentFiles(program);
41
-
42
- if (!meta.hasComponent && !meta.hasComponentBrowser) {
43
- meta.hasComponent = program
44
- .get("body")
45
- .some(child => child.isMarkoClass());
46
- }
47
- },
48
- exit(program) {
49
- const { file } = program.hub;
50
- const meta = file.metadata.marko;
51
- const { styleFile, packageFile, componentBrowserFile } =
52
- getComponentFiles(program);
53
-
54
- if (packageFile) {
55
- meta.deps.unshift(`package: ${packageFile}`);
56
- }
57
-
58
- if (styleFile) {
59
- meta.deps.unshift(styleFile);
60
- }
61
-
62
- if (meta.hasComponentBrowser) {
63
- meta.component = componentBrowserFile;
64
- } else if (meta.hasComponent || meta.hasStatefulTagParams) {
65
- meta.component = file.opts.filename;
66
- }
67
-
68
- meta.component =
69
- meta.component && resolveRelativePath(file, meta.component);
70
- meta.deps = meta.deps.map(filename =>
71
- typeof filename === "string"
72
- ? resolveRelativePath(file, filename)
73
- : filename
74
- );
75
-
76
- meta.imports = program.node.body
77
- .filter(child => t.isImportDeclaration(child))
78
- .map(child => child.source.value);
79
- }
80
- },
81
- MarkoTag(tag) {
82
- const { file } = tag.hub;
83
- const tagDef = getTagDef(tag);
84
- // Check if tag uses stateful tag params.
85
- const meta = tag.hub.file.metadata.marko;
86
-
87
- if (tagDef) {
88
- if (tagDef.html && !tagDef.template && !tagDef.renderer) {
89
- if (tagDef.htmlType === "custom-element") {
90
- if (tagDef.parseOptions && tagDef.parseOptions.import) {
91
- // TODO: the taglib should be updated to support this as a top level option.
92
- meta.deps.push(
93
- resolve(
94
- tagDef.dir,
95
- resolve(tagDef.dir, tagDef.parseOptions.import)
96
- )
97
- );
98
- }
99
- }
100
- } else if (tag.get("name").isStringLiteral()) {
101
- const relativePath = resolveRelativeTagEntry(file, tagDef);
102
-
103
- if (relativePath) {
104
- tag.node.extra = tag.node.extra || {};
105
- tag.node.extra.relativePath = relativePath;
106
-
107
- if (!meta.tags.includes(relativePath)) {
108
- meta.tags.push(relativePath);
109
- }
110
- }
111
- }
112
-
113
- if (tagDef.translator && tagDef.translator.path) {
114
- if (!meta.watchFiles.includes(tagDef.translator.path)) {
115
- meta.watchFiles.push(tagDef.translator.path);
116
- }
117
- }
118
- }
119
-
120
- if (
121
- meta.hasStatefulTagParams ||
122
- isNativeTag(tag) ||
123
- isMacroTag(tag) ||
124
- !tag.get("body").get("params").length
125
- ) {
126
- return;
127
- }
128
-
129
- if (isDynamicTag(tag)) {
130
- meta.hasStatefulTagParams = true;
131
- return;
132
- }
133
-
134
- let curTag = tag;
135
- while (isAttributeTag(curTag)) {
136
- curTag = findParentTag(curTag);
137
- }
138
-
139
- const tagFile = loadFileForTag(curTag);
140
- const childMeta = tagFile && tagFile.metadata.marko;
141
- meta.hasStatefulTagParams =
142
- childMeta &&
143
- (childMeta.hasStatefulTagParams ||
144
- (childMeta.hasComponent && !childMeta.hasComponentBrowser));
145
- },
146
- ImportDeclaration: {
147
- exit(path) {
148
- const source = path.get("source");
149
- const tagEntry = resolveTagImport(source, source.node.value);
150
-
151
- if (tagEntry) {
152
- const meta = path.hub.file.metadata.marko;
153
- source.node.value = tagEntry;
154
-
155
- if (!meta.tags.includes(tagEntry)) {
156
- meta.tags.push(tagEntry);
157
- }
158
- }
159
- }
160
- }
161
- };
162
-
163
- export const translate = {
164
- MarkoDocumentType,
165
- MarkoDeclaration,
166
- MarkoCDATA,
167
- MarkoTag,
168
- MarkoText,
169
- MarkoPlaceholder,
170
- MarkoScriptlet,
171
- MarkoClass,
172
- MarkoComment,
173
- ReferencedIdentifier(path) {
174
- if (path.node.name === "component" && !path.scope.hasBinding("component")) {
175
- path.replaceWith(path.hub.file._componentInstanceIdentifier);
176
- }
177
- },
178
- Program: {
179
- enter(path) {
180
- const {
181
- hub: { file }
182
- } = path;
183
-
184
- if (file.markoOpts.output === "hydrate") {
185
- addDependencies(file, true);
186
- return;
187
- } else if (
188
- file.markoOpts.resolveVirtualDependency &&
189
- file.markoOpts.output !== "html"
190
- ) {
191
- addDependencies(file, false);
192
- }
193
-
194
- if (file.metadata.marko.moduleCode) {
195
- path
196
- .replaceWith(parseScript(file, file.metadata.marko.moduleCode))[0]
197
- .skip();
198
- return;
199
- }
200
-
201
- file._componentDefIdentifier =
202
- path.scope.generateUidIdentifier("componentDef");
203
-
204
- file._componentInstanceIdentifier =
205
- path.scope.generateUidIdentifier("component");
206
-
207
- // Pre-Analyze tree
208
- analyzeStaticVDOM(path);
209
-
210
- // Move non static content into the renderBody.
211
- const [renderBlock] = path.pushContainer("body", t.blockStatement([]));
212
- path
213
- .get("body")
214
- .filter(isRenderContent)
215
- .forEach(childPath => {
216
- renderBlock.pushContainer("body", childPath.node);
217
- childPath.remove();
218
- });
219
-
220
- file._renderBlock = renderBlock;
221
- path.scope.crawl();
222
- },
223
- exit(path) {
224
- const {
225
- hub: { file }
226
- } = path;
227
- const { markoOpts, _inlineComponentClass } = file;
228
- const includeMetaInSource = markoOpts.meta !== false;
229
- const meta = file.metadata.marko;
230
- const { componentFile, componentBrowserFile } = getComponentFiles(path);
231
- const isHTML = markoOpts.output === "html";
232
-
233
- const renderBlock = file._renderBlock;
234
- const componentClass =
235
- (componentFile &&
236
- importDefault(
237
- file,
238
- resolveRelativePath(file, componentFile),
239
- "marko_component"
240
- )) ||
241
- _inlineComponentClass ||
242
- t.objectExpression([]);
243
-
244
- const componentIdentifier =
245
- path.scope.generateUidIdentifier("marko_component");
246
- const componentTypeIdentifier = path.scope.generateUidIdentifier(
247
- "marko_componentType"
248
- );
249
- const templateIdentifier =
250
- path.scope.generateUidIdentifier("marko_template");
251
- const rendererIdentifier = importDefault(
252
- file,
253
- "marko/src/runtime/components/renderer.js",
254
- "marko_renderer"
255
- );
256
- const templateRendererMember = t.memberExpression(
257
- templateIdentifier,
258
- t.identifier("_")
259
- );
260
- const templateMetaMember = t.memberExpression(
261
- templateIdentifier,
262
- t.identifier("meta")
263
- );
264
-
265
- if (markoOpts.writeVersionComment) {
266
- path.addComment(
267
- "leading",
268
- ` Compiled using marko@${version} - DO NOT EDIT`,
269
- true
270
- );
271
- }
272
-
273
- const runtimeTemplateIdentifier = path.scope.generateUidIdentifier("t");
274
-
275
- path.unshiftContainer(
276
- "body",
277
- [
278
- t.importDeclaration(
279
- [t.importSpecifier(runtimeTemplateIdentifier, t.identifier("t"))],
280
- t.stringLiteral(
281
- `marko/${markoOpts.optimize ? "dist" : "src"}/runtime/${
282
- isHTML ? "html" : "vdom"
283
- }/${markoOpts.hot ? "hot-reload.js" : "index.js"}`
284
- )
285
- ),
286
- t.variableDeclaration("const", [
287
- t.variableDeclarator(
288
- componentTypeIdentifier,
289
- t.stringLiteral(meta.id)
290
- ),
291
- t.variableDeclarator(
292
- templateIdentifier,
293
- t.callExpression(runtimeTemplateIdentifier, [
294
- componentTypeIdentifier
295
- ])
296
- )
297
- ]),
298
- includeMetaInSource &&
299
- t.expressionStatement(
300
- t.assignmentExpression(
301
- "=",
302
- t.memberExpression(templateIdentifier, t.identifier("path")),
303
- t.identifier("__filename")
304
- )
305
- ),
306
- t.exportDefaultDeclaration(templateIdentifier)
307
- ].filter(Boolean)
308
- );
309
-
310
- path.pushContainer(
311
- "body",
312
- [
313
- !isHTML &&
314
- t.expressionStatement(
315
- t.callExpression(
316
- importNamed(
317
- file,
318
- "marko/src/runtime/components/registry",
319
- "r",
320
- "marko_registerComponent"
321
- ),
322
- [
323
- componentTypeIdentifier,
324
- t.arrowFunctionExpression(
325
- [],
326
- componentBrowserFile
327
- ? importDefault(
328
- file,
329
- resolveRelativePath(file, componentBrowserFile),
330
- "marko_split_component"
331
- )
332
- : templateIdentifier
333
- )
334
- ]
335
- )
336
- ),
337
- t.variableDeclaration("const", [
338
- t.variableDeclarator(componentIdentifier, componentClass)
339
- ])
340
- ].filter(Boolean)
341
- );
342
-
343
- const templateRenderOptionsProps = [
344
- t.objectProperty(t.identifier("t"), componentTypeIdentifier)
345
- ];
346
-
347
- if (!meta.component) {
348
- templateRenderOptionsProps.push(
349
- t.objectProperty(t.identifier("i"), t.booleanLiteral(true))
350
- );
351
- }
352
-
353
- if (componentBrowserFile) {
354
- templateRenderOptionsProps.push(
355
- t.objectProperty(t.identifier("s"), t.booleanLiteral(true))
356
- );
357
- }
358
-
359
- if (!markoOpts.optimize) {
360
- templateRenderOptionsProps.push(
361
- t.objectProperty(t.identifier("d"), t.booleanLiteral(true))
362
- );
363
- }
364
-
365
- path.pushContainer(
366
- "body",
367
- t.expressionStatement(
368
- t.assignmentExpression(
369
- "=",
370
- templateRendererMember,
371
- t.callExpression(rendererIdentifier, [
372
- t.functionExpression(
373
- null,
374
- [
375
- t.identifier("input"),
376
- t.identifier("out"),
377
- file._componentDefIdentifier,
378
- file._componentInstanceIdentifier,
379
- t.identifier("state")
380
- ],
381
- renderBlock.node
382
- ),
383
- t.objectExpression(templateRenderOptionsProps),
384
- componentIdentifier
385
- ])
386
- )
387
- )
388
- );
389
- renderBlock.remove();
390
-
391
- if (!isHTML) {
392
- path.pushContainer(
393
- "body",
394
- t.expressionStatement(
395
- t.assignmentExpression(
396
- "=",
397
- t.memberExpression(templateIdentifier, t.identifier("Component")),
398
- t.callExpression(
399
- importDefault(
400
- file,
401
- "marko/src/runtime/components/defineComponent.js",
402
- "marko_defineComponent"
403
- ),
404
- [componentIdentifier, templateRendererMember]
405
- )
406
- )
407
- )
408
- );
409
- }
410
-
411
- if (includeMetaInSource) {
412
- const metaObject = t.objectExpression([
413
- t.objectProperty(t.identifier("id"), componentTypeIdentifier)
414
- ]);
415
-
416
- if (meta.component) {
417
- metaObject.properties.push(
418
- t.objectProperty(
419
- t.identifier("component"),
420
- t.stringLiteral(meta.component)
421
- )
422
- );
423
- }
424
-
425
- if (meta.deps.length) {
426
- metaObject.properties.push(
427
- t.objectProperty(
428
- t.identifier("deps"),
429
- parseExpression(file, JSON.stringify(meta.deps), file.code.length)
430
- )
431
- );
432
- }
433
-
434
- if (meta.tags.length) {
435
- metaObject.properties.push(
436
- t.objectProperty(
437
- t.identifier("tags"),
438
- t.arrayExpression(meta.tags.map(tag => t.stringLiteral(tag)))
439
- )
440
- );
441
- }
442
-
443
- path.pushContainer(
444
- "body",
445
- t.expressionStatement(
446
- t.assignmentExpression("=", templateMetaMember, metaObject)
447
- )
448
- );
449
- }
450
-
451
- optimizeHTMLWrites(path);
452
- }
453
- }
454
- };
455
-
456
- export function getRuntimeEntryFiles(output, optimize) {
457
- const base = `marko/${optimize ? "dist" : "src"}/`;
458
-
459
- return [
460
- `${base}runtime/components`,
461
- `${base}runtime/components/defineComponent`,
462
- `${base}runtime/components/renderer`,
463
- `${base}runtime/components/registry`,
464
- `${base}runtime/components/attach-detach`,
465
- `${base}runtime/helpers/assign`,
466
- `${base}runtime/helpers/class-value`,
467
- `${base}runtime/helpers/dynamic-tag`,
468
- `${base}runtime/helpers/load-nested-tag`,
469
- `${base}runtime/helpers/merge`,
470
- `${base}runtime/helpers/render-tag`,
471
- `${base}runtime/helpers/style-value`,
472
- `${base}runtime/helpers/to-string`,
473
- `${base}core-tags/components/preserve-tag`,
474
- `${base}core-tags/components/init-components-tag`,
475
- `${base}core-tags/components/preferred-script-location-tag`,
476
- `${base}core-tags/core/__flush_here_and_after__`,
477
- `${base}core-tags/core/await/renderer`,
478
- `${base}core-tags/core/await/reorderer-renderer`,
479
- ...(output === "html"
480
- ? [
481
- `${base}runtime/html`,
482
- `${base}runtime/html/hot-reload`,
483
- `${base}runtime/html/helpers/attr`,
484
- `${base}runtime/html/helpers/attrs`,
485
- `${base}runtime/html/helpers/class-attr`,
486
- `${base}runtime/html/helpers/data-marko`,
487
- `${base}runtime/html/helpers/escape-quotes`,
488
- `${base}runtime/html/helpers/escape-script-placeholder`,
489
- `${base}runtime/html/helpers/escape-style-placeholder`,
490
- `${base}runtime/html/helpers/escape-xml`,
491
- `${base}runtime/html/helpers/merge-attrs`,
492
- `${base}runtime/html/helpers/props-script`,
493
- `${base}runtime/html/helpers/style-attr`
494
- ]
495
- : [
496
- `${base}runtime/vdom`,
497
- `${base}runtime/vdom/hot-reload`,
498
- `${base}runtime/vdom/helpers/attrs`,
499
- `${base}runtime/vdom/helpers/const`,
500
- `${base}runtime/vdom/helpers/v-element`,
501
- `${base}runtime/vdom/helpers/v-text`,
502
- `${base}runtime/vdom/preserve-attrs`
503
- ])
504
- ];
505
- }
506
-
507
- function isRenderContent(path) {
508
- const { node } = path;
509
- return t.MARKO_TYPES.includes(node.type) && !node.static;
510
- }
511
-
512
- function resolveRelativeTagEntry(file, tagDef) {
513
- // TODO: support transform and other entries.
514
- const entry = tagDef.template || tagDef.renderer;
515
- return entry && resolveRelativePath(file, entry);
516
- }