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,66 @@
|
|
|
1
|
+
import { getStart } from "@marko/compiler/babel-utils";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import getComponentFiles from "../../util/get-component-files";
|
|
5
|
+
|
|
6
|
+
const STYLE_REG = /^style((?:\.[^.\s\\/:*?"<>|({]+)+)?\s*\{/;
|
|
7
|
+
|
|
8
|
+
export default function (tag) {
|
|
9
|
+
const { hub, node } = tag;
|
|
10
|
+
const { deps } = hub.file.metadata.marko;
|
|
11
|
+
const { rawValue } = node;
|
|
12
|
+
const matchedBlock = STYLE_REG.exec(rawValue);
|
|
13
|
+
if (!matchedBlock) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!tag.parentPath.isProgram()) {
|
|
18
|
+
throw tag
|
|
19
|
+
.get("name")
|
|
20
|
+
.buildCodeFrameError(
|
|
21
|
+
"Style blocks must be at the root of your Marko template.",
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (deps.some((dep) => dep.style)) {
|
|
26
|
+
throw tag
|
|
27
|
+
.get("name")
|
|
28
|
+
.buildCodeFrameError(
|
|
29
|
+
"A Marko file can only contain a single inline style block.",
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (getComponentFiles(tag).styleFile) {
|
|
34
|
+
throw tag
|
|
35
|
+
.get("name")
|
|
36
|
+
.buildCodeFrameError(
|
|
37
|
+
'A Marko file can either have an inline style block, or an external "style.ext" file, but not both.',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const [startContent, type = ".css"] = matchedBlock;
|
|
42
|
+
const codeSartOffset = startContent.length;
|
|
43
|
+
const codeEndOffset = rawValue.lastIndexOf("}");
|
|
44
|
+
const code = rawValue.slice(codeSartOffset, codeEndOffset);
|
|
45
|
+
const base = path.basename(hub.file.opts.filename);
|
|
46
|
+
const start = getStart(hub.file, node.name);
|
|
47
|
+
let startPos = undefined;
|
|
48
|
+
let endPos = undefined;
|
|
49
|
+
|
|
50
|
+
if (start !== null) {
|
|
51
|
+
startPos = start + codeSartOffset;
|
|
52
|
+
endPos = start + codeEndOffset;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
deps.push({
|
|
56
|
+
type: type.slice(1),
|
|
57
|
+
code,
|
|
58
|
+
style: true,
|
|
59
|
+
startPos,
|
|
60
|
+
endPos,
|
|
61
|
+
path: `./${base}`,
|
|
62
|
+
virtualPath: `./${base + type}`,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
tag.remove();
|
|
66
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
|
|
3
|
+
export function enter(path) {
|
|
4
|
+
const args = path.get("arguments");
|
|
5
|
+
|
|
6
|
+
if (!args.length) {
|
|
7
|
+
throw path
|
|
8
|
+
.get("name")
|
|
9
|
+
.buildCodeFrameError(
|
|
10
|
+
'You must provide a promise argument to the "<await>" tag, eg: "<await(promise)>".',
|
|
11
|
+
);
|
|
12
|
+
} else if (args.length > 1) {
|
|
13
|
+
const {
|
|
14
|
+
loc: { start },
|
|
15
|
+
} = args[1].node;
|
|
16
|
+
const {
|
|
17
|
+
loc: { end },
|
|
18
|
+
} = args[args.length - 1].node;
|
|
19
|
+
throw path.hub.file.buildCodeFrameError(
|
|
20
|
+
{ loc: { start, end } },
|
|
21
|
+
'You can only pass one argument to the "<await>" tag.',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [provider] = args;
|
|
26
|
+
path.pushContainer(
|
|
27
|
+
"attributes",
|
|
28
|
+
t.markoAttribute("_provider", provider.node),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
!path.get("attributes").some((attr) => attr.get("name").node === "name")
|
|
33
|
+
) {
|
|
34
|
+
path.pushContainer(
|
|
35
|
+
"attributes",
|
|
36
|
+
t.markoAttribute("_name", t.stringLiteral(provider.toString())),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
path.set("arguments", undefined);
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
|
|
3
|
+
export function enter(path) {
|
|
4
|
+
if (path.hub.file.markoOpts.output === "html") {
|
|
5
|
+
const body = path.get("body");
|
|
6
|
+
|
|
7
|
+
body.pushContainer("body", [
|
|
8
|
+
t.markoTag(t.stringLiteral("init-components"), [], t.markoTagBody()),
|
|
9
|
+
t.markoTag(t.stringLiteral("await-reorderer"), [], t.markoTagBody()),
|
|
10
|
+
t.markoTag(
|
|
11
|
+
t.stringLiteral("_preferred-script-location"),
|
|
12
|
+
[],
|
|
13
|
+
t.markoTagBody(),
|
|
14
|
+
),
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
assertAllowedAttributes,
|
|
4
|
+
importDefault,
|
|
5
|
+
} from "@marko/compiler/babel-utils";
|
|
6
|
+
|
|
7
|
+
export function exit(path) {
|
|
8
|
+
const { node } = path;
|
|
9
|
+
const {
|
|
10
|
+
attributes,
|
|
11
|
+
body: { params },
|
|
12
|
+
} = node;
|
|
13
|
+
const body = node.body.body;
|
|
14
|
+
const namePath = path.get("name");
|
|
15
|
+
const ofAttr = findName(attributes, "of");
|
|
16
|
+
const inAttr = findName(attributes, "in");
|
|
17
|
+
const fromAttr = findName(attributes, "from");
|
|
18
|
+
const toAttr = findName(attributes, "to");
|
|
19
|
+
const block = t.blockStatement(body);
|
|
20
|
+
let forNode;
|
|
21
|
+
let allowedAttributes = ["by"];
|
|
22
|
+
|
|
23
|
+
if (inAttr) {
|
|
24
|
+
allowedAttributes.push("in");
|
|
25
|
+
|
|
26
|
+
const [keyParam, valParam] = params;
|
|
27
|
+
|
|
28
|
+
if (!keyParam) {
|
|
29
|
+
throw namePath.buildCodeFrameError(
|
|
30
|
+
"Invalid 'for in' tag, missing |key, value| params.",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (valParam) {
|
|
35
|
+
block.body.unshift(
|
|
36
|
+
t.variableDeclaration("const", [
|
|
37
|
+
t.variableDeclarator(
|
|
38
|
+
valParam,
|
|
39
|
+
t.memberExpression(inAttr.value, keyParam, true),
|
|
40
|
+
),
|
|
41
|
+
]),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
forNode = t.forInStatement(
|
|
46
|
+
t.variableDeclaration("const", [t.variableDeclarator(keyParam)]),
|
|
47
|
+
inAttr.value,
|
|
48
|
+
block,
|
|
49
|
+
);
|
|
50
|
+
} else if (ofAttr) {
|
|
51
|
+
let ofAttrValue = t.callExpression(
|
|
52
|
+
importDefault(
|
|
53
|
+
path.hub.file,
|
|
54
|
+
"marko/src/runtime/helpers/of-fallback.js",
|
|
55
|
+
"of_fallback",
|
|
56
|
+
),
|
|
57
|
+
[ofAttr.value],
|
|
58
|
+
);
|
|
59
|
+
allowedAttributes.push("of");
|
|
60
|
+
|
|
61
|
+
const [valParam, keyParam, loopParam] = params;
|
|
62
|
+
|
|
63
|
+
if (!valParam) {
|
|
64
|
+
throw namePath.buildCodeFrameError(
|
|
65
|
+
"Invalid 'for of' tag, missing |value, index| params.",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
forNode = [];
|
|
70
|
+
|
|
71
|
+
if (keyParam) {
|
|
72
|
+
const indexName = path.scope.generateUidIdentifier(keyParam.name);
|
|
73
|
+
forNode.push(
|
|
74
|
+
t.variableDeclaration("let", [
|
|
75
|
+
t.variableDeclarator(indexName, t.numericLiteral(0)),
|
|
76
|
+
]),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
block.body.unshift(
|
|
80
|
+
t.variableDeclaration("let", [
|
|
81
|
+
t.variableDeclarator(keyParam, t.updateExpression("++", indexName)),
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (loopParam) {
|
|
87
|
+
ofAttrValue = loopParam;
|
|
88
|
+
forNode.push(
|
|
89
|
+
t.variableDeclaration("const", [
|
|
90
|
+
t.variableDeclarator(loopParam, ofAttr.value),
|
|
91
|
+
]),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
forNode.push(
|
|
96
|
+
t.forOfStatement(
|
|
97
|
+
t.variableDeclaration("const", [t.variableDeclarator(valParam)]),
|
|
98
|
+
ofAttrValue,
|
|
99
|
+
block,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
} else if (fromAttr && toAttr) {
|
|
103
|
+
allowedAttributes.push("from", "to", "step");
|
|
104
|
+
|
|
105
|
+
const stepAttr = findName(attributes, "step") || {
|
|
106
|
+
value: t.numericLiteral(1),
|
|
107
|
+
};
|
|
108
|
+
const stepValue = stepAttr ? stepAttr.value : t.numericLiteral(1);
|
|
109
|
+
const [indexParam] = params;
|
|
110
|
+
const stepsName = path.scope.generateUidIdentifier("steps");
|
|
111
|
+
const stepName = path.scope.generateUidIdentifier("step");
|
|
112
|
+
|
|
113
|
+
if (indexParam) {
|
|
114
|
+
block.body.unshift(
|
|
115
|
+
t.variableDeclaration("const", [
|
|
116
|
+
t.variableDeclarator(
|
|
117
|
+
indexParam,
|
|
118
|
+
t.binaryExpression(
|
|
119
|
+
"+",
|
|
120
|
+
fromAttr.value,
|
|
121
|
+
t.binaryExpression("*", stepName, stepValue),
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
]),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
forNode = t.forStatement(
|
|
129
|
+
t.variableDeclaration("let", [
|
|
130
|
+
t.variableDeclarator(
|
|
131
|
+
stepsName,
|
|
132
|
+
t.binaryExpression(
|
|
133
|
+
"/",
|
|
134
|
+
t.binaryExpression("-", toAttr.value, fromAttr.value),
|
|
135
|
+
stepValue,
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
t.variableDeclarator(stepName, t.numericLiteral(0)),
|
|
139
|
+
]),
|
|
140
|
+
t.binaryExpression("<=", stepName, stepsName),
|
|
141
|
+
t.updateExpression("++", stepName),
|
|
142
|
+
block,
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
throw namePath.buildCodeFrameError(
|
|
146
|
+
"Invalid 'for' tag, missing an 'of', 'in' or 'to' attribute.",
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
assertAllowedAttributes(path, allowedAttributes);
|
|
151
|
+
path.replaceWithMultiple([].concat(forNode));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function findName(arr, value) {
|
|
155
|
+
return arr.find((obj) => obj.name === value);
|
|
156
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
assertNoArgs,
|
|
4
|
+
assertNoAttributes,
|
|
5
|
+
assertNoParams,
|
|
6
|
+
} from "@marko/compiler/babel-utils";
|
|
7
|
+
|
|
8
|
+
import writeHTML from "../../util/html-out-write";
|
|
9
|
+
import writeVDOM from "../../util/vdom-out-write";
|
|
10
|
+
import withPreviousLocation from "../../util/with-previous-location";
|
|
11
|
+
|
|
12
|
+
export function enter(path) {
|
|
13
|
+
assertNoArgs(path);
|
|
14
|
+
assertNoParams(path);
|
|
15
|
+
assertNoAttributes(path);
|
|
16
|
+
|
|
17
|
+
if (path.hub.file.markoOpts.output === "html") {
|
|
18
|
+
path.replaceWithMultiple([
|
|
19
|
+
writeHTML`<!--`,
|
|
20
|
+
...path.node.body.body,
|
|
21
|
+
writeHTML`-->`,
|
|
22
|
+
]);
|
|
23
|
+
} else {
|
|
24
|
+
const templateQuasis = [];
|
|
25
|
+
const templateExpressions = [];
|
|
26
|
+
let currentQuasi = "";
|
|
27
|
+
for (const child of path.node.body.body) {
|
|
28
|
+
if (t.isMarkoText(child)) {
|
|
29
|
+
currentQuasi += child.value;
|
|
30
|
+
} else if (t.isMarkoPlaceholder(child)) {
|
|
31
|
+
templateQuasis.push(t.templateElement({ raw: currentQuasi }));
|
|
32
|
+
templateExpressions.push(child.value);
|
|
33
|
+
currentQuasi = "";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let value;
|
|
38
|
+
if (templateExpressions.length === 0) {
|
|
39
|
+
value = t.stringLiteral(currentQuasi);
|
|
40
|
+
} else {
|
|
41
|
+
templateQuasis.push(t.templateElement({ raw: currentQuasi }));
|
|
42
|
+
value = t.templateLiteral(templateQuasis, templateExpressions);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
path.replaceWith(
|
|
46
|
+
withPreviousLocation(
|
|
47
|
+
writeVDOM("comment", value, path.hub.file._componentInstanceIdentifier),
|
|
48
|
+
path.node,
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
assertNoAttributes,
|
|
4
|
+
assertNoParams,
|
|
5
|
+
} from "@marko/compiler/babel-utils";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
export function enter(tag) {
|
|
9
|
+
const {
|
|
10
|
+
hub: { file },
|
|
11
|
+
} = tag;
|
|
12
|
+
assertNoParams(tag);
|
|
13
|
+
assertNoAttributes(tag);
|
|
14
|
+
|
|
15
|
+
const fs = file.markoOpts.fileSystem;
|
|
16
|
+
const tagName = tag.get("name").node.value;
|
|
17
|
+
const tagExample = `<${tagName}("./path-to-file.ext")>`;
|
|
18
|
+
const args = tag.get("arguments");
|
|
19
|
+
|
|
20
|
+
if (args.length !== 1) {
|
|
21
|
+
throw tag.buildCodeFrameError(
|
|
22
|
+
`A single path argument is required for ${tagExample}.`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const [content] = args;
|
|
27
|
+
|
|
28
|
+
if (!content.isStringLiteral()) {
|
|
29
|
+
throw content.buildCodeFrameError(
|
|
30
|
+
`The argument to ${tagExample} must be a static string.`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const dir = path.dirname(file.opts.filename);
|
|
35
|
+
const fullPath = path.resolve(dir, content.node.value);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const stat = fs.statSync(fullPath);
|
|
39
|
+
|
|
40
|
+
if (!stat.isFile()) {
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
throw content.buildCodeFrameError(`Unable to find file for <${tagName}>.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
tag.replaceWith(
|
|
48
|
+
t.markoPlaceholder(
|
|
49
|
+
t.stringLiteral(fs.readFileSync(fullPath).toString("utf-8")),
|
|
50
|
+
tagName === "include-text",
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import {
|
|
3
|
+
assertNoAttributes,
|
|
4
|
+
assertNoParams,
|
|
5
|
+
getArgOrSequence,
|
|
6
|
+
} from "@marko/compiler/babel-utils";
|
|
7
|
+
|
|
8
|
+
import withPreviousLocation from "../../util/with-previous-location";
|
|
9
|
+
|
|
10
|
+
export function exit(path) {
|
|
11
|
+
assertNoParams(path);
|
|
12
|
+
assertNoAttributes(path);
|
|
13
|
+
const arg = getArgOrSequence(path);
|
|
14
|
+
|
|
15
|
+
if (!arg) {
|
|
16
|
+
throw path
|
|
17
|
+
.get("name")
|
|
18
|
+
.buildCodeFrameError(
|
|
19
|
+
"A condition is required for the <while(condition)> tag.",
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
path.replaceWith(
|
|
24
|
+
withPreviousLocation(
|
|
25
|
+
t.whileStatement(
|
|
26
|
+
getArgOrSequence(path),
|
|
27
|
+
t.blockStatement(path.node.body.body),
|
|
28
|
+
),
|
|
29
|
+
path.node,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import { diagnosticDeprecate } from "@marko/compiler/babel-utils";
|
|
3
|
+
|
|
4
|
+
import withPreviousLocation from "../../util/with-previous-location";
|
|
5
|
+
const kHadAssignment = Symbol();
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
AssignmentExpression(path, state) {
|
|
9
|
+
if (
|
|
10
|
+
!state[kHadAssignment] &&
|
|
11
|
+
path.node.left.type === "Identifier" &&
|
|
12
|
+
path.node.left.name === "data"
|
|
13
|
+
) {
|
|
14
|
+
state[kHadAssignment] = true;
|
|
15
|
+
|
|
16
|
+
let root = path.parentPath;
|
|
17
|
+
while (root.parentPath.type !== "Program") {
|
|
18
|
+
root = root.parentPath;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
root.insertBefore(
|
|
22
|
+
t.markoScriptlet([
|
|
23
|
+
t.variableDeclaration("var", [
|
|
24
|
+
t.variableDeclarator(t.identifier("data")),
|
|
25
|
+
]),
|
|
26
|
+
]),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
ReferencedIdentifier(path, state) {
|
|
31
|
+
if (
|
|
32
|
+
!state[kHadAssignment] &&
|
|
33
|
+
path.node.name === "data" &&
|
|
34
|
+
!path.scope.hasBinding("data")
|
|
35
|
+
) {
|
|
36
|
+
diagnosticDeprecate(path, {
|
|
37
|
+
label: "The 'data' variable is deprecated. Use 'input' instead.",
|
|
38
|
+
fix() {
|
|
39
|
+
path.replaceWith(
|
|
40
|
+
withPreviousLocation(t.identifier("input"), path.node),
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
|
|
3
|
+
import write from "../util/html-out-write";
|
|
4
|
+
import withPreviousLocation from "../util/with-previous-location";
|
|
5
|
+
|
|
6
|
+
export default function (path) {
|
|
7
|
+
const { node } = path;
|
|
8
|
+
|
|
9
|
+
path.replaceWith(
|
|
10
|
+
withPreviousLocation(write`${t.stringLiteral(node.value)}`, node),
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { types as t } from "@marko/compiler";
|
|
2
|
+
import { decode } from "he";
|
|
3
|
+
|
|
4
|
+
import write from "../util/vdom-out-write";
|
|
5
|
+
import withPreviousLocation from "../util/with-previous-location";
|
|
6
|
+
|
|
7
|
+
export default function (path) {
|
|
8
|
+
const { node } = path;
|
|
9
|
+
|
|
10
|
+
path.replaceWith(
|
|
11
|
+
withPreviousLocation(
|
|
12
|
+
write(
|
|
13
|
+
"t",
|
|
14
|
+
t.stringLiteral(decode(node.value)),
|
|
15
|
+
path.hub.file._componentInstanceIdentifier,
|
|
16
|
+
),
|
|
17
|
+
node,
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
}
|