@marko/translator-default 5.29.1 → 5.30.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.
@@ -1,5 +1,10 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
2
  var _babelUtils = require("@marko/babel-utils");
3
+
4
+
5
+
6
+
7
+
3
8
  var _toString = _interopRequireDefault(require("marko/src/runtime/helpers/to-string"));
4
9
  var _escapeXml = require("marko/src/runtime/html/helpers/escape-xml");
5
10
  var _escapeScriptPlaceholder = _interopRequireDefault(require("marko/src/runtime/html/helpers/escape-script-placeholder"));
@@ -31,15 +36,15 @@ function _default(path) {
31
36
  node,
32
37
  hub: { file }
33
38
  } = path;
34
- const { confident, value: computed } = path.get("value").evaluate();
39
+ const computed = (0, _babelUtils.computeNode)(node.value);
35
40
  let { escape, value } = node;
36
41
 
37
42
  if (escape) {
38
43
  const tagName = findParentTagName(path);
39
44
  const escapeType = ESCAPE_TYPES[tagName] || ESCAPE_TYPES.html;
40
45
 
41
- value = confident ?
42
- _compiler.types.stringLiteral(escapeType.fn(computed)) :
46
+ value = computed ?
47
+ _compiler.types.stringLiteral(escapeType.fn(computed.value)) :
43
48
  _compiler.types.callExpression(
44
49
  escapeType.name ?
45
50
  (0, _babelUtils.importNamed)(
@@ -52,8 +57,8 @@ function _default(path) {
52
57
  [value]);
53
58
 
54
59
  } else {
55
- value = confident ?
56
- _compiler.types.stringLiteral((0, _toString.default)(computed)) :
60
+ value = computed ?
61
+ _compiler.types.stringLiteral((0, _toString.default)(computed.value)) :
57
62
  _compiler.types.callExpression(
58
63
  (0, _babelUtils.importDefault)(
59
64
  file,
@@ -1,13 +1,14 @@
1
- "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _vdomOutWrite = _interopRequireDefault(require("../util/vdom-out-write"));
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _babelUtils = require("@marko/babel-utils");
2
+ var _vdomOutWrite = _interopRequireDefault(require("../util/vdom-out-write"));
2
3
  var _withPreviousLocation = _interopRequireDefault(require("../util/with-previous-location"));
3
4
 
4
5
  function _default(path) {
5
6
  const { node } = path;
6
7
  const { escape, value } = node;
7
8
  const method = escape ? "t" : "h";
8
- const { confident, value: computed } = path.get("value").evaluate();
9
+ const computed = (0, _babelUtils.computeNode)(value);
9
10
 
10
- if (confident && !computed) {
11
+ if (computed && computed.value == null) {
11
12
  path.remove();
12
13
  } else {
13
14
  path.replaceWith(
@@ -9,27 +9,29 @@ var _withPreviousLocation = _interopRequireDefault(require("../../../util/with-p
9
9
  hub: { file }
10
10
  } = tag;
11
11
  if (!(0, _babelUtils.isNativeTag)(tag)) return;
12
- if (value.isStringLiteral()) return;
13
12
 
14
- const { confident, value: computed } = value.evaluate();
13
+ const computed = (0, _babelUtils.computeNode)(value.node);
14
+ if (computed) {
15
+ const str = (0, _classValue.default)(computed.value);
16
+ if (str) {
17
+ value.replaceWith(_compiler.types.stringLiteral(str));
18
+ } else {
19
+ value.parentPath.remove();
20
+ }
21
+ } else {
22
+ value.replaceWith(
23
+ (0, _withPreviousLocation.default)(
24
+ _compiler.types.callExpression(
25
+ (0, _babelUtils.importDefault)(
26
+ file,
27
+ "marko/src/runtime/helpers/class-value.js",
28
+ "marko_class_merge"),
15
29
 
16
- const s = (0, _classValue.default)(computed);
17
- value.replaceWith(
18
- confident ?
19
- s ?
20
- _compiler.types.stringLiteral(s) :
21
- _compiler.types.nullLiteral() :
22
- (0, _withPreviousLocation.default)(
23
- _compiler.types.callExpression(
24
- (0, _babelUtils.importDefault)(
25
- file,
26
- "marko/src/runtime/helpers/class-value.js",
27
- "marko_class_merge"),
30
+ [value.node]),
28
31
 
29
- [value.node]),
30
-
31
- value.node));
32
+ value.node));
32
33
 
33
34
 
35
+ }
34
36
  }
35
37
  };exports.default = _default;
@@ -2,6 +2,9 @@
2
2
  var _babelUtils = require("@marko/babel-utils");var _default =
3
3
 
4
4
  {
5
+ enter(tag) {
6
+ tag.node.isPreserved = true;
7
+ },
5
8
  exit(tag, attr, value) {
6
9
  _noUpdate.default.exit(tag, attr, value, {
7
10
  if: (0, _babelUtils.getArgOrSequence)(attr),
@@ -1,6 +1,9 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _noUpdate = _interopRequireDefault(require("./no-update"));var _default =
2
2
 
3
3
  {
4
+ enter(tag) {
5
+ tag.node.isPreserved = true;
6
+ },
4
7
  exit(tag, attr, value) {
5
8
  _noUpdate.default.exit(tag, attr, value, { bodyOnly: true });
6
9
  }
@@ -2,6 +2,9 @@
2
2
  var _babelUtils = require("@marko/babel-utils");var _default =
3
3
 
4
4
  {
5
+ enter(tag) {
6
+ tag.node.isPreserved = true;
7
+ },
5
8
  exit(tag, attr, value) {
6
9
  _noUpdate.default.exit(tag, attr, value, { if: (0, _babelUtils.getArgOrSequence)(attr) });
7
10
  }
@@ -3,6 +3,9 @@ var _babelUtils = require("@marko/babel-utils");
3
3
  const EMPTY_OBJECT = {};var _default =
4
4
 
5
5
  {
6
+ enter(tag) {
7
+ tag.node.isPreserved = true;
8
+ },
6
9
  exit(tag, attr, _, opts = EMPTY_OBJECT) {
7
10
  attr.remove();
8
11
  const { node } = tag;
@@ -8,24 +8,30 @@ var _withPreviousLocation = _interopRequireDefault(require("../../../util/with-p
8
8
  const {
9
9
  hub: { file }
10
10
  } = tag;
11
- if (value.isStringLiteral()) return;
12
11
  if (!(0, _babelUtils.isNativeTag)(tag)) return;
13
12
 
14
- const { confident, value: computed } = value.evaluate();
15
- value.replaceWith(
16
- (0, _withPreviousLocation.default)(
17
- confident ?
18
- _compiler.types.stringLiteral((0, _styleValue.default)(computed) || "") :
19
- _compiler.types.callExpression(
20
- (0, _babelUtils.importDefault)(
21
- file,
22
- "marko/src/runtime/helpers/style-value.js",
23
- "marko_style_merge"),
13
+ const computed = (0, _babelUtils.computeNode)(value.node);
14
+ if (computed) {
15
+ const str = (0, _styleValue.default)(computed.value);
16
+ if (str) {
17
+ value.replaceWith(_compiler.types.stringLiteral(str));
18
+ } else {
19
+ value.parentPath.remove();
20
+ }
21
+ } else {
22
+ value.replaceWith(
23
+ (0, _withPreviousLocation.default)(
24
+ _compiler.types.callExpression(
25
+ (0, _babelUtils.importDefault)(
26
+ file,
27
+ "marko/src/runtime/helpers/style-value.js",
28
+ "marko_style_merge"),
24
29
 
25
- [value.node]),
30
+ [value.node]),
26
31
 
27
- value.node));
32
+ value.node));
28
33
 
29
34
 
35
+ }
30
36
  }
31
37
  };exports.default = _default;
@@ -18,7 +18,9 @@ function _default(path) {
18
18
  tagProperties.push(
19
19
  _compiler.types.objectProperty(
20
20
  _compiler.types.identifier("pa"),
21
- _compiler.types.arrayExpression(node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
21
+ _compiler.types.arrayExpression(
22
+ node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
23
+
22
24
 
23
25
 
24
26
  }
@@ -4,105 +4,116 @@ var _attr = _interopRequireDefault(require("marko/src/runtime/html/helpers/attr"
4
4
  var _util = require("../util");
5
5
 
6
6
  function _default(path, attrs) {
7
- if (!attrs.length) return _compiler.types.stringLiteral("");
8
-
9
7
  const len = attrs.length;
10
8
  if (len === 0) return _compiler.types.stringLiteral("");
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/html/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;
11
23
 
12
- if (attrs.some((attr) => !attr.node.name)) {
13
- const attrsObject = _compiler.types.objectExpression([]);
14
24
  for (let i = 0; i < len; i++) {
25
+ const attr = attrs[i];
15
26
  const {
16
27
  node: { name, value }
17
- } = attrs[i];
28
+ } = attr;
18
29
 
19
30
  if (name) {
20
- attrsObject.properties.push(
21
- _compiler.types.objectProperty(_compiler.types.stringLiteral(name), value));
22
-
31
+ const computed = (0, _util.evaluateAttr)(attr);
32
+ const prop = _compiler.types.objectProperty(
33
+ _compiler.types.stringLiteral(name),
34
+ (computed == null ? void 0 : 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
+ }
23
43
  } else {
24
- mergeSpread(attrsObject.properties, value);
44
+ attrsObjects.push(value);
45
+ props = undefined;
25
46
  }
26
47
  }
27
48
 
28
49
  return _compiler.types.callExpression(
29
50
  (0, _babelUtils.importDefault)(
30
51
  path.hub.file,
31
- "marko/src/runtime/html/helpers/attrs.js",
32
- "marko_attrs"),
33
-
34
- [
35
- attrsObject.properties.length === 1 &&
36
- _compiler.types.isSpreadElement(attrsObject.properties[0]) ?
37
- attrsObject.properties[0].argument :
38
- attrsObject]);
52
+ "marko/src/runtime/html/helpers/merge-attrs.js",
53
+ "marko_merge_attrs"),
39
54
 
55
+ attrsObjects);
40
56
 
41
- } else {
42
- const file = path.hub.file;
43
- const quasis = [];
44
- const expressions = [];
45
- const attrValues = new Map();
46
- let curString = "";
47
-
48
- // Remove duplicate attrs so last one wins.
49
- for (let i = len; i--;) {
50
- const attr = attrs[i];
51
- const { name, value } = attr.node;
52
- if (attrValues.has(name)) continue;
53
- const { confident, computed } = (0, _util.evaluateAttr)(attr);
54
- attrValues.set(name, {
55
- confident,
56
- computed,
57
- value
58
- });
59
- }
57
+ }
60
58
 
61
- for (const [name, { confident, computed, value }] of [
62
- ...attrValues].
63
- reverse()) {
64
- if (confident) {
65
- if (computed == null || computed === false) {
66
- continue;
67
- }
59
+ const file = path.hub.file;
60
+ const quasis = [];
61
+ const expressions = [];
62
+ const attrValues = new Map();
63
+ let curString = "";
64
+
65
+ // Remove duplicate attrs so last one wins.
66
+ for (let i = len; i--;) {
67
+ const attr = attrs[i];
68
+ const { name, value } = attr.node;
69
+ if (attrValues.has(name)) continue;
70
+ const computed = (0, _util.evaluateAttr)(attr);
71
+ attrValues.set(
72
+ name,
73
+ computed ?
74
+ {
75
+ confident: true,
76
+ computed: computed.value,
77
+ value
78
+ } :
79
+ {
80
+ confident: false,
81
+ computed: undefined,
82
+ value
83
+ });
68
84
 
69
- curString += (0, _attr.default)(name, computed);
70
- } else {
71
- quasis.push(curString);
72
- curString = "";
73
- expressions.push(
74
- _compiler.types.callExpression(
75
- (0, _babelUtils.importDefault)(
76
- file,
77
- "marko/src/runtime/html/helpers/attr.js",
78
- "marko_attr"),
85
+ }
79
86
 
80
- [_compiler.types.stringLiteral(name), value]));
87
+ for (const [name, { confident, computed, value }] of [
88
+ ...attrValues].
89
+ reverse()) {
90
+ if (confident) {
91
+ if (computed == null || computed === false) {
92
+ continue;
93
+ }
81
94
 
95
+ curString += (0, _attr.default)(name, computed);
96
+ } else {
97
+ quasis.push(curString);
98
+ curString = "";
99
+ expressions.push(
100
+ _compiler.types.callExpression(
101
+ (0, _babelUtils.importDefault)(
102
+ file,
103
+ "marko/src/runtime/html/helpers/attr.js",
104
+ "marko_attr"),
82
105
 
83
- }
84
- }
106
+ [_compiler.types.stringLiteral(name), value]));
85
107
 
86
- quasis.push(curString);
87
108
 
88
- if (expressions.length) {
89
- return (0, _babelUtils.normalizeTemplateString)(quasis, ...expressions);
90
- } else {
91
- return _compiler.types.stringLiteral(quasis.join(""));
92
109
  }
93
110
  }
94
- }
95
111
 
96
- function mergeSpread(properties, value) {
97
- if (_compiler.types.isObjectExpression(value)) {
98
- for (const prop of value.properties) {
99
- if (_compiler.types.isSpreadElement(prop)) {
100
- mergeSpread(properties, prop.argument);
101
- } else {
102
- properties.push(prop);
103
- }
104
- }
112
+ quasis.push(curString);
113
+
114
+ if (expressions.length) {
115
+ return (0, _babelUtils.normalizeTemplateString)(quasis, ...expressions);
105
116
  } else {
106
- properties.push(_compiler.types.spreadElement(value));
117
+ return _compiler.types.stringLiteral(quasis.join(""));
107
118
  }
108
119
  }
@@ -75,7 +75,9 @@ function _default(path, isNullable) {
75
75
  tagProperties.push(
76
76
  _compiler.types.objectProperty(
77
77
  _compiler.types.identifier("pa"),
78
- _compiler.types.arrayExpression(node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
78
+ _compiler.types.arrayExpression(
79
+ node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
80
+
79
81
 
80
82
 
81
83
  }
@@ -0,0 +1,104 @@
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/babel-utils");
3
+ var _util = require("../util");
4
+
5
+ function _default(path, attrs) {
6
+ const len = attrs.length;
7
+ if (len === 0) return _compiler.types.nullLiteral();
8
+ if (len === 1 && attrs[0].node.type === "MarkoSpreadAttribute") {
9
+ return _compiler.types.callExpression(
10
+ (0, _babelUtils.importDefault)(
11
+ path.hub.file,
12
+ "marko/src/runtime/vdom/helpers/attrs.js",
13
+ "marko_attrs"),
14
+
15
+ [attrs[0].node.value]);
16
+
17
+ }
18
+
19
+ if (attrs.some((attr) => attr.node.type === "MarkoSpreadAttribute")) {
20
+ const attrsObjects = [];
21
+ let props;
22
+
23
+ for (let i = 0; i < len; i++) {
24
+ const attr = attrs[i];
25
+ const {
26
+ node: { name, value }
27
+ } = attr;
28
+
29
+ if (name) {
30
+ const computed = (0, _util.evaluateAttr)(attr);
31
+ const prop = _compiler.types.objectProperty(
32
+ _compiler.types.stringLiteral(name),
33
+ (computed == null ? void 0 : computed.value) !== undefined ?
34
+ _compiler.types.stringLiteral(computed.value) :
35
+ value);
36
+
37
+ if (props) {
38
+ props.push(prop);
39
+ } else {
40
+ attrsObjects.push(_compiler.types.objectExpression(props = [prop]));
41
+ }
42
+ } else {
43
+ attrsObjects.push(value);
44
+ props = undefined;
45
+ }
46
+ }
47
+
48
+ return _compiler.types.callExpression(
49
+ (0, _babelUtils.importDefault)(
50
+ path.hub.file,
51
+ "marko/src/runtime/vdom/helpers/merge-attrs.js",
52
+ "marko_merge_attrs"),
53
+
54
+ attrsObjects);
55
+
56
+ }
57
+
58
+ const attrValues = new Map();
59
+ const props = [];
60
+
61
+ // Remove duplicate attrs so last one wins.
62
+ for (let i = len; i--;) {
63
+ const attr = attrs[i];
64
+ const { name, value } = attr.node;
65
+ if (attrValues.has(name)) continue;
66
+ const computed = (0, _util.evaluateAttr)(attr);
67
+ attrValues.set(
68
+ name,
69
+ computed ?
70
+ {
71
+ confident: true,
72
+ computed: computed.value,
73
+ value
74
+ } :
75
+ {
76
+ confident: false,
77
+ computed: undefined,
78
+ value
79
+ });
80
+
81
+ }
82
+
83
+ for (const [name, { confident, computed, value }] of [
84
+ ...attrValues].
85
+ reverse()) {
86
+ if (confident) {
87
+ if (computed == null || computed === false) {
88
+ continue;
89
+ }
90
+
91
+ props.push(
92
+ _compiler.types.objectProperty(_compiler.types.stringLiteral(name), _compiler.types.stringLiteral(computed)));
93
+
94
+ } else {
95
+ props.push(_compiler.types.objectProperty(_compiler.types.stringLiteral(name), value));
96
+ }
97
+ }
98
+
99
+ if (props.length) {
100
+ return _compiler.types.objectExpression(props);
101
+ }
102
+
103
+ return _compiler.types.nullLiteral();
104
+ }
@@ -1,12 +1,8 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;exports.tagArguments = tagArguments;var _compiler = require("@marko/compiler");
2
2
  var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
3
3
  var FLAGS = _interopRequireWildcard(require("../../util/runtime-flags"));
4
- var _util = require("../util");
5
4
  var _babelUtils = require("@marko/babel-utils");
6
-
7
-
8
-
9
-
5
+ var _attributes = _interopRequireDefault(require("./attributes"));
10
6
  var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));function _getRequireWildcardCache(nodeInterop) {if (typeof WeakMap !== "function") return null;var cacheBabelInterop = new WeakMap();var cacheNodeInterop = new WeakMap();return (_getRequireWildcardCache = function (nodeInterop) {return nodeInterop ? cacheNodeInterop : cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj, nodeInterop) {if (!nodeInterop && obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache(nodeInterop);if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}
11
7
 
12
8
  const SIMPLE_ATTRS = ["id", "class", "style"];
@@ -30,48 +26,11 @@ function tagArguments(path, isStatic) {
30
26
  handlers
31
27
  } = node;
32
28
  const tagProperties = path.node.extra && path.node.extra.properties || [];
33
- const attrs = path.get("attributes");
34
- const seen = new Set();
35
- const len = attrs.length;
36
- const hasSpread = attrs.some((attr) => !attr.node.name);
29
+ const attrsObj = (0, _attributes.default)(path, path.get("attributes"));
37
30
  let runtimeFlags = 0;
38
31
 
39
- for (let i = len; i--;) {
40
- const attr = attrs[i];
41
- const { name } = attr.node;
42
- if (seen.has(name)) {
43
- if (!hasSpread) attr.remove();
44
- }
45
-
46
- seen.add(name);
47
- const { confident, computed } = (0, _util.evaluateAttr)(attr);
48
-
49
- if (confident) {
50
- if (computed == null || computed === false) {
51
- if (!hasSpread) attr.remove();
52
- } else {
53
- attr.set("value", _compiler.types.stringLiteral(computed));
54
- }
55
- }
56
- }
57
-
58
- let attrsObj = (0, _util.getAttrs)(path, true, true);
59
-
60
- if (!_compiler.types.isNullLiteral(attrsObj)) {
61
- if (
62
- !_compiler.types.isObjectExpression(attrsObj) ||
63
- attrsObj.properties.some(_compiler.types.isSpreadElement))
64
- {
65
- runtimeFlags |= FLAGS.SPREAD_ATTRS;
66
- attrsObj = _compiler.types.callExpression(
67
- (0, _babelUtils.importDefault)(
68
- file,
69
- "marko/src/runtime/vdom/helpers/attrs.js",
70
- "marko_attrs"),
71
-
72
- [attrsObj]);
73
-
74
- }
32
+ if (!_compiler.types.isNullLiteral(attrsObj) && !_compiler.types.isObjectExpression(attrsObj)) {
33
+ runtimeFlags |= FLAGS.SPREAD_ATTRS;
75
34
  }
76
35
 
77
36
  const writeArgs = [
@@ -90,7 +49,9 @@ function tagArguments(path, isStatic) {
90
49
  tagProperties.push(
91
50
  _compiler.types.objectProperty(
92
51
  _compiler.types.identifier("pa"),
93
- _compiler.types.arrayExpression(node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
52
+ _compiler.types.arrayExpression(
53
+ node.preserveAttrs.map((name) => _compiler.types.stringLiteral(name)))));
54
+
94
55
 
95
56
 
96
57
  }
package/dist/tag/util.js CHANGED
@@ -1,5 +1,7 @@
1
- "use strict";exports.__esModule = true;exports.buildEventHandlerArray = buildEventHandlerArray;exports.evaluateAttr = evaluateAttr;exports.getAttrs = getAttrs;var _compiler = require("@marko/compiler");
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.buildEventHandlerArray = buildEventHandlerArray;exports.evaluateAttr = evaluateAttr;exports.getAttrs = getAttrs;var _compiler = require("@marko/compiler");
2
2
  var _babelUtils = require("@marko/babel-utils");
3
+ var _classValue = _interopRequireDefault(require("marko/src/runtime/helpers/class-value"));
4
+ var _styleValue = _interopRequireDefault(require("marko/src/runtime/helpers/style-value"));
3
5
 
4
6
  function getAttrs(path, preserveNames, skipRenderBody) {
5
7
  const { node } = path;
@@ -155,32 +157,44 @@ function buildEventHandlerArray(path) {
155
157
 
156
158
  }
157
159
 
158
- function evaluateAttr(attr) {
159
- const name = attr.get("name").node;
160
- const value = attr.get("value");
161
- let confident = false;
162
- let computed = undefined;
160
+ function evaluateAttr(attr) {var _classToString, _styleToString;
161
+ const computed = (0, _babelUtils.computeNode)(attr.node.value);
162
+ if (computed) {
163
+ const { value } = computed;
164
+ switch (attr.node.name) {
165
+ case "class":
166
+ return {
167
+ value: (_classToString = (0, _classValue.default)(value)) == null ? void 0 : _classToString.replace(/\s+/, " ").trim()
168
+ };
169
+ case "style":
170
+ return {
171
+ value: (_styleToString = (0, _styleValue.default)(value)) == null ? void 0 : _styleToString.
172
+ replace(/\s+/, " ").
173
+ trim().
174
+ replace(/;$/, "")
175
+ };}
176
+
177
+
178
+ if (value == null || value === false) {
179
+ return { value: undefined };
180
+ }
163
181
 
164
- if (name) {
165
- if (value.isRegExpLiteral()) {
166
- confident = true;
167
- computed = value.get("pattern").node;
168
- } else {
169
- const evaluated = value.evaluate();
170
- ({ confident, value: computed } = evaluated);
182
+ if (value === true) {
183
+ return { value: "" };
184
+ }
185
+
186
+ if (typeof value === "object") {
187
+ switch (value.toString) {
188
+ case Object.prototype.toString:
189
+ case Array.prototype.toString:
190
+ return { value: JSON.stringify(value) };
191
+ case RegExp.prototype.toString:
192
+ return { value: value.source };}
171
193
 
172
- if (computed === true) {
173
- computed = "";
174
- } else if (computed != null && computed !== false) {
175
- computed = computed + "";
176
- }
177
194
  }
178
- }
179
195
 
180
- return {
181
- confident,
182
- computed
183
- };
196
+ return { value: value + "" };
197
+ }
184
198
  }
185
199
 
186
200
  function camelCase(string) {
@@ -82,7 +82,8 @@ var parseModuleCode = _interopRequireWildcard(require("./parse-module-code"));fu
82
82
  displayText: "static <statement>",
83
83
  description:
84
84
  "A JavaScript statement which is only evaluated once your template is loaded.",
85
- descriptionMoreURL: "https://markojs.com/docs/syntax/#static-javascript"
85
+ descriptionMoreURL:
86
+ "https://markojs.com/docs/syntax/#static-javascript"
86
87
  }]
87
88
 
88
89
  },
@@ -284,7 +285,7 @@ var parseModuleCode = _interopRequireWildcard(require("./parse-module-code"));fu
284
285
  },
285
286
  "<await>": {
286
287
  renderer: "marko/src/core-tags/core/await/renderer.js",
287
- types: "marko/src/core-tags/core/await/index.marko",
288
+ types: "marko/src/core-tags/core/await/index.d.marko",
288
289
  "code-generator": translateAwait,
289
290
  "@_provider": "expression",
290
291
  "@_name": "string",
@@ -28,7 +28,9 @@ function enter(path) {
28
28
  _compiler.types.markoAttribute("_provider", provider.node));
29
29
 
30
30
 
31
- if (!path.get("attributes").some((attr) => attr.get("name").node === "name")) {
31
+ if (
32
+ !path.get("attributes").some((attr) => attr.get("name").node === "name"))
33
+ {
32
34
  path.pushContainer(
33
35
  "attributes",
34
36
  _compiler.types.markoAttribute("_name", _compiler.types.stringLiteral(provider.toString())));
@@ -44,7 +44,11 @@ function exit(path) {
44
44
  block);
45
45
 
46
46
  } else if (ofAttr) {
47
- let ofAttrValue = ofAttr.value;
47
+ let ofAttrValue = _compiler.types.logicalExpression(
48
+ "||",
49
+ ofAttr.value,
50
+ _compiler.types.arrayExpression([]));
51
+
48
52
  allowedAttributes.push("of");
49
53
 
50
54
  const [valParam, keyParam, loopParam] = params;
@@ -1,8 +1,13 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _path = _interopRequireDefault(require("path"));
2
2
  var _magicString = _interopRequireDefault(require("magic-string"));
3
3
  var _compiler = require("@marko/compiler");
4
+ var _resolveFrom = _interopRequireDefault(require("resolve-from"));
4
5
  var _babelUtils = require("@marko/babel-utils");var _default =
5
6
 
7
+
8
+
9
+
10
+
6
11
  (entryFile, isHydrate) => {
7
12
  const { resolveVirtualDependency, hydrateIncludeImports } =
8
13
  entryFile.markoOpts;
@@ -15,7 +20,6 @@ var _babelUtils = require("@marko/babel-utils");var _default =
15
20
  return;
16
21
  }
17
22
 
18
- const registerId = _compiler.types.identifier("register");
19
23
  const watchFiles = new Set();
20
24
  let hasComponents = false;
21
25
  let splitComponentIndex = 0;
@@ -32,7 +36,7 @@ var _babelUtils = require("@marko/babel-utils");var _default =
32
36
 
33
37
  if (splitComponentIndex) {
34
38
  markoComponentsImport.specifiers.push(
35
- _compiler.types.importSpecifier(registerId, registerId));
39
+ _compiler.types.importSpecifier(_compiler.types.identifier("register"), _compiler.types.identifier("register")));
36
40
 
37
41
  }
38
42
  markoComponentsImport.specifiers.push(_compiler.types.importSpecifier(initId, initId));
@@ -86,6 +90,15 @@ var _babelUtils = require("@marko/babel-utils");var _default =
86
90
  if (!hydratedFiles.has(resolvePath(file, tag))) {
87
91
  addHydrateDeps((0, _babelUtils.loadFileForImport)(file, tag));
88
92
  }
93
+ } else {
94
+ const importedTemplates = tryGetTemplateImports(file, tag);
95
+ if (importedTemplates) {
96
+ for (const templateFile of importedTemplates) {
97
+ if (!hydratedFiles.has(resolvePath(file, templateFile))) {
98
+ addHydrateDeps((0, _babelUtils.loadFileForImport)(file, templateFile));
99
+ }
100
+ }
101
+ }
89
102
  }
90
103
  }
91
104
 
@@ -104,7 +117,7 @@ var _babelUtils = require("@marko/babel-utils");var _default =
104
117
  program.pushContainer(
105
118
  "body",
106
119
  _compiler.types.expressionStatement(
107
- _compiler.types.callExpression(registerId, [
120
+ _compiler.types.callExpression(_compiler.types.identifier("register"), [
108
121
  _compiler.types.stringLiteral(meta.id),
109
122
  splitComponentId])));
110
123
 
@@ -168,6 +181,62 @@ var _babelUtils = require("@marko/babel-utils");var _default =
168
181
  }
169
182
  };exports.default = _default;
170
183
 
184
+ function tryGetTemplateImports(file, rendererRelativePath) {
185
+ const resolvedRendererPath = _path.default.join(
186
+ file.opts.filename,
187
+ "..",
188
+ rendererRelativePath);
189
+
190
+ let templateImports;
191
+
192
+ try {
193
+ for (const statement of (0, _babelUtils.parseStatements)(
194
+ file,
195
+ file.markoOpts.fileSystem.readFileSync(resolvedRendererPath, "utf-8")))
196
+ {
197
+ if (statement.type === "ImportDeclaration") {
198
+ addImport(statement.source.value);
199
+ } else {
200
+ _compiler.types.traverseFast(statement, (node) => {
201
+ if (
202
+ node.type === "CallExpression" && (
203
+ node.callee.name === "require" ||
204
+ node.callee.type === "MemberExpression" &&
205
+ node.callee.object.type === "Identifier" &&
206
+ node.callee.object.name === "require" &&
207
+ node.callee.property.type === "Identifier" &&
208
+ node.callee.property.name === "resolve") &&
209
+ node.arguments.length === 1 &&
210
+ node.arguments[0].type === "StringLiteral")
211
+ {
212
+ addImport(node.arguments[0].value);
213
+ }
214
+ });
215
+ }
216
+ }
217
+ } catch {
218
+
219
+ // Ignore
220
+ }
221
+ return templateImports;
222
+
223
+ function addImport(request) {
224
+ if (request.endsWith(".marko")) {
225
+ const resolvedTemplatePath =
226
+ request[0] === "." ?
227
+ _path.default.resolve(resolvedRendererPath, "..", request) :
228
+ _resolveFrom.default.silent(_path.default.dirname(resolvedRendererPath), request);
229
+ if (resolvedTemplatePath) {
230
+ if (templateImports) {
231
+ templateImports.push(resolvedTemplatePath);
232
+ } else {
233
+ templateImports = [resolvedTemplatePath];
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+
171
240
  function toTestFn(val) {
172
241
  if (typeof val === "function") {
173
242
  return val;
@@ -6,10 +6,16 @@ var _babelUtils = require("@marko/babel-utils");
6
6
 
7
7
 
8
8
 
9
+
9
10
  var _keyManager = require("./key-manager");
10
11
  var _vdomOutWrite = _interopRequireDefault(require("./vdom-out-write"));
11
12
  var _nativeTagVdom = require("../tag/native-tag[vdom]");
12
- var _directives = _interopRequireDefault(require("../tag/attribute/directives"));
13
+
14
+ const skipDirectives = new Set([
15
+ "no-update",
16
+ "no-update-if",
17
+ "no-update-body",
18
+ "no-update-body-if"]);
13
19
 
14
20
  const staticNodes = new WeakSet();
15
21
 
@@ -22,10 +28,14 @@ const mergeStaticCreateVisitor = {
22
28
 
23
29
  },
24
30
  MarkoPlaceholder(path, state) {
25
- const { value } = path.get("value").evaluate();
31
+ const computed = (0, _babelUtils.computeNode)(path.node.value);
26
32
  state.currentRoot = _compiler.types.callExpression(
27
33
  _compiler.types.memberExpression(state.currentRoot, _compiler.types.identifier("t")),
28
- [_compiler.types.stringLiteral(value != null ? value.toString() : "")]);
34
+ [
35
+ _compiler.types.stringLiteral(
36
+ computed && computed.value != null ? `${computed.value}` : "")]);
37
+
38
+
29
39
 
30
40
  },
31
41
  MarkoTag(path, state) {
@@ -44,8 +54,8 @@ const analyzeStaticVisitor = {
44
54
  },
45
55
  MarkoPlaceholder(path) {
46
56
  if (path.node.escape) {
47
- const { confident } = path.get("value").evaluate();
48
- if (confident) {
57
+ const computed = (0, _babelUtils.computeNode)(path.node.value);
58
+ if (computed) {
49
59
  staticNodes.add(path.node);
50
60
  }
51
61
  }
@@ -68,24 +78,18 @@ const analyzeStaticVisitor = {
68
78
  // check attributes
69
79
  isStatic =
70
80
  isStatic &&
71
- path.get("attributes").every((attr) => {
72
- if (
73
- !_compiler.types.isMarkoAttribute(attr) ||
74
- attr.node.arguments ||
75
- attr.node.modifier ||
76
- _directives.default[attr.node.name])
77
-
78
- return false;
79
-
80
- const attrValue = attr.get("value");
81
- const exclude =
82
- _compiler.types.isObjectExpression(attrValue) ||
83
- _compiler.types.isArrayExpression(attrValue) ||
84
- _compiler.types.isRegExpLiteral(attrValue);
85
- if (exclude) return false;
86
- const { confident } = attrValue.evaluate();
87
- return confident;
88
- });
81
+ path.
82
+ get("attributes").
83
+ every(
84
+ (attr) =>
85
+ _compiler.types.isMarkoAttribute(attr) &&
86
+ !(
87
+ attr.node.arguments ||
88
+ attr.node.modifier ||
89
+ skipDirectives.has(attr.node.name) ||
90
+ !(0, _babelUtils.computeNode)(attr.node.value)));
91
+
92
+
89
93
 
90
94
  // check children
91
95
  isStatic =
package/package.json CHANGED
@@ -1,26 +1,7 @@
1
1
  {
2
2
  "name": "@marko/translator-default",
3
+ "version": "5.30.0",
3
4
  "description": "Translates Marko templates to the default Marko runtime.",
4
- "version": "5.29.1",
5
- "author": "Dylan Piercey <dpiercey@ebay.com>",
6
- "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
7
- "dependencies": {
8
- "@babel/runtime": "^7.16.0",
9
- "@marko/babel-utils": "^6.2.0",
10
- "escape-string-regexp": "^4.0.0",
11
- "magic-string": "^0.27.0",
12
- "self-closing-tags": "^1.0.1"
13
- },
14
- "devDependencies": {
15
- "@marko/compiler": "^5.31.1",
16
- "marko": "^5.29.1"
17
- },
18
- "files": [
19
- "dist",
20
- "index.d.ts"
21
- ],
22
- "types": "index.d.ts",
23
- "homepage": "https://github.com/marko-js/marko/blob/master/packages/translator-default/README.md",
24
5
  "keywords": [
25
6
  "babel",
26
7
  "htmljs",
@@ -29,10 +10,34 @@
29
10
  "parser",
30
11
  "plugin"
31
12
  ],
13
+ "homepage": "https://github.com/marko-js/marko/blob/master/packages/translator-default/README.md",
14
+ "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/marko-js/marko/tree/master/packages/translator-default"
18
+ },
32
19
  "license": "MIT",
20
+ "author": "Dylan Piercey <dpiercey@ebay.com>",
33
21
  "main": "dist/index.js",
34
- "main:dev": "src/index.js",
35
- "main:npm": "dist/index.js",
22
+ "types": "index.d.ts",
23
+ "files": [
24
+ "dist",
25
+ "index.d.ts"
26
+ ],
27
+ "scripts": {
28
+ "build": "babel ./src --out-dir ./dist --delete-dir-on-start --copy-files --config-file ../../babel.config.js --env-name=production"
29
+ },
30
+ "dependencies": {
31
+ "@babel/runtime": "^7.16.0",
32
+ "@marko/babel-utils": "^6.3.0",
33
+ "escape-string-regexp": "^4.0.0",
34
+ "magic-string": "^0.27.0",
35
+ "self-closing-tags": "^1.0.1"
36
+ },
37
+ "devDependencies": {
38
+ "@marko/compiler": "^5.32.0",
39
+ "marko": "^5.30.0"
40
+ },
36
41
  "peerDependencies": {
37
42
  "@marko/compiler": "^5.16.1",
38
43
  "marko": "^5.17.2"
@@ -40,8 +45,6 @@
40
45
  "publishConfig": {
41
46
  "access": "public"
42
47
  },
43
- "repository": {
44
- "type": "git",
45
- "url": "https://github.com/marko-js/marko/tree/master/packages/translator-default"
46
- }
48
+ "main:dev": "src/index.js",
49
+ "main:npm": "dist/index.js"
47
50
  }