@marko/language-tools 2.4.0 → 2.4.2
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/index.js +31 -29
- package/dist/index.mjs +31 -29
- package/marko.internal.d.ts +23 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1964,7 +1964,7 @@ constructor(_?: Return) {}
|
|
|
1964
1964
|
this.#extractor.copy(returned);
|
|
1965
1965
|
this.#extractor.write(");\n");
|
|
1966
1966
|
}
|
|
1967
|
-
#writeChildren(parent, children) {
|
|
1967
|
+
#writeChildren(parent, children, skipRenderId = false) {
|
|
1968
1968
|
var _a, _b;
|
|
1969
1969
|
const last = children.length - 1;
|
|
1970
1970
|
let returnTag;
|
|
@@ -1979,27 +1979,31 @@ constructor(_?: Return) {}
|
|
|
1979
1979
|
break;
|
|
1980
1980
|
case "if": {
|
|
1981
1981
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
1982
|
-
let renderId
|
|
1983
|
-
if (!
|
|
1984
|
-
|
|
1985
|
-
|
|
1982
|
+
let renderId;
|
|
1983
|
+
if (!skipRenderId) {
|
|
1984
|
+
renderId = this.#getRenderId(child);
|
|
1985
|
+
if (!renderId && alternates) {
|
|
1986
|
+
for (const { node } of alternates) {
|
|
1987
|
+
if (renderId = this.#getRenderId(node)) break;
|
|
1988
|
+
}
|
|
1986
1989
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
)}, ${renderId}, (() => {
|
|
1990
|
+
if (renderId) {
|
|
1991
|
+
this.#extractor.write(
|
|
1992
|
+
`${varShared("assertRendered")}(${varShared(
|
|
1993
|
+
"rendered"
|
|
1994
|
+
)}, ${renderId}, (() => {
|
|
1993
1995
|
`
|
|
1994
|
-
|
|
1996
|
+
);
|
|
1997
|
+
}
|
|
1995
1998
|
}
|
|
1996
1999
|
this.#writeComments(child);
|
|
1997
2000
|
this.#extractor.write("if (").copy(
|
|
1998
2001
|
this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
|
|
1999
2002
|
).write(") {\n");
|
|
2000
|
-
|
|
2003
|
+
const ifBody = this.#processBody(child);
|
|
2004
|
+
if (ifBody == null ? void 0 : ifBody.renderBody) {
|
|
2001
2005
|
const localBindings = getHoistSources(child);
|
|
2002
|
-
this.#writeChildren(child,
|
|
2006
|
+
this.#writeChildren(child, ifBody.renderBody, true);
|
|
2003
2007
|
if (localBindings) {
|
|
2004
2008
|
this.#extractor.write("return {\nscope:");
|
|
2005
2009
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2018,9 +2022,10 @@ constructor(_?: Return) {}
|
|
|
2018
2022
|
} else {
|
|
2019
2023
|
this.#extractor.write("\n} else if (undefined) {\n");
|
|
2020
2024
|
}
|
|
2021
|
-
|
|
2025
|
+
const alternateBody = this.#processBody(node);
|
|
2026
|
+
if (alternateBody == null ? void 0 : alternateBody.renderBody) {
|
|
2022
2027
|
const localBindings = getHoistSources(node);
|
|
2023
|
-
this.#writeChildren(node,
|
|
2028
|
+
this.#writeChildren(node, alternateBody.renderBody, true);
|
|
2024
2029
|
if (localBindings) {
|
|
2025
2030
|
this.#extractor.write("return {\nscope:");
|
|
2026
2031
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2487,23 +2492,22 @@ const attrTags = ${varShared(
|
|
|
2487
2492
|
}
|
|
2488
2493
|
#writeTagInputObject(tag) {
|
|
2489
2494
|
if (!tag.params) this.#writeComments(tag);
|
|
2490
|
-
const body = this.#processBody(tag);
|
|
2491
|
-
let writeInputObj = true;
|
|
2492
2495
|
let hasInput = false;
|
|
2496
|
+
this.#extractor.write("{\n");
|
|
2493
2497
|
if (tag.args) {
|
|
2494
2498
|
hasInput = true;
|
|
2495
|
-
this.#extractor.copy(
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
this.#extractor.write("{\n");
|
|
2499
|
+
this.#extractor.write("[").copy({
|
|
2500
|
+
start: tag.args.start,
|
|
2501
|
+
end: tag.args.start + 1
|
|
2502
|
+
}).write('"value"').copy({
|
|
2503
|
+
start: tag.args.end - 1,
|
|
2504
|
+
end: tag.args.end
|
|
2505
|
+
}).write(`]: ${varShared("tuple")}(`).copy(tag.args.value).write(")").write(",\n");
|
|
2503
2506
|
}
|
|
2504
2507
|
if (this.#writeAttrs(tag)) {
|
|
2505
2508
|
hasInput = true;
|
|
2506
2509
|
}
|
|
2510
|
+
const body = this.#processBody(tag);
|
|
2507
2511
|
let hasRenderBody = false;
|
|
2508
2512
|
if (body) {
|
|
2509
2513
|
hasInput = true;
|
|
@@ -2549,9 +2553,7 @@ const attrTags = ${varShared(
|
|
|
2549
2553
|
if (!hasInput) {
|
|
2550
2554
|
this.#writeTagNameComment(tag);
|
|
2551
2555
|
}
|
|
2552
|
-
|
|
2553
|
-
this.#extractor.write("\n}");
|
|
2554
|
-
}
|
|
2556
|
+
this.#extractor.write("\n}");
|
|
2555
2557
|
}
|
|
2556
2558
|
#writeObjectKeys(keys) {
|
|
2557
2559
|
this.#extractor.write("{");
|
package/dist/index.mjs
CHANGED
|
@@ -1928,7 +1928,7 @@ constructor(_?: Return) {}
|
|
|
1928
1928
|
this.#extractor.copy(returned);
|
|
1929
1929
|
this.#extractor.write(");\n");
|
|
1930
1930
|
}
|
|
1931
|
-
#writeChildren(parent, children) {
|
|
1931
|
+
#writeChildren(parent, children, skipRenderId = false) {
|
|
1932
1932
|
var _a, _b;
|
|
1933
1933
|
const last = children.length - 1;
|
|
1934
1934
|
let returnTag;
|
|
@@ -1943,27 +1943,31 @@ constructor(_?: Return) {}
|
|
|
1943
1943
|
break;
|
|
1944
1944
|
case "if": {
|
|
1945
1945
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
1946
|
-
let renderId
|
|
1947
|
-
if (!
|
|
1948
|
-
|
|
1949
|
-
|
|
1946
|
+
let renderId;
|
|
1947
|
+
if (!skipRenderId) {
|
|
1948
|
+
renderId = this.#getRenderId(child);
|
|
1949
|
+
if (!renderId && alternates) {
|
|
1950
|
+
for (const { node } of alternates) {
|
|
1951
|
+
if (renderId = this.#getRenderId(node)) break;
|
|
1952
|
+
}
|
|
1950
1953
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
)}, ${renderId}, (() => {
|
|
1954
|
+
if (renderId) {
|
|
1955
|
+
this.#extractor.write(
|
|
1956
|
+
`${varShared("assertRendered")}(${varShared(
|
|
1957
|
+
"rendered"
|
|
1958
|
+
)}, ${renderId}, (() => {
|
|
1957
1959
|
`
|
|
1958
|
-
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1959
1962
|
}
|
|
1960
1963
|
this.#writeComments(child);
|
|
1961
1964
|
this.#extractor.write("if (").copy(
|
|
1962
1965
|
this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
|
|
1963
1966
|
).write(") {\n");
|
|
1964
|
-
|
|
1967
|
+
const ifBody = this.#processBody(child);
|
|
1968
|
+
if (ifBody == null ? void 0 : ifBody.renderBody) {
|
|
1965
1969
|
const localBindings = getHoistSources(child);
|
|
1966
|
-
this.#writeChildren(child,
|
|
1970
|
+
this.#writeChildren(child, ifBody.renderBody, true);
|
|
1967
1971
|
if (localBindings) {
|
|
1968
1972
|
this.#extractor.write("return {\nscope:");
|
|
1969
1973
|
this.#writeObjectKeys(localBindings);
|
|
@@ -1982,9 +1986,10 @@ constructor(_?: Return) {}
|
|
|
1982
1986
|
} else {
|
|
1983
1987
|
this.#extractor.write("\n} else if (undefined) {\n");
|
|
1984
1988
|
}
|
|
1985
|
-
|
|
1989
|
+
const alternateBody = this.#processBody(node);
|
|
1990
|
+
if (alternateBody == null ? void 0 : alternateBody.renderBody) {
|
|
1986
1991
|
const localBindings = getHoistSources(node);
|
|
1987
|
-
this.#writeChildren(node,
|
|
1992
|
+
this.#writeChildren(node, alternateBody.renderBody, true);
|
|
1988
1993
|
if (localBindings) {
|
|
1989
1994
|
this.#extractor.write("return {\nscope:");
|
|
1990
1995
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2451,23 +2456,22 @@ const attrTags = ${varShared(
|
|
|
2451
2456
|
}
|
|
2452
2457
|
#writeTagInputObject(tag) {
|
|
2453
2458
|
if (!tag.params) this.#writeComments(tag);
|
|
2454
|
-
const body = this.#processBody(tag);
|
|
2455
|
-
let writeInputObj = true;
|
|
2456
2459
|
let hasInput = false;
|
|
2460
|
+
this.#extractor.write("{\n");
|
|
2457
2461
|
if (tag.args) {
|
|
2458
2462
|
hasInput = true;
|
|
2459
|
-
this.#extractor.copy(
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
this.#extractor.write("{\n");
|
|
2463
|
+
this.#extractor.write("[").copy({
|
|
2464
|
+
start: tag.args.start,
|
|
2465
|
+
end: tag.args.start + 1
|
|
2466
|
+
}).write('"value"').copy({
|
|
2467
|
+
start: tag.args.end - 1,
|
|
2468
|
+
end: tag.args.end
|
|
2469
|
+
}).write(`]: ${varShared("tuple")}(`).copy(tag.args.value).write(")").write(",\n");
|
|
2467
2470
|
}
|
|
2468
2471
|
if (this.#writeAttrs(tag)) {
|
|
2469
2472
|
hasInput = true;
|
|
2470
2473
|
}
|
|
2474
|
+
const body = this.#processBody(tag);
|
|
2471
2475
|
let hasRenderBody = false;
|
|
2472
2476
|
if (body) {
|
|
2473
2477
|
hasInput = true;
|
|
@@ -2513,9 +2517,7 @@ const attrTags = ${varShared(
|
|
|
2513
2517
|
if (!hasInput) {
|
|
2514
2518
|
this.#writeTagNameComment(tag);
|
|
2515
2519
|
}
|
|
2516
|
-
|
|
2517
|
-
this.#extractor.write("\n}");
|
|
2518
|
-
}
|
|
2520
|
+
this.#extractor.write("\n}");
|
|
2519
2521
|
}
|
|
2520
2522
|
#writeObjectKeys(keys) {
|
|
2521
2523
|
this.#extractor.write("{");
|
package/marko.internal.d.ts
CHANGED
|
@@ -310,10 +310,14 @@ declare global {
|
|
|
310
310
|
? NativeTagRenderer<Name>
|
|
311
311
|
: [Name] extends [AnyMarkoBody]
|
|
312
312
|
? BodyRenderer<Name>
|
|
313
|
-
: [Name] extends [
|
|
314
|
-
|
|
315
|
-
]
|
|
316
|
-
|
|
313
|
+
: [Name] extends [{ renderBody?: AnyMarkoBody }]
|
|
314
|
+
? [Name["renderBody"]] extends [AnyMarkoBody]
|
|
315
|
+
? BodyRenderer<Name["renderBody"]>
|
|
316
|
+
: BaseRenderer<
|
|
317
|
+
RenderBodyInput<
|
|
318
|
+
BodyParameters<Exclude<Name["renderBody"], void>>
|
|
319
|
+
>
|
|
320
|
+
>
|
|
317
321
|
: DefaultRenderer;
|
|
318
322
|
|
|
319
323
|
export type TemplateRenderer<Template> = Template extends {
|
|
@@ -345,8 +349,12 @@ declare global {
|
|
|
345
349
|
export interface BodyRenderer<Body extends AnyMarkoBody> {
|
|
346
350
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
347
351
|
(): () => <__marko_internal_input extends unknown>(
|
|
348
|
-
|
|
349
|
-
|
|
352
|
+
input: Marko.Directives &
|
|
353
|
+
RenderBodyInput<BodyParameters<Body>> &
|
|
354
|
+
Relate<
|
|
355
|
+
__marko_internal_input,
|
|
356
|
+
Marko.Directives & RenderBodyInput<BodyParameters<Body>>
|
|
357
|
+
>,
|
|
350
358
|
) => ReturnAndScope<
|
|
351
359
|
Scopes<__marko_internal_input>,
|
|
352
360
|
BodyReturnType<Body>
|
|
@@ -393,12 +401,15 @@ type ReturnAndScope<Scope, Return> = {
|
|
|
393
401
|
scope: Scope;
|
|
394
402
|
};
|
|
395
403
|
|
|
396
|
-
type
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
:
|
|
404
|
+
type RenderBodyInput<Args extends readonly unknown[]> = Args extends {
|
|
405
|
+
length: infer Length;
|
|
406
|
+
}
|
|
407
|
+
? number extends Length
|
|
408
|
+
? { value?: Args }
|
|
409
|
+
: 0 extends Length
|
|
410
|
+
? { value?: [] }
|
|
411
|
+
: { value: Args }
|
|
412
|
+
: never;
|
|
402
413
|
|
|
403
414
|
type Scopes<Input> = [0] extends [1 & Input]
|
|
404
415
|
? never
|
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.4.
|
|
4
|
+
"version": "2.4.2",
|
|
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"
|