@marko/translator-default 5.20.7 → 5.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. package/dist/cdata/index.js +1 -2
  2. package/dist/cdata/index[html].js +1 -2
  3. package/dist/cdata/index[vdom].js +1 -2
  4. package/dist/class.js +1 -2
  5. package/dist/comment/index.js +1 -2
  6. package/dist/comment/index[html].js +1 -2
  7. package/dist/comment/index[vdom].js +1 -2
  8. package/dist/declaration/index.js +1 -2
  9. package/dist/declaration/index[html].js +1 -2
  10. package/dist/declaration/index[vdom].js +1 -2
  11. package/dist/document-type/index.js +1 -2
  12. package/dist/document-type/index[html].js +1 -2
  13. package/dist/document-type/index[vdom].js +1 -2
  14. package/dist/index.js +1 -2
  15. package/dist/placeholder/index.js +1 -2
  16. package/dist/placeholder/index[html].js +1 -2
  17. package/dist/placeholder/index[vdom].js +1 -2
  18. package/dist/scriptlet.js +1 -2
  19. package/dist/tag/attribute/directives/class.js +1 -2
  20. package/dist/tag/attribute/directives/index.js +1 -2
  21. package/dist/tag/attribute/directives/no-update-body-if.js +1 -2
  22. package/dist/tag/attribute/directives/no-update-body.js +1 -2
  23. package/dist/tag/attribute/directives/no-update-if.js +1 -2
  24. package/dist/tag/attribute/directives/no-update.js +1 -2
  25. package/dist/tag/attribute/directives/style.js +1 -2
  26. package/dist/tag/attribute/index.js +1 -2
  27. package/dist/tag/attribute/modifiers/index.js +1 -2
  28. package/dist/tag/attribute/modifiers/no-update.js +1 -2
  29. package/dist/tag/attribute/modifiers/scoped.js +1 -2
  30. package/dist/tag/attribute-tag.js +1 -2
  31. package/dist/tag/custom-tag.js +1 -2
  32. package/dist/tag/dynamic-tag.js +1 -2
  33. package/dist/tag/index.js +1 -2
  34. package/dist/tag/macro-tag.js +1 -2
  35. package/dist/tag/native-tag.js +1 -2
  36. package/dist/tag/native-tag[html]/attributes.js +1 -2
  37. package/dist/tag/native-tag[html]/index.js +1 -2
  38. package/dist/tag/native-tag[vdom]/index.js +1 -2
  39. package/dist/tag/util.js +1 -2
  40. package/dist/taglib/core/conditional/translate-else-if.js +1 -2
  41. package/dist/taglib/core/conditional/translate-else.js +1 -2
  42. package/dist/taglib/core/conditional/translate-if.js +1 -2
  43. package/dist/taglib/core/conditional/util.js +1 -2
  44. package/dist/taglib/core/index.js +11 -26
  45. package/dist/taglib/core/macro/parse.js +1 -2
  46. package/dist/taglib/core/macro/translate.js +1 -2
  47. package/dist/taglib/core/parse-class.js +2 -3
  48. package/dist/taglib/core/parse-export.js +1 -2
  49. package/dist/taglib/core/parse-import.js +1 -2
  50. package/dist/taglib/core/parse-module-code.js +1 -2
  51. package/dist/taglib/core/parse-static.js +1 -2
  52. package/dist/taglib/core/parse-style.js +1 -2
  53. package/dist/taglib/core/transform-style.js +1 -2
  54. package/dist/taglib/core/translate-await.js +1 -2
  55. package/dist/taglib/core/translate-body.js +1 -2
  56. package/dist/taglib/core/translate-for.js +1 -2
  57. package/dist/taglib/core/translate-html-comment.js +1 -2
  58. package/dist/taglib/core/translate-include-content.js +1 -2
  59. package/dist/taglib/core/translate-server-only.js +1 -2
  60. package/dist/taglib/core/translate-while.js +1 -2
  61. package/dist/taglib/index.js +1 -2
  62. package/dist/taglib/migrate/all-templates.js +1 -2
  63. package/dist/taglib/migrate/index.js +1 -2
  64. package/dist/text/index.js +1 -2
  65. package/dist/text/index[html].js +1 -2
  66. package/dist/text/index[vdom].js +1 -2
  67. package/dist/util/add-dependencies.js +1 -2
  68. package/dist/util/get-component-files.js +1 -2
  69. package/dist/util/html-out-write.js +1 -2
  70. package/dist/util/key-manager.js +1 -2
  71. package/dist/util/optimize-html-writes.js +1 -2
  72. package/dist/util/optimize-vdom-create.js +1 -2
  73. package/dist/util/plugin-hooks.js +1 -2
  74. package/dist/util/runtime-flags.js +1 -2
  75. package/dist/util/vdom-out-write.js +1 -2
  76. package/dist/util/with-previous-location.js +1 -2
  77. package/package.json +6 -7
  78. package/src/index.js +516 -0
  79. package/LICENSE +0 -21
  80. package/dist/cdata/index.js.map +0 -1
  81. package/dist/cdata/index[html].js.map +0 -1
  82. package/dist/cdata/index[vdom].js.map +0 -1
  83. package/dist/class.js.map +0 -1
  84. package/dist/comment/index.js.map +0 -1
  85. package/dist/comment/index[html].js.map +0 -1
  86. package/dist/comment/index[vdom].js.map +0 -1
  87. package/dist/declaration/index.js.map +0 -1
  88. package/dist/declaration/index[html].js.map +0 -1
  89. package/dist/declaration/index[vdom].js.map +0 -1
  90. package/dist/document-type/index.js.map +0 -1
  91. package/dist/document-type/index[html].js.map +0 -1
  92. package/dist/document-type/index[vdom].js.map +0 -1
  93. package/dist/index.js.map +0 -1
  94. package/dist/placeholder/index.js.map +0 -1
  95. package/dist/placeholder/index[html].js.map +0 -1
  96. package/dist/placeholder/index[vdom].js.map +0 -1
  97. package/dist/scriptlet.js.map +0 -1
  98. package/dist/tag/attribute/directives/class.js.map +0 -1
  99. package/dist/tag/attribute/directives/index.js.map +0 -1
  100. package/dist/tag/attribute/directives/no-update-body-if.js.map +0 -1
  101. package/dist/tag/attribute/directives/no-update-body.js.map +0 -1
  102. package/dist/tag/attribute/directives/no-update-if.js.map +0 -1
  103. package/dist/tag/attribute/directives/no-update.js.map +0 -1
  104. package/dist/tag/attribute/directives/style.js.map +0 -1
  105. package/dist/tag/attribute/index.js.map +0 -1
  106. package/dist/tag/attribute/modifiers/index.js.map +0 -1
  107. package/dist/tag/attribute/modifiers/no-update.js.map +0 -1
  108. package/dist/tag/attribute/modifiers/scoped.js.map +0 -1
  109. package/dist/tag/attribute-tag.js.map +0 -1
  110. package/dist/tag/custom-tag.js.map +0 -1
  111. package/dist/tag/dynamic-tag.js.map +0 -1
  112. package/dist/tag/index.js.map +0 -1
  113. package/dist/tag/macro-tag.js.map +0 -1
  114. package/dist/tag/native-tag.js.map +0 -1
  115. package/dist/tag/native-tag[html]/attributes.js.map +0 -1
  116. package/dist/tag/native-tag[html]/index.js.map +0 -1
  117. package/dist/tag/native-tag[vdom]/index.js.map +0 -1
  118. package/dist/tag/util.js.map +0 -1
  119. package/dist/taglib/core/conditional/translate-else-if.js.map +0 -1
  120. package/dist/taglib/core/conditional/translate-else.js.map +0 -1
  121. package/dist/taglib/core/conditional/translate-if.js.map +0 -1
  122. package/dist/taglib/core/conditional/util.js.map +0 -1
  123. package/dist/taglib/core/index.js.map +0 -1
  124. package/dist/taglib/core/macro/parse.js.map +0 -1
  125. package/dist/taglib/core/macro/translate.js.map +0 -1
  126. package/dist/taglib/core/parse-class.js.map +0 -1
  127. package/dist/taglib/core/parse-export.js.map +0 -1
  128. package/dist/taglib/core/parse-import.js.map +0 -1
  129. package/dist/taglib/core/parse-module-code.js.map +0 -1
  130. package/dist/taglib/core/parse-static.js.map +0 -1
  131. package/dist/taglib/core/parse-style.js.map +0 -1
  132. package/dist/taglib/core/transform-style.js.map +0 -1
  133. package/dist/taglib/core/translate-await.js.map +0 -1
  134. package/dist/taglib/core/translate-body.js.map +0 -1
  135. package/dist/taglib/core/translate-for.js.map +0 -1
  136. package/dist/taglib/core/translate-html-comment.js.map +0 -1
  137. package/dist/taglib/core/translate-include-content.js.map +0 -1
  138. package/dist/taglib/core/translate-server-only.js.map +0 -1
  139. package/dist/taglib/core/translate-while.js.map +0 -1
  140. package/dist/taglib/index.js.map +0 -1
  141. package/dist/taglib/migrate/all-templates.js.map +0 -1
  142. package/dist/taglib/migrate/index.js.map +0 -1
  143. package/dist/text/index.js.map +0 -1
  144. package/dist/text/index[html].js.map +0 -1
  145. package/dist/text/index[vdom].js.map +0 -1
  146. package/dist/util/add-dependencies.js.map +0 -1
  147. package/dist/util/get-component-files.js.map +0 -1
  148. package/dist/util/html-out-write.js.map +0 -1
  149. package/dist/util/key-manager.js.map +0 -1
  150. package/dist/util/optimize-html-writes.js.map +0 -1
  151. package/dist/util/optimize-vdom-create.js.map +0 -1
  152. package/dist/util/plugin-hooks.js.map +0 -1
  153. package/dist/util/runtime-flags.js.map +0 -1
  154. package/dist/util/vdom-out-write.js.map +0 -1
  155. package/dist/util/with-previous-location.js.map +0 -1
@@ -12,5 +12,4 @@ function write(strings, ...expressions) {
12
12
 
13
13
 
14
14
  }
15
- }
16
- //# sourceMappingURL=html-out-write.js.map
15
+ }
@@ -172,5 +172,4 @@ function getUserKey(path) {
172
172
  }
173
173
 
174
174
  return key;
175
- }
176
- //# sourceMappingURL=key-manager.js.map
175
+ }
@@ -49,5 +49,4 @@ function getOutContent(path) {
49
49
  path.get("callee.property.name").node === "w" &&
50
50
  path.get("arguments.0").node);
51
51
 
52
- }
53
- //# sourceMappingURL=optimize-html-writes.js.map
52
+ }
@@ -145,5 +145,4 @@ function analyzeStaticVDOM(path) {
145
145
 
146
146
  function shouldRun(markoOpts) {
147
147
  return markoOpts.optimize && markoOpts.output !== "html";
148
- }
149
- //# sourceMappingURL=optimize-vdom-create.js.map
148
+ }
@@ -19,5 +19,4 @@ function exit(plugin, ...args) {
19
19
  if (typeof fn === "function") {
20
20
  fn(...args);
21
21
  }
22
- }
23
- //# sourceMappingURL=plugin-hooks.js.map
22
+ }
@@ -1,5 +1,4 @@
1
1
  "use strict";exports.__esModule = true;exports.SPREAD_ATTRS = exports.IS_CUSTOM_ELEMENT = exports.HAS_SIMPLE_ATTRS = void 0;const HAS_SIMPLE_ATTRS = 1;exports.HAS_SIMPLE_ATTRS = HAS_SIMPLE_ATTRS;
2
2
  const IS_CUSTOM_ELEMENT = 2; // TODO: impl custom elements.
3
3
  exports.IS_CUSTOM_ELEMENT = IS_CUSTOM_ELEMENT;const SPREAD_ATTRS = 4; // TODO: impl custom elements.
4
- exports.SPREAD_ATTRS = SPREAD_ATTRS;
5
- //# sourceMappingURL=runtime-flags.js.map
4
+ exports.SPREAD_ATTRS = SPREAD_ATTRS;
@@ -7,5 +7,4 @@ function write(method, ...args) {
7
7
  args));
8
8
 
9
9
 
10
- }
11
- //# sourceMappingURL=vdom-out-write.js.map
10
+ }
@@ -3,5 +3,4 @@
3
3
  newNode.loc = originalNode.loc;
4
4
  newNode.end = originalNode.end;
5
5
  return newNode;
6
- }
7
- //# sourceMappingURL=with-previous-location.js.map
6
+ }
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.20.7",
4
+ "version": "5.21.0",
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.20.7",
9
+ "@marko/babel-utils": "^5.21.0",
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.20.7",
16
- "marko": "^5.20.7"
15
+ "@marko/compiler": "^5.21.0",
16
+ "marko": "^5.21.0"
17
17
  },
18
18
  "files": [
19
19
  "dist"
@@ -28,7 +28,7 @@
28
28
  "plugin"
29
29
  ],
30
30
  "license": "MIT",
31
- "main": "dist/index.js",
31
+ "main": "src/index.js",
32
32
  "main:dev": "src/index.js",
33
33
  "main:npm": "dist/index.js",
34
34
  "peerDependencies": {
@@ -41,6 +41,5 @@
41
41
  "repository": {
42
42
  "type": "git",
43
43
  "url": "https://github.com/marko-js/marko/tree/master/packages/translator-default"
44
- },
45
- "gitHead": "e980c3a4d2dc5cc37b75b98f07ef2e7856c892fb"
44
+ }
46
45
  }
package/src/index.js ADDED
@@ -0,0 +1,516 @@
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
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright 2020 eBay Inc. and contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cdata/index.js"],"names":["path","hub","file","markoOpts","output"],"mappings":"uJAAA;AACA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM;AACJC,IAAAA,GAAG,EAAE;AACHC,MAAAA,IAAI,EAAE,EAAEC,SAAF,EADH,EADD;;AAIFH,EAAAA,IAJJ;AAKA,MAAIG,SAAS,CAACC,MAAV,KAAqB,MAAzB,EAAiC;AAC/B,4BAAcJ,IAAd;AACD,GAFD,MAEO;AACL,4BAAcA,IAAd;AACD;AACF","sourcesContent":["import translateHTML from \"./index[html]\";\nimport translateVDOM from \"./index[vdom]\";\n\nexport default function (path) {\n const {\n hub: {\n file: { markoOpts }\n }\n } = path;\n if (markoOpts.output === \"html\") {\n translateHTML(path);\n } else {\n translateVDOM(path);\n }\n}\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cdata/index[html].js"],"names":["path","node","replaceWith","t","stringLiteral","value"],"mappings":"uJAAA;AACA;AACA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM,EAAEC,IAAF,KAAWD,IAAjB;;AAEAA,EAAAA,IAAI,CAACE,WAAL;AACE;AACE,4BAAM,YAAWC,gBAAEC,aAAF,CAAgBH,IAAI,CAACI,KAArB,CAA4B,KAD/C;AAEEJ,EAAAA,IAFF,CADF;;;AAMD","sourcesContent":["import { types as t } from \"@marko/compiler\";\nimport write from \"../util/html-out-write\";\nimport withPreviousLocation from \"../util/with-previous-location\";\n\nexport default function (path) {\n const { node } = path;\n\n path.replaceWith(\n withPreviousLocation(\n write`<![CDATA[${t.stringLiteral(node.value)}]]>`,\n node\n )\n );\n}\n"],"file":"index[html].js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cdata/index[vdom].js"],"names":["path","node","replaceWith","t","stringLiteral","value"],"mappings":"uJAAA;AACA;AACA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM,EAAEC,IAAF,KAAWD,IAAjB;;AAEAA,EAAAA,IAAI,CAACE,WAAL;AACE,qCAAqB,2BAAM,GAAN,EAAWC,gBAAEC,aAAF,CAAgBH,IAAI,CAACI,KAArB,CAAX,CAArB,EAA8DJ,IAA9D,CADF;;AAGD","sourcesContent":["import { types as t } from \"@marko/compiler\";\nimport write from \"../util/vdom-out-write\";\nimport withPreviousLocation from \"../util/with-previous-location\";\n\nexport default function (path) {\n const { node } = path;\n\n path.replaceWith(\n withPreviousLocation(write(\"t\", t.stringLiteral(node.value)), node)\n );\n}\n"],"file":"index[vdom].js"}
package/dist/class.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/class.js"],"names":["path","hub","file","node","body","classProperties","onCreateMethod","find","prop","computed","t","isIdentifier","key","name","objectProperties","map","isClassMethod","type","start","end","loc","isClassProperty","static","push","assignmentExpression","memberExpression","thisExpression","value","undefined","buildCodeFrameError","filter","Boolean","length","objectMethod","identifier","blockStatement","unshift","_inlineComponentClass","objectExpression","remove"],"mappings":"kEAAA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM;AACJC,IAAAA,GAAG,EAAE,EAAEC,IAAF,EADD;AAEJC,IAAAA,IAAI,EAAE;AACJC,MAAAA,IAAI,EAAE,EAAEA,IAAF,EADF,EAFF;;AAKFJ,EAAAA,IALJ;;AAOA,QAAMK,eAAe,GAAG,EAAxB;AACA,MAAIC,cAAc,GAAGF,IAAI,CAACG,IAAL;AACnB,GAAAC,IAAI;AACFA,EAAAA,IAAI,CAACC,QAAL,KAAkB,KAAlB;AACAC,kBAAEC,YAAF,CAAeH,IAAI,CAACI,GAApB,CADA;AAEAJ,EAAAA,IAAI,CAACI,GAAL,CAASC,IAAT,KAAkB,UAJD,CAArB;;;AAOA,QAAMC,gBAAgB,GAAGV,IAAI;AAC1BW,EAAAA,GADsB,CAClB,CAAAP,IAAI,KAAI;AACX,QAAIE,gBAAEM,aAAF,CAAgBR,IAAhB,CAAJ,EAA2B;AACzBA,MAAAA,IAAI,CAACS,IAAL,GAAY,cAAZ;AACA,aAAOT,IAAI,CAACU,KAAZ;AACA,aAAOV,IAAI,CAACW,GAAZ;AACA,aAAOX,IAAI,CAACY,GAAZ;AACA,aAAOZ,IAAP;AACD,KAND,MAMO,IAAIE,gBAAEW,eAAF,CAAkBb,IAAlB,KAA2B,CAACA,IAAI,CAACc,MAArC,EAA6C;AAClDjB,MAAAA,eAAe,CAACkB,IAAhB;AACEb,sBAAEc,oBAAF;AACE,SADF;AAEEd,sBAAEe,gBAAF,CAAmBf,gBAAEgB,cAAF,EAAnB,EAAuClB,IAAI,CAACI,GAA5C,EAAiDJ,IAAI,CAACC,QAAtD,CAFF;AAGED,MAAAA,IAAI,CAACmB,KAHP,CADF;;;;AAQA,aAAOC,SAAP;AACD;;AAED,UAAM1B,IAAI,CAAC2B,mBAAL;AACJrB,IAAAA,IADI;AAEJ,8CAFI,CAAN;;AAID,GAxBsB;AAyBtBsB,EAAAA,MAzBsB,CAyBfC,OAzBe,CAAzB;;AA2BA,MAAI1B,eAAe,CAAC2B,MAApB,EAA4B;AAC1B,QAAI,CAAC1B,cAAL,EAAqB;AACnBQ,MAAAA,gBAAgB,CAACS,IAAjB;AACGjB,MAAAA,cAAc,GAAGI,gBAAEuB,YAAF;AAChB,cADgB;AAEhBvB,sBAAEwB,UAAF,CAAa,UAAb,CAFgB;AAGhB,QAHgB;AAIhBxB,sBAAEyB,cAAF,CAAiB,EAAjB,CAJgB,CADpB;;;AAQD;;AAED7B,IAAAA,cAAc,CAACF,IAAf,CAAoBA,IAApB,CAAyBgC,OAAzB,CAAiC,GAAG/B,eAApC;AACD;;AAEDH,EAAAA,IAAI,CAACmC,qBAAL,GAA6B3B,gBAAE4B,gBAAF,CAAmBxB,gBAAnB,CAA7B;AACAd,EAAAA,IAAI,CAACuC,MAAL;AACD","sourcesContent":["import { types as t } from \"@marko/compiler\";\n\nexport default function (path) {\n const {\n hub: { file },\n node: {\n body: { body }\n }\n } = path;\n\n const classProperties = [];\n let onCreateMethod = body.find(\n prop =>\n prop.computed === false &&\n t.isIdentifier(prop.key) &&\n prop.key.name === \"onCreate\"\n );\n\n const objectProperties = body\n .map(prop => {\n if (t.isClassMethod(prop)) {\n prop.type = \"ObjectMethod\";\n delete prop.start;\n delete prop.end;\n delete prop.loc;\n return prop;\n } else if (t.isClassProperty(prop) && !prop.static) {\n classProperties.push(\n t.assignmentExpression(\n \"=\",\n t.memberExpression(t.thisExpression(), prop.key, prop.computed),\n prop.value\n )\n );\n\n return undefined;\n }\n\n throw file.buildCodeFrameError(\n prop,\n \"Unsupported class property on component.\"\n );\n })\n .filter(Boolean);\n\n if (classProperties.length) {\n if (!onCreateMethod) {\n objectProperties.push(\n (onCreateMethod = t.objectMethod(\n \"method\",\n t.identifier(\"onCreate\"),\n [],\n t.blockStatement([])\n ))\n );\n }\n\n onCreateMethod.body.body.unshift(...classProperties);\n }\n\n file._inlineComponentClass = t.objectExpression(objectProperties);\n path.remove();\n}\n"],"file":"class.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/comment/index.js"],"names":["path","hub","file","markoOpts","output"],"mappings":"uJAAA;AACA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM;AACJC,IAAAA,GAAG,EAAE;AACHC,MAAAA,IAAI,EAAE,EAAEC,SAAF,EADH,EADD;;AAIFH,EAAAA,IAJJ;AAKA,MAAIG,SAAS,CAACC,MAAV,KAAqB,MAAzB,EAAiC;AAC/B,4BAAcJ,IAAd;AACD,GAFD,MAEO;AACL,4BAAcA,IAAd;AACD;AACF","sourcesContent":["import translateHTML from \"./index[html]\";\nimport translateVDOM from \"./index[vdom]\";\n\nexport default function (path) {\n const {\n hub: {\n file: { markoOpts }\n }\n } = path;\n if (markoOpts.output === \"html\") {\n translateHTML(path);\n } else {\n translateVDOM(path);\n }\n}\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/comment/index[html].js"],"names":["ieConditionalCommentRegExp","path","node","test","value","replaceWith","t","stringLiteral","remove"],"mappings":"uJAAA;AACA;AACA;AACA,MAAMA,0BAA0B,GAAG,qBAAnC;;AAEe,kBAAUC,IAAV,EAAgB;AAC7B,QAAM,EAAEC,IAAF,KAAWD,IAAjB;;AAEA,MAAID,0BAA0B,CAACG,IAA3B,CAAgCD,IAAI,CAACE,KAArC,CAAJ,EAAiD;AAC/CH,IAAAA,IAAI,CAACI,WAAL;AACE,uCAAqB,0BAAM,OAAMC,gBAAEC,aAAF,CAAgBL,IAAI,CAACE,KAArB,CAA4B,KAA7D,EAAmEF,IAAnE,CADF;;AAGD,GAJD,MAIO;AACLD,IAAAA,IAAI,CAACO,MAAL;AACD;AACF","sourcesContent":["import { types as t } from \"@marko/compiler\";\nimport write from \"../util/html-out-write\";\nimport withPreviousLocation from \"../util/with-previous-location\";\nconst ieConditionalCommentRegExp = /^\\[if |<!\\[endif\\]$/;\n\nexport default function (path) {\n const { node } = path;\n\n if (ieConditionalCommentRegExp.test(node.value)) {\n path.replaceWith(\n withPreviousLocation(write`<!--${t.stringLiteral(node.value)}-->`, node)\n );\n } else {\n path.remove();\n }\n}\n"],"file":"index[html].js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/comment/index[vdom].js"],"names":["path","remove"],"mappings":"kEAAe,kBAAUA,IAAV,EAAgB;AAC7BA,EAAAA,IAAI,CAACC,MAAL;AACD","sourcesContent":["export default function (path) {\n path.remove();\n}\n"],"file":"index[vdom].js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/declaration/index.js"],"names":["path","hub","file","markoOpts","output"],"mappings":"uJAAA;AACA;;AAEe,kBAAUA,IAAV,EAAgB;AAC7B,QAAM;AACJC,IAAAA,GAAG,EAAE;AACHC,MAAAA,IAAI,EAAE,EAAEC,SAAF,EADH,EADD;;AAIFH,EAAAA,IAJJ;AAKA,MAAIG,SAAS,CAACC,MAAV,KAAqB,MAAzB,EAAiC;AAC/B,4BAAcJ,IAAd;AACD,GAFD,MAEO;AACL,4BAAcA,IAAd;AACD;AACF","sourcesContent":["import translateHTML from \"./index[html]\";\nimport translateVDOM from \"./index[vdom]\";\n\nexport default function (path) {\n const {\n hub: {\n file: { markoOpts }\n }\n } = path;\n if (markoOpts.output === \"html\") {\n translateHTML(path);\n } else {\n translateVDOM(path);\n }\n}\n"],"file":"index.js"}