@marko/language-tools 2.5.25 → 2.5.27
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/index.d.ts +1 -1
- package/dist/extractors/script/util/runtime-overrides.d.ts +1 -1
- package/dist/extractors/style/index.d.ts +1 -1
- package/dist/index.js +21 -10
- package/dist/index.mjs +21 -10
- package/dist/util/project.d.ts +1 -1
- package/marko.internal.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TaglibLookup } from "@marko/babel-utils";
|
|
1
|
+
import type { TaglibLookup } from "@marko/compiler/babel-utils";
|
|
2
2
|
import type TS from "typescript/lib/tsserverlibrary";
|
|
3
3
|
import { type Parsed } from "../../parser";
|
|
4
4
|
import type { Meta } from "../../util/project";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getRuntimeOverrides(runtimeTypes: string, generics: string, applyGenerics: string): string;
|
|
1
|
+
export declare function getRuntimeOverrides(runtimeTypes: string, generics: string, applyGenerics: string, returnType: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1824,9 +1824,9 @@ function isTemplateTag(ts, tag) {
|
|
|
1824
1824
|
// src/extractors/script/util/runtime-overrides.ts
|
|
1825
1825
|
var RuntimeOverloads = /* @__PURE__ */ new Map();
|
|
1826
1826
|
var commentsReg = /\/\*(?:[^*]|\*[^/])*\*\//gm;
|
|
1827
|
-
var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)/gm;
|
|
1827
|
+
var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)|\b(Return)\b/gm;
|
|
1828
1828
|
var overrideBlockReg = /\/\*[*\s]*@marko-overload-start[*\s]*\*\/([\s\S]+)\/\*[*\s]*@marko-overload-end[*\s]*\*\//g;
|
|
1829
|
-
function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
1829
|
+
function getRuntimeOverrides(runtimeTypes, generics, applyGenerics, returnType) {
|
|
1830
1830
|
let overloads = RuntimeOverloads.get(runtimeTypes);
|
|
1831
1831
|
if (!overloads) {
|
|
1832
1832
|
const match = overrideBlockReg.exec(runtimeTypes);
|
|
@@ -1837,15 +1837,17 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1837
1837
|
let lastIndex = 0;
|
|
1838
1838
|
content = content.replace(commentsReg, "");
|
|
1839
1839
|
while (replaceMatch = replaceTokensReg.exec(content)) {
|
|
1840
|
-
const [, methodName, propertyName] = replaceMatch;
|
|
1840
|
+
const [, methodName, propertyName, returnName] = replaceMatch;
|
|
1841
1841
|
const curText = content.slice(lastIndex, replaceMatch.index);
|
|
1842
1842
|
lastIndex = replaceTokensReg.lastIndex;
|
|
1843
1843
|
if (methodName) {
|
|
1844
1844
|
overloads.push(curText + methodName, 0 /* Generics */);
|
|
1845
|
+
} else if (returnName) {
|
|
1846
|
+
overloads.push(curText, 2 /* Return */);
|
|
1845
1847
|
} else {
|
|
1846
1848
|
overloads.push(
|
|
1847
1849
|
curText,
|
|
1848
|
-
propertyName === "Component" ?
|
|
1850
|
+
propertyName === "Component" ? 3 /* Component */ : 1 /* Input */
|
|
1849
1851
|
);
|
|
1850
1852
|
}
|
|
1851
1853
|
}
|
|
@@ -1863,7 +1865,10 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1863
1865
|
case 1 /* Input */:
|
|
1864
1866
|
result += appliedInput;
|
|
1865
1867
|
break;
|
|
1866
|
-
case 2 /*
|
|
1868
|
+
case 2 /* Return */:
|
|
1869
|
+
result += returnType;
|
|
1870
|
+
break;
|
|
1871
|
+
case 3 /* Component */:
|
|
1867
1872
|
result += appliedComponent;
|
|
1868
1873
|
break;
|
|
1869
1874
|
default:
|
|
@@ -2182,12 +2187,18 @@ ${varShared("noop")}(`);
|
|
|
2182
2187
|
const internalInput = varLocal("input");
|
|
2183
2188
|
const internalInputWithExtends = `${internalInput} extends unknown`;
|
|
2184
2189
|
const internalApply = varLocal("apply");
|
|
2190
|
+
const returnTypeStr = didReturn ? `typeof ${templateName + typeArgsStr} extends () => infer Return ? Return : never` : "void";
|
|
2185
2191
|
const renderAndReturn = `(input: Marko.Directives & Input${typeArgsStr} & ${varShared(
|
|
2186
2192
|
"Relate"
|
|
2187
2193
|
)}<${internalInput}, Marko.Directives & Input${typeArgsStr}>) => (${varShared(
|
|
2188
2194
|
"ReturnWithScope"
|
|
2189
|
-
)}<${internalInput}, ${
|
|
2190
|
-
const templateOverrideClass = `${templateBaseClass}<{${this.#runtimeTypes ? getRuntimeOverrides(
|
|
2195
|
+
)}<${internalInput}, ${returnTypeStr}>)`;
|
|
2196
|
+
const templateOverrideClass = `${templateBaseClass}<{${this.#runtimeTypes ? getRuntimeOverrides(
|
|
2197
|
+
this.#runtimeTypes,
|
|
2198
|
+
typeParamsStr,
|
|
2199
|
+
typeArgsStr,
|
|
2200
|
+
returnTypeStr
|
|
2201
|
+
) : ""}
|
|
2191
2202
|
${this.#api ? `api: "${this.#api}",` : ""}
|
|
2192
2203
|
_${typeParamsStr ? `<${internalApply} = 1>(): ${internalApply} extends 0
|
|
2193
2204
|
? ${typeParamsStr}() => <${internalInputWithExtends}>${renderAndReturn}
|
|
@@ -2447,11 +2458,11 @@ constructor(_?: Return) {}
|
|
|
2447
2458
|
const tagName = tag.nameText;
|
|
2448
2459
|
const renderId = this.#getRenderId(tag);
|
|
2449
2460
|
const def = tagName ? this.#lookup.getTag(tagName) : void 0;
|
|
2450
|
-
const
|
|
2451
|
-
const
|
|
2461
|
+
const importPath = resolveTagImport(this.#filename, def);
|
|
2462
|
+
const isHTML = !importPath && (def == null ? void 0 : def.html);
|
|
2452
2463
|
let tagIdentifier;
|
|
2453
2464
|
let isTemplate = false;
|
|
2454
|
-
if (!
|
|
2465
|
+
if (!def || importPath) {
|
|
2455
2466
|
const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
|
|
2456
2467
|
const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
|
|
2457
2468
|
if (isIdentifier || isMarkoFile || !importPath) {
|
package/dist/index.mjs
CHANGED
|
@@ -1784,9 +1784,9 @@ function isTemplateTag(ts, tag) {
|
|
|
1784
1784
|
// src/extractors/script/util/runtime-overrides.ts
|
|
1785
1785
|
var RuntimeOverloads = /* @__PURE__ */ new Map();
|
|
1786
1786
|
var commentsReg = /\/\*(?:[^*]|\*[^/])*\*\//gm;
|
|
1787
|
-
var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)/gm;
|
|
1787
|
+
var replaceTokensReg = /\babstract\s+(\w+)|Marko\.(TemplateInput(?:<[^>]+>)?|Component)|\b(Return)\b/gm;
|
|
1788
1788
|
var overrideBlockReg = /\/\*[*\s]*@marko-overload-start[*\s]*\*\/([\s\S]+)\/\*[*\s]*@marko-overload-end[*\s]*\*\//g;
|
|
1789
|
-
function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
1789
|
+
function getRuntimeOverrides(runtimeTypes, generics, applyGenerics, returnType) {
|
|
1790
1790
|
let overloads = RuntimeOverloads.get(runtimeTypes);
|
|
1791
1791
|
if (!overloads) {
|
|
1792
1792
|
const match = overrideBlockReg.exec(runtimeTypes);
|
|
@@ -1797,15 +1797,17 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1797
1797
|
let lastIndex = 0;
|
|
1798
1798
|
content = content.replace(commentsReg, "");
|
|
1799
1799
|
while (replaceMatch = replaceTokensReg.exec(content)) {
|
|
1800
|
-
const [, methodName, propertyName] = replaceMatch;
|
|
1800
|
+
const [, methodName, propertyName, returnName] = replaceMatch;
|
|
1801
1801
|
const curText = content.slice(lastIndex, replaceMatch.index);
|
|
1802
1802
|
lastIndex = replaceTokensReg.lastIndex;
|
|
1803
1803
|
if (methodName) {
|
|
1804
1804
|
overloads.push(curText + methodName, 0 /* Generics */);
|
|
1805
|
+
} else if (returnName) {
|
|
1806
|
+
overloads.push(curText, 2 /* Return */);
|
|
1805
1807
|
} else {
|
|
1806
1808
|
overloads.push(
|
|
1807
1809
|
curText,
|
|
1808
|
-
propertyName === "Component" ?
|
|
1810
|
+
propertyName === "Component" ? 3 /* Component */ : 1 /* Input */
|
|
1809
1811
|
);
|
|
1810
1812
|
}
|
|
1811
1813
|
}
|
|
@@ -1823,7 +1825,10 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1823
1825
|
case 1 /* Input */:
|
|
1824
1826
|
result += appliedInput;
|
|
1825
1827
|
break;
|
|
1826
|
-
case 2 /*
|
|
1828
|
+
case 2 /* Return */:
|
|
1829
|
+
result += returnType;
|
|
1830
|
+
break;
|
|
1831
|
+
case 3 /* Component */:
|
|
1827
1832
|
result += appliedComponent;
|
|
1828
1833
|
break;
|
|
1829
1834
|
default:
|
|
@@ -2145,12 +2150,18 @@ ${varShared("noop")}(`);
|
|
|
2145
2150
|
const internalInput = varLocal("input");
|
|
2146
2151
|
const internalInputWithExtends = `${internalInput} extends unknown`;
|
|
2147
2152
|
const internalApply = varLocal("apply");
|
|
2153
|
+
const returnTypeStr = didReturn ? `typeof ${templateName + typeArgsStr} extends () => infer Return ? Return : never` : "void";
|
|
2148
2154
|
const renderAndReturn = `(input: Marko.Directives & Input${typeArgsStr} & ${varShared(
|
|
2149
2155
|
"Relate"
|
|
2150
2156
|
)}<${internalInput}, Marko.Directives & Input${typeArgsStr}>) => (${varShared(
|
|
2151
2157
|
"ReturnWithScope"
|
|
2152
|
-
)}<${internalInput}, ${
|
|
2153
|
-
const templateOverrideClass = `${templateBaseClass}<{${this.#runtimeTypes ? getRuntimeOverrides(
|
|
2158
|
+
)}<${internalInput}, ${returnTypeStr}>)`;
|
|
2159
|
+
const templateOverrideClass = `${templateBaseClass}<{${this.#runtimeTypes ? getRuntimeOverrides(
|
|
2160
|
+
this.#runtimeTypes,
|
|
2161
|
+
typeParamsStr,
|
|
2162
|
+
typeArgsStr,
|
|
2163
|
+
returnTypeStr
|
|
2164
|
+
) : ""}
|
|
2154
2165
|
${this.#api ? `api: "${this.#api}",` : ""}
|
|
2155
2166
|
_${typeParamsStr ? `<${internalApply} = 1>(): ${internalApply} extends 0
|
|
2156
2167
|
? ${typeParamsStr}() => <${internalInputWithExtends}>${renderAndReturn}
|
|
@@ -2410,11 +2421,11 @@ constructor(_?: Return) {}
|
|
|
2410
2421
|
const tagName = tag.nameText;
|
|
2411
2422
|
const renderId = this.#getRenderId(tag);
|
|
2412
2423
|
const def = tagName ? this.#lookup.getTag(tagName) : void 0;
|
|
2413
|
-
const
|
|
2414
|
-
const
|
|
2424
|
+
const importPath = resolveTagImport(this.#filename, def);
|
|
2425
|
+
const isHTML = !importPath && (def == null ? void 0 : def.html);
|
|
2415
2426
|
let tagIdentifier;
|
|
2416
2427
|
let isTemplate = false;
|
|
2417
|
-
if (!
|
|
2428
|
+
if (!def || importPath) {
|
|
2418
2429
|
const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
|
|
2419
2430
|
const isMarkoFile = importPath == null ? void 0 : importPath.endsWith(".marko");
|
|
2420
2431
|
if (isIdentifier || isMarkoFile || !importPath) {
|
package/dist/util/project.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TaglibLookup } from "@marko/babel-utils";
|
|
2
1
|
import type * as Compiler from "@marko/compiler";
|
|
2
|
+
import type { TaglibLookup } from "@marko/compiler/babel-utils";
|
|
3
3
|
import type TS from "typescript/lib/tsserverlibrary";
|
|
4
4
|
import { ScriptLang } from "../extractors/script";
|
|
5
5
|
export interface Meta {
|
package/marko.internal.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ declare global {
|
|
|
135
135
|
: Handler
|
|
136
136
|
: (...args: any) => any; // If typescript ever actually supports partial application maybe we do this.
|
|
137
137
|
|
|
138
|
-
export function renderTemplate<Name extends Marko.Template
|
|
138
|
+
export function renderTemplate<Name extends Marko.Template<any, any>>(
|
|
139
139
|
template: Name,
|
|
140
140
|
): TemplateRenderer<Name>;
|
|
141
141
|
export function renderNativeTag<Name extends string>(
|
|
@@ -328,7 +328,7 @@ declare global {
|
|
|
328
328
|
// currently falls back to DefaultRenderer too eagerly.
|
|
329
329
|
export type DynamicRenderer<Name> = [0] extends [1 & Name]
|
|
330
330
|
? DefaultRenderer
|
|
331
|
-
: [Name] extends [Marko.Template]
|
|
331
|
+
: [Name] extends [Marko.Template<any, any>]
|
|
332
332
|
? TemplateRenderer<Name>
|
|
333
333
|
: [Name] extends [string]
|
|
334
334
|
? NativeTagRenderer<Name>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/language-tools",
|
|
3
3
|
"description": "Marko Language Tools",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.27",
|
|
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"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/parser": "^7.28.0",
|
|
11
11
|
"@luxass/strip-json-comments": "^1.4.0",
|
|
12
|
-
"htmljs-parser": "^5.
|
|
12
|
+
"htmljs-parser": "^5.6.1",
|
|
13
13
|
"relative-import-path": "^1.0.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|