marko 5.39.51 → 5.40.1

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 (34) hide show
  1. package/dist/compiler/index.js +0 -2
  2. package/dist/core-tags/core/await/index.d.marko +17 -0
  3. package/dist/core-tags/core/script.d.marko +6 -1
  4. package/dist/runtime/vdom/VElement.js +10 -29
  5. package/dist/runtime/vdom/morphdom/index.js +0 -1
  6. package/dist/taglib/index.js +3 -6
  7. package/dist/translator/index.js +6 -17
  8. package/dist/translator/tag/attribute/index.js +0 -16
  9. package/dist/translator/tag/attribute-tag.js +4 -11
  10. package/dist/translator/tag/native-tag[html]/index.js +1 -13
  11. package/dist/translator/tag/native-tag[vdom]/index.js +0 -12
  12. package/dist/translator/tag/util.js +64 -53
  13. package/dist/translator/taglib/core/index.js +17 -366
  14. package/dist/translator/util/runtime-flags.js +2 -3
  15. package/dist/translator.js +4 -2
  16. package/docs/marko-json.md +3 -6
  17. package/package.json +4 -4
  18. package/src/compiler/index.js +0 -2
  19. package/src/core-tags/core/await/index.d.marko +17 -0
  20. package/src/core-tags/core/script.d.marko +6 -1
  21. package/src/runtime/vdom/VElement.js +10 -29
  22. package/src/runtime/vdom/morphdom/index.js +0 -1
  23. package/src/taglib/index.js +3 -6
  24. package/src/translator/index.js +4 -15
  25. package/src/translator/tag/attribute/index.js +1 -17
  26. package/src/translator/tag/attribute-tag.js +4 -11
  27. package/src/translator/tag/native-tag[html]/index.js +0 -12
  28. package/src/translator/tag/native-tag[vdom]/index.js +1 -13
  29. package/src/translator/tag/util.js +64 -53
  30. package/src/translator/taglib/core/index.js +0 -349
  31. package/src/translator/util/runtime-flags.js +1 -2
  32. package/src/translator.js +2 -0
  33. package/tags-html.d.ts +65 -65
  34. package/translator/index.d.ts +1 -0
@@ -147,8 +147,6 @@ exports.compileFileForBrowser = compileFileForBrowser;
147
147
  exports.configure = configure;
148
148
 
149
149
  exports.taglibLookup = taglib.lookup;
150
- exports.taglibLoader = taglib.loader;
151
- exports.taglibFinder = taglib.finder;
152
150
  exports.buildTaglibLookup = taglib.lookup.buildLookup;
153
151
  exports.clearCaches = function clearCaches() {
154
152
  compiler._clearDefaults();
@@ -1,11 +1,28 @@
1
+ /**
2
+ * Renders asynchronously with the result of the promise in its argument:
3
+ * `@then` with the value it resolves to, `@catch` with the error it rejects
4
+ * with, and `@placeholder` while it is pending.
5
+ *
6
+ * [Marko 5 docs](https://v5.markojs.com/docs/core-tags/#await)
7
+ */
1
8
  export type Input<T> = {
2
9
  value: readonly [T];
10
+ /** Rendered with the value the promise resolves to. */
3
11
  then?: Marko.AttrTag<{ renderBody: Marko.Body<[Awaited<T>]> }>;
12
+ /** Rendered with the error the promise rejects with. */
4
13
  catch?: Marko.AttrTag<{ renderBody: Marko.Body<[unknown]> }>;
14
+ /** Displayed while the promise is pending. */
5
15
  placeholder?: Marko.AttrTag<{ renderBody: Marko.Body }>;
16
+ /**
17
+ * Sends the content after this tag without waiting for the promise, and
18
+ * moves this tag's content into place in the browser once it settles.
19
+ */
6
20
  "client-reorder"?: boolean;
21
+ /** Names this tag for debugging and for another tag's `show-after`. */
7
22
  name?: string;
23
+ /** Rejects with a `TimeoutError` after this many milliseconds (10,000 by default). */
8
24
  timeout?: number;
25
+ /** With `client-reorder`, keeps this tag after the `<await>` with this name. */
9
26
  "show-after"?: string;
10
27
  } | {
11
28
  value: T;
@@ -1,5 +1,10 @@
1
- /** File for types only, not actual implementation **/
1
+ /* File for types only, not actual implementation */
2
2
 
3
+ /**
4
+ * A native `<script>` element.
5
+ *
6
+ * [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/script)
7
+ */
3
8
  export interface Input extends Marko.HTML.Script {
4
9
  value?(): unknown;
5
10
  }
@@ -8,7 +8,6 @@ var VNode = require("./VNode");
8
8
  var isTextOnly = require("./is-text-only");
9
9
  var ATTR_XLINK_HREF = "xlink:href";
10
10
  var xmlnsRegExp = /^xmlns(:|$)/;
11
- var hasOwnProperty = Object.prototype.hasOwnProperty;
12
11
  var NS_XLINK = "http://www.w3.org/1999/xlink";
13
12
  var NS_HTML = "http://www.w3.org/1999/xhtml";
14
13
  var NS_MATH = "http://www.w3.org/1998/Math/MathML";
@@ -19,7 +18,6 @@ var DEFAULT_NS = {
19
18
  };
20
19
 
21
20
  var FLAG_SIMPLE_ATTRS = 1;
22
- var FLAG_CUSTOM_ELEMENT = 2;
23
21
  var FLAG_SPREAD_ATTRS = 4;
24
22
 
25
23
  var ATTR_HREF = "href";
@@ -72,14 +70,6 @@ function normalizeValue(value) {
72
70
  return value + "";
73
71
  }
74
72
 
75
- function assign(a, b) {
76
- for (var key in b) {
77
- if (hasOwnProperty.call(b, key)) {
78
- a[key] = b[key];
79
- }
80
- }
81
- }
82
-
83
73
  function VElementClone(other) {
84
74
  this.ck_ = other.ck_;
85
75
  this.ch_ = null;
@@ -174,30 +164,25 @@ VElement.prototype = {
174
164
  var attributes = this.cl_;
175
165
  var namespaceURI = DEFAULT_NS[tagName] || parentNamespaceURI || NS_HTML;
176
166
 
177
- var flags = this.u_;
178
167
  var el = (host.ownerDocument || host).createElementNS(
179
168
  namespaceURI,
180
169
  tagName
181
170
  );
182
171
 
183
- if (flags & FLAG_CUSTOM_ELEMENT) {
184
- assign(el, attributes);
185
- } else {
186
- for (var attrName in attributes) {
187
- var attrValue = normalizeValue(attributes[attrName]);
172
+ for (var attrName in attributes) {
173
+ var attrValue = normalizeValue(attributes[attrName]);
188
174
 
189
- if (attrValue !== undefined) {
190
- if (attrName == ATTR_XLINK_HREF) {
191
- el.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
192
- } else {
193
- el.setAttribute(attrName, attrValue);
194
- }
175
+ if (attrValue !== undefined) {
176
+ if (attrName == ATTR_XLINK_HREF) {
177
+ el.setAttributeNS(NS_XLINK, ATTR_HREF, attrValue);
178
+ } else {
179
+ el.setAttribute(attrName, attrValue);
195
180
  }
196
181
  }
182
+ }
197
183
 
198
- if (isTextOnly(tagName)) {
199
- el.textContent = this.cn_;
200
- }
184
+ if (isTextOnly(tagName)) {
185
+ el.textContent = this.cn_;
201
186
  }
202
187
 
203
188
  vElementByDOMNode.set(el, this);
@@ -266,10 +251,6 @@ VElement.cr_ = function (fromEl, vFromEl, toEl) {
266
251
  var toFlags = toEl.u_;
267
252
  var attrs = toEl.cl_;
268
253
 
269
- if (toFlags & FLAG_CUSTOM_ELEMENT) {
270
- return assign(fromEl, attrs);
271
- }
272
-
273
254
  var props = toEl._R_;
274
255
  var attrName;
275
256
 
@@ -35,7 +35,6 @@ var FRAGMENT_NODE = 12;
35
35
  var DOCTYPE_NODE = 10;
36
36
 
37
37
  // var FLAG_SIMPLE_ATTRS = 1;
38
- // var FLAG_CUSTOM_ELEMENT = 2;
39
38
  // var FLAG_SPREAD_ATTRS = 4;
40
39
 
41
40
  function isAutoKey(key) {
@@ -3,6 +3,7 @@
3
3
  // eslint-disable-next-line no-constant-binary-expression
4
4
 
5
5
  const compiler = require("@marko/compiler");
6
+ const path = require("path");
6
7
 
7
8
  function clearCache() {
8
9
  compiler.taglib.clearCaches();
@@ -12,11 +13,9 @@ function register(taglibProps, taglibPath) {
12
13
  return compiler.taglib.register(taglibPath, taglibProps);
13
14
  }
14
15
 
16
+ // A path relative to the working directory, as it was read before.
15
17
  function registerFromFile(taglibPath) {
16
- return register(
17
- compiler.taglib._loader.loadTaglibFromFile(taglibPath),
18
- taglibPath
19
- );
18
+ return register(undefined, path.resolve(taglibPath));
20
19
  }
21
20
 
22
21
  exports.clearCache = clearCache;
@@ -25,8 +24,6 @@ exports.registerFromFile = registerFromFile;
25
24
  exports.buildLookup = compiler.taglib.buildLookup;
26
25
  exports.excludeDir = compiler.taglib.excludeDir;
27
26
  exports.excludePackage = compiler.taglib.excludePackage;
28
- exports.loader = compiler.taglib._loader;
29
- exports.finder = compiler.taglib._finder;
30
27
  exports.lookup = {
31
28
  buildLookup: function (dir, translator) {
32
29
  if (!translator || !Array.isArray(translator.taglibs)) {
@@ -1,6 +1,4 @@
1
- "use strict";exports.__esModule = true;exports.analyze = void 0;exports.getRuntimeEntryFiles = getRuntimeEntryFiles;exports.version = exports.translate = exports.taglibs = exports.tagDiscoveryDirs = exports.preferAPI = exports.optionalTaglibs = exports.internalEntryBuilder = void 0;var _path = require("path");
2
-
3
- var _compiler = require("@marko/compiler");
1
+ "use strict";exports.__esModule = true;exports.classTaglibs = exports.analyze = void 0;exports.getRuntimeEntryFiles = getRuntimeEntryFiles;exports.version = exports.translate = exports.taglibs = exports.tagDiscoveryDirs = exports.preferAPI = exports.optionalTaglibs = exports.internalEntryBuilder = void 0;var _compiler = require("@marko/compiler");
4
2
  var _babelUtils = require("@marko/compiler/babel-utils");
5
3
 
6
4
 
@@ -39,9 +37,12 @@ var _optimizeVdomCreate = require("./util/optimize-vdom-create");
39
37
 
40
38
 
41
39
 
42
- var _taglib = _interopRequireWildcard(require("./taglib"));exports.optionalTaglibs = _taglib.optionalTaglibs;exports.taglibs = _taglib.default;function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}const CLASS_HYDRATION_SELF = "self";const CLASS_HYDRATION_DESCENDANT = "descendant";const version = exports.version = _package.default.version;const tagDiscoveryDirs = exports.tagDiscoveryDirs = ["components"];
43
40
 
44
41
 
42
+
43
+ var _taglib = _interopRequireWildcard(require("./taglib"));exports.optionalTaglibs = _taglib.optionalTaglibs;exports.taglibs = _taglib.default;function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}const CLASS_HYDRATION_SELF = "self";const CLASS_HYDRATION_DESCENDANT = "descendant";const version = exports.version = _package.default.version;const tagDiscoveryDirs = exports.tagDiscoveryDirs = ["components"]; // Its taglibs declare attributes, nested tags and renderers, and its tag folders
44
+ // take renderers, hook files and older template names.
45
+ const classTaglibs = exports.classTaglibs = true;
45
46
  const preferAPI = exports.preferAPI = "class";
46
47
  const analyze = exports.analyze = {
47
48
  Program: {
@@ -105,19 +106,7 @@ const analyze = exports.analyze = {
105
106
  let relativePath;
106
107
 
107
108
  if (tagDef) {
108
- if (tagDef.html && !tagDef.template && !tagDef.renderer) {
109
- if (tagDef.htmlType === "custom-element") {
110
- if (tagDef.parseOptions && tagDef.parseOptions.import) {
111
- // TODO: the taglib should be updated to support this as a top level option.
112
- meta.deps.push(
113
- (0, _path.resolve)(
114
- tagDef.dir,
115
- (0, _path.resolve)(tagDef.dir, tagDef.parseOptions.import)
116
- )
117
- );
118
- }
119
- }
120
- } else if (_compiler.types.isStringLiteral(tag.node.name)) {
109
+ if (!(0, _babelUtils.isNativeTag)(tag)) {
121
110
  relativePath = resolveRelativeTagEntry(file, tagDef);
122
111
  }
123
112
 
@@ -1,9 +1,5 @@
1
1
  "use strict";exports.__esModule = true;exports.default = void 0;var _babelUtils = require("@marko/compiler/babel-utils");
2
2
 
3
-
4
-
5
-
6
-
7
3
  var _directives = _interopRequireDefault(require("./directives"));
8
4
  var _modifiers = _interopRequireDefault(require("./modifiers"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
9
5
 
@@ -91,18 +87,6 @@ const attachedDetachedLoaded = new WeakSet();var _default = exports.default =
91
87
  return;
92
88
  }
93
89
 
94
- const tagDef = (0, _babelUtils.getTagDef)(tag);
95
-
96
- if (tagDef) {
97
- if (!tagDef.html && !tagDef.getAttribute(name)) {
98
- throw attr.buildCodeFrameError(
99
- `<${
100
- tag.get("name.value").node}> does not support the "${
101
- name}" attribute.`
102
- );
103
- }
104
- }
105
-
106
90
  if (args && args.length) {
107
91
  throw attr.buildCodeFrameError(
108
92
  `Unsupported arguments on the "${name}" attribute.`
@@ -35,17 +35,10 @@ function analyzeAttributeTags(rootTag) {
35
35
  (0, _babelUtils.assertNoArgs)(child);
36
36
  const tagDef = (0, _babelUtils.getTagDef)(child) || {};
37
37
  const name = (0, _babelUtils.getFullyResolvedTagName)(child);
38
- let {
39
- targetProperty = child.node.name.value.slice(1),
40
- isRepeated = false
41
- } = tagDef;
42
-
43
- const preserveName =
44
- tagDef.preserveName === true || tagDef.removeDashes === false;
45
-
46
- if (!preserveName) {
47
- targetProperty = removeDashes(targetProperty);
48
- }
38
+ const { isRepeated = false } = tagDef;
39
+ const targetProperty = removeDashes(
40
+ tagDef.targetProperty || child.node.name.value.slice(1)
41
+ );
49
42
 
50
43
  const attrTagMeta = (attributeTags ||= {})[name] ||= {
51
44
  targetProperty,
@@ -1,6 +1,4 @@
1
- "use strict";exports.__esModule = true;exports.default = _default;var _path = require("path");
2
-
3
- var _compiler = require("@marko/compiler");
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
4
2
  var _babelUtils = require("@marko/compiler/babel-utils");
5
3
 
6
4
 
@@ -14,8 +12,6 @@ var _keyManager = require("../../util/key-manager");
14
12
  var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));
15
13
  var _attributes = _interopRequireDefault(require("./attributes"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
16
14
 
17
- const EMPTY_OBJECT = {};
18
-
19
15
  /**
20
16
  * Translates the html streaming version of a standard html element.
21
17
  */
@@ -34,14 +30,6 @@ function _default(path, isNullable) {
34
30
  const tagDef = (0, _babelUtils.getTagDef)(path);
35
31
  const meta = file.metadata.marko;
36
32
 
37
- if (tagDef) {
38
- const { parseOptions = EMPTY_OBJECT } = tagDef;
39
- if (parseOptions.import) {
40
- // TODO: the taglib should be updated to support this as a top level option.
41
- file.metadata.marko.deps.push((0, _path.resolve)(tagDef.dir, parseOptions.import));
42
- }
43
- }
44
-
45
33
  if (handlers) {
46
34
  Object.entries(handlers).forEach(
47
35
  ([eventName, { arguments: args, once }]) => {
@@ -1,9 +1,6 @@
1
1
  "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
2
  var _babelUtils = require("@marko/compiler/babel-utils");
3
3
 
4
-
5
-
6
-
7
4
  var FLAGS = _interopRequireWildcard(require("../../util/runtime-flags"));
8
5
  var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
9
6
  var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));
@@ -186,15 +183,6 @@ function tagArguments(path) {
186
183
  runtimeFlags |= FLAGS.HAS_SIMPLE_ATTRS;
187
184
  }
188
185
 
189
- const tagDef = (0, _babelUtils.getTagDef)(path);
190
-
191
- if (tagDef) {
192
- const { htmlType } = tagDef;
193
- if (htmlType === "custom-element") {
194
- runtimeFlags |= FLAGS.IS_CUSTOM_ELEMENT;
195
- }
196
- }
197
-
198
186
  writeArgs.push(_compiler.types.numericLiteral(runtimeFlags));
199
187
 
200
188
  if (tagProperties.length) {
@@ -32,43 +32,27 @@ function getAttrs(path, preserveNames, isAttrTag) {
32
32
  const { name, value } = attributes[i];
33
33
 
34
34
  if (name) {
35
- const attrDef = tagDef && tagDef.getAttribute(name);
35
+ const attrDef = getAttrDef(tagDef, name);
36
36
  let targetProperties = properties;
37
- let targetProperty = name;
38
- let preserveName = preserveNames;
39
-
40
- if (attrDef) {
41
- if (attrDef.targetProperty) {
42
- const key = attrDef.targetProperty;
43
- preserveName =
44
- attrDef.preserveName !== false && attrDef.removeDashes !== true;
45
-
46
- if (attrDef.dynamicAttribute) {
47
- let targetObject = targetObjects[key];
48
-
49
- if (!targetObject) {
50
- properties.push(
51
- _compiler.types.objectProperty(
52
- _compiler.types.stringLiteral(key),
53
- targetObject = targetObjects[key] = _compiler.types.objectExpression([])
54
- )
55
- );
56
- }
57
-
58
- targetProperties = targetObject.properties;
59
- } else {
60
- targetProperty = key;
61
- }
62
- } else if (
63
- !preserveName && (
64
- attrDef.preserveName === true || attrDef.removeDashes === false))
65
- {
66
- preserveName = true;
37
+ let targetProperty;
38
+
39
+ if (attrDef?.dynamicAttribute && attrDef.targetProperty) {
40
+ const key = attrDef.targetProperty;
41
+ let targetObject = targetObjects[key];
42
+
43
+ if (!targetObject) {
44
+ properties.push(
45
+ _compiler.types.objectProperty(
46
+ _compiler.types.stringLiteral(key),
47
+ targetObject = targetObjects[key] = _compiler.types.objectExpression([])
48
+ )
49
+ );
67
50
  }
68
- }
69
51
 
70
- if (!preserveName) {
71
- targetProperty = camelCase(targetProperty);
52
+ targetProperties = targetObject.properties;
53
+ targetProperty = keepsDashes(attrDef) ? name : camelCase(name);
54
+ } else {
55
+ targetProperty = getAttrProperty(attrDef, name, preserveNames);
72
56
  }
73
57
 
74
58
  foundProperties[targetProperty] = true;
@@ -95,26 +79,22 @@ function getAttrs(path, preserveNames, isAttrTag) {
95
79
  }
96
80
 
97
81
  // Default parameters
98
- tagDef &&
99
- tagDef.forEachAttribute &&
100
- tagDef.forEachAttribute((attr) => {
101
- if (foundProperties[attr.name] || attr.dynamicAttribute) {
102
- return;
103
- }
104
-
105
- if (attr.defaultValue !== undefined) {
106
- properties.push(
107
- _compiler.types.objectProperty(
108
- _compiler.types.stringLiteral(attr.name),
109
- _compiler.types.stringLiteral(attr.defaultValue + "")
110
- )
111
- );
112
- } else if (attr.required) {
113
- throw path.
114
- get("name").
115
- buildCodeFrameError(`The "${attr.name}" attribute is required.`);
82
+ if (tagDef?.attributes) {
83
+ for (const name in tagDef.attributes) {
84
+ const attr = tagDef.attributes[name];
85
+ if (attr.defaultValue !== undefined && !attr.dynamicAttribute) {
86
+ const property = getAttrProperty(attr, name, preserveNames);
87
+ if (!foundProperties[property]) {
88
+ properties.push(
89
+ _compiler.types.objectProperty(
90
+ _compiler.types.stringLiteral(property),
91
+ _compiler.types.stringLiteral(attr.defaultValue + "")
92
+ )
93
+ );
94
+ }
95
+ }
116
96
  }
117
- });
97
+ }
118
98
 
119
99
  let attrsObject =
120
100
  properties.length === 0 ?
@@ -260,4 +240,35 @@ function findRootTag(tag) {
260
240
  }
261
241
 
262
242
  return cur;
243
+ }
244
+
245
+ // A declared attribute, else the `*` attribute, else one whose pattern matches.
246
+ function getAttrDef(tagDef, name) {
247
+ if (!tagDef) return;
248
+ const attr =
249
+ tagDef.attributes && (tagDef.attributes[name] || tagDef.attributes["*"]);
250
+ if (attr || !tagDef.patternAttributes) return attr;
251
+ for (const patternAttr of tagDef.patternAttributes) {
252
+ if (patternAttr.pattern.test(name)) return patternAttr;
253
+ }
254
+ }
255
+
256
+ // The input property an attribute is passed as: camelCased unless its name is
257
+ // kept, and renamed by a declared target property.
258
+ function getAttrProperty(attrDef, name, preserveNames) {
259
+ if (!attrDef) return preserveNames ? name : camelCase(name);
260
+ if (attrDef.targetProperty) {
261
+ return keepsDashes(attrDef) ?
262
+ attrDef.targetProperty :
263
+ camelCase(attrDef.targetProperty);
264
+ }
265
+ return preserveNames ||
266
+ attrDef.preserveName === true ||
267
+ attrDef.removeDashes === false ?
268
+ name :
269
+ camelCase(name);
270
+ }
271
+
272
+ function keepsDashes(attrDef) {
273
+ return attrDef.preserveName !== false && attrDef.removeDashes !== true;
263
274
  }