marko 5.36.4 → 5.37.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.
Files changed (244) hide show
  1. package/dist/compiler/index.js +11 -11
  2. package/dist/core-tags/components/init-components-tag.js +4 -4
  3. package/dist/core-tags/components/preferred-script-location-tag.js +2 -2
  4. package/dist/core-tags/core/__flush_here_and_after__.js +1 -1
  5. package/dist/core-tags/core/await/AsyncValue.js +21 -21
  6. package/dist/core-tags/core/await/renderer.js +24 -24
  7. package/dist/core-tags/core/await/reorderer-renderer.js +6 -6
  8. package/dist/node-require/browser-refresh.js +18 -1
  9. package/dist/node-require/index.js +7 -7
  10. package/dist/node_modules/@internal/components-beginComponent/index-browser.js +5 -5
  11. package/dist/node_modules/@internal/components-beginComponent/index.js +12 -12
  12. package/dist/node_modules/@internal/components-define-widget-legacy/index-browser.js +99 -99
  13. package/dist/node_modules/@internal/components-define-widget-legacy/index.js +3 -3
  14. package/dist/node_modules/@internal/components-endComponent/index.js +3 -3
  15. package/dist/node_modules/@internal/components-entry/index-browser.js +2 -2
  16. package/dist/node_modules/@internal/components-entry/index.js +29 -29
  17. package/dist/node_modules/@internal/components-entry-legacy/index-browser.js +13 -13
  18. package/dist/node_modules/@internal/components-entry-legacy/index.js +1 -1
  19. package/dist/node_modules/@internal/components-registry/index-browser.js +102 -102
  20. package/dist/node_modules/@internal/components-registry/index.js +2 -2
  21. package/dist/node_modules/@internal/components-util/index-browser.js +20 -20
  22. package/dist/node_modules/@internal/components-util/index.js +24 -20
  23. package/dist/node_modules/@internal/create-readable/index-browser.js +1 -1
  24. package/dist/node_modules/@internal/create-readable/index.js +9 -9
  25. package/dist/node_modules/@internal/preserve-tag/index-browser.js +8 -8
  26. package/dist/node_modules/@internal/preserve-tag/index.js +6 -6
  27. package/dist/node_modules/@internal/set-immediate/index-browser.js +2 -2
  28. package/dist/node_modules/@internal/set-immediate/index-worker.js +3 -3
  29. package/dist/node_modules/@internal/set-immediate/index.js +3 -3
  30. package/dist/runtime/RenderResult.js +24 -24
  31. package/dist/runtime/components/Component.js +163 -163
  32. package/dist/runtime/components/ComponentDef.js +34 -34
  33. package/dist/runtime/components/ComponentsContext.js +20 -20
  34. package/dist/runtime/components/GlobalComponentsContext.js +4 -4
  35. package/dist/runtime/components/KeySequence.js +3 -3
  36. package/dist/runtime/components/ServerComponent.js +17 -17
  37. package/dist/runtime/components/State.js +28 -28
  38. package/dist/runtime/components/attach-detach.js +8 -8
  39. package/dist/runtime/components/defineComponent.js +5 -5
  40. package/dist/runtime/components/dom-data.js +6 -6
  41. package/dist/runtime/components/event-delegation.js +10 -10
  42. package/dist/runtime/components/legacy/defineComponent-legacy.js +1 -1
  43. package/dist/runtime/components/legacy/defineRenderer-legacy.js +25 -25
  44. package/dist/runtime/components/legacy/dependencies/index.js +10 -10
  45. package/dist/runtime/components/legacy/renderer-legacy.js +56 -56
  46. package/dist/runtime/components/renderer.js +45 -45
  47. package/dist/runtime/components/update-manager.js +4 -4
  48. package/dist/runtime/createOut.js +1 -1
  49. package/dist/runtime/dom-insert.js +5 -5
  50. package/dist/runtime/helpers/_change-case.js +2 -2
  51. package/dist/runtime/helpers/dynamic-tag.js +33 -33
  52. package/dist/runtime/helpers/render-tag.js +1 -1
  53. package/dist/runtime/helpers/serialize-noop.js +2 -2
  54. package/dist/runtime/helpers/style-value.js +1 -1
  55. package/dist/runtime/helpers/tags-compat/runtime-dom.js +35 -35
  56. package/dist/runtime/helpers/tags-compat/runtime-html.js +16 -16
  57. package/dist/runtime/html/AsyncStream.js +28 -28
  58. package/dist/runtime/html/BufferedWriter.js +2 -2
  59. package/dist/runtime/html/StringWriter.js +2 -2
  60. package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
  61. package/dist/runtime/html/helpers/attr.js +11 -11
  62. package/dist/runtime/html/helpers/attrs.js +6 -6
  63. package/dist/runtime/html/helpers/data-marko.js +6 -6
  64. package/dist/runtime/html/helpers/escape-quotes.js +2 -2
  65. package/dist/runtime/html/helpers/escape-xml.js +1 -1
  66. package/dist/runtime/html/helpers/merge-attrs.js +11 -11
  67. package/dist/runtime/html/helpers/props-script.js +1 -1
  68. package/dist/runtime/html/index.js +2 -2
  69. package/dist/runtime/renderable.js +5 -5
  70. package/dist/runtime/vdom/AsyncVDOMBuilder.js +100 -100
  71. package/dist/runtime/vdom/VComment.js +7 -7
  72. package/dist/runtime/vdom/VComponent.js +5 -5
  73. package/dist/runtime/vdom/VDocumentFragment.js +8 -8
  74. package/dist/runtime/vdom/VElement.js +52 -52
  75. package/dist/runtime/vdom/VFragment.js +9 -9
  76. package/dist/runtime/vdom/VNode.js +34 -34
  77. package/dist/runtime/vdom/VText.js +8 -8
  78. package/dist/runtime/vdom/helpers/attrs.js +6 -6
  79. package/dist/runtime/vdom/helpers/const-element.js +3 -3
  80. package/dist/runtime/vdom/hot-reload.js +20 -20
  81. package/dist/runtime/vdom/index.js +2 -2
  82. package/dist/runtime/vdom/morphdom/fragment.js +10 -10
  83. package/dist/runtime/vdom/morphdom/helpers.js +5 -5
  84. package/dist/runtime/vdom/morphdom/index.js +81 -81
  85. package/dist/runtime/vdom/vdom.js +15 -15
  86. package/dist/taglib/index.js +7 -7
  87. package/dist/translator/cdata/index.js +15 -0
  88. package/dist/translator/cdata/index[html].js +15 -0
  89. package/dist/translator/cdata/index[vdom].js +12 -0
  90. package/dist/translator/class.js +65 -0
  91. package/dist/translator/comment/index.js +15 -0
  92. package/dist/translator/comment/index[html].js +17 -0
  93. package/dist/translator/comment/index[vdom].js +3 -0
  94. package/dist/translator/declaration/index.js +15 -0
  95. package/dist/translator/declaration/index[html].js +12 -0
  96. package/dist/translator/declaration/index[vdom].js +3 -0
  97. package/dist/translator/document-type/index.js +15 -0
  98. package/dist/translator/document-type/index[html].js +12 -0
  99. package/dist/translator/document-type/index[vdom].js +3 -0
  100. package/dist/translator/index.js +551 -0
  101. package/dist/translator/placeholder/index.js +15 -0
  102. package/dist/translator/placeholder/index[html].js +93 -0
  103. package/dist/translator/placeholder/index[vdom].js +22 -0
  104. package/dist/translator/scriptlet.js +4 -0
  105. package/dist/translator/tag/attribute/directives/class.js +42 -0
  106. package/dist/translator/tag/attribute/directives/index.js +15 -0
  107. package/dist/translator/tag/attribute/directives/no-update-body-if.js +15 -0
  108. package/dist/translator/tag/attribute/directives/no-update-body.js +10 -0
  109. package/dist/translator/tag/attribute/directives/no-update-if.js +12 -0
  110. package/dist/translator/tag/attribute/directives/no-update.js +48 -0
  111. package/dist/translator/tag/attribute/directives/style.js +42 -0
  112. package/dist/translator/tag/attribute/index.js +150 -0
  113. package/dist/translator/tag/attribute/modifiers/index.js +7 -0
  114. package/dist/translator/tag/attribute/modifiers/no-update.js +14 -0
  115. package/dist/translator/tag/attribute/modifiers/scoped.js +23 -0
  116. package/dist/translator/tag/attribute-tag.js +149 -0
  117. package/dist/translator/tag/custom-tag.js +146 -0
  118. package/dist/translator/tag/dynamic-tag.js +74 -0
  119. package/dist/translator/tag/index.js +287 -0
  120. package/dist/translator/tag/macro-tag.js +7 -0
  121. package/dist/translator/tag/native-tag.js +27 -0
  122. package/dist/translator/tag/native-tag[html]/attributes.js +151 -0
  123. package/dist/translator/tag/native-tag[html]/index.js +221 -0
  124. package/dist/translator/tag/native-tag[vdom]/attributes.js +105 -0
  125. package/dist/translator/tag/native-tag[vdom]/index.js +189 -0
  126. package/dist/translator/tag/util.js +246 -0
  127. package/dist/translator/taglib/core/conditional/translate-else-if.js +20 -0
  128. package/dist/translator/taglib/core/conditional/translate-else.js +20 -0
  129. package/dist/translator/taglib/core/conditional/translate-if.js +8 -0
  130. package/dist/translator/taglib/core/conditional/util.js +41 -0
  131. package/dist/translator/taglib/core/index.js +474 -0
  132. package/dist/translator/taglib/core/macro/parse.js +17 -0
  133. package/dist/translator/taglib/core/macro/translate.js +48 -0
  134. package/dist/translator/taglib/core/parse-class.js +79 -0
  135. package/dist/translator/taglib/core/parse-export.js +14 -0
  136. package/dist/translator/taglib/core/parse-import.js +14 -0
  137. package/dist/translator/taglib/core/parse-module-code.js +18 -0
  138. package/dist/translator/taglib/core/parse-static.js +18 -0
  139. package/dist/translator/taglib/core/transform-style.js +66 -0
  140. package/dist/translator/taglib/core/translate-await.js +41 -0
  141. package/dist/translator/taglib/core/translate-body.js +17 -0
  142. package/dist/translator/taglib/core/translate-for.js +156 -0
  143. package/dist/translator/taglib/core/translate-html-comment.js +52 -0
  144. package/dist/translator/taglib/core/translate-include-content.js +53 -0
  145. package/dist/translator/taglib/core/translate-server-only.js +5 -0
  146. package/dist/translator/taglib/core/translate-while.js +32 -0
  147. package/dist/translator/taglib/index.js +6 -0
  148. package/dist/translator/taglib/migrate/all-templates.js +46 -0
  149. package/dist/translator/taglib/migrate/index.js +5 -0
  150. package/dist/translator/text/index.js +10 -0
  151. package/dist/translator/text/index[html].js +12 -0
  152. package/dist/translator/text/index[vdom].js +20 -0
  153. package/dist/translator/util/add-dependencies.js +329 -0
  154. package/dist/translator/util/escape-regexp.js +4 -0
  155. package/dist/translator/util/get-component-files.js +86 -0
  156. package/dist/translator/util/html-out-write.js +15 -0
  157. package/dist/translator/util/key-manager.js +176 -0
  158. package/dist/translator/util/optimize-html-writes.js +52 -0
  159. package/dist/translator/util/optimize-vdom-create.js +164 -0
  160. package/dist/translator/util/plugin-hooks.js +22 -0
  161. package/dist/translator/util/runtime-flags.js +3 -0
  162. package/dist/translator/util/vdom-out-write.js +10 -0
  163. package/dist/translator/util/with-previous-location.js +6 -0
  164. package/package.json +7 -4
  165. package/src/taglib/index.js +2 -2
  166. package/src/translator/cdata/index.js +15 -0
  167. package/src/translator/cdata/index[html].js +15 -0
  168. package/src/translator/cdata/index[vdom].js +12 -0
  169. package/src/translator/class.js +65 -0
  170. package/src/translator/comment/index.js +15 -0
  171. package/src/translator/comment/index[html].js +17 -0
  172. package/src/translator/comment/index[vdom].js +3 -0
  173. package/src/translator/declaration/index.js +15 -0
  174. package/src/translator/declaration/index[html].js +12 -0
  175. package/src/translator/declaration/index[vdom].js +3 -0
  176. package/src/translator/document-type/index.js +15 -0
  177. package/src/translator/document-type/index[html].js +12 -0
  178. package/src/translator/document-type/index[vdom].js +3 -0
  179. package/src/translator/index.js +551 -0
  180. package/src/translator/placeholder/index.js +15 -0
  181. package/src/translator/placeholder/index[html].js +93 -0
  182. package/src/translator/placeholder/index[vdom].js +22 -0
  183. package/src/translator/scriptlet.js +4 -0
  184. package/src/translator/tag/attribute/directives/class.js +42 -0
  185. package/src/translator/tag/attribute/directives/index.js +15 -0
  186. package/src/translator/tag/attribute/directives/no-update-body-if.js +15 -0
  187. package/src/translator/tag/attribute/directives/no-update-body.js +10 -0
  188. package/src/translator/tag/attribute/directives/no-update-if.js +12 -0
  189. package/src/translator/tag/attribute/directives/no-update.js +48 -0
  190. package/src/translator/tag/attribute/directives/style.js +42 -0
  191. package/src/translator/tag/attribute/index.js +150 -0
  192. package/src/translator/tag/attribute/modifiers/index.js +7 -0
  193. package/src/translator/tag/attribute/modifiers/no-update.js +14 -0
  194. package/src/translator/tag/attribute/modifiers/scoped.js +23 -0
  195. package/src/translator/tag/attribute-tag.js +149 -0
  196. package/src/translator/tag/custom-tag.js +146 -0
  197. package/src/translator/tag/dynamic-tag.js +74 -0
  198. package/src/translator/tag/index.js +287 -0
  199. package/src/translator/tag/macro-tag.js +7 -0
  200. package/src/translator/tag/native-tag.js +27 -0
  201. package/src/translator/tag/native-tag[html]/attributes.js +151 -0
  202. package/src/translator/tag/native-tag[html]/index.js +221 -0
  203. package/src/translator/tag/native-tag[vdom]/attributes.js +105 -0
  204. package/src/translator/tag/native-tag[vdom]/index.js +189 -0
  205. package/src/translator/tag/util.js +246 -0
  206. package/src/translator/taglib/core/conditional/translate-else-if.js +20 -0
  207. package/src/translator/taglib/core/conditional/translate-else.js +20 -0
  208. package/src/translator/taglib/core/conditional/translate-if.js +8 -0
  209. package/src/translator/taglib/core/conditional/util.js +41 -0
  210. package/src/translator/taglib/core/index.js +474 -0
  211. package/src/translator/taglib/core/macro/parse.js +17 -0
  212. package/src/translator/taglib/core/macro/translate.js +48 -0
  213. package/src/translator/taglib/core/parse-class.js +79 -0
  214. package/src/translator/taglib/core/parse-export.js +14 -0
  215. package/src/translator/taglib/core/parse-import.js +14 -0
  216. package/src/translator/taglib/core/parse-module-code.js +18 -0
  217. package/src/translator/taglib/core/parse-static.js +18 -0
  218. package/src/translator/taglib/core/transform-style.js +66 -0
  219. package/src/translator/taglib/core/translate-await.js +41 -0
  220. package/src/translator/taglib/core/translate-body.js +17 -0
  221. package/src/translator/taglib/core/translate-for.js +156 -0
  222. package/src/translator/taglib/core/translate-html-comment.js +52 -0
  223. package/src/translator/taglib/core/translate-include-content.js +53 -0
  224. package/src/translator/taglib/core/translate-server-only.js +5 -0
  225. package/src/translator/taglib/core/translate-while.js +32 -0
  226. package/src/translator/taglib/index.js +7 -0
  227. package/src/translator/taglib/migrate/all-templates.js +46 -0
  228. package/src/translator/taglib/migrate/index.js +5 -0
  229. package/src/translator/text/index.js +10 -0
  230. package/src/translator/text/index[html].js +12 -0
  231. package/src/translator/text/index[vdom].js +20 -0
  232. package/src/translator/util/add-dependencies.js +329 -0
  233. package/src/translator/util/escape-regexp.js +4 -0
  234. package/src/translator/util/get-component-files.js +86 -0
  235. package/src/translator/util/html-out-write.js +15 -0
  236. package/src/translator/util/key-manager.js +176 -0
  237. package/src/translator/util/optimize-html-writes.js +52 -0
  238. package/src/translator/util/optimize-vdom-create.js +164 -0
  239. package/src/translator/util/plugin-hooks.js +22 -0
  240. package/src/translator/util/runtime-flags.js +3 -0
  241. package/src/translator/util/vdom-out-write.js +10 -0
  242. package/src/translator/util/with-previous-location.js +6 -0
  243. package/translator/index.d.ts +7 -0
  244. package/translator/package.json +5 -0
@@ -0,0 +1,551 @@
1
+ import { types as t } from "@marko/compiler";
2
+ import {
3
+ findParentTag,
4
+ getTagDef,
5
+ importDefault,
6
+ importNamed,
7
+ isAttributeTag,
8
+ isDynamicTag,
9
+ isMacroTag,
10
+ isNativeTag,
11
+ loadFileForTag,
12
+ parseExpression,
13
+ parseStatements,
14
+ resolveRelativePath,
15
+ resolveTagImport,
16
+ } from "@marko/compiler/babel-utils";
17
+ import { version } from "marko/package.json";
18
+ import { resolve } from "path";
19
+
20
+ import MarkoCDATA from "./cdata";
21
+ import MarkoClass from "./class";
22
+ import MarkoComment from "./comment";
23
+ import MarkoDeclaration from "./declaration";
24
+ import MarkoDocumentType from "./document-type";
25
+ import MarkoPlaceholder from "./placeholder";
26
+ import MarkoScriptlet from "./scriptlet";
27
+ import MarkoTag from "./tag";
28
+ import MarkoText from "./text";
29
+ import addDependencies from "./util/add-dependencies";
30
+ import getComponentFiles from "./util/get-component-files";
31
+ import { optimizeHTMLWrites } from "./util/optimize-html-writes";
32
+ import { analyzeStaticVDOM } from "./util/optimize-vdom-create";
33
+
34
+ export { optionalTaglibs, default as taglibs } from "./taglib";
35
+ export { entryBuilder as internalEntryBuilder } from "./util/add-dependencies";
36
+
37
+ export const analyze = {
38
+ Program: {
39
+ enter(program) {
40
+ // Pre populate metadata for component files.
41
+ const meta = program.hub.file.metadata.marko;
42
+ getComponentFiles(program);
43
+
44
+ if (!meta.hasComponent && !meta.hasComponentBrowser) {
45
+ meta.hasComponent = program
46
+ .get("body")
47
+ .some((child) => child.isMarkoClass());
48
+ }
49
+ },
50
+ exit(program) {
51
+ const { file } = program.hub;
52
+ const meta = file.metadata.marko;
53
+ const componentFiles = getComponentFiles(program);
54
+ const { styleFile, packageFile, componentBrowserFile } = componentFiles;
55
+
56
+ if (packageFile) {
57
+ meta.deps.unshift(`package: ${packageFile}`);
58
+ }
59
+
60
+ if (styleFile) {
61
+ meta.deps.unshift(styleFile);
62
+ }
63
+
64
+ if (!meta.widgetBind) {
65
+ if (meta.hasComponentBrowser) {
66
+ meta.component = componentBrowserFile;
67
+ } else if (
68
+ meta.hasComponent ||
69
+ meta.hasStatefulTagParams ||
70
+ meta.hasFunctionEventHandlers
71
+ ) {
72
+ meta.component = file.opts.filename;
73
+ } else if (meta.hasStringEventHandlers) {
74
+ meta.component = componentFiles.componentBrowserFile =
75
+ "marko/src/runtime/helpers/empty-component.js";
76
+ meta.hasComponentBrowser = true;
77
+ }
78
+ }
79
+
80
+ meta.component =
81
+ meta.component && resolveRelativePath(file, meta.component);
82
+ meta.deps = meta.deps.map((filename) =>
83
+ typeof filename === "string"
84
+ ? resolveRelativePath(file, filename)
85
+ : filename,
86
+ );
87
+ },
88
+ },
89
+ MarkoTag(tag) {
90
+ const { file } = tag.hub;
91
+ const tagDef = getTagDef(tag);
92
+ // Check if tag uses stateful tag params.
93
+ const meta = tag.hub.file.metadata.marko;
94
+
95
+ if (tagDef) {
96
+ if (tagDef.html && !tagDef.template && !tagDef.renderer) {
97
+ if (tagDef.htmlType === "custom-element") {
98
+ if (tagDef.parseOptions && tagDef.parseOptions.import) {
99
+ // TODO: the taglib should be updated to support this as a top level option.
100
+ meta.deps.push(
101
+ resolve(
102
+ tagDef.dir,
103
+ resolve(tagDef.dir, tagDef.parseOptions.import),
104
+ ),
105
+ );
106
+ }
107
+ }
108
+ } else if (tag.get("name").isStringLiteral()) {
109
+ const relativePath = resolveRelativeTagEntry(file, tagDef);
110
+
111
+ if (relativePath) {
112
+ tag.node.extra = tag.node.extra || {};
113
+ tag.node.extra.relativePath = relativePath;
114
+
115
+ if (!meta.tags.includes(relativePath)) {
116
+ meta.tags.push(relativePath);
117
+ }
118
+ }
119
+ }
120
+
121
+ if (tagDef.translator && tagDef.translator.path) {
122
+ if (!meta.watchFiles.includes(tagDef.translator.path)) {
123
+ meta.watchFiles.push(tagDef.translator.path);
124
+ }
125
+ }
126
+ }
127
+
128
+ if (!(meta.hasFunctionEventHandlers || meta.hasStringEventHandlers)) {
129
+ for (const attr of tag.node.attributes) {
130
+ if (
131
+ t.isMarkoAttribute(attr) &&
132
+ attr.arguments &&
133
+ /^on[-A-Z]/.test(attr.name)
134
+ ) {
135
+ if (
136
+ attr.arguments.length >= 1 &&
137
+ attr.arguments[0].type === "StringLiteral"
138
+ ) {
139
+ meta.hasStringEventHandlers = true;
140
+ } else {
141
+ meta.hasFunctionEventHandlers = true;
142
+ }
143
+ break;
144
+ }
145
+ }
146
+ }
147
+
148
+ if (
149
+ meta.hasStatefulTagParams ||
150
+ isNativeTag(tag) ||
151
+ isMacroTag(tag) ||
152
+ !tag.get("body").get("params").length
153
+ ) {
154
+ return;
155
+ }
156
+
157
+ if (isDynamicTag(tag)) {
158
+ meta.hasStatefulTagParams = true;
159
+ return;
160
+ }
161
+
162
+ let curTag = tag;
163
+ while (isAttributeTag(curTag)) {
164
+ curTag = findParentTag(curTag);
165
+ }
166
+
167
+ const tagFile = loadFileForTag(curTag);
168
+ const childMeta = tagFile && tagFile.metadata.marko;
169
+ meta.hasStatefulTagParams =
170
+ childMeta &&
171
+ (childMeta.hasStatefulTagParams ||
172
+ childMeta.hasFunctionEventHandlers ||
173
+ (childMeta.hasComponent && !childMeta.hasComponentBrowser));
174
+ },
175
+ ImportDeclaration: {
176
+ exit(path) {
177
+ const source = path.get("source");
178
+ const tagEntry = resolveTagImport(source, source.node.value);
179
+
180
+ if (tagEntry) {
181
+ const meta = path.hub.file.metadata.marko;
182
+ source.node.value = tagEntry;
183
+
184
+ if (!meta.tags.includes(tagEntry)) {
185
+ meta.tags.push(tagEntry);
186
+ }
187
+ }
188
+ },
189
+ },
190
+ };
191
+
192
+ export const translate = {
193
+ MarkoDocumentType,
194
+ MarkoDeclaration,
195
+ MarkoCDATA,
196
+ MarkoTag,
197
+ MarkoText,
198
+ MarkoPlaceholder,
199
+ MarkoScriptlet,
200
+ MarkoClass,
201
+ MarkoComment,
202
+ ReferencedIdentifier(path) {
203
+ if (path.node.name === "component" && !path.scope.hasBinding("component")) {
204
+ path.replaceWith(path.hub.file._componentInstanceIdentifier);
205
+ }
206
+ },
207
+ Program: {
208
+ enter(path) {
209
+ const {
210
+ hub: { file },
211
+ } = path;
212
+
213
+ if (file.markoOpts.output === "hydrate") {
214
+ addDependencies(file, true);
215
+ return;
216
+ } else if (
217
+ file.markoOpts.resolveVirtualDependency &&
218
+ file.markoOpts.output !== "html"
219
+ ) {
220
+ addDependencies(file, false);
221
+ }
222
+
223
+ if (file.metadata.marko.moduleCode) {
224
+ path
225
+ .replaceWith(
226
+ t.program(
227
+ parseStatements(file, file.metadata.marko.moduleCode),
228
+ undefined,
229
+ file.markoOpts.modules === "cjs" ? "script" : "module",
230
+ ),
231
+ )[0]
232
+ .skip();
233
+ return;
234
+ }
235
+
236
+ file._componentDefIdentifier =
237
+ path.scope.generateUidIdentifier("componentDef");
238
+
239
+ file._componentInstanceIdentifier =
240
+ path.scope.generateUidIdentifier("component");
241
+
242
+ // Pre-Analyze tree
243
+ analyzeStaticVDOM(path);
244
+
245
+ // Move non static content into the renderBody.
246
+ const [renderBlock] = path.pushContainer("body", t.blockStatement([]));
247
+ path
248
+ .get("body")
249
+ .filter(isRenderContent)
250
+ .forEach((childPath) => {
251
+ renderBlock.pushContainer("body", childPath.node);
252
+ childPath.remove();
253
+ });
254
+
255
+ file._renderBlock = renderBlock;
256
+ path.scope.crawl();
257
+ },
258
+ exit(path) {
259
+ const {
260
+ hub: { file },
261
+ } = path;
262
+ const { markoOpts, _inlineComponentClass } = file;
263
+ const includeMetaInSource = markoOpts.meta !== false;
264
+ const meta = file.metadata.marko;
265
+ const { componentFile, componentBrowserFile } = getComponentFiles(path);
266
+ const isHTML = markoOpts.output === "html";
267
+
268
+ const renderBlock = file._renderBlock;
269
+ const componentClass =
270
+ (componentFile &&
271
+ importDefault(
272
+ file,
273
+ resolveRelativePath(file, componentFile),
274
+ "marko_component",
275
+ )) ||
276
+ _inlineComponentClass ||
277
+ t.objectExpression([]);
278
+
279
+ const componentIdentifier =
280
+ path.scope.generateUidIdentifier("marko_component");
281
+ const componentTypeIdentifier = path.scope.generateUidIdentifier(
282
+ "marko_componentType",
283
+ );
284
+ const templateIdentifier =
285
+ path.scope.generateUidIdentifier("marko_template");
286
+ const rendererIdentifier = importDefault(
287
+ file,
288
+ "marko/src/runtime/components/renderer.js",
289
+ "marko_renderer",
290
+ );
291
+ const templateRendererMember = t.memberExpression(
292
+ templateIdentifier,
293
+ t.identifier("_"),
294
+ );
295
+ const templateMetaMember = t.memberExpression(
296
+ templateIdentifier,
297
+ t.identifier("meta"),
298
+ );
299
+
300
+ if (markoOpts.writeVersionComment) {
301
+ path.addComment(
302
+ "leading",
303
+ ` Compiled using marko@${version} - DO NOT EDIT`,
304
+ true,
305
+ );
306
+ }
307
+
308
+ const runtimeTemplateIdentifier = path.scope.generateUidIdentifier("t");
309
+
310
+ path.unshiftContainer(
311
+ "body",
312
+ [
313
+ t.importDeclaration(
314
+ [t.importSpecifier(runtimeTemplateIdentifier, t.identifier("t"))],
315
+ t.stringLiteral(
316
+ `marko/${markoOpts.optimize ? "dist" : "src"}/runtime/${
317
+ isHTML ? "html" : "vdom"
318
+ }/${markoOpts.hot ? "hot-reload.js" : "index.js"}`,
319
+ ),
320
+ ),
321
+ t.variableDeclaration("const", [
322
+ t.variableDeclarator(
323
+ componentTypeIdentifier,
324
+ t.stringLiteral(meta.id),
325
+ ),
326
+ t.variableDeclarator(
327
+ templateIdentifier,
328
+ t.callExpression(runtimeTemplateIdentifier, [
329
+ componentTypeIdentifier,
330
+ ]),
331
+ ),
332
+ ]),
333
+ includeMetaInSource &&
334
+ t.expressionStatement(
335
+ t.assignmentExpression(
336
+ "=",
337
+ t.memberExpression(templateIdentifier, t.identifier("path")),
338
+ t.identifier("__filename"),
339
+ ),
340
+ ),
341
+ t.exportDefaultDeclaration(templateIdentifier),
342
+ ].filter(Boolean),
343
+ );
344
+
345
+ path.pushContainer(
346
+ "body",
347
+ [
348
+ !isHTML &&
349
+ t.expressionStatement(
350
+ t.callExpression(
351
+ importNamed(
352
+ file,
353
+ "marko/src/runtime/components/registry.js",
354
+ "r",
355
+ "marko_registerComponent",
356
+ ),
357
+ [
358
+ componentTypeIdentifier,
359
+ t.arrowFunctionExpression(
360
+ [],
361
+ componentBrowserFile
362
+ ? importDefault(
363
+ file,
364
+ resolveRelativePath(file, componentBrowserFile),
365
+ "marko_split_component",
366
+ )
367
+ : templateIdentifier,
368
+ ),
369
+ ],
370
+ ),
371
+ ),
372
+ t.variableDeclaration("const", [
373
+ t.variableDeclarator(componentIdentifier, componentClass),
374
+ ]),
375
+ ].filter(Boolean),
376
+ );
377
+
378
+ const templateRenderOptionsProps = [
379
+ t.objectProperty(t.identifier("t"), componentTypeIdentifier),
380
+ ];
381
+
382
+ if (!meta.component) {
383
+ templateRenderOptionsProps.push(
384
+ t.objectProperty(t.identifier("i"), t.booleanLiteral(true)),
385
+ );
386
+ }
387
+
388
+ if (componentBrowserFile) {
389
+ templateRenderOptionsProps.push(
390
+ t.objectProperty(t.identifier("s"), t.booleanLiteral(true)),
391
+ );
392
+ }
393
+
394
+ if (!markoOpts.optimize) {
395
+ templateRenderOptionsProps.push(
396
+ t.objectProperty(t.identifier("d"), t.booleanLiteral(true)),
397
+ );
398
+ }
399
+
400
+ path.pushContainer(
401
+ "body",
402
+ t.expressionStatement(
403
+ t.assignmentExpression(
404
+ "=",
405
+ templateRendererMember,
406
+ t.callExpression(rendererIdentifier, [
407
+ t.functionExpression(
408
+ null,
409
+ [
410
+ t.identifier("input"),
411
+ t.identifier("out"),
412
+ file._componentDefIdentifier,
413
+ file._componentInstanceIdentifier,
414
+ t.identifier("state"),
415
+ t.identifier("$global"),
416
+ ],
417
+ renderBlock.node,
418
+ ),
419
+ t.objectExpression(templateRenderOptionsProps),
420
+ componentIdentifier,
421
+ ]),
422
+ ),
423
+ ),
424
+ );
425
+ renderBlock.remove();
426
+
427
+ if (!isHTML) {
428
+ path.pushContainer(
429
+ "body",
430
+ t.expressionStatement(
431
+ t.assignmentExpression(
432
+ "=",
433
+ t.memberExpression(templateIdentifier, t.identifier("Component")),
434
+ t.callExpression(
435
+ importDefault(
436
+ file,
437
+ "marko/src/runtime/components/defineComponent.js",
438
+ "marko_defineComponent",
439
+ ),
440
+ [componentIdentifier, templateRendererMember],
441
+ ),
442
+ ),
443
+ ),
444
+ );
445
+ }
446
+
447
+ if (includeMetaInSource) {
448
+ const metaObject = t.objectExpression([
449
+ t.objectProperty(t.identifier("id"), componentTypeIdentifier),
450
+ ]);
451
+
452
+ if (meta.component) {
453
+ metaObject.properties.push(
454
+ t.objectProperty(
455
+ t.identifier("component"),
456
+ t.stringLiteral(meta.component),
457
+ ),
458
+ );
459
+ }
460
+
461
+ if (meta.deps.length) {
462
+ metaObject.properties.push(
463
+ t.objectProperty(
464
+ t.identifier("deps"),
465
+ parseExpression(file, JSON.stringify(meta.deps)),
466
+ ),
467
+ );
468
+ }
469
+
470
+ if (meta.tags.length) {
471
+ metaObject.properties.push(
472
+ t.objectProperty(
473
+ t.identifier("tags"),
474
+ t.arrayExpression(meta.tags.map((tag) => t.stringLiteral(tag))),
475
+ ),
476
+ );
477
+ }
478
+
479
+ path.pushContainer(
480
+ "body",
481
+ t.expressionStatement(
482
+ t.assignmentExpression("=", templateMetaMember, metaObject),
483
+ ),
484
+ );
485
+ }
486
+
487
+ optimizeHTMLWrites(path);
488
+ },
489
+ },
490
+ };
491
+
492
+ export function getRuntimeEntryFiles(output, optimize) {
493
+ const base = `marko/${optimize ? "dist" : "src"}/`;
494
+
495
+ return [
496
+ `${base}runtime/components/index.js`,
497
+ `${base}runtime/components/defineComponent.js`,
498
+ `${base}runtime/components/renderer.js`,
499
+ `${base}runtime/components/registry.js`,
500
+ `${base}runtime/components/attach-detach.js`,
501
+ `${base}runtime/helpers/assign.js`,
502
+ `${base}runtime/helpers/class-value.js`,
503
+ `${base}runtime/helpers/of-fallback.js`,
504
+ `${base}runtime/helpers/dynamic-tag.js`,
505
+ `${base}runtime/helpers/attr-tag.js`,
506
+ `${base}runtime/helpers/merge.js`,
507
+ `${base}runtime/helpers/render-tag.js`,
508
+ `${base}runtime/helpers/style-value.js`,
509
+ `${base}runtime/helpers/to-string.js`,
510
+ `${base}runtime/helpers/empty-component.js`,
511
+ `${base}core-tags/components/preserve-tag.js`,
512
+ ...(output === "html"
513
+ ? [
514
+ `${base}runtime/html/index.js`,
515
+ `${base}runtime/html/hot-reload.js`,
516
+ `${base}runtime/html/helpers/attr.js`,
517
+ `${base}runtime/html/helpers/attrs.js`,
518
+ `${base}runtime/html/helpers/class-attr.js`,
519
+ `${base}runtime/html/helpers/data-marko.js`,
520
+ `${base}runtime/html/helpers/escape-quotes.js`,
521
+ `${base}runtime/html/helpers/escape-script-placeholder.js`,
522
+ `${base}runtime/html/helpers/escape-style-placeholder.js`,
523
+ `${base}runtime/html/helpers/escape-xml.js`,
524
+ `${base}runtime/html/helpers/merge-attrs.js`,
525
+ `${base}runtime/html/helpers/props-script.js`,
526
+ `${base}runtime/html/helpers/style-attr.js`,
527
+ `${base}core-tags/components/init-components-tag.js`,
528
+ `${base}core-tags/components/preferred-script-location-tag.js`,
529
+ `${base}core-tags/core/__flush_here_and_after__.js`,
530
+ `${base}core-tags/core/await/renderer.js`,
531
+ `${base}core-tags/core/await/reorderer-renderer.js`,
532
+ ]
533
+ : [
534
+ `${base}runtime/vdom/index.js`,
535
+ `${base}runtime/vdom/hot-reload.js`,
536
+ `${base}runtime/vdom/helpers/attrs.js`,
537
+ `${base}runtime/vdom/helpers/const-element.js`,
538
+ ]),
539
+ ];
540
+ }
541
+
542
+ function isRenderContent(path) {
543
+ const { node } = path;
544
+ return t.MARKO_TYPES.includes(node.type) && !node.static;
545
+ }
546
+
547
+ function resolveRelativeTagEntry(file, tagDef) {
548
+ // TODO: support transform and other entries.
549
+ const entry = tagDef.template || tagDef.renderer;
550
+ return entry && resolveRelativePath(file, entry);
551
+ }
@@ -0,0 +1,15 @@
1
+ import translateHTML from "./index[html]";
2
+ import translateVDOM from "./index[vdom]";
3
+
4
+ export default function (path) {
5
+ const {
6
+ hub: {
7
+ file: { markoOpts },
8
+ },
9
+ } = path;
10
+ if (markoOpts.output === "html") {
11
+ translateHTML(path);
12
+ } else {
13
+ translateVDOM(path);
14
+ }
15
+ }
@@ -0,0 +1,93 @@
1
+ import { types as t } from "@marko/compiler";
2
+ import {
3
+ computeNode,
4
+ getTagDef,
5
+ importDefault,
6
+ importNamed,
7
+ } from "@marko/compiler/babel-utils";
8
+ import toString from "marko/src/runtime/helpers/to-string";
9
+ import escapeScript from "marko/src/runtime/html/helpers/escape-script-placeholder";
10
+ import escapeStyle from "marko/src/runtime/html/helpers/escape-style-placeholder";
11
+ import { x as escapeXML } from "marko/src/runtime/html/helpers/escape-xml";
12
+
13
+ import write from "../util/html-out-write";
14
+ import withPreviousLocation from "../util/with-previous-location";
15
+
16
+ const ESCAPE_TYPES = {
17
+ html: {
18
+ name: "x",
19
+ module: "marko/src/runtime/html/helpers/escape-xml.js",
20
+ alias: "marko_escapeXml",
21
+ fn: escapeXML,
22
+ },
23
+ script: {
24
+ module: "marko/src/runtime/html/helpers/escape-script-placeholder.js",
25
+ alias: "marko_escapeScript",
26
+ fn: escapeScript,
27
+ },
28
+ style: {
29
+ module: "marko/src/runtime/html/helpers/escape-style-placeholder.js",
30
+ alias: "marko_escapeStyle",
31
+ fn: escapeStyle,
32
+ },
33
+ };
34
+
35
+ export default function (path) {
36
+ const {
37
+ node,
38
+ hub: { file },
39
+ } = path;
40
+ const computed = computeNode(node.value);
41
+ let { escape, value } = node;
42
+
43
+ if (escape) {
44
+ const tagName = findParentTagName(path);
45
+ const escapeType = ESCAPE_TYPES[tagName] || ESCAPE_TYPES.html;
46
+
47
+ value = computed
48
+ ? t.stringLiteral(escapeType.fn(computed.value))
49
+ : t.callExpression(
50
+ escapeType.name
51
+ ? importNamed(
52
+ file,
53
+ escapeType.module,
54
+ escapeType.name,
55
+ escapeType.alias,
56
+ )
57
+ : importDefault(file, escapeType.module, escapeType.alias),
58
+ [value],
59
+ );
60
+ } else {
61
+ value = computed
62
+ ? t.stringLiteral(toString(computed.value))
63
+ : t.callExpression(
64
+ importDefault(
65
+ file,
66
+ "marko/src/runtime/helpers/to-string.js",
67
+ "marko_to_string",
68
+ ),
69
+ [value],
70
+ );
71
+ }
72
+
73
+ const replacement = write`${value}`;
74
+
75
+ if (replacement) {
76
+ path.replaceWith(withPreviousLocation(replacement, node));
77
+ } else {
78
+ path.remove();
79
+ }
80
+ }
81
+
82
+ function findParentTagName(path) {
83
+ while ((path = path.parentPath)) {
84
+ if (path.isProgram()) {
85
+ return;
86
+ }
87
+
88
+ if (path.isMarkoTag()) {
89
+ const tagDef = getTagDef(path);
90
+ return tagDef && tagDef.html && path.get("name.value").node;
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,22 @@
1
+ import { computeNode } from "@marko/compiler/babel-utils";
2
+
3
+ import write from "../util/vdom-out-write";
4
+ import withPreviousLocation from "../util/with-previous-location";
5
+
6
+ export default function (path) {
7
+ const { node } = path;
8
+ const { escape, value } = node;
9
+ const method = escape ? "t" : "h";
10
+ const computed = computeNode(value);
11
+
12
+ if (computed && computed.value == null) {
13
+ path.remove();
14
+ } else {
15
+ path.replaceWith(
16
+ withPreviousLocation(
17
+ write(method, value, path.hub.file._componentInstanceIdentifier),
18
+ node,
19
+ ),
20
+ );
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ export default function (path) {
2
+ const { node } = path;
3
+ path.replaceWithMultiple(node.body);
4
+ }