@marko/language-tools 2.5.40 → 2.5.42
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/extractors/script/util/get-runtime-api.d.ts +6 -2
- package/dist/index.js +79 -55
- package/dist/index.mjs +79 -55
- package/marko.internal.d.ts +9 -7
- package/package.json +6 -6
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { TaglibLookup } from "@marko/compiler/babel-utils";
|
|
1
2
|
import { Parsed } from "../../../parser";
|
|
2
|
-
export type RuntimeAPI = (typeof RuntimeAPI)[keyof typeof RuntimeAPI]
|
|
3
|
+
export type RuntimeAPI = (typeof RuntimeAPI)[keyof typeof RuntimeAPI];
|
|
3
4
|
export declare const RuntimeAPI: {
|
|
4
5
|
readonly tags: "tags";
|
|
5
6
|
readonly class: "class";
|
|
6
7
|
};
|
|
7
8
|
export declare function getRuntimeAPI(translator: {
|
|
8
9
|
preferAPI?: string;
|
|
9
|
-
} | undefined, parsed: Parsed):
|
|
10
|
+
} | undefined, lookup: TaglibLookup, parsed: Parsed): {
|
|
11
|
+
interop: boolean;
|
|
12
|
+
api: RuntimeAPI;
|
|
13
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1678,31 +1678,50 @@ var RuntimeAPI = {
|
|
|
1678
1678
|
tags: "tags",
|
|
1679
1679
|
class: "class"
|
|
1680
1680
|
};
|
|
1681
|
-
function getRuntimeAPI(translator, parsed) {
|
|
1682
|
-
|
|
1681
|
+
function getRuntimeAPI(translator, lookup, parsed) {
|
|
1682
|
+
const api = detectAPIFromTranslator(translator);
|
|
1683
|
+
return {
|
|
1684
|
+
interop: !api,
|
|
1685
|
+
api: api || detectAPIFromFileName(parsed.filename, lookup) || detectAPIFromProgram(parsed, parsed.program) || (lookup.exclusiveTagDiscoveryDirs === "tags" ? RuntimeAPI.tags : RuntimeAPI.class)
|
|
1686
|
+
};
|
|
1683
1687
|
}
|
|
1684
1688
|
function detectAPIFromTranslator(translator) {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
return RuntimeAPI.class;
|
|
1688
|
-
case "tags":
|
|
1689
|
-
return RuntimeAPI.tags;
|
|
1689
|
+
if ((translator == null ? void 0 : translator.preferAPI) === "tags") {
|
|
1690
|
+
return RuntimeAPI.tags;
|
|
1690
1691
|
}
|
|
1691
1692
|
}
|
|
1692
|
-
function detectAPIFromFileName(filename) {
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1693
|
+
function detectAPIFromFileName(filename, lookup) {
|
|
1694
|
+
var _a;
|
|
1695
|
+
const tagsDir = getTagsDir(filename);
|
|
1696
|
+
if (tagsDir && !((_a = lookup.manualTagsDirs) == null ? void 0 : _a.has(tagsDir))) {
|
|
1697
|
+
return RuntimeAPI.tags;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
function getTagsDir(filename) {
|
|
1701
|
+
var _a;
|
|
1702
|
+
const pathSeparator = (_a = /\/|\\/.exec(filename)) == null ? void 0 : _a[0];
|
|
1703
|
+
if (pathSeparator) {
|
|
1704
|
+
let previousIndex = filename.length - 1;
|
|
1705
|
+
while (previousIndex > 0) {
|
|
1706
|
+
const index = filename.lastIndexOf(pathSeparator, previousIndex);
|
|
1707
|
+
switch (previousIndex - index) {
|
|
1708
|
+
case 4: {
|
|
1709
|
+
if (filename.startsWith("tags", index + 1)) {
|
|
1710
|
+
return filename.slice(0, index + 5);
|
|
1711
|
+
}
|
|
1712
|
+
break;
|
|
1701
1713
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1714
|
+
case 10: {
|
|
1715
|
+
if (filename.startsWith("components", index + 1)) {
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
break;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
previousIndex = index - 1;
|
|
1704
1722
|
}
|
|
1705
1723
|
}
|
|
1724
|
+
return false;
|
|
1706
1725
|
}
|
|
1707
1726
|
function detectAPIFromProgram(parsed, program) {
|
|
1708
1727
|
if (program.comments) {
|
|
@@ -1747,11 +1766,12 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1747
1766
|
return RuntimeAPI.tags;
|
|
1748
1767
|
}
|
|
1749
1768
|
switch (tag.nameText) {
|
|
1750
|
-
case "
|
|
1751
|
-
case "include-text":
|
|
1769
|
+
case "await-reorderer":
|
|
1752
1770
|
case "include-html":
|
|
1771
|
+
case "include-text":
|
|
1753
1772
|
case "init-components":
|
|
1754
|
-
case "
|
|
1773
|
+
case "macro":
|
|
1774
|
+
case "module-code":
|
|
1755
1775
|
case "while":
|
|
1756
1776
|
return RuntimeAPI.class;
|
|
1757
1777
|
case "const":
|
|
@@ -1762,8 +1782,6 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1762
1782
|
case "lifecycle":
|
|
1763
1783
|
case "log":
|
|
1764
1784
|
case "return":
|
|
1765
|
-
case "html-script":
|
|
1766
|
-
case "html-style":
|
|
1767
1785
|
case "try":
|
|
1768
1786
|
return RuntimeAPI.tags;
|
|
1769
1787
|
}
|
|
@@ -1776,9 +1794,7 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1776
1794
|
if (attr.args) {
|
|
1777
1795
|
return RuntimeAPI.class;
|
|
1778
1796
|
}
|
|
1779
|
-
if (
|
|
1780
|
-
parsed.read(attr.name)
|
|
1781
|
-
)) {
|
|
1797
|
+
if (/:/.test(parsed.read(attr.name))) {
|
|
1782
1798
|
return RuntimeAPI.class;
|
|
1783
1799
|
}
|
|
1784
1800
|
}
|
|
@@ -1983,6 +1999,8 @@ function extractScript(opts) {
|
|
|
1983
1999
|
var ScriptExtractor = class {
|
|
1984
2000
|
#code;
|
|
1985
2001
|
#filename;
|
|
2002
|
+
#api;
|
|
2003
|
+
#interop;
|
|
1986
2004
|
#parsed;
|
|
1987
2005
|
#extractor;
|
|
1988
2006
|
#scriptParser;
|
|
@@ -1993,14 +2011,20 @@ var ScriptExtractor = class {
|
|
|
1993
2011
|
#scriptLang;
|
|
1994
2012
|
#ts;
|
|
1995
2013
|
#runtimeTypes;
|
|
1996
|
-
#api;
|
|
1997
2014
|
#mutationOffsets;
|
|
1998
2015
|
#tagId = 1;
|
|
1999
2016
|
#renderId = 1;
|
|
2000
2017
|
constructor(opts) {
|
|
2001
2018
|
const { parsed, lookup, scriptLang } = opts;
|
|
2002
|
-
|
|
2019
|
+
const { api, interop } = getRuntimeAPI(
|
|
2020
|
+
opts.translator,
|
|
2021
|
+
opts.lookup,
|
|
2022
|
+
parsed
|
|
2023
|
+
);
|
|
2003
2024
|
this.#code = parsed.code;
|
|
2025
|
+
this.#filename = parsed.filename;
|
|
2026
|
+
this.#api = api;
|
|
2027
|
+
this.#interop = interop;
|
|
2004
2028
|
this.#scriptLang = scriptLang;
|
|
2005
2029
|
this.#parsed = parsed;
|
|
2006
2030
|
this.#lookup = lookup;
|
|
@@ -2009,7 +2033,6 @@ var ScriptExtractor = class {
|
|
|
2009
2033
|
this.#extractor = new Extractor(parsed);
|
|
2010
2034
|
this.#scriptParser = new ScriptParser(parsed);
|
|
2011
2035
|
this.#read = parsed.read.bind(parsed);
|
|
2012
|
-
this.#api = getRuntimeAPI(opts.translator, parsed);
|
|
2013
2036
|
this.#mutationOffsets = crawlProgramScope(this.#parsed, this.#scriptParser);
|
|
2014
2037
|
this.#writeProgram(parsed.program);
|
|
2015
2038
|
}
|
|
@@ -2018,7 +2041,7 @@ var ScriptExtractor = class {
|
|
|
2018
2041
|
}
|
|
2019
2042
|
#writeProgram(program) {
|
|
2020
2043
|
this.#writeCommentPragmas(program);
|
|
2021
|
-
const componentFileName = this.#api
|
|
2044
|
+
const componentFileName = this.#api === RuntimeAPI.class ? getComponentFilename(this.#filename) : void 0;
|
|
2022
2045
|
const inputType = this.#getInputType(program);
|
|
2023
2046
|
let componentClassBody;
|
|
2024
2047
|
for (const node of program.static) {
|
|
@@ -2108,7 +2131,7 @@ var ScriptExtractor = class {
|
|
|
2108
2131
|
);
|
|
2109
2132
|
}
|
|
2110
2133
|
}
|
|
2111
|
-
if (this.#api
|
|
2134
|
+
if (this.#api === RuntimeAPI.class) {
|
|
2112
2135
|
if (isExternalComponentFile) {
|
|
2113
2136
|
const componentImport = `"${stripExt((0, import_relative_import_path.relativeImportPath)(this.#filename, componentFileName))}"`;
|
|
2114
2137
|
if (this.#scriptLang === "ts" /* ts */) {
|
|
@@ -2170,7 +2193,7 @@ export type { Component };
|
|
|
2170
2193
|
function ${templateName}() {
|
|
2171
2194
|
`);
|
|
2172
2195
|
}
|
|
2173
|
-
this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api
|
|
2196
|
+
this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api === RuntimeAPI.class ? `
|
|
2174
2197
|
const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
|
|
2175
2198
|
const state = ${varShared("state")}(component);
|
|
2176
2199
|
const out = ${varShared("out")};` : ""}
|
|
@@ -2192,7 +2215,7 @@ function ${templateName}() {
|
|
|
2192
2215
|
);
|
|
2193
2216
|
}
|
|
2194
2217
|
this.#extractor.write(
|
|
2195
|
-
`${varShared("noop")}({ ${hoists ? hoists.join(SEP_COMMA_SPACE) + SEP_COMMA_SPACE : ""}${this.#api
|
|
2218
|
+
`${varShared("noop")}({ ${hoists ? hoists.join(SEP_COMMA_SPACE) + SEP_COMMA_SPACE : ""}${this.#api === RuntimeAPI.class ? "component, state, out, " : ""}input, $global, $signal });
|
|
2196
2219
|
`
|
|
2197
2220
|
);
|
|
2198
2221
|
if (didReturn) {
|
|
@@ -2219,7 +2242,7 @@ function ${templateName}() {
|
|
|
2219
2242
|
typeArgsStr,
|
|
2220
2243
|
returnTypeStr
|
|
2221
2244
|
) : ""}
|
|
2222
|
-
${this.#
|
|
2245
|
+
${this.#interop ? `api: "${this.#api}",` : ""}
|
|
2223
2246
|
_${typeParamsStr ? `<${internalApply} = 1>(): ${internalApply} extends 0
|
|
2224
2247
|
? ${typeParamsStr}() => <${internalInputWithExtends}>${renderAndReturn}
|
|
2225
2248
|
: () => <${internalInputWithExtends}, ${typeParamsStr.slice(
|
|
@@ -2664,7 +2687,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2664
2687
|
}
|
|
2665
2688
|
} else if (attr.args) {
|
|
2666
2689
|
this.#extractor.write('"').copy(name).write('": ');
|
|
2667
|
-
if (this.#api
|
|
2690
|
+
if (this.#api === RuntimeAPI.class && typeof name !== "string" && this.#read(name).startsWith("on")) {
|
|
2668
2691
|
const stringLiteralFirstArgMatch = this.#execAtIndex(
|
|
2669
2692
|
REG_ATTR_ARG_LITERAL,
|
|
2670
2693
|
attr.args.value.start
|
|
@@ -2843,7 +2866,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2843
2866
|
const body = this.#processBody(tag);
|
|
2844
2867
|
let hasInput = false;
|
|
2845
2868
|
let writeInputObj = true;
|
|
2846
|
-
if (tag.args && (this.#api
|
|
2869
|
+
if (tag.args && (this.#api === RuntimeAPI.tags || !!this.#getDynamicTagExpression(tag))) {
|
|
2847
2870
|
hasInput = true;
|
|
2848
2871
|
this.#extractor.copy(tag.args.value);
|
|
2849
2872
|
if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
|
|
@@ -2887,26 +2910,19 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2887
2910
|
}
|
|
2888
2911
|
if (tag.params || hasBodyContent) {
|
|
2889
2912
|
this.#extractor.write("[");
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
this.#extractor.write(
|
|
2896
|
-
|
|
2897
|
-
default: {
|
|
2898
|
-
const tagId = this.#tagIds.get(
|
|
2899
|
-
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2913
|
+
if (this.#interop) {
|
|
2914
|
+
const tagId = this.#tagIds.get(
|
|
2915
|
+
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2916
|
+
);
|
|
2917
|
+
if (tagId) {
|
|
2918
|
+
this.#extractor.write(
|
|
2919
|
+
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2900
2920
|
);
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2904
|
-
);
|
|
2905
|
-
} else {
|
|
2906
|
-
this.#extractor.write(varShared("content"));
|
|
2907
|
-
}
|
|
2908
|
-
break;
|
|
2921
|
+
} else {
|
|
2922
|
+
this.#extractor.write(varShared("content"));
|
|
2909
2923
|
}
|
|
2924
|
+
} else {
|
|
2925
|
+
this.#extractor.write('"content"');
|
|
2910
2926
|
}
|
|
2911
2927
|
this.#writeTagNameComment(tag);
|
|
2912
2928
|
this.#extractor.write("]: ");
|
|
@@ -3697,7 +3713,15 @@ function loadMeta(dir) {
|
|
|
3697
3713
|
let cached = metaByDir.get(dir);
|
|
3698
3714
|
if (!cached) {
|
|
3699
3715
|
const require2 = (0, import_module.createRequire)(import_path2.default.join(dir, "_.js"));
|
|
3700
|
-
const configPath =
|
|
3716
|
+
const configPath = (() => {
|
|
3717
|
+
try {
|
|
3718
|
+
return require2.resolve("@marko/compiler/config");
|
|
3719
|
+
} catch {
|
|
3720
|
+
return (0, import_module.createRequire)(require2.resolve("marko/package.json")).resolve(
|
|
3721
|
+
"@marko/compiler/config"
|
|
3722
|
+
);
|
|
3723
|
+
}
|
|
3724
|
+
})();
|
|
3701
3725
|
const config = interopDefault(require2(configPath));
|
|
3702
3726
|
const translatorPath = require2.resolve(config.translator);
|
|
3703
3727
|
cached = metaByTranslator.get(translatorPath);
|
package/dist/index.mjs
CHANGED
|
@@ -1638,31 +1638,50 @@ var RuntimeAPI = {
|
|
|
1638
1638
|
tags: "tags",
|
|
1639
1639
|
class: "class"
|
|
1640
1640
|
};
|
|
1641
|
-
function getRuntimeAPI(translator, parsed) {
|
|
1642
|
-
|
|
1641
|
+
function getRuntimeAPI(translator, lookup, parsed) {
|
|
1642
|
+
const api = detectAPIFromTranslator(translator);
|
|
1643
|
+
return {
|
|
1644
|
+
interop: !api,
|
|
1645
|
+
api: api || detectAPIFromFileName(parsed.filename, lookup) || detectAPIFromProgram(parsed, parsed.program) || (lookup.exclusiveTagDiscoveryDirs === "tags" ? RuntimeAPI.tags : RuntimeAPI.class)
|
|
1646
|
+
};
|
|
1643
1647
|
}
|
|
1644
1648
|
function detectAPIFromTranslator(translator) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
return RuntimeAPI.class;
|
|
1648
|
-
case "tags":
|
|
1649
|
-
return RuntimeAPI.tags;
|
|
1649
|
+
if ((translator == null ? void 0 : translator.preferAPI) === "tags") {
|
|
1650
|
+
return RuntimeAPI.tags;
|
|
1650
1651
|
}
|
|
1651
1652
|
}
|
|
1652
|
-
function detectAPIFromFileName(filename) {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1653
|
+
function detectAPIFromFileName(filename, lookup) {
|
|
1654
|
+
var _a;
|
|
1655
|
+
const tagsDir = getTagsDir(filename);
|
|
1656
|
+
if (tagsDir && !((_a = lookup.manualTagsDirs) == null ? void 0 : _a.has(tagsDir))) {
|
|
1657
|
+
return RuntimeAPI.tags;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
function getTagsDir(filename) {
|
|
1661
|
+
var _a;
|
|
1662
|
+
const pathSeparator = (_a = /\/|\\/.exec(filename)) == null ? void 0 : _a[0];
|
|
1663
|
+
if (pathSeparator) {
|
|
1664
|
+
let previousIndex = filename.length - 1;
|
|
1665
|
+
while (previousIndex > 0) {
|
|
1666
|
+
const index = filename.lastIndexOf(pathSeparator, previousIndex);
|
|
1667
|
+
switch (previousIndex - index) {
|
|
1668
|
+
case 4: {
|
|
1669
|
+
if (filename.startsWith("tags", index + 1)) {
|
|
1670
|
+
return filename.slice(0, index + 5);
|
|
1671
|
+
}
|
|
1672
|
+
break;
|
|
1661
1673
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1674
|
+
case 10: {
|
|
1675
|
+
if (filename.startsWith("components", index + 1)) {
|
|
1676
|
+
return false;
|
|
1677
|
+
}
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
previousIndex = index - 1;
|
|
1664
1682
|
}
|
|
1665
1683
|
}
|
|
1684
|
+
return false;
|
|
1666
1685
|
}
|
|
1667
1686
|
function detectAPIFromProgram(parsed, program) {
|
|
1668
1687
|
if (program.comments) {
|
|
@@ -1707,11 +1726,12 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1707
1726
|
return RuntimeAPI.tags;
|
|
1708
1727
|
}
|
|
1709
1728
|
switch (tag.nameText) {
|
|
1710
|
-
case "
|
|
1711
|
-
case "include-text":
|
|
1729
|
+
case "await-reorderer":
|
|
1712
1730
|
case "include-html":
|
|
1731
|
+
case "include-text":
|
|
1713
1732
|
case "init-components":
|
|
1714
|
-
case "
|
|
1733
|
+
case "macro":
|
|
1734
|
+
case "module-code":
|
|
1715
1735
|
case "while":
|
|
1716
1736
|
return RuntimeAPI.class;
|
|
1717
1737
|
case "const":
|
|
@@ -1722,8 +1742,6 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1722
1742
|
case "lifecycle":
|
|
1723
1743
|
case "log":
|
|
1724
1744
|
case "return":
|
|
1725
|
-
case "html-script":
|
|
1726
|
-
case "html-style":
|
|
1727
1745
|
case "try":
|
|
1728
1746
|
return RuntimeAPI.tags;
|
|
1729
1747
|
}
|
|
@@ -1736,9 +1754,7 @@ function detectAPIFromTag(parsed, tag) {
|
|
|
1736
1754
|
if (attr.args) {
|
|
1737
1755
|
return RuntimeAPI.class;
|
|
1738
1756
|
}
|
|
1739
|
-
if (
|
|
1740
|
-
parsed.read(attr.name)
|
|
1741
|
-
)) {
|
|
1757
|
+
if (/:/.test(parsed.read(attr.name))) {
|
|
1742
1758
|
return RuntimeAPI.class;
|
|
1743
1759
|
}
|
|
1744
1760
|
}
|
|
@@ -1946,6 +1962,8 @@ function extractScript(opts) {
|
|
|
1946
1962
|
var ScriptExtractor = class {
|
|
1947
1963
|
#code;
|
|
1948
1964
|
#filename;
|
|
1965
|
+
#api;
|
|
1966
|
+
#interop;
|
|
1949
1967
|
#parsed;
|
|
1950
1968
|
#extractor;
|
|
1951
1969
|
#scriptParser;
|
|
@@ -1956,14 +1974,20 @@ var ScriptExtractor = class {
|
|
|
1956
1974
|
#scriptLang;
|
|
1957
1975
|
#ts;
|
|
1958
1976
|
#runtimeTypes;
|
|
1959
|
-
#api;
|
|
1960
1977
|
#mutationOffsets;
|
|
1961
1978
|
#tagId = 1;
|
|
1962
1979
|
#renderId = 1;
|
|
1963
1980
|
constructor(opts) {
|
|
1964
1981
|
const { parsed, lookup, scriptLang } = opts;
|
|
1965
|
-
|
|
1982
|
+
const { api, interop } = getRuntimeAPI(
|
|
1983
|
+
opts.translator,
|
|
1984
|
+
opts.lookup,
|
|
1985
|
+
parsed
|
|
1986
|
+
);
|
|
1966
1987
|
this.#code = parsed.code;
|
|
1988
|
+
this.#filename = parsed.filename;
|
|
1989
|
+
this.#api = api;
|
|
1990
|
+
this.#interop = interop;
|
|
1967
1991
|
this.#scriptLang = scriptLang;
|
|
1968
1992
|
this.#parsed = parsed;
|
|
1969
1993
|
this.#lookup = lookup;
|
|
@@ -1972,7 +1996,6 @@ var ScriptExtractor = class {
|
|
|
1972
1996
|
this.#extractor = new Extractor(parsed);
|
|
1973
1997
|
this.#scriptParser = new ScriptParser(parsed);
|
|
1974
1998
|
this.#read = parsed.read.bind(parsed);
|
|
1975
|
-
this.#api = getRuntimeAPI(opts.translator, parsed);
|
|
1976
1999
|
this.#mutationOffsets = crawlProgramScope(this.#parsed, this.#scriptParser);
|
|
1977
2000
|
this.#writeProgram(parsed.program);
|
|
1978
2001
|
}
|
|
@@ -1981,7 +2004,7 @@ var ScriptExtractor = class {
|
|
|
1981
2004
|
}
|
|
1982
2005
|
#writeProgram(program) {
|
|
1983
2006
|
this.#writeCommentPragmas(program);
|
|
1984
|
-
const componentFileName = this.#api
|
|
2007
|
+
const componentFileName = this.#api === RuntimeAPI.class ? getComponentFilename(this.#filename) : void 0;
|
|
1985
2008
|
const inputType = this.#getInputType(program);
|
|
1986
2009
|
let componentClassBody;
|
|
1987
2010
|
for (const node of program.static) {
|
|
@@ -2071,7 +2094,7 @@ var ScriptExtractor = class {
|
|
|
2071
2094
|
);
|
|
2072
2095
|
}
|
|
2073
2096
|
}
|
|
2074
|
-
if (this.#api
|
|
2097
|
+
if (this.#api === RuntimeAPI.class) {
|
|
2075
2098
|
if (isExternalComponentFile) {
|
|
2076
2099
|
const componentImport = `"${stripExt(relativeImportPath(this.#filename, componentFileName))}"`;
|
|
2077
2100
|
if (this.#scriptLang === "ts" /* ts */) {
|
|
@@ -2133,7 +2156,7 @@ export type { Component };
|
|
|
2133
2156
|
function ${templateName}() {
|
|
2134
2157
|
`);
|
|
2135
2158
|
}
|
|
2136
|
-
this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api
|
|
2159
|
+
this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api === RuntimeAPI.class ? `
|
|
2137
2160
|
const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
|
|
2138
2161
|
const state = ${varShared("state")}(component);
|
|
2139
2162
|
const out = ${varShared("out")};` : ""}
|
|
@@ -2155,7 +2178,7 @@ function ${templateName}() {
|
|
|
2155
2178
|
);
|
|
2156
2179
|
}
|
|
2157
2180
|
this.#extractor.write(
|
|
2158
|
-
`${varShared("noop")}({ ${hoists ? hoists.join(SEP_COMMA_SPACE) + SEP_COMMA_SPACE : ""}${this.#api
|
|
2181
|
+
`${varShared("noop")}({ ${hoists ? hoists.join(SEP_COMMA_SPACE) + SEP_COMMA_SPACE : ""}${this.#api === RuntimeAPI.class ? "component, state, out, " : ""}input, $global, $signal });
|
|
2159
2182
|
`
|
|
2160
2183
|
);
|
|
2161
2184
|
if (didReturn) {
|
|
@@ -2182,7 +2205,7 @@ function ${templateName}() {
|
|
|
2182
2205
|
typeArgsStr,
|
|
2183
2206
|
returnTypeStr
|
|
2184
2207
|
) : ""}
|
|
2185
|
-
${this.#
|
|
2208
|
+
${this.#interop ? `api: "${this.#api}",` : ""}
|
|
2186
2209
|
_${typeParamsStr ? `<${internalApply} = 1>(): ${internalApply} extends 0
|
|
2187
2210
|
? ${typeParamsStr}() => <${internalInputWithExtends}>${renderAndReturn}
|
|
2188
2211
|
: () => <${internalInputWithExtends}, ${typeParamsStr.slice(
|
|
@@ -2627,7 +2650,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2627
2650
|
}
|
|
2628
2651
|
} else if (attr.args) {
|
|
2629
2652
|
this.#extractor.write('"').copy(name).write('": ');
|
|
2630
|
-
if (this.#api
|
|
2653
|
+
if (this.#api === RuntimeAPI.class && typeof name !== "string" && this.#read(name).startsWith("on")) {
|
|
2631
2654
|
const stringLiteralFirstArgMatch = this.#execAtIndex(
|
|
2632
2655
|
REG_ATTR_ARG_LITERAL,
|
|
2633
2656
|
attr.args.value.start
|
|
@@ -2806,7 +2829,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2806
2829
|
const body = this.#processBody(tag);
|
|
2807
2830
|
let hasInput = false;
|
|
2808
2831
|
let writeInputObj = true;
|
|
2809
|
-
if (tag.args && (this.#api
|
|
2832
|
+
if (tag.args && (this.#api === RuntimeAPI.tags || !!this.#getDynamicTagExpression(tag))) {
|
|
2810
2833
|
hasInput = true;
|
|
2811
2834
|
this.#extractor.copy(tag.args.value);
|
|
2812
2835
|
if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
|
|
@@ -2850,26 +2873,19 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2850
2873
|
}
|
|
2851
2874
|
if (tag.params || hasBodyContent) {
|
|
2852
2875
|
this.#extractor.write("[");
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
this.#extractor.write(
|
|
2859
|
-
|
|
2860
|
-
default: {
|
|
2861
|
-
const tagId = this.#tagIds.get(
|
|
2862
|
-
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2876
|
+
if (this.#interop) {
|
|
2877
|
+
const tagId = this.#tagIds.get(
|
|
2878
|
+
tag.type === 16 /* AttrTag */ ? tag.owner : tag
|
|
2879
|
+
);
|
|
2880
|
+
if (tagId) {
|
|
2881
|
+
this.#extractor.write(
|
|
2882
|
+
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2863
2883
|
);
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
`${varShared("contentFor")}(${varLocal("tag_" + tagId)})`
|
|
2867
|
-
);
|
|
2868
|
-
} else {
|
|
2869
|
-
this.#extractor.write(varShared("content"));
|
|
2870
|
-
}
|
|
2871
|
-
break;
|
|
2884
|
+
} else {
|
|
2885
|
+
this.#extractor.write(varShared("content"));
|
|
2872
2886
|
}
|
|
2887
|
+
} else {
|
|
2888
|
+
this.#extractor.write('"content"');
|
|
2873
2889
|
}
|
|
2874
2890
|
this.#writeTagNameComment(tag);
|
|
2875
2891
|
this.#extractor.write("]: ");
|
|
@@ -3660,7 +3676,15 @@ function loadMeta(dir) {
|
|
|
3660
3676
|
let cached = metaByDir.get(dir);
|
|
3661
3677
|
if (!cached) {
|
|
3662
3678
|
const require2 = createRequire(path2.join(dir, "_.js"));
|
|
3663
|
-
const configPath =
|
|
3679
|
+
const configPath = (() => {
|
|
3680
|
+
try {
|
|
3681
|
+
return require2.resolve("@marko/compiler/config");
|
|
3682
|
+
} catch {
|
|
3683
|
+
return createRequire(require2.resolve("marko/package.json")).resolve(
|
|
3684
|
+
"@marko/compiler/config"
|
|
3685
|
+
);
|
|
3686
|
+
}
|
|
3687
|
+
})();
|
|
3664
3688
|
const config = interopDefault(require2(configPath));
|
|
3665
3689
|
const translatorPath = require2.resolve(config.translator);
|
|
3666
3690
|
cached = metaByTranslator.get(translatorPath);
|
package/marko.internal.d.ts
CHANGED
|
@@ -38,13 +38,15 @@ declare global {
|
|
|
38
38
|
|
|
39
39
|
export function contentFor<Name>(
|
|
40
40
|
tag: Name,
|
|
41
|
-
):
|
|
42
|
-
?
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
? "
|
|
46
|
-
:
|
|
47
|
-
|
|
41
|
+
): [0] extends [1 & Name]
|
|
42
|
+
? DefaultBodyContentKey
|
|
43
|
+
: Name extends { api: infer API }
|
|
44
|
+
? API extends "tags"
|
|
45
|
+
? "content"
|
|
46
|
+
: API extends "class"
|
|
47
|
+
? "renderBody"
|
|
48
|
+
: DefaultBodyContentKey
|
|
49
|
+
: DefaultBodyContentKey;
|
|
48
50
|
|
|
49
51
|
export const Template: new <Overrides = unknown>() => {
|
|
50
52
|
[K in Exclude<
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/language-tools",
|
|
3
3
|
"description": "Marko Language Tools",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.42",
|
|
5
5
|
"bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@marko/compiler": "^5.28.4"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@babel/parser": "^7.28.
|
|
10
|
+
"@babel/parser": "^7.28.5",
|
|
11
11
|
"@luxass/strip-json-comments": "^1.4.0",
|
|
12
12
|
"htmljs-parser": "^5.7.4",
|
|
13
13
|
"relative-import-path": "^1.0.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@babel/code-frame": "^7.27.1",
|
|
17
|
-
"@marko/compiler": "^5.39.
|
|
17
|
+
"@marko/compiler": "^5.39.45",
|
|
18
18
|
"@types/babel__code-frame": "^7.0.6",
|
|
19
|
-
"@typescript/vfs": "^1.6.
|
|
20
|
-
"marko": "^5.
|
|
19
|
+
"@typescript/vfs": "^1.6.2",
|
|
20
|
+
"marko": "^5.38.1",
|
|
21
21
|
"mitata": "^1.0.34",
|
|
22
|
-
"tsx": "^4.
|
|
22
|
+
"tsx": "^4.21.0"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|