@marko/translator-default 5.24.0 → 5.25.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +2 -0
- package/dist/tag/attribute-tag.js +76 -28
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -468,6 +468,8 @@ function getRuntimeEntryFiles(output, optimize) {
|
|
468
468
|
`${base}runtime/helpers/dynamic-tag.js`,
|
469
469
|
`${base}runtime/helpers/load-nested-tag.js`,
|
470
470
|
`${base}runtime/helpers/merge.js`,
|
471
|
+
`${base}runtime/helpers/repeatable.js`,
|
472
|
+
`${base}runtime/helpers/self-iterator.js`,
|
471
473
|
`${base}runtime/helpers/render-tag.js`,
|
472
474
|
`${base}runtime/helpers/style-value.js`,
|
473
475
|
`${base}runtime/helpers/to-string.js`,
|
@@ -6,6 +6,7 @@ var _babelUtils = require("@marko/babel-utils");
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
|
9
10
|
var _util = require("./util");
|
10
11
|
var _withPreviousLocation = _interopRequireDefault(require("../util/with-previous-location"));
|
11
12
|
|
@@ -14,13 +15,13 @@ const parentIdentifierLookup = new WeakMap();
|
|
14
15
|
|
15
16
|
// TODO: optimize inline repeated @tags.
|
16
17
|
|
17
|
-
function _default(
|
18
|
-
const { node } =
|
19
|
-
const namePath =
|
18
|
+
function _default(tag) {
|
19
|
+
const { node } = tag;
|
20
|
+
const namePath = tag.get("name");
|
20
21
|
const tagName = namePath.node.value;
|
21
|
-
const parentPath = (0, _babelUtils.findParentTag)(
|
22
|
+
const parentPath = (0, _babelUtils.findParentTag)(tag);
|
22
23
|
|
23
|
-
(0, _babelUtils.assertNoArgs)(
|
24
|
+
(0, _babelUtils.assertNoArgs)(tag);
|
24
25
|
|
25
26
|
if (!parentPath) {
|
26
27
|
throw namePath.buildCodeFrameError(
|
@@ -29,10 +30,10 @@ function _default(path) {
|
|
29
30
|
}
|
30
31
|
|
31
32
|
const parentAttributes = parentPath.get("attributes");
|
32
|
-
const tagDef = (0, _babelUtils.getTagDef)(
|
33
|
+
const tagDef = (0, _babelUtils.getTagDef)(tag);
|
33
34
|
const { isRepeated, targetProperty = tagName.slice(1) } =
|
34
35
|
tagDef || EMPTY_OBJECT;
|
35
|
-
const isDynamic = isRepeated || parentPath !==
|
36
|
+
const isDynamic = isRepeated || parentPath !== tag.parentPath.parentPath;
|
36
37
|
parentPath.node.exampleAttributeTag = node;
|
37
38
|
|
38
39
|
if (isDynamic) {
|
@@ -49,28 +50,40 @@ function _default(path) {
|
|
49
50
|
}
|
50
51
|
}
|
51
52
|
} else {
|
52
|
-
|
53
|
-
|
54
|
-
{
|
55
|
-
throw namePath.buildCodeFrameError(
|
56
|
-
`Only one "${tagName}" tag is allowed here.`);
|
53
|
+
const previousAttr = parentAttributes.find(
|
54
|
+
(attr) => attr.get("name").node === targetProperty);
|
57
55
|
|
58
|
-
}
|
59
56
|
|
60
|
-
|
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)]));
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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)]));
|
67
76
|
|
68
|
-
parentPath.pushContainer(
|
69
|
-
"attributes",
|
70
|
-
_compiler.types.markoAttribute(targetProperty, attrs));
|
71
77
|
|
78
|
+
}
|
79
|
+
} else {
|
80
|
+
parentPath.pushContainer(
|
81
|
+
"attributes",
|
82
|
+
_compiler.types.markoAttribute(targetProperty, getAttrTagObject(tag)));
|
83
|
+
|
84
|
+
}
|
72
85
|
|
73
|
-
|
86
|
+
tag.remove();
|
74
87
|
return;
|
75
88
|
}
|
76
89
|
|
@@ -84,7 +97,7 @@ function _default(path) {
|
|
84
97
|
|
85
98
|
if (!identifier) {
|
86
99
|
identifier = identifiers[targetProperty] =
|
87
|
-
|
100
|
+
tag.scope.generateUidIdentifier(targetProperty);
|
88
101
|
parentPath.
|
89
102
|
get("body").
|
90
103
|
unshiftContainer(
|
@@ -103,22 +116,33 @@ function _default(path) {
|
|
103
116
|
}
|
104
117
|
|
105
118
|
if (isRepeated) {
|
106
|
-
|
119
|
+
tag.replaceWith(
|
107
120
|
(0, _withPreviousLocation.default)(
|
108
121
|
_compiler.types.expressionStatement(
|
109
122
|
_compiler.types.callExpression(
|
110
123
|
_compiler.types.memberExpression(identifier, _compiler.types.identifier("push")),
|
111
|
-
[(
|
124
|
+
[getAttrTagObject(tag)])),
|
112
125
|
|
113
126
|
|
114
127
|
node));
|
115
128
|
|
116
129
|
|
117
130
|
} else {
|
118
|
-
|
131
|
+
tag.replaceWith(
|
119
132
|
(0, _withPreviousLocation.default)(
|
120
133
|
_compiler.types.expressionStatement(
|
121
|
-
_compiler.types.assignmentExpression(
|
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
|
+
|
122
146
|
|
123
147
|
node));
|
124
148
|
|
@@ -126,6 +150,30 @@ function _default(path) {
|
|
126
150
|
}
|
127
151
|
}
|
128
152
|
|
153
|
+
function getAttrTagObject(tag) {
|
154
|
+
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
|
+
|
165
|
+
if (_compiler.types.isNullLiteral(attrs)) {
|
166
|
+
return _compiler.types.objectExpression([iteratorProp]);
|
167
|
+
}
|
168
|
+
|
169
|
+
if (_compiler.types.isObjectExpression(attrs)) {
|
170
|
+
attrs.properties.push(iteratorProp);
|
171
|
+
return attrs;
|
172
|
+
}
|
173
|
+
|
174
|
+
return _compiler.types.objectExpression([iteratorProp, _compiler.types.spreadElement(attrs)]);
|
175
|
+
}
|
176
|
+
|
129
177
|
function isAttributeTagChild(tag) {
|
130
178
|
if ((0, _babelUtils.isAttributeTag)(tag)) {
|
131
179
|
return true;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@marko/translator-default",
|
3
3
|
"description": "Translates Marko templates to the default Marko runtime.",
|
4
|
-
"version": "5.
|
4
|
+
"version": "5.25.0",
|
5
5
|
"author": "Dylan Piercey <dpiercey@ebay.com>",
|
6
6
|
"bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
|
7
7
|
"dependencies": {
|
@@ -12,8 +12,8 @@
|
|
12
12
|
"self-closing-tags": "^1.0.1"
|
13
13
|
},
|
14
14
|
"devDependencies": {
|
15
|
-
"@marko/compiler": "^5.
|
16
|
-
"marko": "^5.
|
15
|
+
"@marko/compiler": "^5.27.0",
|
16
|
+
"marko": "^5.25.0"
|
17
17
|
},
|
18
18
|
"files": [
|
19
19
|
"dist"
|