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,221 @@
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/compiler/babel-utils");
3
+
4
+
5
+
6
+
7
+ var _path = require("path");
8
+ var _selfClosingTags = _interopRequireDefault(require("self-closing-tags"));
9
+
10
+ var _htmlOutWrite = _interopRequireDefault(require("../../util/html-out-write"));
11
+ var _keyManager = require("../../util/key-manager");
12
+ var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));
13
+ var _attributes = _interopRequireDefault(require("./attributes"));
14
+
15
+ const EMPTY_OBJECT = {};
16
+
17
+ /**
18
+ * Translates the html streaming version of a standard html element.
19
+ */
20
+ function _default(path, isNullable) {
21
+ const {
22
+ hub: { file },
23
+ node
24
+ } = path;
25
+ const {
26
+ key,
27
+ name,
28
+ body: { body },
29
+ handlers
30
+ } = node;
31
+ const tagProperties = path.node.extra && path.node.extra.properties || [];
32
+ const tagDef = (0, _babelUtils.getTagDef)(path);
33
+ const meta = file.metadata.marko;
34
+
35
+ if (tagDef) {
36
+ const { parseOptions = EMPTY_OBJECT } = tagDef;
37
+ if (parseOptions.import) {
38
+ // TODO: the taglib should be updated to support this as a top level option.
39
+ file.metadata.marko.deps.push((0, _path.resolve)(tagDef.dir, parseOptions.import));
40
+ }
41
+ }
42
+
43
+ if (handlers) {
44
+ Object.entries(handlers).forEach(
45
+ ([eventName, { arguments: args, once }]) => {
46
+ const delegateArgs = [_compiler.types.stringLiteral(eventName), args[0]];
47
+
48
+ // TODO: look into only sending this if once is true.
49
+ delegateArgs.push(_compiler.types.booleanLiteral(once));
50
+
51
+ if (args.length > 1) {
52
+ delegateArgs.push(_compiler.types.arrayExpression(args.slice(1)));
53
+ }
54
+
55
+ // TODO: why do we output eventName twice.
56
+ tagProperties.push(
57
+ _compiler.types.objectProperty(
58
+ _compiler.types.stringLiteral(`on${eventName}`),
59
+ _compiler.types.callExpression(
60
+ _compiler.types.memberExpression(
61
+ file._componentDefIdentifier,
62
+ _compiler.types.identifier("d")
63
+ ),
64
+ delegateArgs
65
+ )
66
+ )
67
+ );
68
+ }
69
+ );
70
+ }
71
+
72
+ const isHTML = file.markoOpts.output === "html";
73
+ let dataMarko = _compiler.types.stringLiteral("");
74
+
75
+ if (node.preserveAttrs) {
76
+ tagProperties.push(
77
+ _compiler.types.objectProperty(
78
+ _compiler.types.identifier("pa"),
79
+ _compiler.types.objectExpression(
80
+ node.preserveAttrs.map((name) =>
81
+ _compiler.types.objectProperty(
82
+ _compiler.types.isValidIdentifier(name) ?
83
+ _compiler.types.identifier(name) :
84
+ _compiler.types.stringLiteral(name),
85
+ _compiler.types.numericLiteral(1)
86
+ )
87
+ )
88
+ )
89
+ )
90
+ );
91
+ }
92
+
93
+ if (isHTML) {
94
+ if (
95
+ !meta.hasStatefulTagParams &&
96
+ !meta.hasFunctionEventHandlers && (
97
+ meta.hasComponentBrowser || !meta.hasComponent) ||
98
+ isPreserved(path))
99
+ {
100
+ const dataMarkoArgs = [_compiler.types.identifier("out"), file._componentDefIdentifier];
101
+
102
+ if (tagProperties.length) {
103
+ // TODO we should pre evaluate this if it is static.
104
+ dataMarkoArgs.push(_compiler.types.objectExpression(tagProperties));
105
+ }
106
+
107
+ if ((0, _keyManager.hasUserKey)(path) || key && node.isPreserved) {
108
+ if (dataMarkoArgs.length === 2) {
109
+ dataMarkoArgs.push(_compiler.types.numericLiteral(0));
110
+ }
111
+
112
+ dataMarkoArgs.push(key);
113
+ }
114
+
115
+ if (dataMarkoArgs.length > 2) {
116
+ dataMarko = _compiler.types.callExpression(
117
+ (0, _babelUtils.importDefault)(
118
+ file,
119
+ "marko/src/runtime/html/helpers/data-marko.js",
120
+ "marko_props"
121
+ ),
122
+ dataMarkoArgs
123
+ );
124
+ }
125
+ }
126
+ }
127
+
128
+ const translatedAttrs = (0, _attributes.default)(path, path.get("attributes"));
129
+ let isSelfClosing = false;
130
+ let openTagEnding = ">";
131
+
132
+ if (_compiler.types.isStringLiteral(name)) {
133
+ if (
134
+ tagDef &&
135
+ tagDef.htmlType && (
136
+ tagDef.htmlType === "svg" || tagDef.htmlType === "math"))
137
+ {
138
+ if (!body.length) {
139
+ isSelfClosing = true;
140
+ openTagEnding = " />";
141
+ }
142
+ } else if (_selfClosingTags.default.voidElements.indexOf(name.value) !== -1) {
143
+ isSelfClosing = true;
144
+ }
145
+ }
146
+
147
+ const isEmpty = isSelfClosing || !body.length;
148
+ let writeStartNode = (0, _babelUtils.normalizeTemplateString)`<${name}${dataMarko}${translatedAttrs}${openTagEnding}`;
149
+
150
+ writeStartNode = (0, _withPreviousLocation.default)(
151
+ isEmpty && !isSelfClosing ?
152
+ (0, _htmlOutWrite.default)`${writeStartNode}</${name}>` :
153
+ (0, _htmlOutWrite.default)`${writeStartNode}`,
154
+ name
155
+ );
156
+
157
+ if (isNullable) {
158
+ writeStartNode = _compiler.types.ifStatement(name, writeStartNode);
159
+
160
+ if (!isEmpty) {
161
+ writeStartNode.alternate = _compiler.types.expressionStatement(
162
+ _compiler.types.callExpression(
163
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
164
+ [
165
+ (0, _babelUtils.normalizeTemplateString)`f_${key}`,
166
+ file._componentInstanceIdentifier,
167
+ _compiler.types.numericLiteral(1)]
168
+
169
+ )
170
+ );
171
+ }
172
+ }
173
+
174
+ if (isEmpty) {
175
+ path.replaceWith(writeStartNode);
176
+ return;
177
+ }
178
+
179
+ let needsBlock;
180
+ for (const childNode of body) {
181
+ if (_compiler.types.isVariableDeclaration(childNode)) {
182
+ if (childNode.kind === "const" || childNode.kind === "let") {
183
+ needsBlock = true;
184
+ break;
185
+ }
186
+ }
187
+ }
188
+
189
+ let writeEndNode = (0, _htmlOutWrite.default)`</${name}>`;
190
+
191
+ if (isNullable) {
192
+ writeEndNode = _compiler.types.ifStatement(
193
+ name,
194
+ writeEndNode,
195
+ _compiler.types.expressionStatement(
196
+ _compiler.types.callExpression(
197
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
198
+ []
199
+ )
200
+ )
201
+ );
202
+ }
203
+
204
+ path.replaceWithMultiple(
205
+ [writeStartNode].
206
+ concat(needsBlock ? _compiler.types.blockStatement(body) : body).
207
+ concat(writeEndNode)
208
+ );
209
+ }
210
+
211
+ function isPreserved(path) {
212
+ let parentTag = path;
213
+ do {
214
+ parentTag = parentTag.parentPath.parentPath;
215
+ if (parentTag.get("isPreserved").node === true) {
216
+ return true;
217
+ }
218
+ } while (_compiler.types.isMarkoTag(parentTag));
219
+
220
+ return false;
221
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/compiler/babel-utils");
3
+
4
+ var _util = require("../util");
5
+
6
+ function _default(path, attrs) {
7
+ const len = attrs.length;
8
+ if (len === 0) return _compiler.types.nullLiteral();
9
+ if (len === 1 && attrs[0].node.type === "MarkoSpreadAttribute") {
10
+ return _compiler.types.callExpression(
11
+ (0, _babelUtils.importDefault)(
12
+ path.hub.file,
13
+ "marko/src/runtime/vdom/helpers/attrs.js",
14
+ "marko_attrs"
15
+ ),
16
+ [attrs[0].node.value]
17
+ );
18
+ }
19
+
20
+ if (attrs.some((attr) => attr.node.type === "MarkoSpreadAttribute")) {
21
+ const attrsObjects = [];
22
+ let props;
23
+
24
+ for (let i = 0; i < len; i++) {
25
+ const attr = attrs[i];
26
+ const {
27
+ node: { name, value }
28
+ } = attr;
29
+
30
+ if (name) {
31
+ const computed = (0, _util.evaluateAttr)(attr);
32
+ const prop = _compiler.types.objectProperty(
33
+ _compiler.types.stringLiteral(name),
34
+ computed?.value !== undefined ?
35
+ _compiler.types.stringLiteral(computed.value) :
36
+ value
37
+ );
38
+ if (props) {
39
+ props.push(prop);
40
+ } else {
41
+ attrsObjects.push(_compiler.types.objectExpression(props = [prop]));
42
+ }
43
+ } else {
44
+ attrsObjects.push(value);
45
+ props = undefined;
46
+ }
47
+ }
48
+
49
+ return _compiler.types.callExpression(
50
+ (0, _babelUtils.importDefault)(
51
+ path.hub.file,
52
+ "marko/src/runtime/vdom/helpers/merge-attrs.js",
53
+ "marko_merge_attrs"
54
+ ),
55
+ attrsObjects
56
+ );
57
+ }
58
+
59
+ const attrValues = new Map();
60
+ const props = [];
61
+
62
+ // Remove duplicate attrs so last one wins.
63
+ for (let i = len; i--;) {
64
+ const attr = attrs[i];
65
+ const { name, value } = attr.node;
66
+ if (attrValues.has(name)) continue;
67
+ const computed = (0, _util.evaluateAttr)(attr);
68
+ attrValues.set(
69
+ name,
70
+ computed ?
71
+ {
72
+ confident: true,
73
+ computed: computed.value,
74
+ value
75
+ } :
76
+ {
77
+ confident: false,
78
+ computed: undefined,
79
+ value
80
+ }
81
+ );
82
+ }
83
+
84
+ for (const [name, { confident, computed, value }] of [
85
+ ...attrValues].
86
+ reverse()) {
87
+ if (confident) {
88
+ if (computed == null || computed === false) {
89
+ continue;
90
+ }
91
+
92
+ props.push(
93
+ _compiler.types.objectProperty(_compiler.types.stringLiteral(name), _compiler.types.stringLiteral(computed))
94
+ );
95
+ } else {
96
+ props.push(_compiler.types.objectProperty(_compiler.types.stringLiteral(name), value));
97
+ }
98
+ }
99
+
100
+ if (props.length) {
101
+ return _compiler.types.objectExpression(props);
102
+ }
103
+
104
+ return _compiler.types.nullLiteral();
105
+ }
@@ -0,0 +1,189 @@
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/compiler/babel-utils");
3
+
4
+
5
+
6
+
7
+ var FLAGS = _interopRequireWildcard(require("../../util/runtime-flags"));
8
+ var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
9
+ var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));
10
+ var _attributes = _interopRequireDefault(require("./attributes"));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;}
11
+
12
+ const SIMPLE_ATTRS = ["id", "class", "style"];
13
+
14
+ /**
15
+ * Translates the html streaming version of a standard html element.
16
+ */
17
+ function _default(path, isNullable) {
18
+ const { node } = path;
19
+ const {
20
+ name,
21
+ key,
22
+ body: { body }
23
+ } = node;
24
+
25
+ const isEmpty = !body.length;
26
+ const writeArgs = tagArguments(path, false);
27
+ let writeStartNode = (0, _withPreviousLocation.default)(
28
+ (0, _vdomOutWrite.default)(isEmpty ? "e" : "be", ...writeArgs),
29
+ node.name
30
+ );
31
+
32
+ if (isNullable) {
33
+ writeStartNode = _compiler.types.ifStatement(name, writeStartNode);
34
+
35
+ if (!isEmpty) {
36
+ writeStartNode.alternate = _compiler.types.expressionStatement(
37
+ _compiler.types.callExpression(
38
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
39
+ [
40
+ (0, _babelUtils.normalizeTemplateString)`f_${key}`,
41
+ path.hub.file._componentInstanceIdentifier]
42
+
43
+ )
44
+ );
45
+ }
46
+ }
47
+
48
+ if (isEmpty) {
49
+ path.replaceWith(writeStartNode);
50
+ return;
51
+ }
52
+
53
+ let writeEndNode = (0, _vdomOutWrite.default)("ee");
54
+ if (isNullable) {
55
+ writeEndNode = _compiler.types.ifStatement(
56
+ name,
57
+ writeEndNode,
58
+ _compiler.types.expressionStatement(
59
+ _compiler.types.callExpression(
60
+ _compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
61
+ []
62
+ )
63
+ )
64
+ );
65
+ }
66
+
67
+ let needsBlock;
68
+ for (const childNode of body) {
69
+ if (_compiler.types.isVariableDeclaration(childNode)) {
70
+ if (childNode.kind === "const" || childNode.kind === "let") {
71
+ needsBlock = true;
72
+ break;
73
+ }
74
+ }
75
+ }
76
+
77
+ path.replaceWithMultiple(
78
+ [writeStartNode].
79
+ concat(needsBlock ? _compiler.types.blockStatement(body) : body).
80
+ concat(writeEndNode)
81
+ );
82
+ }
83
+
84
+ function isPropertyName({ key }, names) {
85
+ if (_compiler.types.isStringLiteral(key)) {
86
+ return names.includes(key.value);
87
+ } else if (_compiler.types.isIdentifier(key)) {
88
+ return names.includes(key.name);
89
+ }
90
+ }
91
+
92
+ function tagArguments(path) {
93
+ const {
94
+ hub: { file },
95
+ node
96
+ } = path;
97
+ const {
98
+ name,
99
+ key,
100
+ body: { body },
101
+ handlers
102
+ } = node;
103
+ const tagProperties = path.node.extra && path.node.extra.properties || [];
104
+ const attrsObj = (0, _attributes.default)(path, path.get("attributes"));
105
+ let runtimeFlags = 0;
106
+
107
+ if (!_compiler.types.isNullLiteral(attrsObj) && !_compiler.types.isObjectExpression(attrsObj)) {
108
+ runtimeFlags |= FLAGS.SPREAD_ATTRS;
109
+ }
110
+
111
+ const writeArgs = [
112
+ name,
113
+ attrsObj,
114
+ key,
115
+ file._componentInstanceIdentifier,
116
+ body.length ? _compiler.types.nullLiteral() : _compiler.types.numericLiteral(0)];
117
+
118
+
119
+ if (node.preserveAttrs) {
120
+ tagProperties.push(
121
+ _compiler.types.objectProperty(
122
+ _compiler.types.identifier("pa"),
123
+ _compiler.types.objectExpression(
124
+ node.preserveAttrs.map((name) =>
125
+ _compiler.types.objectProperty(
126
+ _compiler.types.isValidIdentifier(name) ?
127
+ _compiler.types.identifier(name) :
128
+ _compiler.types.stringLiteral(name),
129
+ _compiler.types.numericLiteral(1)
130
+ )
131
+ )
132
+ )
133
+ )
134
+ );
135
+ }
136
+
137
+ if (handlers) {
138
+ Object.entries(handlers).forEach(
139
+ ([eventName, { arguments: args, once }]) => {
140
+ const delegateArgs = [_compiler.types.stringLiteral(eventName), args[0]];
141
+
142
+ // TODO: look into only sending this if once is true.
143
+ delegateArgs.push(_compiler.types.booleanLiteral(once));
144
+
145
+ if (args.length > 1) {
146
+ delegateArgs.push(_compiler.types.arrayExpression(args.slice(1)));
147
+ }
148
+
149
+ // TODO: why do we output eventName twice.
150
+ tagProperties.push(
151
+ _compiler.types.objectProperty(
152
+ _compiler.types.stringLiteral(`on${eventName}`),
153
+ _compiler.types.callExpression(
154
+ _compiler.types.memberExpression(
155
+ file._componentDefIdentifier,
156
+ _compiler.types.identifier("d")
157
+ ),
158
+ delegateArgs
159
+ )
160
+ )
161
+ );
162
+ }
163
+ );
164
+ }
165
+
166
+ if (
167
+ _compiler.types.isObjectExpression(attrsObj) &&
168
+ attrsObj.properties.every((n) => isPropertyName(n, SIMPLE_ATTRS)) &&
169
+ !node.preserveAttrs)
170
+ {
171
+ runtimeFlags |= FLAGS.HAS_SIMPLE_ATTRS;
172
+ }
173
+
174
+ const tagDef = (0, _babelUtils.getTagDef)(path);
175
+
176
+ if (tagDef) {
177
+ const { htmlType } = tagDef;
178
+ if (htmlType === "custom-element") {
179
+ runtimeFlags |= FLAGS.IS_CUSTOM_ELEMENT;
180
+ }
181
+ }
182
+
183
+ writeArgs.push(_compiler.types.numericLiteral(runtimeFlags));
184
+
185
+ if (tagProperties.length) {
186
+ writeArgs.push(_compiler.types.objectExpression(tagProperties));
187
+ }
188
+ return writeArgs;
189
+ }