@marko/translator-default 5.31.13 → 5.31.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +2 -5
- package/dist/tag/attribute-tag.js +149 -151
- package/dist/tag/index.js +6 -2
- package/dist/tag/native-tag[vdom]/index.js +83 -87
- package/dist/tag/util.js +61 -36
- package/dist/util/optimize-vdom-create.js +16 -8
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -472,10 +472,9 @@ function getRuntimeEntryFiles(output, optimize) {
|
|
472
472
|
`${base}runtime/helpers/assign.js`,
|
473
473
|
`${base}runtime/helpers/class-value.js`,
|
474
474
|
`${base}runtime/helpers/dynamic-tag.js`,
|
475
|
-
`${base}runtime/helpers/
|
475
|
+
`${base}runtime/helpers/attr-tag.js`,
|
476
476
|
`${base}runtime/helpers/merge.js`,
|
477
477
|
`${base}runtime/helpers/repeatable.js`,
|
478
|
-
`${base}runtime/helpers/self-iterator.js`,
|
479
478
|
`${base}runtime/helpers/render-tag.js`,
|
480
479
|
`${base}runtime/helpers/style-value.js`,
|
481
480
|
`${base}runtime/helpers/to-string.js`,
|
@@ -505,9 +504,7 @@ function getRuntimeEntryFiles(output, optimize) {
|
|
505
504
|
`${base}runtime/vdom/index.js`,
|
506
505
|
`${base}runtime/vdom/hot-reload.js`,
|
507
506
|
`${base}runtime/vdom/helpers/attrs.js`,
|
508
|
-
`${base}runtime/vdom/helpers/const.js`,
|
509
|
-
`${base}runtime/vdom/helpers/v-element.js`,
|
510
|
-
`${base}runtime/vdom/helpers/v-text.js`,
|
507
|
+
`${base}runtime/vdom/helpers/const-element.js`,
|
511
508
|
`${base}runtime/vdom/preserve-attrs.js`])];
|
512
509
|
|
513
510
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
"use strict";
|
1
|
+
"use strict";exports.__esModule = true;exports.analyzeAttributeTags = analyzeAttributeTags;exports.default = translateAttributeTag;var _babelUtils = require("@marko/babel-utils");
|
2
|
+
|
2
3
|
|
3
4
|
|
4
5
|
|
@@ -7,182 +8,179 @@
|
|
7
8
|
|
8
9
|
|
9
10
|
var _compiler = require("@marko/compiler");
|
10
|
-
var _withPreviousLocation = _interopRequireDefault(require("../util/with-previous-location"));
|
11
11
|
var _util = require("./util");
|
12
12
|
|
13
|
-
const
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
const
|
22
|
-
const
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
const contentTypeCache = new WeakMap();
|
14
|
+
const ContentType = {
|
15
|
+
attribute: 0,
|
16
|
+
render: 1,
|
17
|
+
mixed: 2
|
18
|
+
};
|
19
|
+
|
20
|
+
function analyzeAttributeTags(rootTag) {
|
21
|
+
const visit = [rootTag];
|
22
|
+
const parentTags = [rootTag];
|
23
|
+
let i = 0;
|
24
|
+
let attributeTags;
|
25
|
+
|
26
|
+
while (i < visit.length) {
|
27
|
+
const tag = visit[i++];
|
28
|
+
for (const child of tag.get("body").get("body")) {
|
29
|
+
if ((0, _babelUtils.isAttributeTag)(child)) {
|
30
|
+
(0, _babelUtils.assertNoArgs)(child);
|
31
|
+
const tagDef = (0, _babelUtils.getTagDef)(child) || {};
|
32
|
+
const name = (0, _babelUtils.getFullyResolvedTagName)(child);
|
33
|
+
let {
|
34
|
+
targetProperty = child.node.name.value.slice(1),
|
35
|
+
isRepeated = false
|
36
|
+
} = tagDef;
|
37
|
+
|
38
|
+
const preserveName =
|
39
|
+
tagDef.preserveName === true || tagDef.removeDashes === false;
|
40
|
+
|
41
|
+
if (!preserveName) {
|
42
|
+
targetProperty = removeDashes(targetProperty);
|
43
|
+
}
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
const attrTagMeta = (attributeTags ||= {})[name] ||= {
|
46
|
+
targetProperty,
|
47
|
+
isRepeated
|
48
|
+
};
|
49
|
+
|
50
|
+
(child.node.extra ||= {}).attributeTag = attrTagMeta;
|
51
|
+
|
52
|
+
const parentTag = (0, _babelUtils.findParentTag)(child);
|
53
|
+
const parentTagExtra = parentTag.node.extra ||= {};
|
54
|
+
parentTagExtra.hasAttributeTags = true;
|
55
|
+
parentTags.push(child);
|
56
|
+
visit.push(child);
|
57
|
+
} else if ((0, _babelUtils.isTransparentTag)(child)) {
|
58
|
+
switch (getContentType(child)) {
|
59
|
+
case ContentType.mixed:
|
60
|
+
throw child.buildCodeFrameError(
|
61
|
+
"Cannot mix @tags with other content when under a control flow."
|
62
|
+
);
|
63
|
+
case ContentType.attribute:
|
64
|
+
visit.push(child);
|
65
|
+
break;
|
66
|
+
case ContentType.render:
|
67
|
+
break;
|
49
68
|
}
|
50
69
|
}
|
51
70
|
}
|
52
|
-
} else {
|
53
|
-
const previousAttr = parentAttributes.find(
|
54
|
-
(attr) => attr.get("name").node === targetProperty
|
55
|
-
);
|
56
|
-
|
57
|
-
if (previousAttr) {
|
58
|
-
const previousValue = previousAttr.get("value").node;
|
59
|
-
if (_compiler.types.isObjectExpression(previousValue)) {
|
60
|
-
previousAttr.set(
|
61
|
-
"value",
|
62
|
-
_compiler.types.arrayExpression([previousValue, getAttrTagObject(tag)])
|
63
|
-
);
|
64
|
-
} else if (_compiler.types.isArrayExpression(previousAttr)) {
|
65
|
-
previousAttr.elements.push(getAttrTagObject(tag));
|
66
|
-
} else {
|
67
|
-
previousAttr.set(
|
68
|
-
"value",
|
69
|
-
_compiler.types.callExpression(
|
70
|
-
(0, _babelUtils.importDefault)(
|
71
|
-
tag.hub.file,
|
72
|
-
"marko/src/runtime/helpers/repeatable.js",
|
73
|
-
"marko_repeatable"
|
74
|
-
),
|
75
|
-
[previousValue, getAttrTagObject(tag)]
|
76
|
-
)
|
77
|
-
);
|
78
|
-
}
|
79
|
-
} else {
|
80
|
-
parentPath.pushContainer(
|
81
|
-
"attributes",
|
82
|
-
_compiler.types.markoAttribute(targetProperty, getAttrTagObject(tag))
|
83
|
-
);
|
84
|
-
}
|
85
|
-
|
86
|
-
tag.remove();
|
87
|
-
return;
|
88
71
|
}
|
89
72
|
|
90
|
-
|
73
|
+
if (attributeTags) {
|
74
|
+
(rootTag.node.extra ??= {}).attributeTags = attributeTags;
|
75
|
+
|
76
|
+
for (const parentTag of parentTags) {
|
77
|
+
if (getContentType(parentTag) === ContentType.mixed) {
|
78
|
+
// move all non scriptlet / attribute tag children to the end of the renderbody
|
79
|
+
const renderBody = [
|
80
|
+
_compiler.types.expressionStatement(_compiler.types.stringLiteral("END_ATTRIBUTE_TAGS"))];
|
81
|
+
|
82
|
+
const body = parentTag.get("body");
|
83
|
+
for (const child of body.get("body")) {
|
84
|
+
if (
|
85
|
+
child.isMarkoScriptlet() ||
|
86
|
+
(0, _babelUtils.isAttributeTag)(child) ||
|
87
|
+
(0, _babelUtils.isTransparentTag)(child) &&
|
88
|
+
getContentType(child) === ContentType.attribute)
|
89
|
+
{
|
90
|
+
continue;
|
91
|
+
}
|
92
|
+
|
93
|
+
renderBody.push(child.node);
|
94
|
+
child.remove();
|
95
|
+
}
|
91
96
|
|
92
|
-
|
93
|
-
|
97
|
+
body.node.body = body.node.body.concat(renderBody);
|
98
|
+
}
|
99
|
+
}
|
94
100
|
}
|
101
|
+
}
|
95
102
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
tag.
|
101
|
-
|
102
|
-
|
103
|
-
unshiftContainer(
|
104
|
-
"body",
|
105
|
-
_compiler.types.variableDeclaration(isRepeated ? "const" : "let", [
|
106
|
-
_compiler.types.variableDeclarator(
|
107
|
-
identifier,
|
108
|
-
isRepeated ? _compiler.types.arrayExpression([]) : _compiler.types.nullLiteral()
|
109
|
-
)]
|
110
|
-
)
|
111
|
-
);
|
112
|
-
parentPath.pushContainer(
|
113
|
-
"attributes",
|
114
|
-
_compiler.types.markoAttribute(targetProperty, identifier)
|
115
|
-
);
|
103
|
+
function translateAttributeTag(tag) {
|
104
|
+
const { node } = tag;
|
105
|
+
const meta = node.extra?.attributeTag;
|
106
|
+
if (!meta) {
|
107
|
+
throw tag.
|
108
|
+
get("name").
|
109
|
+
buildCodeFrameError("@tags must be nested within another element.");
|
116
110
|
}
|
117
111
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
} else {
|
131
|
-
tag.replaceWith(
|
132
|
-
(0, _withPreviousLocation.default)(
|
133
|
-
_compiler.types.expressionStatement(
|
134
|
-
_compiler.types.assignmentExpression(
|
135
|
-
"=",
|
136
|
-
identifier,
|
137
|
-
_compiler.types.callExpression(
|
138
|
-
(0, _babelUtils.importDefault)(
|
139
|
-
tag.hub.file,
|
140
|
-
"marko/src/runtime/helpers/repeatable.js",
|
141
|
-
"marko_repeatable"
|
142
|
-
),
|
143
|
-
[identifier, getAttrTagObject(tag)]
|
144
|
-
)
|
145
|
-
)
|
112
|
+
(0, _babelUtils.assertNoArgs)(tag);
|
113
|
+
|
114
|
+
tag.replaceWith(
|
115
|
+
_compiler.types.expressionStatement(
|
116
|
+
_compiler.types.callExpression(
|
117
|
+
(0, _babelUtils.importNamed)(
|
118
|
+
tag.hub.file,
|
119
|
+
"marko/src/runtime/helpers/attr-tag.js",
|
120
|
+
meta.isRepeated ? "r" : "a",
|
121
|
+
meta.isRepeated ?
|
122
|
+
"marko_repeated_attr_tag" :
|
123
|
+
"marko_repeatable_attr_tag"
|
146
124
|
),
|
147
|
-
|
125
|
+
[_compiler.types.stringLiteral(meta.targetProperty), getAttrTagObject(tag)]
|
148
126
|
)
|
149
|
-
)
|
150
|
-
|
127
|
+
)
|
128
|
+
);
|
151
129
|
}
|
152
130
|
|
153
131
|
function getAttrTagObject(tag) {
|
154
132
|
const attrs = (0, _util.getAttrs)(tag);
|
155
|
-
const iteratorProp = _compiler.types.objectProperty(
|
156
|
-
_compiler.types.memberExpression(_compiler.types.identifier("Symbol"), _compiler.types.identifier("iterator")),
|
157
|
-
(0, _babelUtils.importDefault)(
|
158
|
-
tag.hub.file,
|
159
|
-
"marko/src/runtime/helpers/self-iterator.js",
|
160
|
-
"marko_self_iterator"
|
161
|
-
),
|
162
|
-
true
|
163
|
-
);
|
164
133
|
|
165
134
|
if (_compiler.types.isNullLiteral(attrs)) {
|
166
|
-
return _compiler.types.objectExpression([
|
167
|
-
}
|
168
|
-
|
169
|
-
if (_compiler.types.isObjectExpression(attrs)) {
|
170
|
-
attrs.properties.push(iteratorProp);
|
171
|
-
return attrs;
|
135
|
+
return _compiler.types.objectExpression([]);
|
172
136
|
}
|
173
137
|
|
174
|
-
return
|
138
|
+
return attrs;
|
175
139
|
}
|
176
140
|
|
177
|
-
function
|
178
|
-
|
179
|
-
|
180
|
-
|
141
|
+
function getContentType(tag) {
|
142
|
+
const { node } = tag;
|
143
|
+
const cached = contentTypeCache.get(node);
|
144
|
+
if (cached !== undefined) return cached;
|
145
|
+
|
146
|
+
const body = tag.get("body").get("body");
|
147
|
+
let hasAttributeTag = false;
|
148
|
+
let hasRenderBody = false;
|
149
|
+
|
150
|
+
for (const child of body) {
|
151
|
+
if ((0, _babelUtils.isAttributeTag)(child)) {
|
152
|
+
hasAttributeTag = true;
|
153
|
+
} else if ((0, _babelUtils.isTransparentTag)(child)) {
|
154
|
+
switch (getContentType(child)) {
|
155
|
+
case ContentType.mixed:
|
156
|
+
contentTypeCache.set(node, ContentType.mixed);
|
157
|
+
return ContentType.mixed;
|
158
|
+
case ContentType.attribute:
|
159
|
+
hasAttributeTag = true;
|
160
|
+
break;
|
161
|
+
case ContentType.render:
|
162
|
+
hasRenderBody = true;
|
163
|
+
break;
|
164
|
+
}
|
165
|
+
} else if (!child.isMarkoScriptlet()) {
|
166
|
+
hasRenderBody = true;
|
167
|
+
}
|
181
168
|
|
182
|
-
|
183
|
-
|
184
|
-
|
169
|
+
if (hasAttributeTag && hasRenderBody) {
|
170
|
+
contentTypeCache.set(node, ContentType.mixed);
|
171
|
+
return ContentType.mixed;
|
172
|
+
}
|
185
173
|
}
|
186
174
|
|
187
|
-
|
175
|
+
const result = hasAttributeTag ? ContentType.attribute : ContentType.render;
|
176
|
+
contentTypeCache.set(node, result);
|
177
|
+
return result;
|
178
|
+
}
|
179
|
+
|
180
|
+
function removeDashes(str) {
|
181
|
+
return str.replace(/-([a-z])/g, matchToUpperCase);
|
182
|
+
}
|
183
|
+
|
184
|
+
function matchToUpperCase(_match, lower) {
|
185
|
+
return lower.toUpperCase();
|
188
186
|
}
|
package/dist/tag/index.js
CHANGED
@@ -13,11 +13,11 @@ var _keyManager = require("../util/key-manager");
|
|
13
13
|
var _optimizeVdomCreate = require("../util/optimize-vdom-create");
|
14
14
|
var _pluginHooks = require("../util/plugin-hooks");
|
15
15
|
var _attribute = _interopRequireDefault(require("./attribute"));
|
16
|
-
var _attributeTag =
|
16
|
+
var _attributeTag = _interopRequireWildcard(require("./attribute-tag"));
|
17
17
|
var _customTag = _interopRequireDefault(require("./custom-tag"));
|
18
18
|
var _dynamicTag = _interopRequireDefault(require("./dynamic-tag"));
|
19
19
|
var _macroTag = _interopRequireDefault(require("./macro-tag"));
|
20
|
-
var _nativeTag = _interopRequireDefault(require("./native-tag"));var _default = exports.default =
|
20
|
+
var _nativeTag = _interopRequireDefault(require("./native-tag"));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 && Object.prototype.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;}var _default = exports.default =
|
21
21
|
|
22
22
|
{
|
23
23
|
enter(path) {
|
@@ -54,6 +54,10 @@ var _nativeTag = _interopRequireDefault(require("./native-tag"));var _default =
|
|
54
54
|
}
|
55
55
|
|
56
56
|
if (!(0, _babelUtils.isAttributeTag)(path)) {
|
57
|
+
if ((0, _babelUtils.isDynamicTag)(path) || !((0, _babelUtils.isMacroTag)(path) || (0, _babelUtils.isNativeTag)(path))) {
|
58
|
+
(0, _attributeTag.analyzeAttributeTags)(path);
|
59
|
+
}
|
60
|
+
|
57
61
|
(0, _keyManager.getKeyManager)(path).resolveKey(path);
|
58
62
|
}
|
59
63
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = _default;var _babelUtils = require("@marko/babel-utils");
|
2
2
|
var _compiler = require("@marko/compiler");
|
3
3
|
var FLAGS = _interopRequireWildcard(require("../../util/runtime-flags"));
|
4
4
|
var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
|
@@ -7,7 +7,85 @@ var _attributes = _interopRequireDefault(require("./attributes"));function _getR
|
|
7
7
|
|
8
8
|
const SIMPLE_ATTRS = ["id", "class", "style"];
|
9
9
|
|
10
|
-
|
10
|
+
/**
|
11
|
+
* Translates the html streaming version of a standard html element.
|
12
|
+
*/
|
13
|
+
function _default(path, isNullable) {
|
14
|
+
const { node } = path;
|
15
|
+
const {
|
16
|
+
name,
|
17
|
+
key,
|
18
|
+
body: { body }
|
19
|
+
} = node;
|
20
|
+
|
21
|
+
const isEmpty = !body.length;
|
22
|
+
const writeArgs = tagArguments(path, false);
|
23
|
+
let writeStartNode = (0, _withPreviousLocation.default)(
|
24
|
+
(0, _vdomOutWrite.default)(isEmpty ? "e" : "be", ...writeArgs),
|
25
|
+
node.name
|
26
|
+
);
|
27
|
+
|
28
|
+
if (isNullable) {
|
29
|
+
writeStartNode = _compiler.types.ifStatement(
|
30
|
+
name,
|
31
|
+
writeStartNode,
|
32
|
+
_compiler.types.expressionStatement(
|
33
|
+
_compiler.types.callExpression(
|
34
|
+
_compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
|
35
|
+
[
|
36
|
+
(0, _babelUtils.normalizeTemplateString)`f_${key}`,
|
37
|
+
path.hub.file._componentInstanceIdentifier]
|
38
|
+
|
39
|
+
)
|
40
|
+
)
|
41
|
+
);
|
42
|
+
}
|
43
|
+
|
44
|
+
if (isEmpty) {
|
45
|
+
path.replaceWith(writeStartNode);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
let writeEndNode = (0, _vdomOutWrite.default)("ee");
|
50
|
+
if (isNullable) {
|
51
|
+
writeEndNode = _compiler.types.ifStatement(
|
52
|
+
name,
|
53
|
+
writeEndNode,
|
54
|
+
_compiler.types.expressionStatement(
|
55
|
+
_compiler.types.callExpression(
|
56
|
+
_compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
|
57
|
+
[]
|
58
|
+
)
|
59
|
+
)
|
60
|
+
);
|
61
|
+
}
|
62
|
+
|
63
|
+
let needsBlock;
|
64
|
+
for (const childNode of body) {
|
65
|
+
if (_compiler.types.isVariableDeclaration(childNode)) {
|
66
|
+
if (childNode.kind === "const" || childNode.kind === "let") {
|
67
|
+
needsBlock = true;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
path.replaceWithMultiple(
|
74
|
+
[writeStartNode].
|
75
|
+
concat(needsBlock ? _compiler.types.blockStatement(body) : body).
|
76
|
+
concat(writeEndNode)
|
77
|
+
);
|
78
|
+
}
|
79
|
+
|
80
|
+
function isPropertyName({ key }, names) {
|
81
|
+
if (_compiler.types.isStringLiteral(key)) {
|
82
|
+
return names.includes(key.value);
|
83
|
+
} else if (_compiler.types.isIdentifier(key)) {
|
84
|
+
return names.includes(key.name);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
function tagArguments(path) {
|
11
89
|
const {
|
12
90
|
hub: { file },
|
13
91
|
node
|
@@ -29,13 +107,9 @@ function tagArguments(path, isStatic) {
|
|
29
107
|
const writeArgs = [
|
30
108
|
name,
|
31
109
|
attrsObj,
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
_compiler.types.numericLiteral(body.length) :
|
36
|
-
body.length ?
|
37
|
-
_compiler.types.nullLiteral() :
|
38
|
-
_compiler.types.numericLiteral(0)];
|
110
|
+
key,
|
111
|
+
file._componentInstanceIdentifier,
|
112
|
+
body.length ? _compiler.types.nullLiteral() : _compiler.types.numericLiteral(0)];
|
39
113
|
|
40
114
|
|
41
115
|
if (node.preserveAttrs) {
|
@@ -101,82 +175,4 @@ function tagArguments(path, isStatic) {
|
|
101
175
|
writeArgs.push(_compiler.types.objectExpression(tagProperties));
|
102
176
|
}
|
103
177
|
return writeArgs;
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Translates the html streaming version of a standard html element.
|
108
|
-
*/
|
109
|
-
function _default(path, isNullable) {
|
110
|
-
const { node } = path;
|
111
|
-
const {
|
112
|
-
name,
|
113
|
-
key,
|
114
|
-
body: { body }
|
115
|
-
} = node;
|
116
|
-
|
117
|
-
const isEmpty = !body.length;
|
118
|
-
const writeArgs = tagArguments(path, false);
|
119
|
-
let writeStartNode = (0, _withPreviousLocation.default)(
|
120
|
-
(0, _vdomOutWrite.default)(isEmpty ? "e" : "be", ...writeArgs),
|
121
|
-
node.name
|
122
|
-
);
|
123
|
-
|
124
|
-
if (isNullable) {
|
125
|
-
writeStartNode = _compiler.types.ifStatement(
|
126
|
-
name,
|
127
|
-
writeStartNode,
|
128
|
-
_compiler.types.expressionStatement(
|
129
|
-
_compiler.types.callExpression(
|
130
|
-
_compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("bf")),
|
131
|
-
[
|
132
|
-
(0, _babelUtils.normalizeTemplateString)`f_${key}`,
|
133
|
-
path.hub.file._componentInstanceIdentifier]
|
134
|
-
|
135
|
-
)
|
136
|
-
)
|
137
|
-
);
|
138
|
-
}
|
139
|
-
|
140
|
-
if (isEmpty) {
|
141
|
-
path.replaceWith(writeStartNode);
|
142
|
-
return;
|
143
|
-
}
|
144
|
-
|
145
|
-
let writeEndNode = (0, _vdomOutWrite.default)("ee");
|
146
|
-
if (isNullable) {
|
147
|
-
writeEndNode = _compiler.types.ifStatement(
|
148
|
-
name,
|
149
|
-
writeEndNode,
|
150
|
-
_compiler.types.expressionStatement(
|
151
|
-
_compiler.types.callExpression(
|
152
|
-
_compiler.types.memberExpression(_compiler.types.identifier("out"), _compiler.types.identifier("ef")),
|
153
|
-
[]
|
154
|
-
)
|
155
|
-
)
|
156
|
-
);
|
157
|
-
}
|
158
|
-
|
159
|
-
let needsBlock;
|
160
|
-
for (const childNode of body) {
|
161
|
-
if (_compiler.types.isVariableDeclaration(childNode)) {
|
162
|
-
if (childNode.kind === "const" || childNode.kind === "let") {
|
163
|
-
needsBlock = true;
|
164
|
-
break;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
path.replaceWithMultiple(
|
170
|
-
[writeStartNode].
|
171
|
-
concat(needsBlock ? _compiler.types.blockStatement(body) : body).
|
172
|
-
concat(writeEndNode)
|
173
|
-
);
|
174
|
-
}
|
175
|
-
|
176
|
-
function isPropertyName({ key }, names) {
|
177
|
-
if (_compiler.types.isStringLiteral(key)) {
|
178
|
-
return names.includes(key.value);
|
179
|
-
} else if (_compiler.types.isIdentifier(key)) {
|
180
|
-
return names.includes(key.name);
|
181
|
-
}
|
182
178
|
}
|
package/dist/tag/util.js
CHANGED
@@ -3,12 +3,12 @@ var _compiler = require("@marko/compiler");
|
|
3
3
|
var _classValue = _interopRequireDefault(require("marko/src/runtime/helpers/class-value"));
|
4
4
|
var _styleValue = _interopRequireDefault(require("marko/src/runtime/helpers/style-value"));
|
5
5
|
|
6
|
-
function getAttrs(path, preserveNames
|
6
|
+
function getAttrs(path, preserveNames) {
|
7
7
|
const { node } = path;
|
8
8
|
const {
|
9
|
+
extra,
|
9
10
|
attributes,
|
10
|
-
body: { body, params }
|
11
|
-
hasDynamicAttrTags
|
11
|
+
body: { body, params }
|
12
12
|
} = node;
|
13
13
|
const attrsLen = attributes.length;
|
14
14
|
const childLen = body.length;
|
@@ -16,6 +16,7 @@ function getAttrs(path, preserveNames, skipRenderBody) {
|
|
16
16
|
const targetObjects = {};
|
17
17
|
const tagDef = (0, _babelUtils.getTagDef)(path);
|
18
18
|
const foundProperties = {};
|
19
|
+
const hasAttributeTags = extra?.hasAttributeTags;
|
19
20
|
|
20
21
|
for (let i = 0; i < attrsLen; i++) {
|
21
22
|
const { name, value } = attributes[i];
|
@@ -69,34 +70,16 @@ function getAttrs(path, preserveNames, skipRenderBody) {
|
|
69
70
|
}
|
70
71
|
}
|
71
72
|
|
72
|
-
if (
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
);
|
80
|
-
path.
|
81
|
-
insertBefore(body.slice(0, endDynamicAttrTagsIndex)).
|
82
|
-
map((child) => child.skip());
|
83
|
-
}
|
84
|
-
|
85
|
-
if (!hasDynamicAttrTags || endDynamicAttrTagsIndex !== childLen - 1) {
|
86
|
-
properties.push(
|
87
|
-
_compiler.types.objectProperty(
|
88
|
-
_compiler.types.stringLiteral("renderBody"),
|
89
|
-
_compiler.types.arrowFunctionExpression(
|
90
|
-
[_compiler.types.identifier("out"), ...params],
|
91
|
-
_compiler.types.blockStatement(
|
92
|
-
hasDynamicAttrTags ?
|
93
|
-
body.slice(endDynamicAttrTagsIndex + 1) :
|
94
|
-
body
|
95
|
-
)
|
96
|
-
)
|
73
|
+
if (childLen && !hasAttributeTags) {
|
74
|
+
properties.push(
|
75
|
+
_compiler.types.objectProperty(
|
76
|
+
_compiler.types.stringLiteral("renderBody"),
|
77
|
+
_compiler.types.arrowFunctionExpression(
|
78
|
+
[_compiler.types.identifier("out"), ...params],
|
79
|
+
_compiler.types.blockStatement(body)
|
97
80
|
)
|
98
|
-
)
|
99
|
-
|
81
|
+
)
|
82
|
+
);
|
100
83
|
}
|
101
84
|
|
102
85
|
// Default parameters
|
@@ -121,15 +104,55 @@ function getAttrs(path, preserveNames, skipRenderBody) {
|
|
121
104
|
}
|
122
105
|
});
|
123
106
|
|
124
|
-
|
125
|
-
|
126
|
-
|
107
|
+
let attrsObject =
|
108
|
+
properties.length === 0 ?
|
109
|
+
_compiler.types.nullLiteral() :
|
110
|
+
!hasAttributeTags &&
|
111
|
+
properties.length === 1 &&
|
112
|
+
_compiler.types.isSpreadElement(properties[0]) ?
|
113
|
+
properties[0].argument :
|
114
|
+
_compiler.types.objectExpression(properties);
|
115
|
+
|
116
|
+
if (hasAttributeTags) {
|
117
|
+
const endAttributeTagsIndex = findLastIndex(
|
118
|
+
body,
|
119
|
+
(node) =>
|
120
|
+
_compiler.types.isExpressionStatement(node) &&
|
121
|
+
_compiler.types.isStringLiteral(node.expression) &&
|
122
|
+
node.expression.value === "END_ATTRIBUTE_TAGS"
|
123
|
+
);
|
124
|
+
|
125
|
+
let attrTagBody = body;
|
126
|
+
|
127
|
+
if (endAttributeTagsIndex !== -1) {
|
128
|
+
attrTagBody = body.slice(0, endAttributeTagsIndex);
|
129
|
+
attrTagBody.push(
|
130
|
+
_compiler.types.returnStatement(
|
131
|
+
_compiler.types.arrowFunctionExpression(
|
132
|
+
[_compiler.types.identifier("out"), ...params],
|
133
|
+
_compiler.types.blockStatement(body.slice(endAttributeTagsIndex + 1))
|
134
|
+
)
|
135
|
+
)
|
136
|
+
);
|
137
|
+
}
|
127
138
|
|
128
|
-
|
129
|
-
|
139
|
+
const attrTagFn = _compiler.types.arrowFunctionExpression(
|
140
|
+
[],
|
141
|
+
_compiler.types.blockStatement(attrTagBody)
|
142
|
+
);
|
143
|
+
|
144
|
+
attrsObject = _compiler.types.callExpression(
|
145
|
+
(0, _babelUtils.importNamed)(
|
146
|
+
path.hub.file,
|
147
|
+
"marko/src/runtime/helpers/attr-tag.js",
|
148
|
+
"i",
|
149
|
+
"marko_render_input"
|
150
|
+
),
|
151
|
+
properties.length === 0 ? [attrTagFn] : [attrTagFn, attrsObject]
|
152
|
+
);
|
130
153
|
}
|
131
154
|
|
132
|
-
return
|
155
|
+
return attrsObject;
|
133
156
|
}
|
134
157
|
|
135
158
|
function buildEventHandlerArray(path) {
|
@@ -207,6 +230,8 @@ function findLastIndex(arr, check) {
|
|
207
230
|
return i;
|
208
231
|
}
|
209
232
|
}
|
233
|
+
|
234
|
+
return -1;
|
210
235
|
}
|
211
236
|
|
212
237
|
function mergeSpread(properties, value) {
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
var _compiler = require("@marko/compiler");
|
9
9
|
var _he = require("he");
|
10
|
-
var
|
10
|
+
var _attributes = _interopRequireDefault(require("../tag/native-tag[vdom]/attributes"));
|
11
11
|
var _keyManager = require("./key-manager");
|
12
12
|
var _vdomOutWrite = _interopRequireDefault(require("./vdom-out-write"));
|
13
13
|
|
@@ -40,10 +40,9 @@ const mergeStaticCreateVisitor = {
|
|
40
40
|
},
|
41
41
|
MarkoTag(path, state) {
|
42
42
|
(0, _keyManager.getKeyManager)(path).resolveKey(path);
|
43
|
-
const writeArgs = (0, _nativeTagVdom.tagArguments)(path, true);
|
44
43
|
state.currentRoot = _compiler.types.callExpression(
|
45
44
|
_compiler.types.memberExpression(state.currentRoot, _compiler.types.identifier("e")),
|
46
|
-
|
45
|
+
getConstElementArgs(path)
|
47
46
|
);
|
48
47
|
}
|
49
48
|
};
|
@@ -70,7 +69,8 @@ const analyzeStaticVisitor = {
|
|
70
69
|
let isStatic =
|
71
70
|
(0, _babelUtils.isNativeTag)(path) &&
|
72
71
|
!path.node.body.params.length &&
|
73
|
-
!path.node.arguments
|
72
|
+
!path.node.arguments &&
|
73
|
+
!(0, _keyManager.hasUserKey)(path);
|
74
74
|
|
75
75
|
const tagDef = (0, _babelUtils.getTagDef)(path);
|
76
76
|
isStatic = isStatic && !tagDef.translator;
|
@@ -118,15 +118,14 @@ function optimizeStaticVDOM(path) {
|
|
118
118
|
}
|
119
119
|
|
120
120
|
const identifier = path.scope.generateUidIdentifier("marko_node");
|
121
|
-
const writeArgs = (0, _nativeTagVdom.tagArguments)(path, true);
|
122
121
|
const state = {
|
123
122
|
currentRoot: _compiler.types.callExpression(
|
124
123
|
(0, _babelUtils.importDefault)(
|
125
124
|
file,
|
126
|
-
"marko/src/runtime/vdom/helpers/
|
127
|
-
"
|
125
|
+
"marko/src/runtime/vdom/helpers/const-element.js",
|
126
|
+
"marko_constElement"
|
128
127
|
),
|
129
|
-
|
128
|
+
getConstElementArgs(path)
|
130
129
|
)
|
131
130
|
};
|
132
131
|
|
@@ -148,4 +147,13 @@ function analyzeStaticVDOM(path) {
|
|
148
147
|
|
149
148
|
function shouldRun(markoOpts) {
|
150
149
|
return markoOpts.optimize && markoOpts.output !== "html";
|
150
|
+
}
|
151
|
+
|
152
|
+
function getConstElementArgs(path) {
|
153
|
+
const { node } = path;
|
154
|
+
return [
|
155
|
+
node.name,
|
156
|
+
(0, _attributes.default)(path, path.get("attributes")),
|
157
|
+
_compiler.types.numericLiteral(node.body.body.length)];
|
158
|
+
|
151
159
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@marko/translator-default",
|
3
|
-
"version": "5.31.
|
3
|
+
"version": "5.31.15",
|
4
4
|
"description": "Translates Marko templates to the default Marko runtime.",
|
5
5
|
"keywords": [
|
6
6
|
"babel",
|
@@ -34,8 +34,8 @@
|
|
34
34
|
"self-closing-tags": "^1.0.1"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
37
|
-
"@marko/compiler": "^5.34.
|
38
|
-
"marko": "^5.32.
|
37
|
+
"@marko/compiler": "^5.34.7",
|
38
|
+
"marko": "^5.32.10"
|
39
39
|
},
|
40
40
|
"peerDependencies": {
|
41
41
|
"@marko/compiler": "^5.16.1",
|