marko 5.39.51 → 5.40.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 (33) 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/translator/index.d.ts +1 -0
@@ -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
  let complain = "MARKO_DEBUG" && require("complain");
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,5 +1,3 @@
1
- import { resolve } from "path";
2
-
3
1
  import { types as t } from "@marko/compiler";
4
2
  import {
5
3
  findParentTag,
@@ -39,6 +37,9 @@ const CLASS_HYDRATION_DESCENDANT = "descendant";
39
37
 
40
38
  export const version = markoPkg.version;
41
39
  export const tagDiscoveryDirs = ["components"];
40
+ // Its taglibs declare attributes, nested tags and renderers, and its tag folders
41
+ // take renderers, hook files and older template names.
42
+ export const classTaglibs = true;
42
43
  export { optionalTaglibs, default as taglibs } from "./taglib";
43
44
  export { entryBuilder as internalEntryBuilder } from "./util/add-dependencies";
44
45
 
@@ -105,19 +106,7 @@ export const 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
- resolve(
114
- tagDef.dir,
115
- resolve(tagDef.dir, tagDef.parseOptions.import),
116
- ),
117
- );
118
- }
119
- }
120
- } else if (t.isStringLiteral(tag.node.name)) {
109
+ if (!isNativeTag(tag)) {
121
110
  relativePath = resolveRelativeTagEntry(file, tagDef);
122
111
  }
123
112
 
@@ -1,8 +1,4 @@
1
- import {
2
- getTagDef,
3
- importDefault,
4
- isNativeTag,
5
- } from "@marko/compiler/babel-utils";
1
+ import { importDefault, isNativeTag } from "@marko/compiler/babel-utils";
6
2
 
7
3
  import directives from "./directives";
8
4
  import modifiers from "./modifiers";
@@ -91,18 +87,6 @@ export default {
91
87
  return;
92
88
  }
93
89
 
94
- const tagDef = getTagDef(tag);
95
-
96
- if (tagDef) {
97
- if (!tagDef.html && !tagDef.getAttribute(name)) {
98
- throw attr.buildCodeFrameError(
99
- `<${
100
- tag.get("name.value").node
101
- }> does not support the "${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 @@ export function analyzeAttributeTags(rootTag) {
35
35
  assertNoArgs(child);
36
36
  const tagDef = getTagDef(child) || {};
37
37
  const name = 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,5 +1,3 @@
1
- import { resolve } from "path";
2
-
3
1
  import { types as t } from "@marko/compiler";
4
2
  import {
5
3
  getTagDef,
@@ -14,8 +12,6 @@ import { hasUserKey } from "../../util/key-manager";
14
12
  import withPreviousLocation from "../../util/with-previous-location";
15
13
  import translateAttributes from "./attributes";
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 @@ export default function (path, isNullable) {
34
30
  const tagDef = 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(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,8 +1,5 @@
1
1
  import { types as t } from "@marko/compiler";
2
- import {
3
- getTagDef,
4
- normalizeTemplateString,
5
- } from "@marko/compiler/babel-utils";
2
+ import { normalizeTemplateString } from "@marko/compiler/babel-utils";
6
3
 
7
4
  import * as FLAGS from "../../util/runtime-flags";
8
5
  import write from "../../util/vdom-out-write";
@@ -186,15 +183,6 @@ function tagArguments(path) {
186
183
  runtimeFlags |= FLAGS.HAS_SIMPLE_ATTRS;
187
184
  }
188
185
 
189
- const tagDef = 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(t.numericLiteral(runtimeFlags));
199
187
 
200
188
  if (tagProperties.length) {
@@ -32,43 +32,27 @@ export 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
- t.objectProperty(
52
- t.stringLiteral(key),
53
- (targetObject = targetObjects[key] = t.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
+ t.objectProperty(
46
+ t.stringLiteral(key),
47
+ (targetObject = targetObjects[key] = t.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 @@ export 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
- t.objectProperty(
108
- t.stringLiteral(attr.name),
109
- t.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
+ t.objectProperty(
90
+ t.stringLiteral(property),
91
+ t.stringLiteral(attr.defaultValue + ""),
92
+ ),
93
+ );
94
+ }
116
95
  }
117
- });
96
+ }
97
+ }
118
98
 
119
99
  let attrsObject =
120
100
  properties.length === 0
@@ -261,3 +241,34 @@ function findRootTag(tag) {
261
241
 
262
242
  return cur;
263
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;
274
+ }