@marko/language-tools 2.3.1 → 2.4.1
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 +128 -152
- package/dist/index.mjs +128 -156
- package/dist/processors/index.d.ts +2 -2
- package/dist/util/project.d.ts +1 -1
- package/marko.internal.d.ts +46 -77
- package/package.json +9 -11
- package/dist/extractors/script/util/is-valid-identifier.d.ts +0 -1
package/dist/index.mjs
CHANGED
|
@@ -10,8 +10,7 @@ import { TagType, createParser } from "htmljs-parser";
|
|
|
10
10
|
// src/util/get-node-at-offset.ts
|
|
11
11
|
function getNodeAtOffset(offset, program) {
|
|
12
12
|
const childNode = childAtOffset(offset, program.body);
|
|
13
|
-
if (childNode)
|
|
14
|
-
return visitChildNode(offset, childNode);
|
|
13
|
+
if (childNode) return visitChildNode(offset, childNode);
|
|
15
14
|
return childAtOffset(offset, program.static) || program;
|
|
16
15
|
}
|
|
17
16
|
function visitChildNode(offset, child) {
|
|
@@ -75,8 +74,7 @@ function visitAttrNode(offset, attr) {
|
|
|
75
74
|
}
|
|
76
75
|
function childAtOffset(offset, children) {
|
|
77
76
|
let max = children.length - 1;
|
|
78
|
-
if (max === -1)
|
|
79
|
-
return void 0;
|
|
77
|
+
if (max === -1) return void 0;
|
|
80
78
|
let min = 0;
|
|
81
79
|
while (min < max) {
|
|
82
80
|
const mid = 1 + min + max >>> 1;
|
|
@@ -258,6 +256,7 @@ var Builder = class {
|
|
|
258
256
|
}
|
|
259
257
|
if (!range.expressions.length) {
|
|
260
258
|
switch (nameText = this.#code.slice(range.start, range.end)) {
|
|
259
|
+
// All statement types will early return.
|
|
261
260
|
case "style": {
|
|
262
261
|
styleBlockReg.lastIndex = range.end;
|
|
263
262
|
const styleBlockMatch = styleBlockReg.exec(this.#code);
|
|
@@ -332,6 +331,8 @@ var Builder = class {
|
|
|
332
331
|
);
|
|
333
332
|
this.#comments = void 0;
|
|
334
333
|
return TagType.statement;
|
|
334
|
+
// The following are all still tags,
|
|
335
|
+
// but with a different body type.
|
|
335
336
|
case "area":
|
|
336
337
|
case "base":
|
|
337
338
|
case "br":
|
|
@@ -591,8 +592,7 @@ var Builder = class {
|
|
|
591
592
|
}
|
|
592
593
|
onCloseTagEnd(range) {
|
|
593
594
|
const parent = this.#parentNode;
|
|
594
|
-
if (hasCloseTag(parent))
|
|
595
|
-
parent.close.end = range.end;
|
|
595
|
+
if (hasCloseTag(parent)) parent.close.end = range.end;
|
|
596
596
|
parent.end = range.end;
|
|
597
597
|
this.#parentNode = parent.parent;
|
|
598
598
|
}
|
|
@@ -691,8 +691,7 @@ var Extracted = class {
|
|
|
691
691
|
}
|
|
692
692
|
sourcePositionAt(generatedOffset) {
|
|
693
693
|
const sourceOffset = this.sourceOffsetAt(generatedOffset);
|
|
694
|
-
if (sourceOffset !== void 0)
|
|
695
|
-
return this.parsed.positionAt(sourceOffset);
|
|
694
|
+
if (sourceOffset !== void 0) return this.parsed.positionAt(sourceOffset);
|
|
696
695
|
}
|
|
697
696
|
sourceLocationAt(generatedStart, generatedEnd) {
|
|
698
697
|
const sourceRange = this.#generatedToSource.rangeAt(
|
|
@@ -768,8 +767,7 @@ var TokenView = class {
|
|
|
768
767
|
}
|
|
769
768
|
const startToken = this.#tokens[max];
|
|
770
769
|
const startTokenInStart = this.inStart(startToken);
|
|
771
|
-
if (startTokenInStart >= inEnd)
|
|
772
|
-
return;
|
|
770
|
+
if (startTokenInStart >= inEnd) return;
|
|
773
771
|
max = this.#last;
|
|
774
772
|
while (min < max) {
|
|
775
773
|
const mid = 1 + min + max >>> 1;
|
|
@@ -784,8 +782,7 @@ var TokenView = class {
|
|
|
784
782
|
const endToken = this.#tokens[min];
|
|
785
783
|
const endTokenInStart = this.inStart(endToken);
|
|
786
784
|
const endTokenInEnd = endTokenInStart + endToken.length;
|
|
787
|
-
if (endTokenInEnd < inStart)
|
|
788
|
-
return;
|
|
785
|
+
if (endTokenInEnd < inStart) return;
|
|
789
786
|
const startIndex = inStart - startTokenInStart;
|
|
790
787
|
const endIndex = inEnd - endTokenInStart;
|
|
791
788
|
const start = this.outStart(startToken) + Math.max(0, startIndex);
|
|
@@ -947,16 +944,6 @@ var ScriptParser = class {
|
|
|
947
944
|
}
|
|
948
945
|
};
|
|
949
946
|
|
|
950
|
-
// src/extractors/script/util/is-valid-identifier.ts
|
|
951
|
-
import {
|
|
952
|
-
isIdentifierName,
|
|
953
|
-
isKeyword,
|
|
954
|
-
isStrictBindReservedWord
|
|
955
|
-
} from "@babel/helper-validator-identifier";
|
|
956
|
-
function isValidIdentifier(name) {
|
|
957
|
-
return isIdentifierName(name) && !isKeyword(name) && !isStrictBindReservedWord(name, true);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
947
|
// src/extractors/script/util/attach-scopes.ts
|
|
961
948
|
import * as t from "@babel/types";
|
|
962
949
|
var ATTR_UNAMED = "value";
|
|
@@ -1327,6 +1314,10 @@ function* getVarIdentifiers(parsed, lVal, objectPath, sourceName) {
|
|
|
1327
1314
|
function trackMutationsInClosures(root, scope, mutations) {
|
|
1328
1315
|
traverse(root, (node) => {
|
|
1329
1316
|
switch (node.type) {
|
|
1317
|
+
// Since the root will always be an expression it's impossible
|
|
1318
|
+
// to hit a "FunctionDeclaration" without first going through
|
|
1319
|
+
// a a different function context. So we don't need to track it.
|
|
1320
|
+
// case "FunctionDeclaration":
|
|
1330
1321
|
case "FunctionExpression":
|
|
1331
1322
|
case "ObjectMethod":
|
|
1332
1323
|
case "ArrowFunctionExpression":
|
|
@@ -1338,8 +1329,7 @@ function trackMutationsInClosures(root, scope, mutations) {
|
|
|
1338
1329
|
});
|
|
1339
1330
|
}
|
|
1340
1331
|
function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows, parentBlockMutations) {
|
|
1341
|
-
if (!node)
|
|
1342
|
-
return;
|
|
1332
|
+
if (!node) return;
|
|
1343
1333
|
let block = parentBlock;
|
|
1344
1334
|
let blockShadows = parentBlockShadows;
|
|
1345
1335
|
let blockMutations = parentBlockMutations;
|
|
@@ -1462,8 +1452,7 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
|
|
|
1462
1452
|
}
|
|
1463
1453
|
if (block !== parentBlock && blockMutations.length) {
|
|
1464
1454
|
for (const { name, start } of blockMutations) {
|
|
1465
|
-
if (blockShadows.has(name))
|
|
1466
|
-
continue;
|
|
1455
|
+
if (blockShadows.has(name)) continue;
|
|
1467
1456
|
const binding = resolveWritableVar(scope, name);
|
|
1468
1457
|
if (binding) {
|
|
1469
1458
|
binding.mutated = true;
|
|
@@ -1480,10 +1469,8 @@ function trackShadows(node, scope, shadows) {
|
|
|
1480
1469
|
}
|
|
1481
1470
|
}
|
|
1482
1471
|
function traverse(node, enter) {
|
|
1483
|
-
if (!node)
|
|
1484
|
-
|
|
1485
|
-
if (enter(node))
|
|
1486
|
-
return;
|
|
1472
|
+
if (!node) return;
|
|
1473
|
+
if (enter(node)) return;
|
|
1487
1474
|
for (const key of t.VISITOR_KEYS[node.type]) {
|
|
1488
1475
|
const child = node[key];
|
|
1489
1476
|
if (Array.isArray(child)) {
|
|
@@ -1581,8 +1568,7 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1581
1568
|
var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
|
|
1582
1569
|
function getJSDocInputType(comment, ts) {
|
|
1583
1570
|
var _a, _b, _c, _d;
|
|
1584
|
-
if (!MaybeInputTypedefReg.test(comment))
|
|
1585
|
-
return;
|
|
1571
|
+
if (!MaybeInputTypedefReg.test(comment)) return;
|
|
1586
1572
|
const sourceFile = ts.createSourceFile(
|
|
1587
1573
|
"_.js",
|
|
1588
1574
|
comment,
|
|
@@ -1591,8 +1577,7 @@ function getJSDocInputType(comment, ts) {
|
|
|
1591
1577
|
ts.ScriptKind.JS
|
|
1592
1578
|
);
|
|
1593
1579
|
const tags = (_b = (_a = sourceFile.endOfFileToken.jsDoc) == null ? void 0 : _a[0]) == null ? void 0 : _b.tags;
|
|
1594
|
-
if (!(tags && hasInputTypeDef(ts, sourceFile, tags)))
|
|
1595
|
-
return;
|
|
1580
|
+
if (!(tags && hasInputTypeDef(ts, sourceFile, tags))) return;
|
|
1596
1581
|
let typeParameters;
|
|
1597
1582
|
for (const tag of tags) {
|
|
1598
1583
|
if (isTemplateTag(ts, tag)) {
|
|
@@ -1642,10 +1627,11 @@ var REG_EXT = /(?<=[/\\][^/\\]+)\.[^.]+$/;
|
|
|
1642
1627
|
var REG_BLOCK = /\s*{/y;
|
|
1643
1628
|
var REG_NEW_LINE = /^|(\r?\n)/g;
|
|
1644
1629
|
var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]+|\\.|(?!\1))*)\1\s*([,)])/my;
|
|
1645
|
-
var REG_TAG_IMPORT = /(?<=(['"]))<([
|
|
1630
|
+
var REG_TAG_IMPORT = /(?<=(['"]))<([^'">]+)>(?=\1)/;
|
|
1646
1631
|
var REG_INPUT_TYPE = /\s*(interface|type)\s+Input\b/y;
|
|
1647
1632
|
var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
|
|
1648
1633
|
var REG_COMMENT_PRAGMA = /\/\/(?:\s*@ts-|\/\s*<)/y;
|
|
1634
|
+
var REG_TAG_NAME_IDENTIFIER = /^[A-Z][a-zA-Z_$]+$/;
|
|
1649
1635
|
var IF_TAG_ALTERNATES = /* @__PURE__ */ new WeakMap();
|
|
1650
1636
|
var WROTE_COMMENT = /* @__PURE__ */ new WeakSet();
|
|
1651
1637
|
var START_OF_FILE = { start: 0, end: 0 };
|
|
@@ -1942,7 +1928,7 @@ constructor(_?: Return) {}
|
|
|
1942
1928
|
this.#extractor.copy(returned);
|
|
1943
1929
|
this.#extractor.write(");\n");
|
|
1944
1930
|
}
|
|
1945
|
-
#writeChildren(parent, children) {
|
|
1931
|
+
#writeChildren(parent, children, skipRenderId = false) {
|
|
1946
1932
|
var _a, _b;
|
|
1947
1933
|
const last = children.length - 1;
|
|
1948
1934
|
let returnTag;
|
|
@@ -1957,28 +1943,31 @@ constructor(_?: Return) {}
|
|
|
1957
1943
|
break;
|
|
1958
1944
|
case "if": {
|
|
1959
1945
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
1960
|
-
let renderId
|
|
1961
|
-
if (!
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
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
|
+
}
|
|
1965
1953
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
)}, ${renderId}, (() => {
|
|
1954
|
+
if (renderId) {
|
|
1955
|
+
this.#extractor.write(
|
|
1956
|
+
`${varShared("assertRendered")}(${varShared(
|
|
1957
|
+
"rendered"
|
|
1958
|
+
)}, ${renderId}, (() => {
|
|
1972
1959
|
`
|
|
1973
|
-
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1974
1962
|
}
|
|
1975
1963
|
this.#writeComments(child);
|
|
1976
1964
|
this.#extractor.write("if (").copy(
|
|
1977
1965
|
this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
|
|
1978
1966
|
).write(") {\n");
|
|
1979
|
-
|
|
1967
|
+
const ifBody = this.#processBody(child);
|
|
1968
|
+
if (ifBody == null ? void 0 : ifBody.renderBody) {
|
|
1980
1969
|
const localBindings = getHoistSources(child);
|
|
1981
|
-
this.#writeChildren(child,
|
|
1970
|
+
this.#writeChildren(child, ifBody.renderBody, true);
|
|
1982
1971
|
if (localBindings) {
|
|
1983
1972
|
this.#extractor.write("return {\nscope:");
|
|
1984
1973
|
this.#writeObjectKeys(localBindings);
|
|
@@ -1997,9 +1986,10 @@ constructor(_?: Return) {}
|
|
|
1997
1986
|
} else {
|
|
1998
1987
|
this.#extractor.write("\n} else if (undefined) {\n");
|
|
1999
1988
|
}
|
|
2000
|
-
|
|
1989
|
+
const alternateBody = this.#processBody(node);
|
|
1990
|
+
if (alternateBody == null ? void 0 : alternateBody.renderBody) {
|
|
2001
1991
|
const localBindings = getHoistSources(node);
|
|
2002
|
-
this.#writeChildren(node,
|
|
1992
|
+
this.#writeChildren(node, alternateBody.renderBody, true);
|
|
2003
1993
|
if (localBindings) {
|
|
2004
1994
|
this.#extractor.write("return {\nscope:");
|
|
2005
1995
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2132,7 +2122,7 @@ constructor(_?: Return) {}
|
|
|
2132
2122
|
if (def) {
|
|
2133
2123
|
const importPath = resolveTagImport(this.#filename, def);
|
|
2134
2124
|
const renderer = (importPath == null ? void 0 : importPath.endsWith(".marko")) ? `renderTemplate(import("${importPath}"))` : def.html ? `renderNativeTag("${def.name}")` : "missingTag";
|
|
2135
|
-
if (!def.html &&
|
|
2125
|
+
if (!def.html && REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2136
2126
|
this.#extractor.write(
|
|
2137
2127
|
`${varShared("renderPreferLocal")}(
|
|
2138
2128
|
// @ts-expect-error We expect the compiler to error because we are checking if the tag is defined.
|
|
@@ -2142,7 +2132,7 @@ ${varShared(renderer)})`);
|
|
|
2142
2132
|
} else {
|
|
2143
2133
|
this.#extractor.write(varShared(renderer));
|
|
2144
2134
|
}
|
|
2145
|
-
} else if (
|
|
2135
|
+
} else if (REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2146
2136
|
this.#extractor.write(`${varShared("renderDynamicTag")}(
|
|
2147
2137
|
`).copy(tag.name).write("\n)");
|
|
2148
2138
|
} else {
|
|
@@ -2364,13 +2354,11 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2364
2354
|
}
|
|
2365
2355
|
if (dynamicAttrTagParents) {
|
|
2366
2356
|
this.#writeDynamicAttrTagParents(dynamicAttrTagParents);
|
|
2367
|
-
if (wasMerge)
|
|
2368
|
-
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2357
|
+
if (wasMerge) this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2369
2358
|
}
|
|
2370
2359
|
}
|
|
2371
2360
|
#writeStaticAttrTags(staticAttrTags, wasMerge) {
|
|
2372
|
-
if (!wasMerge)
|
|
2373
|
-
this.#extractor.write("...{");
|
|
2361
|
+
if (!wasMerge) this.#extractor.write("...{");
|
|
2374
2362
|
this.#extractor.write(
|
|
2375
2363
|
`[${varShared("never")}](){
|
|
2376
2364
|
const attrTags = ${varShared(
|
|
@@ -2386,27 +2374,27 @@ const attrTags = ${varShared(
|
|
|
2386
2374
|
}
|
|
2387
2375
|
}
|
|
2388
2376
|
this.#extractor.write("\n}");
|
|
2389
|
-
if (!wasMerge)
|
|
2390
|
-
this.#extractor.write("}");
|
|
2377
|
+
if (!wasMerge) this.#extractor.write("}");
|
|
2391
2378
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2392
2379
|
for (const nameText in staticAttrTags) {
|
|
2393
2380
|
const attrTag = staticAttrTags[nameText];
|
|
2394
2381
|
const attrTagDef = this.#lookup.getTag(nameText);
|
|
2395
|
-
const isRepeated = attrTag.length > 1
|
|
2382
|
+
const isRepeated = attrTag.length > 1;
|
|
2396
2383
|
const [firstAttrTag] = attrTag;
|
|
2397
2384
|
const name = (attrTagDef == null ? void 0 : attrTagDef.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
|
|
2398
2385
|
this.#extractor.write(`["${name}"`);
|
|
2399
2386
|
this.#writeTagNameComment(firstAttrTag);
|
|
2400
2387
|
this.#extractor.write("]: ");
|
|
2401
2388
|
if (isRepeated) {
|
|
2402
|
-
this.#extractor.write("
|
|
2389
|
+
this.#extractor.write(`${varShared("repeatedAttrTag")}(
|
|
2390
|
+
`);
|
|
2403
2391
|
}
|
|
2404
2392
|
for (const childNode of attrTag) {
|
|
2405
2393
|
this.#writeTagInputObject(childNode);
|
|
2406
2394
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2407
2395
|
}
|
|
2408
2396
|
if (isRepeated) {
|
|
2409
|
-
this.#extractor.write(`
|
|
2397
|
+
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2410
2398
|
}
|
|
2411
2399
|
}
|
|
2412
2400
|
}
|
|
@@ -2445,8 +2433,7 @@ const attrTags = ${varShared(
|
|
|
2445
2433
|
case "for": {
|
|
2446
2434
|
this.#extractor.write(`${varShared("forAttrTag")}({
|
|
2447
2435
|
`);
|
|
2448
|
-
if (!this.#writeAttrs(tag))
|
|
2449
|
-
this.#writeTagNameComment(tag);
|
|
2436
|
+
if (!this.#writeAttrs(tag)) this.#writeTagNameComment(tag);
|
|
2450
2437
|
this.#extractor.write("}, \n");
|
|
2451
2438
|
this.#writeComments(tag);
|
|
2452
2439
|
this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => (");
|
|
@@ -2456,12 +2443,11 @@ const attrTags = ${varShared(
|
|
|
2456
2443
|
}
|
|
2457
2444
|
case "while": {
|
|
2458
2445
|
this.#writeComments(tag);
|
|
2459
|
-
this.#extractor.write(
|
|
2460
|
-
`).copy(
|
|
2446
|
+
this.#extractor.write("((\n").copy(
|
|
2461
2447
|
this.#getRangeWithoutTrailingComma((_c = tag.args) == null ? void 0 : _c.value) || "undefined"
|
|
2462
|
-
).write("\n) ?
|
|
2448
|
+
).write("\n) ? ");
|
|
2463
2449
|
this.#writeDynamicAttrTagBody(tag);
|
|
2464
|
-
this.#extractor.write("
|
|
2450
|
+
this.#extractor.write(" : {})");
|
|
2465
2451
|
break;
|
|
2466
2452
|
}
|
|
2467
2453
|
}
|
|
@@ -2469,24 +2455,24 @@ const attrTags = ${varShared(
|
|
|
2469
2455
|
}
|
|
2470
2456
|
}
|
|
2471
2457
|
#writeTagInputObject(tag) {
|
|
2472
|
-
if (!tag.params)
|
|
2473
|
-
|
|
2458
|
+
if (!tag.params) this.#writeComments(tag);
|
|
2459
|
+
const body = this.#processBody(tag);
|
|
2460
|
+
let writeInputObj = true;
|
|
2474
2461
|
let hasInput = false;
|
|
2475
|
-
this.#extractor.write("{\n");
|
|
2476
2462
|
if (tag.args) {
|
|
2477
2463
|
hasInput = true;
|
|
2478
|
-
this.#extractor.
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2464
|
+
this.#extractor.copy(tag.args.value);
|
|
2465
|
+
if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
|
|
2466
|
+
this.#extractor.write(",\n{\n");
|
|
2467
|
+
} else {
|
|
2468
|
+
writeInputObj = false;
|
|
2469
|
+
}
|
|
2470
|
+
} else {
|
|
2471
|
+
this.#extractor.write("{\n");
|
|
2485
2472
|
}
|
|
2486
2473
|
if (this.#writeAttrs(tag)) {
|
|
2487
2474
|
hasInput = true;
|
|
2488
2475
|
}
|
|
2489
|
-
const body = this.#processBody(tag);
|
|
2490
2476
|
let hasRenderBody = false;
|
|
2491
2477
|
if (body) {
|
|
2492
2478
|
hasInput = true;
|
|
@@ -2532,7 +2518,9 @@ const attrTags = ${varShared(
|
|
|
2532
2518
|
if (!hasInput) {
|
|
2533
2519
|
this.#writeTagNameComment(tag);
|
|
2534
2520
|
}
|
|
2535
|
-
|
|
2521
|
+
if (writeInputObj) {
|
|
2522
|
+
this.#extractor.write("\n}");
|
|
2523
|
+
}
|
|
2536
2524
|
}
|
|
2537
2525
|
#writeObjectKeys(keys) {
|
|
2538
2526
|
this.#extractor.write("{");
|
|
@@ -2546,8 +2534,7 @@ const attrTags = ${varShared(
|
|
|
2546
2534
|
}
|
|
2547
2535
|
#copyWithMutationsReplaced(range) {
|
|
2548
2536
|
const mutations = this.#mutationOffsets;
|
|
2549
|
-
if (!mutations)
|
|
2550
|
-
return this.#extractor.copy(range);
|
|
2537
|
+
if (!mutations) return this.#extractor.copy(range);
|
|
2551
2538
|
const len = mutations.length;
|
|
2552
2539
|
let curOffset = range.start;
|
|
2553
2540
|
let minIndex = 0;
|
|
@@ -2597,8 +2584,7 @@ const attrTags = ${varShared(
|
|
|
2597
2584
|
#processBody(parent) {
|
|
2598
2585
|
var _a;
|
|
2599
2586
|
const { body } = parent;
|
|
2600
|
-
if (!body)
|
|
2601
|
-
return;
|
|
2587
|
+
if (!body) return;
|
|
2602
2588
|
const last = body.length - 1;
|
|
2603
2589
|
let renderBody;
|
|
2604
2590
|
let staticAttrTags;
|
|
@@ -2631,56 +2617,55 @@ const attrTags = ${varShared(
|
|
|
2631
2617
|
case "if": {
|
|
2632
2618
|
let alternates;
|
|
2633
2619
|
hasDynamicAttrTags ||= child.hasAttrTags;
|
|
2634
|
-
loop:
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2620
|
+
loop: while (i <= last) {
|
|
2621
|
+
const nextChild = body[i++];
|
|
2622
|
+
switch (nextChild.type) {
|
|
2623
|
+
case 17 /* Text */:
|
|
2624
|
+
if (this.#isEmptyText(nextChild)) {
|
|
2625
|
+
continue loop;
|
|
2626
|
+
} else {
|
|
2627
|
+
break;
|
|
2628
|
+
}
|
|
2629
|
+
case 1 /* Tag */:
|
|
2630
|
+
switch (nextChild.nameText) {
|
|
2631
|
+
case "else-if": {
|
|
2632
|
+
const alternate = {
|
|
2633
|
+
condition: this.#getRangeWithoutTrailingComma(
|
|
2634
|
+
(_a = nextChild.args) == null ? void 0 : _a.value
|
|
2635
|
+
) || this.#getAttrValue(nextChild, ATTR_UNAMED2),
|
|
2636
|
+
node: nextChild
|
|
2637
|
+
};
|
|
2638
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2639
|
+
if (alternates) {
|
|
2640
|
+
alternates.push(alternate);
|
|
2641
|
+
} else {
|
|
2642
|
+
alternates = [alternate];
|
|
2643
|
+
}
|
|
2640
2644
|
continue loop;
|
|
2641
|
-
} else {
|
|
2642
|
-
break;
|
|
2643
2645
|
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
if (alternates) {
|
|
2655
|
-
alternates.push(alternate);
|
|
2656
|
-
} else {
|
|
2657
|
-
alternates = [alternate];
|
|
2658
|
-
}
|
|
2659
|
-
continue loop;
|
|
2646
|
+
case "else": {
|
|
2647
|
+
const alternate = {
|
|
2648
|
+
condition: this.#getAttrValue(nextChild, "if"),
|
|
2649
|
+
node: nextChild
|
|
2650
|
+
};
|
|
2651
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2652
|
+
if (alternates) {
|
|
2653
|
+
alternates.push(alternate);
|
|
2654
|
+
} else {
|
|
2655
|
+
alternates = [alternate];
|
|
2660
2656
|
}
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
};
|
|
2666
|
-
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2667
|
-
if (alternates) {
|
|
2668
|
-
alternates.push(alternate);
|
|
2669
|
-
} else {
|
|
2670
|
-
alternates = [alternate];
|
|
2671
|
-
}
|
|
2672
|
-
if (alternate.condition) {
|
|
2673
|
-
continue loop;
|
|
2674
|
-
} else {
|
|
2675
|
-
break loop;
|
|
2676
|
-
}
|
|
2657
|
+
if (alternate.condition) {
|
|
2658
|
+
continue loop;
|
|
2659
|
+
} else {
|
|
2660
|
+
break loop;
|
|
2677
2661
|
}
|
|
2678
2662
|
}
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
i--;
|
|
2682
|
-
break;
|
|
2663
|
+
}
|
|
2664
|
+
break;
|
|
2683
2665
|
}
|
|
2666
|
+
i--;
|
|
2667
|
+
break;
|
|
2668
|
+
}
|
|
2684
2669
|
IF_TAG_ALTERNATES.set(child, alternates);
|
|
2685
2670
|
}
|
|
2686
2671
|
}
|
|
@@ -2748,8 +2733,7 @@ const attrTags = ${varShared(
|
|
|
2748
2733
|
}
|
|
2749
2734
|
}
|
|
2750
2735
|
#getRangeWithoutTrailingComma(range) {
|
|
2751
|
-
if (!range)
|
|
2752
|
-
return void 0;
|
|
2736
|
+
if (!range) return void 0;
|
|
2753
2737
|
const { start } = range;
|
|
2754
2738
|
let end = range.end - 1;
|
|
2755
2739
|
while (end >= start) {
|
|
@@ -2804,8 +2788,7 @@ const attrTags = ${varShared(
|
|
|
2804
2788
|
const code = this.#read(node);
|
|
2805
2789
|
code;
|
|
2806
2790
|
const info = this.#getJSDocInputTypeFromNode(node);
|
|
2807
|
-
if (info)
|
|
2808
|
-
return info;
|
|
2791
|
+
if (info) return info;
|
|
2809
2792
|
}
|
|
2810
2793
|
}
|
|
2811
2794
|
#getJSDocInputTypeFromNode(node) {
|
|
@@ -2840,8 +2823,7 @@ const attrTags = ${varShared(
|
|
|
2840
2823
|
const start = attr.name.start + 1;
|
|
2841
2824
|
const end = attr.name.end - 1;
|
|
2842
2825
|
for (let i = end; i-- > start; ) {
|
|
2843
|
-
if (this.#code.charAt(i) === ":")
|
|
2844
|
-
return i;
|
|
2826
|
+
if (this.#code.charAt(i) === ":") return i;
|
|
2845
2827
|
}
|
|
2846
2828
|
return false;
|
|
2847
2829
|
}
|
|
@@ -2933,8 +2915,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
2933
2915
|
var _a;
|
|
2934
2916
|
const config = getConfig(rootDir);
|
|
2935
2917
|
let typeLibs = config.cache.get(getTypeLibs);
|
|
2936
|
-
if (typeLibs)
|
|
2937
|
-
return typeLibs;
|
|
2918
|
+
if (typeLibs) return typeLibs;
|
|
2938
2919
|
const resolveTypeCompilerOptions = {
|
|
2939
2920
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
2940
2921
|
};
|
|
@@ -2979,8 +2960,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
2979
2960
|
return typeLibs;
|
|
2980
2961
|
}
|
|
2981
2962
|
function getScriptLang(fileName, defaultScriptLang, ts, host) {
|
|
2982
|
-
if (fileName.endsWith(".d.marko"))
|
|
2983
|
-
return "ts" /* ts */;
|
|
2963
|
+
if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
|
|
2984
2964
|
const dir = path2.dirname(fileName);
|
|
2985
2965
|
const config = getConfig(dir);
|
|
2986
2966
|
const cache = config.cache.get(getScriptLang);
|
|
@@ -3135,8 +3115,7 @@ __export(processors_exports, {
|
|
|
3135
3115
|
// src/util/get-ext.ts
|
|
3136
3116
|
function getExt(fileName) {
|
|
3137
3117
|
const extIndex = fileName.lastIndexOf(".");
|
|
3138
|
-
if (extIndex !== -1)
|
|
3139
|
-
return fileName.slice(extIndex);
|
|
3118
|
+
if (extIndex !== -1) return fileName.slice(extIndex);
|
|
3140
3119
|
}
|
|
3141
3120
|
|
|
3142
3121
|
// src/processors/marko.ts
|
|
@@ -3266,8 +3245,7 @@ var marko_default = {
|
|
|
3266
3245
|
statement,
|
|
3267
3246
|
sourceFile
|
|
3268
3247
|
);
|
|
3269
|
-
if (!/^(?:import|export) /.test(printed))
|
|
3270
|
-
code += "static ";
|
|
3248
|
+
if (!/^(?:import|export) /.test(printed)) code += "static ";
|
|
3271
3249
|
code += printed + nlChar;
|
|
3272
3250
|
}
|
|
3273
3251
|
if (componentImpl == null ? void 0 : componentImpl.members.length) {
|
|
@@ -3315,7 +3293,7 @@ var marko_default = {
|
|
|
3315
3293
|
return ts.isTypeAliasDeclaration(statement) && statement.name.escapedText === "Input" && ts.isTypeLiteralNode(statement.type) && !statement.typeParameters && statement.type.members.length === 0 || ts.isInterfaceDeclaration(statement) && statement.name.escapedText === "Input" && !statement.heritageClauses && !statement.typeParameters && statement.members.length === 0;
|
|
3316
3294
|
}
|
|
3317
3295
|
function isExportComponentType(statement) {
|
|
3318
|
-
return ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 1 && statement.exportClause.elements[0].name.escapedText === "Component";
|
|
3296
|
+
return ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 1 && ts.isIdentifier(statement.exportClause.elements[0].name) && statement.exportClause.elements[0].name.escapedText === "Component";
|
|
3319
3297
|
}
|
|
3320
3298
|
function isVariableStatementForName(statement, name) {
|
|
3321
3299
|
if (ts.isVariableStatement(statement)) {
|
|
@@ -3358,8 +3336,7 @@ function isHTMLTag(tag) {
|
|
|
3358
3336
|
return builtinTagsRegex.test(tag);
|
|
3359
3337
|
}
|
|
3360
3338
|
function getAttributeValueType(value) {
|
|
3361
|
-
if (value === void 0 || value[0] !== "=")
|
|
3362
|
-
return void 0;
|
|
3339
|
+
if (value === void 0 || value[0] !== "=") return void 0;
|
|
3363
3340
|
value = value.substring(1).trim();
|
|
3364
3341
|
switch (value) {
|
|
3365
3342
|
case "NaN":
|
|
@@ -3417,8 +3394,7 @@ var HTMLExtractor = class {
|
|
|
3417
3394
|
switch (node.type) {
|
|
3418
3395
|
case 16 /* AttrTag */:
|
|
3419
3396
|
(_a = node.body) == null ? void 0 : _a.forEach((child) => {
|
|
3420
|
-
if (this.#visitNode(child))
|
|
3421
|
-
hasDynamicBody = true;
|
|
3397
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3422
3398
|
});
|
|
3423
3399
|
break;
|
|
3424
3400
|
case 1 /* Tag */: {
|
|
@@ -3460,16 +3436,13 @@ var HTMLExtractor = class {
|
|
|
3460
3436
|
this.#extractor.copy(node.name);
|
|
3461
3437
|
this.#extractor.write(` data-marko-node-id="${id}"`);
|
|
3462
3438
|
(_a = node.attrs) == null ? void 0 : _a.forEach((attr) => {
|
|
3463
|
-
if (attr.type === 10 /* AttrNamed */)
|
|
3464
|
-
|
|
3465
|
-
else if (attr.type === 15 /* AttrSpread */)
|
|
3466
|
-
hasDynamicAttrs = true;
|
|
3439
|
+
if (attr.type === 10 /* AttrNamed */) this.#writeAttrNamed(attr);
|
|
3440
|
+
else if (attr.type === 15 /* AttrSpread */) hasDynamicAttrs = true;
|
|
3467
3441
|
});
|
|
3468
3442
|
this.#extractor.write(">");
|
|
3469
3443
|
if (!isVoidTag(node.nameText)) {
|
|
3470
3444
|
(_b = node.body) == null ? void 0 : _b.forEach((child) => {
|
|
3471
|
-
if (this.#visitNode(child))
|
|
3472
|
-
hasDynamicBody = true;
|
|
3445
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3473
3446
|
});
|
|
3474
3447
|
this.#extractor.write(`</${node.nameText}>`);
|
|
3475
3448
|
}
|
|
@@ -3498,8 +3471,7 @@ var HTMLExtractor = class {
|
|
|
3498
3471
|
}
|
|
3499
3472
|
const valueString = this.#read(attr.value);
|
|
3500
3473
|
const valueType = getAttributeValueType(valueString);
|
|
3501
|
-
if (valueType === void 0)
|
|
3502
|
-
return;
|
|
3474
|
+
if (valueType === void 0) return;
|
|
3503
3475
|
switch (valueType) {
|
|
3504
3476
|
case 0 /* True */:
|
|
3505
3477
|
break;
|
|
@@ -31,6 +31,6 @@ export interface PrintContext {
|
|
|
31
31
|
typeChecker: ts.TypeChecker;
|
|
32
32
|
formatSettings: Required<ts.FormatCodeSettings>;
|
|
33
33
|
}
|
|
34
|
-
export declare const extensions:
|
|
35
|
-
export declare function create(options: CreateProcessorOptions): Record
|
|
34
|
+
export declare const extensions: ProcessorExtension[];
|
|
35
|
+
export declare function create(options: CreateProcessorOptions): Record<ProcessorExtension, Processor>;
|
|
36
36
|
export declare function has(fileName: string): boolean;
|
package/dist/util/project.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export declare function getCache(dir?: string): Map<any, any>;
|
|
|
25
25
|
export declare function getConfig(dir?: string): Omit<Compiler.Config, "cache" | "translator"> & {
|
|
26
26
|
cache: Map<any, any>;
|
|
27
27
|
translator: {
|
|
28
|
+
runtimeTypes?: string;
|
|
28
29
|
[x: string]: unknown;
|
|
29
|
-
runtimeTypes?: string | undefined;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
export declare function getTagLookup(dir: string): TaglibLookup;
|