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,74 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import { importDefault } from "@marko/compiler/babel-utils";
|
|
3
|
+
|
|
4
|
+
import withPreviousLocation from "../util/with-previous-location";
|
|
5
|
+
import { buildEventHandlerArray, getAttrs } from "./util";
|
|
6
|
+
|
|
7
|
+
export default function (path) {
|
|
8
|
+
const {
|
|
9
|
+
node,
|
|
10
|
+
hub: { file },
|
|
11
|
+
} = path;
|
|
12
|
+
const tagProperties = (path.node.extra && path.node.extra.properties) || [];
|
|
13
|
+
const { key, arguments: args } = node;
|
|
14
|
+
const foundAttrs = getAttrs(path, true);
|
|
15
|
+
let renderBodyProp;
|
|
16
|
+
let attrsLen = t.isNullLiteral(foundAttrs) ? 0 : 1;
|
|
17
|
+
|
|
18
|
+
if (node.preserveAttrs) {
|
|
19
|
+
tagProperties.push(
|
|
20
|
+
t.objectProperty(
|
|
21
|
+
t.identifier("pa"),
|
|
22
|
+
t.objectExpression(
|
|
23
|
+
node.preserveAttrs.map((name) =>
|
|
24
|
+
t.objectProperty(
|
|
25
|
+
t.isValidIdentifier(name)
|
|
26
|
+
? t.identifier(name)
|
|
27
|
+
: t.stringLiteral(name),
|
|
28
|
+
t.numericLiteral(1),
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (t.isObjectExpression(foundAttrs)) {
|
|
37
|
+
const renderBodyIndex = foundAttrs.properties.findIndex(
|
|
38
|
+
(prop) => prop.key && prop.key.value === "renderBody",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
attrsLen = foundAttrs.properties.length;
|
|
42
|
+
|
|
43
|
+
if (renderBodyIndex > -1) {
|
|
44
|
+
renderBodyProp = foundAttrs.properties[renderBodyIndex];
|
|
45
|
+
foundAttrs.properties.splice(renderBodyIndex, 1);
|
|
46
|
+
attrsLen--;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const dynamicTagRenderCall = t.expressionStatement(
|
|
51
|
+
t.callExpression(
|
|
52
|
+
importDefault(
|
|
53
|
+
file,
|
|
54
|
+
`marko/src/runtime/helpers/dynamic-tag.js`,
|
|
55
|
+
"marko_dynamic_tag",
|
|
56
|
+
),
|
|
57
|
+
[
|
|
58
|
+
t.identifier("out"),
|
|
59
|
+
node.name,
|
|
60
|
+
attrsLen ? t.arrowFunctionExpression([], foundAttrs) : t.nullLiteral(),
|
|
61
|
+
renderBodyProp ? renderBodyProp.value : t.nullLiteral(),
|
|
62
|
+
args && args.length ? t.arrayExpression(args) : t.nullLiteral(),
|
|
63
|
+
tagProperties.length
|
|
64
|
+
? t.objectExpression(tagProperties)
|
|
65
|
+
: t.nullLiteral(),
|
|
66
|
+
file._componentDefIdentifier,
|
|
67
|
+
key,
|
|
68
|
+
...buildEventHandlerArray(path),
|
|
69
|
+
],
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
path.replaceWith(withPreviousLocation(dynamicTagRenderCall, node));
|
|
74
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
assertNoVar,
|
|
4
|
+
findAttributeTags,
|
|
5
|
+
getTagDef,
|
|
6
|
+
isAttributeTag,
|
|
7
|
+
isDynamicTag,
|
|
8
|
+
isMacroTag,
|
|
9
|
+
isNativeTag,
|
|
10
|
+
isTransparentTag,
|
|
11
|
+
resolveTagImport,
|
|
12
|
+
} from "@marko/compiler/babel-utils";
|
|
13
|
+
import nodePath from "path";
|
|
14
|
+
|
|
15
|
+
import { getKeyManager } from "../util/key-manager";
|
|
16
|
+
import { optimizeStaticVDOM } from "../util/optimize-vdom-create";
|
|
17
|
+
import { enter, exit } from "../util/plugin-hooks";
|
|
18
|
+
import attributeTranslators from "./attribute";
|
|
19
|
+
import attributeTag, { analyzeAttributeTags } from "./attribute-tag";
|
|
20
|
+
import customTag from "./custom-tag";
|
|
21
|
+
import dynamicTag from "./dynamic-tag";
|
|
22
|
+
import macroTag from "./macro-tag";
|
|
23
|
+
import nativeTag from "./native-tag";
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
enter(path) {
|
|
27
|
+
const tagDef = getTagDef(path);
|
|
28
|
+
|
|
29
|
+
if (tagDef && tagDef.translator) {
|
|
30
|
+
const { node } = path;
|
|
31
|
+
enter(tagDef.translator.hook, path, t);
|
|
32
|
+
|
|
33
|
+
if (path.node !== node) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
assertNoVar(path);
|
|
39
|
+
|
|
40
|
+
for (const attr of path.get("attributes")) {
|
|
41
|
+
if (attr.isMarkoAttribute()) {
|
|
42
|
+
const { node } = path;
|
|
43
|
+
attributeTranslators.enter(attr);
|
|
44
|
+
if (path.node !== node) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!isAttributeTag(path)) {
|
|
51
|
+
if (
|
|
52
|
+
!tagDef &&
|
|
53
|
+
path.hub.file.markoOpts.ignoreUnrecognizedTags &&
|
|
54
|
+
(path.node.attributeTags.length || path.node.body.attributeTags) &&
|
|
55
|
+
!isDynamicTag(path)
|
|
56
|
+
) {
|
|
57
|
+
moveIgnoredAttrTags(path);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (isDynamicTag(path) || !(isMacroTag(path) || isNativeTag(path))) {
|
|
61
|
+
analyzeAttributeTags(path);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getKeyManager(path).resolveKey(path);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
optimizeStaticVDOM(path);
|
|
68
|
+
},
|
|
69
|
+
exit(path) {
|
|
70
|
+
let isUnknownDynamic = false;
|
|
71
|
+
let isDynamicNullable = false;
|
|
72
|
+
|
|
73
|
+
if (isDynamicTag(path)) {
|
|
74
|
+
const name = path.get("name");
|
|
75
|
+
const types = findDynamicTagTypes(name);
|
|
76
|
+
if (types && !(types.string && types.component)) {
|
|
77
|
+
if (!name.isIdentifier()) {
|
|
78
|
+
const tagIdentifier = path.scope.generateUidIdentifier(`tagName`);
|
|
79
|
+
path.insertBefore(
|
|
80
|
+
t.variableDeclaration("const", [
|
|
81
|
+
t.variableDeclarator(tagIdentifier, name.node),
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
name.replaceWith(tagIdentifier);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
isDynamicNullable = types.empty;
|
|
89
|
+
path.node._isDynamicString = types.string;
|
|
90
|
+
} else {
|
|
91
|
+
isUnknownDynamic = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const attr of path.get("attributes")) {
|
|
96
|
+
if (attr.isMarkoAttribute()) {
|
|
97
|
+
const { node } = path;
|
|
98
|
+
attributeTranslators.exit(attr);
|
|
99
|
+
if (path.node !== node) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (isUnknownDynamic) {
|
|
106
|
+
return dynamicTag(path);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isAttributeTag(path)) {
|
|
110
|
+
return attributeTag(path);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (isMacroTag(path)) {
|
|
114
|
+
return macroTag(path);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const tagDef = getTagDef(path);
|
|
118
|
+
|
|
119
|
+
if (tagDef && tagDef.translator) {
|
|
120
|
+
const { node } = path;
|
|
121
|
+
|
|
122
|
+
exit(tagDef.translator.hook, path, t);
|
|
123
|
+
|
|
124
|
+
if (path.node !== node) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (isNativeTag(path)) {
|
|
130
|
+
return nativeTag(path, isDynamicNullable);
|
|
131
|
+
} else {
|
|
132
|
+
return customTag(path, isDynamicNullable);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const HANDLE_BINDINGS = ["module", "var", "let", "const"];
|
|
138
|
+
function findDynamicTagTypes(root) {
|
|
139
|
+
const pending = [root];
|
|
140
|
+
const types = {
|
|
141
|
+
string: false,
|
|
142
|
+
empty: false,
|
|
143
|
+
component: false,
|
|
144
|
+
};
|
|
145
|
+
let tagNameImported;
|
|
146
|
+
|
|
147
|
+
let path;
|
|
148
|
+
while ((path = pending.pop())) {
|
|
149
|
+
switch (path.type) {
|
|
150
|
+
case "ConditionalExpression":
|
|
151
|
+
pending.push(path.get("consequent"));
|
|
152
|
+
|
|
153
|
+
if (path.get("alternate").node) {
|
|
154
|
+
pending.push(path.get("alternate"));
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
|
|
158
|
+
case "LogicalExpression":
|
|
159
|
+
if (path.get("operator").node === "||") {
|
|
160
|
+
pending.push(path.get("left"));
|
|
161
|
+
} else {
|
|
162
|
+
types.empty = true;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pending.push(path.get("right"));
|
|
166
|
+
break;
|
|
167
|
+
|
|
168
|
+
case "AssignmentExpression":
|
|
169
|
+
pending.push(path.get("right"));
|
|
170
|
+
break;
|
|
171
|
+
|
|
172
|
+
case "BinaryExpression":
|
|
173
|
+
if (path.get("operator").node !== "+") {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
types.string = true;
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
case "StringLiteral":
|
|
181
|
+
case "TemplateLiteral":
|
|
182
|
+
types.string = true;
|
|
183
|
+
break;
|
|
184
|
+
|
|
185
|
+
case "NullLiteral":
|
|
186
|
+
types.empty = true;
|
|
187
|
+
break;
|
|
188
|
+
|
|
189
|
+
case "Identifier":
|
|
190
|
+
if (path.get("name").node === "undefined") {
|
|
191
|
+
types.empty = true;
|
|
192
|
+
} else {
|
|
193
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
194
|
+
|
|
195
|
+
if (!binding || !HANDLE_BINDINGS.includes(binding.kind)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (binding.kind === "module") {
|
|
200
|
+
const importSource = binding.path.parent.source;
|
|
201
|
+
if (
|
|
202
|
+
t.isStringLiteral(importSource) &&
|
|
203
|
+
isMarkoFile(importSource.value)
|
|
204
|
+
) {
|
|
205
|
+
const resolvedImport =
|
|
206
|
+
resolveTagImport(root.parentPath, importSource.value) ||
|
|
207
|
+
importSource.value;
|
|
208
|
+
|
|
209
|
+
if (tagNameImported === undefined) {
|
|
210
|
+
tagNameImported = resolvedImport;
|
|
211
|
+
} else if (
|
|
212
|
+
tagNameImported &&
|
|
213
|
+
tagNameImported !== resolvedImport
|
|
214
|
+
) {
|
|
215
|
+
tagNameImported = null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
types.component = true;
|
|
219
|
+
} else {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
const initialValue = binding.path.get("init");
|
|
224
|
+
if (initialValue.node) {
|
|
225
|
+
pending.push(initialValue);
|
|
226
|
+
} else {
|
|
227
|
+
types.empty = true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const assignments = binding.constantViolations;
|
|
231
|
+
if (assignments && assignments.length) {
|
|
232
|
+
for (const assignment of assignments) {
|
|
233
|
+
const operator = assignment.get("operator").node;
|
|
234
|
+
if (operator === "=") {
|
|
235
|
+
pending.push(assignment.get("right"));
|
|
236
|
+
} else if (operator === "+=") {
|
|
237
|
+
types.string = true;
|
|
238
|
+
} else {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
|
|
247
|
+
default:
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (tagNameImported && !types.string) {
|
|
253
|
+
(root.parent.extra ??= {}).tagNameImported = tagNameImported;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return types;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isMarkoFile(request) {
|
|
260
|
+
return nodePath.extname(request) === ".marko" || /^<.*>$/.test(request);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function moveIgnoredAttrTags(parentTag) {
|
|
264
|
+
const attrTags = parentTag.node.body.attributeTags
|
|
265
|
+
? parentTag.get("body").get("body")
|
|
266
|
+
: parentTag.get("attributeTags");
|
|
267
|
+
|
|
268
|
+
if (!attrTags.length) return;
|
|
269
|
+
|
|
270
|
+
for (const attrTag of attrTags) {
|
|
271
|
+
if (attrTag.isMarkoTag()) {
|
|
272
|
+
if (isAttributeTag(attrTag)) {
|
|
273
|
+
attrTag.set(
|
|
274
|
+
"name",
|
|
275
|
+
t.stringLiteral(`at_${attrTag.get("name.value").node.slice(1)}`),
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
moveIgnoredAttrTags(attrTag);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
parentTag.node.body.body = parentTag.node.attributeTags.concat(
|
|
284
|
+
parentTag.node.body.body,
|
|
285
|
+
);
|
|
286
|
+
parentTag.node.attributeTags = [];
|
|
287
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNoArgs,
|
|
3
|
+
assertNoAttributeTags,
|
|
4
|
+
assertNoParams,
|
|
5
|
+
} from "@marko/compiler/babel-utils";
|
|
6
|
+
|
|
7
|
+
import nativeTagHtml from "./native-tag[html]";
|
|
8
|
+
import nativeTagVdom from "./native-tag[vdom]";
|
|
9
|
+
|
|
10
|
+
export default function (path, isNullable) {
|
|
11
|
+
const {
|
|
12
|
+
hub: { file },
|
|
13
|
+
} = path;
|
|
14
|
+
const { markoOpts } = file;
|
|
15
|
+
|
|
16
|
+
if (!markoOpts.ignoreUnrecognizedTags) {
|
|
17
|
+
assertNoArgs(path);
|
|
18
|
+
assertNoParams(path);
|
|
19
|
+
assertNoAttributeTags(path);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (markoOpts.output === "html") {
|
|
23
|
+
nativeTagHtml(path, isNullable);
|
|
24
|
+
} else {
|
|
25
|
+
nativeTagVdom(path, isNullable);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
importDefault,
|
|
4
|
+
importNamed,
|
|
5
|
+
normalizeTemplateString,
|
|
6
|
+
} from "@marko/compiler/babel-utils";
|
|
7
|
+
import attrHelper from "marko/src/runtime/html/helpers/attr";
|
|
8
|
+
import { d as escapeDoubleQuotes } from "marko/src/runtime/html/helpers/escape-quotes";
|
|
9
|
+
|
|
10
|
+
import { evaluateAttr } from "../util";
|
|
11
|
+
|
|
12
|
+
export default function (path, attrs) {
|
|
13
|
+
const len = attrs.length;
|
|
14
|
+
if (len === 0) return t.stringLiteral("");
|
|
15
|
+
if (len === 1 && attrs[0].node.type === "MarkoSpreadAttribute") {
|
|
16
|
+
return t.callExpression(
|
|
17
|
+
importDefault(
|
|
18
|
+
path.hub.file,
|
|
19
|
+
"marko/src/runtime/html/helpers/attrs.js",
|
|
20
|
+
"marko_attrs",
|
|
21
|
+
),
|
|
22
|
+
[attrs[0].node.value],
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (attrs.some((attr) => attr.node.type === "MarkoSpreadAttribute")) {
|
|
27
|
+
const attrsObjects = [];
|
|
28
|
+
let props;
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < len; i++) {
|
|
31
|
+
const attr = attrs[i];
|
|
32
|
+
const {
|
|
33
|
+
node: { name, value },
|
|
34
|
+
} = attr;
|
|
35
|
+
|
|
36
|
+
if (name) {
|
|
37
|
+
const computed = evaluateAttr(attr);
|
|
38
|
+
const prop = t.objectProperty(
|
|
39
|
+
t.stringLiteral(name),
|
|
40
|
+
computed?.value !== undefined
|
|
41
|
+
? t.stringLiteral(computed.value)
|
|
42
|
+
: value,
|
|
43
|
+
);
|
|
44
|
+
if (props) {
|
|
45
|
+
props.push(prop);
|
|
46
|
+
} else {
|
|
47
|
+
attrsObjects.push(t.objectExpression((props = [prop])));
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
attrsObjects.push(value);
|
|
51
|
+
props = undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return t.callExpression(
|
|
56
|
+
importDefault(
|
|
57
|
+
path.hub.file,
|
|
58
|
+
"marko/src/runtime/html/helpers/merge-attrs.js",
|
|
59
|
+
"marko_merge_attrs",
|
|
60
|
+
),
|
|
61
|
+
attrsObjects,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const file = path.hub.file;
|
|
66
|
+
const quasis = [];
|
|
67
|
+
const expressions = [];
|
|
68
|
+
const attrValues = new Map();
|
|
69
|
+
let curString = "";
|
|
70
|
+
|
|
71
|
+
// Remove duplicate attrs so last one wins.
|
|
72
|
+
for (let i = len; i--; ) {
|
|
73
|
+
const attr = attrs[i];
|
|
74
|
+
const { name, value } = attr.node;
|
|
75
|
+
if (attrValues.has(name)) continue;
|
|
76
|
+
const computed = evaluateAttr(attr);
|
|
77
|
+
attrValues.set(
|
|
78
|
+
name,
|
|
79
|
+
computed
|
|
80
|
+
? {
|
|
81
|
+
confident: true,
|
|
82
|
+
computed: computed.value,
|
|
83
|
+
value,
|
|
84
|
+
}
|
|
85
|
+
: {
|
|
86
|
+
confident: false,
|
|
87
|
+
computed: undefined,
|
|
88
|
+
value,
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const [name, { confident, computed, value }] of [
|
|
94
|
+
...attrValues,
|
|
95
|
+
].reverse()) {
|
|
96
|
+
if (confident) {
|
|
97
|
+
if (computed == null || computed === false) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
curString += attrHelper(name, computed);
|
|
102
|
+
} else if (value.type === "TemplateLiteral") {
|
|
103
|
+
curString += " " + name + '="';
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < value.expressions.length; i++) {
|
|
106
|
+
const quasi = value.quasis[i];
|
|
107
|
+
const expression = value.expressions[i];
|
|
108
|
+
curString += escapeDoubleQuotes(quasi.value.cooked);
|
|
109
|
+
quasis.push(curString);
|
|
110
|
+
curString = "";
|
|
111
|
+
expressions.push(
|
|
112
|
+
t.callExpression(
|
|
113
|
+
importNamed(
|
|
114
|
+
file,
|
|
115
|
+
"marko/src/runtime/html/helpers/escape-quotes.js",
|
|
116
|
+
"d",
|
|
117
|
+
"marko_escape_double_quotes",
|
|
118
|
+
),
|
|
119
|
+
[expression],
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
curString +=
|
|
125
|
+
escapeDoubleQuotes(
|
|
126
|
+
value.quasis[value.expressions.length].value.cooked,
|
|
127
|
+
) + '"';
|
|
128
|
+
} else {
|
|
129
|
+
quasis.push(curString);
|
|
130
|
+
curString = "";
|
|
131
|
+
expressions.push(
|
|
132
|
+
t.callExpression(
|
|
133
|
+
importDefault(
|
|
134
|
+
file,
|
|
135
|
+
"marko/src/runtime/html/helpers/attr.js",
|
|
136
|
+
"marko_attr",
|
|
137
|
+
),
|
|
138
|
+
[t.stringLiteral(name), value],
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
quasis.push(curString);
|
|
145
|
+
|
|
146
|
+
if (expressions.length) {
|
|
147
|
+
return normalizeTemplateString(quasis, ...expressions);
|
|
148
|
+
} else {
|
|
149
|
+
return t.stringLiteral(quasis.join(""));
|
|
150
|
+
}
|
|
151
|
+
}
|