marko 5.39.49 → 5.39.51

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 (53) hide show
  1. package/dist/runtime/helpers/dynamic-tag.js +11 -4
  2. package/dist/runtime/helpers/load-tag.js +1 -1
  3. package/dist/runtime/helpers/tags-compat/dom-debug.js +1 -1
  4. package/dist/runtime/helpers/tags-compat/dom-debug.mjs +1 -1
  5. package/dist/runtime/helpers/tags-compat/dom.js +1 -1
  6. package/dist/runtime/helpers/tags-compat/dom.mjs +1 -1
  7. package/dist/runtime/helpers/tags-compat/html-debug.js +3 -1
  8. package/dist/runtime/helpers/tags-compat/html-debug.mjs +1 -1
  9. package/dist/runtime/helpers/tags-compat/html.js +3 -1
  10. package/dist/runtime/helpers/tags-compat/html.mjs +1 -1
  11. package/dist/runtime/helpers/tags-compat/runtime-dom.js +50 -51
  12. package/dist/runtime/helpers/tags-compat/runtime-html.js +18 -20
  13. package/dist/runtime/html/AsyncStream.js +10 -10
  14. package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
  15. package/dist/runtime/html/helpers/attr.js +2 -2
  16. package/dist/runtime/html/helpers/escape-xml.js +1 -1
  17. package/dist/runtime/renderable.js +1 -1
  18. package/dist/runtime/vdom/AsyncVDOMBuilder.js +65 -65
  19. package/dist/runtime/vdom/VComment.js +7 -7
  20. package/dist/runtime/vdom/VComponent.js +3 -3
  21. package/dist/runtime/vdom/VDocumentFragment.js +6 -6
  22. package/dist/runtime/vdom/VElement.js +30 -30
  23. package/dist/runtime/vdom/VFragment.js +5 -5
  24. package/dist/runtime/vdom/VNode.js +29 -29
  25. package/dist/runtime/vdom/VText.js +8 -8
  26. package/dist/runtime/vdom/helpers/const-element.js +3 -3
  27. package/dist/runtime/vdom/hot-reload.js +2 -2
  28. package/dist/runtime/vdom/morphdom/fragment.js +3 -3
  29. package/dist/runtime/vdom/morphdom/helpers.js +1 -1
  30. package/dist/runtime/vdom/morphdom/index.js +34 -34
  31. package/dist/runtime/vdom/vdom.js +15 -15
  32. package/dist/translator/index.js +4 -7
  33. package/dist/translator/tag/custom-tag.js +1 -2
  34. package/dist/translator/tag/util.js +5 -2
  35. package/dist/translator/taglib/core/translate-await.js +6 -7
  36. package/dist/translator/util/get-component-files.js +1 -1
  37. package/index.d.ts +3 -8
  38. package/package.json +4 -4
  39. package/src/runtime/helpers/dynamic-tag.js +10 -3
  40. package/src/runtime/helpers/tags-compat/dom-debug.js +1 -1
  41. package/src/runtime/helpers/tags-compat/dom-debug.mjs +1 -1
  42. package/src/runtime/helpers/tags-compat/dom.js +1 -1
  43. package/src/runtime/helpers/tags-compat/dom.mjs +1 -1
  44. package/src/runtime/helpers/tags-compat/html-debug.js +3 -1
  45. package/src/runtime/helpers/tags-compat/html-debug.mjs +1 -1
  46. package/src/runtime/helpers/tags-compat/html.js +3 -1
  47. package/src/runtime/helpers/tags-compat/html.mjs +1 -1
  48. package/src/runtime/helpers/tags-compat/runtime-dom.js +40 -41
  49. package/src/runtime/helpers/tags-compat/runtime-html.js +14 -16
  50. package/src/translator/index.js +4 -7
  51. package/src/translator/tag/custom-tag.js +1 -2
  52. package/src/translator/tag/util.js +5 -2
  53. package/src/translator/taglib/core/translate-await.js +6 -7
@@ -1,4 +1,4 @@
1
- import { compat } from "@marko/runtime-tags/debug/dom";
1
+ import { compat } from "@marko/runtime-tags/debug/dom/compat.feat";
2
2
 
3
3
  import { f, p } from "./runtime-dom.js";
4
4
  p(compat);
@@ -1,3 +1,3 @@
1
1
  const runtimeDom = require("./runtime-dom.js");
2
- runtimeDom.p(require("@marko/runtime-tags/dom").compat);
2
+ runtimeDom.p(require("@marko/runtime-tags/dom/compat.feat").compat);
3
3
  exports.f = runtimeDom.f;
@@ -1,4 +1,4 @@
1
- import { compat } from "@marko/runtime-tags/dom";
1
+ import { compat } from "@marko/runtime-tags/dom/compat.feat";
2
2
 
3
3
  import { f, p } from "./runtime-dom.js";
4
4
  p(compat);
@@ -1,3 +1,5 @@
1
1
  const runtimeHtml = require("./runtime-html.js");
2
- exports.s = runtimeHtml.p(require("@marko/runtime-tags/debug/html").compat);
2
+ exports.s = runtimeHtml.p(
3
+ require("@marko/runtime-tags/debug/html/compat.feat").compat,
4
+ );
3
5
  exports.f = runtimeHtml.f;
@@ -1,4 +1,4 @@
1
- import { compat } from "@marko/runtime-tags/debug/html";
1
+ import { compat } from "@marko/runtime-tags/debug/html/compat.feat";
2
2
 
3
3
  import { f, p } from "./runtime-html.js";
4
4
  export const s = p(compat);
@@ -1,3 +1,5 @@
1
1
  const runtimeHtml = require("./runtime-html.js");
2
- exports.s = runtimeHtml.p(require("@marko/runtime-tags/html").compat);
2
+ exports.s = runtimeHtml.p(
3
+ require("@marko/runtime-tags/html/compat.feat").compat,
4
+ );
3
5
  exports.f = runtimeHtml.f;
@@ -1,4 +1,4 @@
1
- import { compat } from "@marko/runtime-tags/html";
1
+ import { compat } from "@marko/runtime-tags/html/compat.feat";
2
2
 
3
3
  import { f, p } from "./runtime-html.js";
4
4
  export const s = p(compat);
@@ -137,47 +137,44 @@ exports.p = function (domCompat) {
137
137
  }));
138
138
 
139
139
  const rendererCache = new WeakMap();
140
+ const createFragment = () => ___createFragmentNode();
141
+ const createTemplate = domCompat.createTemplate(
142
+ (scope, renderer, input) =>
143
+ renderAndMorph(scope, renderer, undefined, input),
144
+ createFragment,
145
+ );
146
+ const createContent = domCompat.createContent(
147
+ (scope, renderBody, args) =>
148
+ renderAndMorph(scope, undefined, renderBody, args),
149
+ createFragment,
150
+ );
140
151
 
141
- domCompat.patchDynamicTag((dynamicTag) => (...args) => {
142
- const signal = dynamicTag(...args);
143
- return (scope, renderer, getInput) => {
144
- return signal(scope, create5to6Renderer(renderer), getInput);
145
- };
146
- });
147
-
148
- function create5to6Renderer(renderer) {
149
- let newRenderer = renderer;
150
- if (renderer && typeof renderer !== "string") {
151
- if (renderer === noopRenderer) {
152
- return noopRenderer;
153
- }
154
-
155
- const rendererFromAnywhere =
156
- renderer._ ||
157
- renderer.render ||
158
- (renderer.renderer && renderer.renderer.renderer) ||
159
- renderer.renderer;
160
-
161
- if (!domCompat.isRenderer(rendererFromAnywhere || renderer)) {
162
- newRenderer = rendererCache.get(renderer);
163
- if (!newRenderer) {
164
- newRenderer = domCompat.createRenderer(
165
- (scope, input) =>
166
- renderAndMorph(scope, rendererFromAnywhere, renderer, input),
167
- () => ___createFragmentNode(),
168
- );
169
- domCompat.setRendererId(newRenderer, renderer);
170
- rendererCache.set(renderer, newRenderer);
171
- }
152
+ // The Tags runtime hands over what no Tags renderer matches: a Class template becomes a
153
+ // Tags template, and Class content becomes Tags content that morphs in its Class output.
154
+ domCompat.setClassAPIRenderer((value) => {
155
+ if (domCompat.isRenderer(value)) return value;
156
+ let renderer = rendererCache.get(value);
157
+ if (!renderer) {
158
+ const classRenderer = dynamicTag.___getRenderer(value);
159
+ const renderBody = value.renderBody || value;
160
+ if (classRenderer) {
161
+ renderer = createTemplate(value, classRenderer);
162
+ } else if (renderBody === noopRenderer) {
163
+ // Content only the server can render resumes as noop; its markup stays.
164
+ renderer = domCompat.createRenderer(renderBody, createFragment);
165
+ } else if (typeof renderBody === "function") {
166
+ renderer = createContent(renderBody);
172
167
  }
168
+ rendererCache.set(value, renderer);
173
169
  }
174
- return newRenderer;
175
- }
170
+ return renderer;
171
+ });
176
172
 
177
173
  domCompat.init(noopRenderer);
178
174
 
179
175
  function renderAndMorph(scope, renderer, renderBody, input) {
180
- const out = defaultCreateOut(scope.$global);
176
+ const $global = domCompat.getGlobal(scope);
177
+ const out = defaultCreateOut($global);
181
178
  let host = domCompat.getStartNode(scope);
182
179
  let rootNode = host.fragment;
183
180
  if (!rootNode) {
@@ -203,18 +200,19 @@ exports.p = function (domCompat) {
203
200
  domCompat.setScopeNodes(scope, rootNode.startNode, rootNode.endNode);
204
201
  }
205
202
  const existingComponent = scope.___marko5Component;
206
- const componentsContext = ___getComponentsContext(out);
207
- const globalComponentsContext = componentsContext.___globalContext;
208
203
  let customEvents;
209
204
  let normalizedInput;
210
- globalComponentsContext.___rerenderComponent = existingComponent;
205
+ // Cleared so this render gets a context of its own: sharing a Class parent's
206
+ // mid-render context would reset its rerender state for later siblings.
207
+ $global.___components = undefined;
208
+ const componentsContext = ___getComponentsContext(out);
209
+ componentsContext.___globalContext.___rerenderComponent = existingComponent;
211
210
  out.sync();
212
211
  if (renderer) {
213
- const [rawInput] = input;
214
212
  normalizedInput = {};
215
213
 
216
- for (const key in rawInput) {
217
- const value = rawInput[key];
214
+ for (const key in input) {
215
+ const value = input[key];
218
216
  if (/^on[-A-Z]/.test(key) && typeof value === "function") {
219
217
  (customEvents || (customEvents = {}))[toCustomEventName(key)] = [
220
218
  value,
@@ -226,7 +224,8 @@ exports.p = function (domCompat) {
226
224
 
227
225
  renderer(normalizedInput, out);
228
226
  } else {
229
- normalizedInput = input[0];
227
+ // Content a native tag renders has no arguments.
228
+ normalizedInput = input && input[0];
230
229
  RenderBodyComponent({ renderBody, args: input }, out);
231
230
  }
232
231
 
@@ -20,9 +20,7 @@ exports.p = function (htmlCompat) {
20
20
  require("../load-tag").___tagsCompat = htmlCompat;
21
21
  const writersByGlobal = new WeakMap();
22
22
  const boundaryModeByRenderer = new WeakMap();
23
- const isMarko6 = (fn) => typeof fn !== "function" || htmlCompat.isTagsAPI(fn);
24
- const isMarko5 = (fn) =>
25
- typeof fn !== "function" || !htmlCompat.isTagsAPI(fn);
23
+ const isMarko5 = (fn) => !htmlCompat.isRenderer(fn);
26
24
  const writeClassAPIResultToTagsAPI = ({ out }) => {
27
25
  const { writer } = out._state;
28
26
  htmlCompat.write(writer._content);
@@ -184,22 +182,18 @@ exports.p = function (htmlCompat) {
184
182
  {},
185
183
  );
186
184
 
187
- htmlCompat.patchDynamicTag(function getRenderer(tag, scopeId, accessor) {
188
- if (!tag || isMarko6(tag._ || tag.content || tag)) {
189
- return tag;
190
- }
191
-
192
- const renderer5 =
193
- tag._ ||
194
- tag.render ||
195
- (tag.renderer && tag.renderer.renderer) ||
196
- tag.renderer;
185
+ // The Tags runtime hands over what no Tags renderer matches: a Class template or
186
+ // Class content becomes a Tags renderer that writes its Class output in place.
187
+ htmlCompat.setClassAPIRenderer((tag) => {
188
+ if (htmlCompat.isRenderer(tag)) return tag;
189
+ const renderer5 = dynamicTag5.___getRenderer(tag);
197
190
  const renderBody5 = tag.renderBody || tag;
198
191
 
199
- if (!renderer5 && renderBody5) {
192
+ if (!renderer5) {
193
+ if (typeof renderBody5 !== "function") return;
200
194
  htmlCompat.registerRenderBody(renderBody5);
201
195
  }
202
- return (input, ...args) => {
196
+ const render = (input, ...args) => {
203
197
  // tags to class
204
198
  const $global = htmlCompat.$global();
205
199
  htmlCompat.ensureState($global);
@@ -260,9 +254,13 @@ exports.p = function (htmlCompat) {
260
254
 
261
255
  if (async !== false) {
262
256
  async = true;
263
- htmlCompat.fork(scopeId, accessor, out, writeClassAPIResultToTagsAPI);
257
+ htmlCompat.fork(branchId, out, writeClassAPIResultToTagsAPI);
264
258
  }
265
259
  };
260
+ // Keyed by the value, which resumes as itself for a template and as a noop for
261
+ // content, so live content's first client render replaces the server's markup.
262
+ htmlCompat.setRendererId(render, tag);
263
+ return render;
266
264
  });
267
265
 
268
266
  return function register(id, renderer, boundaryMode) {
@@ -130,11 +130,7 @@ export const analyze = {
130
130
  const tagName = tag.node.name.value;
131
131
  const binding =
132
132
  /^[A-Z][a-zA-Z0-9_$]*$/.test(tagName) && tag.scope.getBinding(tagName);
133
- if (
134
- binding &&
135
- binding.path.isImportDefaultSpecifier() &&
136
- binding.identifier.loc
137
- ) {
133
+ if (binding && binding.path.isImportDefaultSpecifier()) {
138
134
  const importSource = binding.path.parent.source.value;
139
135
  relativePath = resolveTagImport(tag, importSource) || importSource;
140
136
  tag.node.extra = tag.node.extra || {};
@@ -168,7 +164,7 @@ export const analyze = {
168
164
  // expression (identifiers, conditionals, etc.) to detect the boundary.
169
165
  const markIfTagsImport = (scope, name) => {
170
166
  const binding = name && scope.getBinding(name);
171
- if (binding && binding.kind === "module" && binding.identifier.loc) {
167
+ if (binding && binding.kind === "module") {
172
168
  const childFile = loadFileForImport(
173
169
  file,
174
170
  binding.path.parent.source.value,
@@ -773,7 +769,8 @@ function getClassHydrationMode(file, visited = new Set()) {
773
769
 
774
770
  visited.add(fileName);
775
771
 
776
- if (meta.component) {
772
+ // A legacy `w-bind` widget can register through a dependency instead of `component`.
773
+ if (meta.component || meta.widgetBind) {
777
774
  return (meta.classHydration = CLASS_HYDRATION_SELF);
778
775
  }
779
776
 
@@ -57,8 +57,7 @@ export default function (path, isNullable) {
57
57
  }
58
58
  }
59
59
 
60
- let binding = !relativePath && path.scope.getBinding(tagName);
61
- if (binding && !binding.identifier.loc) binding = null;
60
+ const binding = !relativePath && path.scope.getBinding(tagName);
62
61
 
63
62
  if (relativePath) {
64
63
  tagIdentifier = node.extra?.tagNameLoad
@@ -25,6 +25,7 @@ export function getAttrs(path, preserveNames, isAttrTag) {
25
25
  const foundProperties = {};
26
26
  const hasAttributeTags = !!attributeTags.length;
27
27
  const isTagsAPI = findRootTag(path)?.node.extra?.featureType === "tags";
28
+ const isTagsAttrTag = isTagsAPI && isAttrTag;
28
29
  const renderBodyKey = isTagsAPI ? "content" : "renderBody";
29
30
 
30
31
  for (let i = 0; i < attrsLen; i++) {
@@ -79,7 +80,9 @@ export function getAttrs(path, preserveNames, isAttrTag) {
79
80
  }
80
81
  }
81
82
 
82
- if (childLen && !hasAttributeTags) {
83
+ // `attr-tag.js` › `i` stores a returned body as `renderBody`, so a Tags
84
+ // attribute tag keeps its body keyed even beside nested attribute tags.
85
+ if (childLen && (!hasAttributeTags || isTagsAttrTag)) {
83
86
  properties.push(
84
87
  t.objectProperty(
85
88
  t.stringLiteral(renderBodyKey),
@@ -126,7 +129,7 @@ export function getAttrs(path, preserveNames, isAttrTag) {
126
129
  if (hasAttributeTags) {
127
130
  let attrTagBody = attributeTags;
128
131
 
129
- if (body.length) {
132
+ if (body.length && !isTagsAttrTag) {
130
133
  attrTagBody = attrTagBody.concat(
131
134
  t.returnStatement(
132
135
  t.arrowFunctionExpression(
@@ -10,14 +10,13 @@ export function enter(path) {
10
10
  'You must provide a promise argument to the "<await>" tag, eg: "<await(promise)>".',
11
11
  );
12
12
  } else if (args.length > 1) {
13
- const {
14
- loc: { start },
15
- } = args[1].node;
16
- const {
17
- loc: { end },
18
- } = args[args.length - 1].node;
13
+ // A built argument has no loc, so the error then marks the tag.
14
+ const first = args[1].node;
15
+ const last = args[args.length - 1].node;
19
16
  throw path.hub.file.buildCodeFrameError(
20
- { loc: { start, end } },
17
+ first.loc && last.loc
18
+ ? { loc: { start: first.loc.start, end: last.loc.end } }
19
+ : path.node,
21
20
  'You can only pass one argument to the "<await>" tag.',
22
21
  );
23
22
  }