marko 5.36.4 → 5.37.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.
- package/dist/compiler/index.js +11 -11
- package/dist/core-tags/components/init-components-tag.js +4 -4
- package/dist/core-tags/components/preferred-script-location-tag.js +2 -2
- package/dist/core-tags/core/__flush_here_and_after__.js +1 -1
- package/dist/core-tags/core/await/AsyncValue.js +21 -21
- package/dist/core-tags/core/await/renderer.js +24 -24
- package/dist/core-tags/core/await/reorderer-renderer.js +6 -6
- package/dist/node-require/browser-refresh.js +18 -1
- package/dist/node-require/index.js +7 -7
- package/dist/node_modules/@internal/components-beginComponent/index-browser.js +5 -5
- package/dist/node_modules/@internal/components-beginComponent/index.js +12 -12
- package/dist/node_modules/@internal/components-define-widget-legacy/index-browser.js +99 -99
- package/dist/node_modules/@internal/components-define-widget-legacy/index.js +3 -3
- package/dist/node_modules/@internal/components-endComponent/index.js +3 -3
- package/dist/node_modules/@internal/components-entry/index-browser.js +2 -2
- package/dist/node_modules/@internal/components-entry/index.js +29 -29
- package/dist/node_modules/@internal/components-entry-legacy/index-browser.js +13 -13
- package/dist/node_modules/@internal/components-entry-legacy/index.js +1 -1
- package/dist/node_modules/@internal/components-registry/index-browser.js +102 -102
- package/dist/node_modules/@internal/components-registry/index.js +2 -2
- package/dist/node_modules/@internal/components-util/index-browser.js +20 -20
- package/dist/node_modules/@internal/components-util/index.js +24 -20
- package/dist/node_modules/@internal/create-readable/index-browser.js +1 -1
- package/dist/node_modules/@internal/create-readable/index.js +9 -9
- package/dist/node_modules/@internal/preserve-tag/index-browser.js +8 -8
- package/dist/node_modules/@internal/preserve-tag/index.js +6 -6
- package/dist/node_modules/@internal/set-immediate/index-browser.js +2 -2
- package/dist/node_modules/@internal/set-immediate/index-worker.js +3 -3
- package/dist/node_modules/@internal/set-immediate/index.js +3 -3
- package/dist/runtime/RenderResult.js +24 -24
- package/dist/runtime/components/Component.js +163 -163
- package/dist/runtime/components/ComponentDef.js +34 -34
- package/dist/runtime/components/ComponentsContext.js +20 -20
- package/dist/runtime/components/GlobalComponentsContext.js +4 -4
- package/dist/runtime/components/KeySequence.js +3 -3
- package/dist/runtime/components/ServerComponent.js +17 -17
- package/dist/runtime/components/State.js +28 -28
- package/dist/runtime/components/attach-detach.js +8 -8
- package/dist/runtime/components/defineComponent.js +5 -5
- package/dist/runtime/components/dom-data.js +6 -6
- package/dist/runtime/components/event-delegation.js +10 -10
- package/dist/runtime/components/legacy/defineComponent-legacy.js +1 -1
- package/dist/runtime/components/legacy/defineRenderer-legacy.js +25 -25
- package/dist/runtime/components/legacy/dependencies/index.js +10 -10
- package/dist/runtime/components/legacy/renderer-legacy.js +56 -56
- package/dist/runtime/components/renderer.js +45 -45
- package/dist/runtime/components/update-manager.js +4 -4
- package/dist/runtime/createOut.js +1 -1
- package/dist/runtime/dom-insert.js +5 -5
- package/dist/runtime/helpers/_change-case.js +2 -2
- package/dist/runtime/helpers/dynamic-tag.js +33 -33
- package/dist/runtime/helpers/render-tag.js +1 -1
- package/dist/runtime/helpers/serialize-noop.js +2 -2
- package/dist/runtime/helpers/style-value.js +1 -1
- package/dist/runtime/helpers/tags-compat/runtime-dom.js +35 -35
- package/dist/runtime/helpers/tags-compat/runtime-html.js +16 -16
- package/dist/runtime/html/AsyncStream.js +28 -28
- package/dist/runtime/html/BufferedWriter.js +2 -2
- package/dist/runtime/html/StringWriter.js +2 -2
- package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
- package/dist/runtime/html/helpers/attr.js +11 -11
- package/dist/runtime/html/helpers/attrs.js +6 -6
- package/dist/runtime/html/helpers/data-marko.js +6 -6
- package/dist/runtime/html/helpers/escape-quotes.js +2 -2
- package/dist/runtime/html/helpers/escape-xml.js +1 -1
- package/dist/runtime/html/helpers/merge-attrs.js +11 -11
- package/dist/runtime/html/helpers/props-script.js +1 -1
- package/dist/runtime/html/index.js +2 -2
- package/dist/runtime/renderable.js +5 -5
- package/dist/runtime/vdom/AsyncVDOMBuilder.js +100 -100
- package/dist/runtime/vdom/VComment.js +7 -7
- package/dist/runtime/vdom/VComponent.js +5 -5
- package/dist/runtime/vdom/VDocumentFragment.js +8 -8
- package/dist/runtime/vdom/VElement.js +52 -52
- package/dist/runtime/vdom/VFragment.js +9 -9
- package/dist/runtime/vdom/VNode.js +34 -34
- package/dist/runtime/vdom/VText.js +8 -8
- package/dist/runtime/vdom/helpers/attrs.js +6 -6
- package/dist/runtime/vdom/helpers/const-element.js +3 -3
- package/dist/runtime/vdom/hot-reload.js +20 -20
- package/dist/runtime/vdom/index.js +2 -2
- package/dist/runtime/vdom/morphdom/fragment.js +10 -10
- package/dist/runtime/vdom/morphdom/helpers.js +5 -5
- package/dist/runtime/vdom/morphdom/index.js +81 -81
- package/dist/runtime/vdom/vdom.js +15 -15
- package/dist/taglib/index.js +7 -7
- package/dist/translator/cdata/index.js +15 -0
- package/dist/translator/cdata/index[html].js +15 -0
- package/dist/translator/cdata/index[vdom].js +12 -0
- package/dist/translator/class.js +65 -0
- package/dist/translator/comment/index.js +15 -0
- package/dist/translator/comment/index[html].js +17 -0
- package/dist/translator/comment/index[vdom].js +3 -0
- package/dist/translator/declaration/index.js +15 -0
- package/dist/translator/declaration/index[html].js +12 -0
- package/dist/translator/declaration/index[vdom].js +3 -0
- package/dist/translator/document-type/index.js +15 -0
- package/dist/translator/document-type/index[html].js +12 -0
- package/dist/translator/document-type/index[vdom].js +3 -0
- package/dist/translator/index.js +551 -0
- package/dist/translator/placeholder/index.js +15 -0
- package/dist/translator/placeholder/index[html].js +93 -0
- package/dist/translator/placeholder/index[vdom].js +22 -0
- package/dist/translator/scriptlet.js +4 -0
- package/dist/translator/tag/attribute/directives/class.js +42 -0
- package/dist/translator/tag/attribute/directives/index.js +15 -0
- package/dist/translator/tag/attribute/directives/no-update-body-if.js +15 -0
- package/dist/translator/tag/attribute/directives/no-update-body.js +10 -0
- package/dist/translator/tag/attribute/directives/no-update-if.js +12 -0
- package/dist/translator/tag/attribute/directives/no-update.js +48 -0
- package/dist/translator/tag/attribute/directives/style.js +42 -0
- package/dist/translator/tag/attribute/index.js +150 -0
- package/dist/translator/tag/attribute/modifiers/index.js +7 -0
- package/dist/translator/tag/attribute/modifiers/no-update.js +14 -0
- package/dist/translator/tag/attribute/modifiers/scoped.js +23 -0
- package/dist/translator/tag/attribute-tag.js +149 -0
- package/dist/translator/tag/custom-tag.js +146 -0
- package/dist/translator/tag/dynamic-tag.js +74 -0
- package/dist/translator/tag/index.js +287 -0
- package/dist/translator/tag/macro-tag.js +7 -0
- package/dist/translator/tag/native-tag.js +27 -0
- package/dist/translator/tag/native-tag[html]/attributes.js +151 -0
- package/dist/translator/tag/native-tag[html]/index.js +221 -0
- package/dist/translator/tag/native-tag[vdom]/attributes.js +105 -0
- package/dist/translator/tag/native-tag[vdom]/index.js +189 -0
- package/dist/translator/tag/util.js +246 -0
- package/dist/translator/taglib/core/conditional/translate-else-if.js +20 -0
- package/dist/translator/taglib/core/conditional/translate-else.js +20 -0
- package/dist/translator/taglib/core/conditional/translate-if.js +8 -0
- package/dist/translator/taglib/core/conditional/util.js +41 -0
- package/dist/translator/taglib/core/index.js +474 -0
- package/dist/translator/taglib/core/macro/parse.js +17 -0
- package/dist/translator/taglib/core/macro/translate.js +48 -0
- package/dist/translator/taglib/core/parse-class.js +79 -0
- package/dist/translator/taglib/core/parse-export.js +14 -0
- package/dist/translator/taglib/core/parse-import.js +14 -0
- package/dist/translator/taglib/core/parse-module-code.js +18 -0
- package/dist/translator/taglib/core/parse-static.js +18 -0
- package/dist/translator/taglib/core/transform-style.js +66 -0
- package/dist/translator/taglib/core/translate-await.js +41 -0
- package/dist/translator/taglib/core/translate-body.js +17 -0
- package/dist/translator/taglib/core/translate-for.js +156 -0
- package/dist/translator/taglib/core/translate-html-comment.js +52 -0
- package/dist/translator/taglib/core/translate-include-content.js +53 -0
- package/dist/translator/taglib/core/translate-server-only.js +5 -0
- package/dist/translator/taglib/core/translate-while.js +32 -0
- package/dist/translator/taglib/index.js +6 -0
- package/dist/translator/taglib/migrate/all-templates.js +46 -0
- package/dist/translator/taglib/migrate/index.js +5 -0
- package/dist/translator/text/index.js +10 -0
- package/dist/translator/text/index[html].js +12 -0
- package/dist/translator/text/index[vdom].js +20 -0
- package/dist/translator/util/add-dependencies.js +329 -0
- package/dist/translator/util/escape-regexp.js +4 -0
- package/dist/translator/util/get-component-files.js +86 -0
- package/dist/translator/util/html-out-write.js +15 -0
- package/dist/translator/util/key-manager.js +176 -0
- package/dist/translator/util/optimize-html-writes.js +52 -0
- package/dist/translator/util/optimize-vdom-create.js +164 -0
- package/dist/translator/util/plugin-hooks.js +22 -0
- package/dist/translator/util/runtime-flags.js +3 -0
- package/dist/translator/util/vdom-out-write.js +10 -0
- package/dist/translator/util/with-previous-location.js +6 -0
- package/package.json +7 -4
- package/src/taglib/index.js +2 -2
- package/src/translator/cdata/index.js +15 -0
- package/src/translator/cdata/index[html].js +15 -0
- package/src/translator/cdata/index[vdom].js +12 -0
- package/src/translator/class.js +65 -0
- package/src/translator/comment/index.js +15 -0
- package/src/translator/comment/index[html].js +17 -0
- package/src/translator/comment/index[vdom].js +3 -0
- package/src/translator/declaration/index.js +15 -0
- package/src/translator/declaration/index[html].js +12 -0
- package/src/translator/declaration/index[vdom].js +3 -0
- package/src/translator/document-type/index.js +15 -0
- package/src/translator/document-type/index[html].js +12 -0
- package/src/translator/document-type/index[vdom].js +3 -0
- package/src/translator/index.js +551 -0
- package/src/translator/placeholder/index.js +15 -0
- package/src/translator/placeholder/index[html].js +93 -0
- package/src/translator/placeholder/index[vdom].js +22 -0
- package/src/translator/scriptlet.js +4 -0
- package/src/translator/tag/attribute/directives/class.js +42 -0
- package/src/translator/tag/attribute/directives/index.js +15 -0
- package/src/translator/tag/attribute/directives/no-update-body-if.js +15 -0
- package/src/translator/tag/attribute/directives/no-update-body.js +10 -0
- package/src/translator/tag/attribute/directives/no-update-if.js +12 -0
- package/src/translator/tag/attribute/directives/no-update.js +48 -0
- package/src/translator/tag/attribute/directives/style.js +42 -0
- package/src/translator/tag/attribute/index.js +150 -0
- package/src/translator/tag/attribute/modifiers/index.js +7 -0
- package/src/translator/tag/attribute/modifiers/no-update.js +14 -0
- package/src/translator/tag/attribute/modifiers/scoped.js +23 -0
- package/src/translator/tag/attribute-tag.js +149 -0
- package/src/translator/tag/custom-tag.js +146 -0
- package/src/translator/tag/dynamic-tag.js +74 -0
- package/src/translator/tag/index.js +287 -0
- package/src/translator/tag/macro-tag.js +7 -0
- package/src/translator/tag/native-tag.js +27 -0
- package/src/translator/tag/native-tag[html]/attributes.js +151 -0
- package/src/translator/tag/native-tag[html]/index.js +221 -0
- package/src/translator/tag/native-tag[vdom]/attributes.js +105 -0
- package/src/translator/tag/native-tag[vdom]/index.js +189 -0
- package/src/translator/tag/util.js +246 -0
- package/src/translator/taglib/core/conditional/translate-else-if.js +20 -0
- package/src/translator/taglib/core/conditional/translate-else.js +20 -0
- package/src/translator/taglib/core/conditional/translate-if.js +8 -0
- package/src/translator/taglib/core/conditional/util.js +41 -0
- package/src/translator/taglib/core/index.js +474 -0
- package/src/translator/taglib/core/macro/parse.js +17 -0
- package/src/translator/taglib/core/macro/translate.js +48 -0
- package/src/translator/taglib/core/parse-class.js +79 -0
- package/src/translator/taglib/core/parse-export.js +14 -0
- package/src/translator/taglib/core/parse-import.js +14 -0
- package/src/translator/taglib/core/parse-module-code.js +18 -0
- package/src/translator/taglib/core/parse-static.js +18 -0
- package/src/translator/taglib/core/transform-style.js +66 -0
- package/src/translator/taglib/core/translate-await.js +41 -0
- package/src/translator/taglib/core/translate-body.js +17 -0
- package/src/translator/taglib/core/translate-for.js +156 -0
- package/src/translator/taglib/core/translate-html-comment.js +52 -0
- package/src/translator/taglib/core/translate-include-content.js +53 -0
- package/src/translator/taglib/core/translate-server-only.js +5 -0
- package/src/translator/taglib/core/translate-while.js +32 -0
- package/src/translator/taglib/index.js +7 -0
- package/src/translator/taglib/migrate/all-templates.js +46 -0
- package/src/translator/taglib/migrate/index.js +5 -0
- package/src/translator/text/index.js +10 -0
- package/src/translator/text/index[html].js +12 -0
- package/src/translator/text/index[vdom].js +20 -0
- package/src/translator/util/add-dependencies.js +329 -0
- package/src/translator/util/escape-regexp.js +4 -0
- package/src/translator/util/get-component-files.js +86 -0
- package/src/translator/util/html-out-write.js +15 -0
- package/src/translator/util/key-manager.js +176 -0
- package/src/translator/util/optimize-html-writes.js +52 -0
- package/src/translator/util/optimize-vdom-create.js +164 -0
- package/src/translator/util/plugin-hooks.js +22 -0
- package/src/translator/util/runtime-flags.js +3 -0
- package/src/translator/util/vdom-out-write.js +10 -0
- package/src/translator/util/with-previous-location.js +6 -0
- package/translator/index.d.ts +7 -0
- package/translator/package.json +5 -0
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _classValue = _interopRequireDefault(require("marko/src/runtime/helpers/class-value"));
|
|
8
|
+
var _styleValue = _interopRequireDefault(require("marko/src/runtime/helpers/style-value"));
|
|
9
|
+
|
|
10
|
+
function getAttrs(path, preserveNames, isAttrTag) {
|
|
11
|
+
const { node } = path;
|
|
12
|
+
const {
|
|
13
|
+
extra,
|
|
14
|
+
attributes,
|
|
15
|
+
attributeTags,
|
|
16
|
+
body: { body, params }
|
|
17
|
+
} = node;
|
|
18
|
+
const attrsLen = attributes.length;
|
|
19
|
+
const childLen = body.length;
|
|
20
|
+
const properties = [];
|
|
21
|
+
const targetObjects = {};
|
|
22
|
+
const tagDef = (0, _babelUtils.getTagDef)(path);
|
|
23
|
+
const foundProperties = {};
|
|
24
|
+
const hasAttributeTags = !!attributeTags.length;
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < attrsLen; i++) {
|
|
27
|
+
const { name, value } = attributes[i];
|
|
28
|
+
|
|
29
|
+
if (name) {
|
|
30
|
+
const attrDef = tagDef && tagDef.getAttribute(name);
|
|
31
|
+
let targetProperties = properties;
|
|
32
|
+
let targetProperty = name;
|
|
33
|
+
let preserveName = preserveNames;
|
|
34
|
+
|
|
35
|
+
if (attrDef) {
|
|
36
|
+
if (attrDef.targetProperty) {
|
|
37
|
+
const key = attrDef.targetProperty;
|
|
38
|
+
preserveName =
|
|
39
|
+
attrDef.preserveName !== false && attrDef.removeDashes !== true;
|
|
40
|
+
|
|
41
|
+
if (attrDef.dynamicAttribute) {
|
|
42
|
+
let targetObject = targetObjects[key];
|
|
43
|
+
|
|
44
|
+
if (!targetObject) {
|
|
45
|
+
properties.push(
|
|
46
|
+
_compiler.types.objectProperty(
|
|
47
|
+
_compiler.types.stringLiteral(key),
|
|
48
|
+
targetObject = targetObjects[key] = _compiler.types.objectExpression([])
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
targetProperties = targetObject.properties;
|
|
54
|
+
} else {
|
|
55
|
+
targetProperty = key;
|
|
56
|
+
}
|
|
57
|
+
} else if (
|
|
58
|
+
!preserveName && (
|
|
59
|
+
attrDef.preserveName === true || attrDef.removeDashes === false))
|
|
60
|
+
{
|
|
61
|
+
preserveName = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!preserveName) {
|
|
66
|
+
targetProperty = camelCase(targetProperty);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
foundProperties[targetProperty] = true;
|
|
70
|
+
targetProperties.push(
|
|
71
|
+
_compiler.types.objectProperty(_compiler.types.stringLiteral(targetProperty), value)
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
mergeSpread(properties, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (childLen && !hasAttributeTags) {
|
|
79
|
+
properties.push(
|
|
80
|
+
_compiler.types.objectProperty(
|
|
81
|
+
_compiler.types.stringLiteral("renderBody"),
|
|
82
|
+
_compiler.types.arrowFunctionExpression(
|
|
83
|
+
[_compiler.types.identifier("out"), ...params],
|
|
84
|
+
_compiler.types.blockStatement(body)
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Default parameters
|
|
91
|
+
tagDef &&
|
|
92
|
+
tagDef.forEachAttribute &&
|
|
93
|
+
tagDef.forEachAttribute((attr) => {
|
|
94
|
+
if (foundProperties[attr.name] || attr.dynamicAttribute) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (attr.defaultValue !== undefined) {
|
|
99
|
+
properties.push(
|
|
100
|
+
_compiler.types.objectProperty(
|
|
101
|
+
_compiler.types.stringLiteral(attr.name),
|
|
102
|
+
_compiler.types.stringLiteral(attr.defaultValue + "")
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
} else if (attr.required) {
|
|
106
|
+
throw path.
|
|
107
|
+
get("name").
|
|
108
|
+
buildCodeFrameError(`The "${attr.name}" attribute is required.`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
let attrsObject =
|
|
113
|
+
properties.length === 0 ?
|
|
114
|
+
_compiler.types.nullLiteral() :
|
|
115
|
+
!hasAttributeTags &&
|
|
116
|
+
!isAttrTag &&
|
|
117
|
+
properties.length === 1 &&
|
|
118
|
+
_compiler.types.isSpreadElement(properties[0]) ?
|
|
119
|
+
properties[0].argument :
|
|
120
|
+
_compiler.types.objectExpression(properties);
|
|
121
|
+
|
|
122
|
+
if (hasAttributeTags) {
|
|
123
|
+
let attrTagBody = attributeTags;
|
|
124
|
+
|
|
125
|
+
if (body.length) {
|
|
126
|
+
attrTagBody = attrTagBody.concat(
|
|
127
|
+
_compiler.types.returnStatement(
|
|
128
|
+
_compiler.types.arrowFunctionExpression(
|
|
129
|
+
[_compiler.types.identifier("out"), ...params],
|
|
130
|
+
_compiler.types.blockStatement(body)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const attrTagFn = _compiler.types.arrowFunctionExpression(
|
|
137
|
+
[],
|
|
138
|
+
_compiler.types.blockStatement(attrTagBody)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
attrsObject = _compiler.types.callExpression(
|
|
142
|
+
(0, _babelUtils.importNamed)(
|
|
143
|
+
path.hub.file,
|
|
144
|
+
"marko/src/runtime/helpers/attr-tag.js",
|
|
145
|
+
"i",
|
|
146
|
+
"marko_render_input"
|
|
147
|
+
),
|
|
148
|
+
properties.length === 0 ? [attrTagFn] : [attrTagFn, attrsObject]
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return attrsObject;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildEventHandlerArray(path) {
|
|
156
|
+
const { handlers } = path.node;
|
|
157
|
+
if (!handlers) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return [
|
|
162
|
+
_compiler.types.arrayExpression(
|
|
163
|
+
Object.entries(handlers).map(([eventName, { arguments: args, once }]) => {
|
|
164
|
+
const parts = [
|
|
165
|
+
_compiler.types.stringLiteral(eventName),
|
|
166
|
+
args[0],
|
|
167
|
+
_compiler.types.booleanLiteral(once)];
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if (args.length > 1) {
|
|
171
|
+
parts.push(_compiler.types.arrayExpression(args.slice(1)));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return _compiler.types.arrayExpression(parts);
|
|
175
|
+
})
|
|
176
|
+
)];
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function evaluateAttr(attr) {
|
|
181
|
+
const computed = (0, _babelUtils.computeNode)(attr.node.value);
|
|
182
|
+
if (computed) {
|
|
183
|
+
const { value } = computed;
|
|
184
|
+
switch (attr.node.name) {
|
|
185
|
+
case "class":
|
|
186
|
+
return {
|
|
187
|
+
value: (0, _classValue.default)(value)?.replace(/\s+/, " ").trim()
|
|
188
|
+
};
|
|
189
|
+
case "style":
|
|
190
|
+
return {
|
|
191
|
+
value: (0, _styleValue.default)(value)?.
|
|
192
|
+
replace(/\s+/, " ").
|
|
193
|
+
trim().
|
|
194
|
+
replace(/;$/, "")
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (value == null || value === false) {
|
|
199
|
+
return { value: undefined };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (value === true) {
|
|
203
|
+
return { value: "" };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (typeof value === "object") {
|
|
207
|
+
switch (value.toString) {
|
|
208
|
+
case Object.prototype.toString:
|
|
209
|
+
case Array.prototype.toString:
|
|
210
|
+
return { value: JSON.stringify(value) };
|
|
211
|
+
case RegExp.prototype.toString:
|
|
212
|
+
return { value: value.source };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return { value: value + "" };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function camelCase(string) {
|
|
221
|
+
return string.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function findLastIndex(arr, check) {
|
|
225
|
+
for (let i = arr.length; i--;) {
|
|
226
|
+
if (check(arr[i])) {
|
|
227
|
+
return i;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return -1;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function mergeSpread(properties, value) {
|
|
235
|
+
if (_compiler.types.isObjectExpression(value)) {
|
|
236
|
+
for (const prop of value.properties) {
|
|
237
|
+
if (_compiler.types.isSpreadElement(prop)) {
|
|
238
|
+
mergeSpread(properties, prop.argument);
|
|
239
|
+
} else {
|
|
240
|
+
properties.push(prop);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
properties.push(_compiler.types.spreadElement(value));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.exit = exit;var _babelUtils = require("@marko/compiler/babel-utils");
|
|
2
|
+
|
|
3
|
+
var _util = require("./util");
|
|
4
|
+
|
|
5
|
+
function exit(path) {
|
|
6
|
+
(0, _babelUtils.assertNoAttributes)(path);
|
|
7
|
+
|
|
8
|
+
const { ifStatement, arguments: args } = path.node;
|
|
9
|
+
|
|
10
|
+
if (!ifStatement) {
|
|
11
|
+
throw path.
|
|
12
|
+
get("name").
|
|
13
|
+
buildCodeFrameError(
|
|
14
|
+
"Invalid 'else-if' tag, expected preceding 'if' or 'else-if' tag."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ifStatement.alternate = (0, _util.buildIfStatement)(path, args);
|
|
19
|
+
path.remove();
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.exit = exit;var _compiler = require("@marko/compiler");
|
|
2
|
+
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
3
|
+
|
|
4
|
+
function exit(path) {
|
|
5
|
+
(0, _babelUtils.assertNoArgs)(path);
|
|
6
|
+
(0, _babelUtils.assertNoAttributes)(path);
|
|
7
|
+
|
|
8
|
+
const { ifStatement } = path.node;
|
|
9
|
+
|
|
10
|
+
if (!ifStatement) {
|
|
11
|
+
throw path.
|
|
12
|
+
get("name").
|
|
13
|
+
buildCodeFrameError(
|
|
14
|
+
"Invalid 'else' tag, expected preceding 'if' or 'else-if' tag."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ifStatement.alternate = _compiler.types.blockStatement(path.node.body.body);
|
|
19
|
+
path.remove();
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.exit = exit;var _babelUtils = require("@marko/compiler/babel-utils");
|
|
2
|
+
|
|
3
|
+
var _util = require("./util");
|
|
4
|
+
|
|
5
|
+
function exit(path) {
|
|
6
|
+
(0, _babelUtils.assertNoAttributes)(path);
|
|
7
|
+
path.replaceWith((0, _util.buildIfStatement)(path, path.node.arguments));
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.buildIfStatement = buildIfStatement;var _compiler = require("@marko/compiler");
|
|
2
|
+
|
|
3
|
+
var _withPreviousLocation = _interopRequireDefault(require("../../../util/with-previous-location"));
|
|
4
|
+
|
|
5
|
+
function buildIfStatement(path, args) {
|
|
6
|
+
if (!args || !args.length) {
|
|
7
|
+
const name = path.get("name");
|
|
8
|
+
throw name.buildCodeFrameError(
|
|
9
|
+
`Invalid '<${name.node.value}>' tag, expected arguments like '<${name.node.value}(test)>'.`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ifStatement = _compiler.types.ifStatement(
|
|
14
|
+
args.length === 1 ? args[0] : _compiler.types.sequenceExpression(args),
|
|
15
|
+
_compiler.types.blockStatement(path.node.body.body)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
let nextPath = path.getNextSibling();
|
|
19
|
+
|
|
20
|
+
while (
|
|
21
|
+
nextPath.isMarkoComment() ||
|
|
22
|
+
nextPath.isMarkoText() && /^\s*$/.test(nextPath.node.value))
|
|
23
|
+
{
|
|
24
|
+
const ignorePath = nextPath;
|
|
25
|
+
nextPath = nextPath.getNextSibling();
|
|
26
|
+
ignorePath.remove();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Provide the if statement to the next part of the if chain.
|
|
30
|
+
if (nextPath.isMarkoTag()) {
|
|
31
|
+
const nextTagName = nextPath.get("name");
|
|
32
|
+
if (
|
|
33
|
+
nextTagName.isStringLiteral({ value: "else" }) ||
|
|
34
|
+
nextTagName.isStringLiteral({ value: "else-if" }))
|
|
35
|
+
{
|
|
36
|
+
nextPath.node.ifStatement = ifStatement;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (0, _withPreviousLocation.default)(ifStatement, path.node);
|
|
41
|
+
}
|