@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.js
CHANGED
|
@@ -53,8 +53,7 @@ var import_htmljs_parser = require("htmljs-parser");
|
|
|
53
53
|
// src/util/get-node-at-offset.ts
|
|
54
54
|
function getNodeAtOffset(offset, program) {
|
|
55
55
|
const childNode = childAtOffset(offset, program.body);
|
|
56
|
-
if (childNode)
|
|
57
|
-
return visitChildNode(offset, childNode);
|
|
56
|
+
if (childNode) return visitChildNode(offset, childNode);
|
|
58
57
|
return childAtOffset(offset, program.static) || program;
|
|
59
58
|
}
|
|
60
59
|
function visitChildNode(offset, child) {
|
|
@@ -118,8 +117,7 @@ function visitAttrNode(offset, attr) {
|
|
|
118
117
|
}
|
|
119
118
|
function childAtOffset(offset, children) {
|
|
120
119
|
let max = children.length - 1;
|
|
121
|
-
if (max === -1)
|
|
122
|
-
return void 0;
|
|
120
|
+
if (max === -1) return void 0;
|
|
123
121
|
let min = 0;
|
|
124
122
|
while (min < max) {
|
|
125
123
|
const mid = 1 + min + max >>> 1;
|
|
@@ -297,6 +295,7 @@ var Builder = class {
|
|
|
297
295
|
}
|
|
298
296
|
if (!range.expressions.length) {
|
|
299
297
|
switch (nameText = this.#code.slice(range.start, range.end)) {
|
|
298
|
+
// All statement types will early return.
|
|
300
299
|
case "style": {
|
|
301
300
|
styleBlockReg.lastIndex = range.end;
|
|
302
301
|
const styleBlockMatch = styleBlockReg.exec(this.#code);
|
|
@@ -371,6 +370,8 @@ var Builder = class {
|
|
|
371
370
|
);
|
|
372
371
|
this.#comments = void 0;
|
|
373
372
|
return import_htmljs_parser.TagType.statement;
|
|
373
|
+
// The following are all still tags,
|
|
374
|
+
// but with a different body type.
|
|
374
375
|
case "area":
|
|
375
376
|
case "base":
|
|
376
377
|
case "br":
|
|
@@ -630,8 +631,7 @@ var Builder = class {
|
|
|
630
631
|
}
|
|
631
632
|
onCloseTagEnd(range) {
|
|
632
633
|
const parent = this.#parentNode;
|
|
633
|
-
if (hasCloseTag(parent))
|
|
634
|
-
parent.close.end = range.end;
|
|
634
|
+
if (hasCloseTag(parent)) parent.close.end = range.end;
|
|
635
635
|
parent.end = range.end;
|
|
636
636
|
this.#parentNode = parent.parent;
|
|
637
637
|
}
|
|
@@ -730,8 +730,7 @@ var Extracted = class {
|
|
|
730
730
|
}
|
|
731
731
|
sourcePositionAt(generatedOffset) {
|
|
732
732
|
const sourceOffset = this.sourceOffsetAt(generatedOffset);
|
|
733
|
-
if (sourceOffset !== void 0)
|
|
734
|
-
return this.parsed.positionAt(sourceOffset);
|
|
733
|
+
if (sourceOffset !== void 0) return this.parsed.positionAt(sourceOffset);
|
|
735
734
|
}
|
|
736
735
|
sourceLocationAt(generatedStart, generatedEnd) {
|
|
737
736
|
const sourceRange = this.#generatedToSource.rangeAt(
|
|
@@ -807,8 +806,7 @@ var TokenView = class {
|
|
|
807
806
|
}
|
|
808
807
|
const startToken = this.#tokens[max];
|
|
809
808
|
const startTokenInStart = this.inStart(startToken);
|
|
810
|
-
if (startTokenInStart >= inEnd)
|
|
811
|
-
return;
|
|
809
|
+
if (startTokenInStart >= inEnd) return;
|
|
812
810
|
max = this.#last;
|
|
813
811
|
while (min < max) {
|
|
814
812
|
const mid = 1 + min + max >>> 1;
|
|
@@ -823,8 +821,7 @@ var TokenView = class {
|
|
|
823
821
|
const endToken = this.#tokens[min];
|
|
824
822
|
const endTokenInStart = this.inStart(endToken);
|
|
825
823
|
const endTokenInEnd = endTokenInStart + endToken.length;
|
|
826
|
-
if (endTokenInEnd < inStart)
|
|
827
|
-
return;
|
|
824
|
+
if (endTokenInEnd < inStart) return;
|
|
828
825
|
const startIndex = inStart - startTokenInStart;
|
|
829
826
|
const endIndex = inEnd - endTokenInStart;
|
|
830
827
|
const start = this.outStart(startToken) + Math.max(0, startIndex);
|
|
@@ -983,12 +980,6 @@ var ScriptParser = class {
|
|
|
983
980
|
}
|
|
984
981
|
};
|
|
985
982
|
|
|
986
|
-
// src/extractors/script/util/is-valid-identifier.ts
|
|
987
|
-
var import_helper_validator_identifier = require("@babel/helper-validator-identifier");
|
|
988
|
-
function isValidIdentifier(name) {
|
|
989
|
-
return (0, import_helper_validator_identifier.isIdentifierName)(name) && !(0, import_helper_validator_identifier.isKeyword)(name) && !(0, import_helper_validator_identifier.isStrictBindReservedWord)(name, true);
|
|
990
|
-
}
|
|
991
|
-
|
|
992
983
|
// src/extractors/script/util/attach-scopes.ts
|
|
993
984
|
var t = __toESM(require("@babel/types"));
|
|
994
985
|
var ATTR_UNAMED = "value";
|
|
@@ -1359,6 +1350,10 @@ function* getVarIdentifiers(parsed, lVal, objectPath, sourceName) {
|
|
|
1359
1350
|
function trackMutationsInClosures(root, scope, mutations) {
|
|
1360
1351
|
traverse(root, (node) => {
|
|
1361
1352
|
switch (node.type) {
|
|
1353
|
+
// Since the root will always be an expression it's impossible
|
|
1354
|
+
// to hit a "FunctionDeclaration" without first going through
|
|
1355
|
+
// a a different function context. So we don't need to track it.
|
|
1356
|
+
// case "FunctionDeclaration":
|
|
1362
1357
|
case "FunctionExpression":
|
|
1363
1358
|
case "ObjectMethod":
|
|
1364
1359
|
case "ArrowFunctionExpression":
|
|
@@ -1370,8 +1365,7 @@ function trackMutationsInClosures(root, scope, mutations) {
|
|
|
1370
1365
|
});
|
|
1371
1366
|
}
|
|
1372
1367
|
function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows, parentBlockMutations) {
|
|
1373
|
-
if (!node)
|
|
1374
|
-
return;
|
|
1368
|
+
if (!node) return;
|
|
1375
1369
|
let block = parentBlock;
|
|
1376
1370
|
let blockShadows = parentBlockShadows;
|
|
1377
1371
|
let blockMutations = parentBlockMutations;
|
|
@@ -1494,8 +1488,7 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
|
|
|
1494
1488
|
}
|
|
1495
1489
|
if (block !== parentBlock && blockMutations.length) {
|
|
1496
1490
|
for (const { name, start } of blockMutations) {
|
|
1497
|
-
if (blockShadows.has(name))
|
|
1498
|
-
continue;
|
|
1491
|
+
if (blockShadows.has(name)) continue;
|
|
1499
1492
|
const binding = resolveWritableVar(scope, name);
|
|
1500
1493
|
if (binding) {
|
|
1501
1494
|
binding.mutated = true;
|
|
@@ -1512,10 +1505,8 @@ function trackShadows(node, scope, shadows) {
|
|
|
1512
1505
|
}
|
|
1513
1506
|
}
|
|
1514
1507
|
function traverse(node, enter) {
|
|
1515
|
-
if (!node)
|
|
1516
|
-
|
|
1517
|
-
if (enter(node))
|
|
1518
|
-
return;
|
|
1508
|
+
if (!node) return;
|
|
1509
|
+
if (enter(node)) return;
|
|
1519
1510
|
for (const key of t.VISITOR_KEYS[node.type]) {
|
|
1520
1511
|
const child = node[key];
|
|
1521
1512
|
if (Array.isArray(child)) {
|
|
@@ -1613,8 +1604,7 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1613
1604
|
var MaybeInputTypedefReg = /@typedef\b[\s\S]*\bInput\b/;
|
|
1614
1605
|
function getJSDocInputType(comment, ts) {
|
|
1615
1606
|
var _a, _b, _c, _d;
|
|
1616
|
-
if (!MaybeInputTypedefReg.test(comment))
|
|
1617
|
-
return;
|
|
1607
|
+
if (!MaybeInputTypedefReg.test(comment)) return;
|
|
1618
1608
|
const sourceFile = ts.createSourceFile(
|
|
1619
1609
|
"_.js",
|
|
1620
1610
|
comment,
|
|
@@ -1623,8 +1613,7 @@ function getJSDocInputType(comment, ts) {
|
|
|
1623
1613
|
ts.ScriptKind.JS
|
|
1624
1614
|
);
|
|
1625
1615
|
const tags = (_b = (_a = sourceFile.endOfFileToken.jsDoc) == null ? void 0 : _a[0]) == null ? void 0 : _b.tags;
|
|
1626
|
-
if (!(tags && hasInputTypeDef(ts, sourceFile, tags)))
|
|
1627
|
-
return;
|
|
1616
|
+
if (!(tags && hasInputTypeDef(ts, sourceFile, tags))) return;
|
|
1628
1617
|
let typeParameters;
|
|
1629
1618
|
for (const tag of tags) {
|
|
1630
1619
|
if (isTemplateTag(ts, tag)) {
|
|
@@ -1674,10 +1663,11 @@ var REG_EXT = /(?<=[/\\][^/\\]+)\.[^.]+$/;
|
|
|
1674
1663
|
var REG_BLOCK = /\s*{/y;
|
|
1675
1664
|
var REG_NEW_LINE = /^|(\r?\n)/g;
|
|
1676
1665
|
var REG_ATTR_ARG_LITERAL = /(?<=\s*)(["'])((?:[^"'\\]+|\\.|(?!\1))*)\1\s*([,)])/my;
|
|
1677
|
-
var REG_TAG_IMPORT = /(?<=(['"]))<([
|
|
1666
|
+
var REG_TAG_IMPORT = /(?<=(['"]))<([^'">]+)>(?=\1)/;
|
|
1678
1667
|
var REG_INPUT_TYPE = /\s*(interface|type)\s+Input\b/y;
|
|
1679
1668
|
var REG_OBJECT_PROPERTY = /^[_$a-z][_$a-z0-9]*$/i;
|
|
1680
1669
|
var REG_COMMENT_PRAGMA = /\/\/(?:\s*@ts-|\/\s*<)/y;
|
|
1670
|
+
var REG_TAG_NAME_IDENTIFIER = /^[A-Z][a-zA-Z_$]+$/;
|
|
1681
1671
|
var IF_TAG_ALTERNATES = /* @__PURE__ */ new WeakMap();
|
|
1682
1672
|
var WROTE_COMMENT = /* @__PURE__ */ new WeakSet();
|
|
1683
1673
|
var START_OF_FILE = { start: 0, end: 0 };
|
|
@@ -1974,7 +1964,7 @@ constructor(_?: Return) {}
|
|
|
1974
1964
|
this.#extractor.copy(returned);
|
|
1975
1965
|
this.#extractor.write(");\n");
|
|
1976
1966
|
}
|
|
1977
|
-
#writeChildren(parent, children) {
|
|
1967
|
+
#writeChildren(parent, children, skipRenderId = false) {
|
|
1978
1968
|
var _a, _b;
|
|
1979
1969
|
const last = children.length - 1;
|
|
1980
1970
|
let returnTag;
|
|
@@ -1989,28 +1979,31 @@ constructor(_?: Return) {}
|
|
|
1989
1979
|
break;
|
|
1990
1980
|
case "if": {
|
|
1991
1981
|
const alternates = IF_TAG_ALTERNATES.get(child);
|
|
1992
|
-
let renderId
|
|
1993
|
-
if (!
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
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
|
+
}
|
|
1997
1989
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
)}, ${renderId}, (() => {
|
|
1990
|
+
if (renderId) {
|
|
1991
|
+
this.#extractor.write(
|
|
1992
|
+
`${varShared("assertRendered")}(${varShared(
|
|
1993
|
+
"rendered"
|
|
1994
|
+
)}, ${renderId}, (() => {
|
|
2004
1995
|
`
|
|
2005
|
-
|
|
1996
|
+
);
|
|
1997
|
+
}
|
|
2006
1998
|
}
|
|
2007
1999
|
this.#writeComments(child);
|
|
2008
2000
|
this.#extractor.write("if (").copy(
|
|
2009
2001
|
this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
|
|
2010
2002
|
).write(") {\n");
|
|
2011
|
-
|
|
2003
|
+
const ifBody = this.#processBody(child);
|
|
2004
|
+
if (ifBody == null ? void 0 : ifBody.renderBody) {
|
|
2012
2005
|
const localBindings = getHoistSources(child);
|
|
2013
|
-
this.#writeChildren(child,
|
|
2006
|
+
this.#writeChildren(child, ifBody.renderBody, true);
|
|
2014
2007
|
if (localBindings) {
|
|
2015
2008
|
this.#extractor.write("return {\nscope:");
|
|
2016
2009
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2029,9 +2022,10 @@ constructor(_?: Return) {}
|
|
|
2029
2022
|
} else {
|
|
2030
2023
|
this.#extractor.write("\n} else if (undefined) {\n");
|
|
2031
2024
|
}
|
|
2032
|
-
|
|
2025
|
+
const alternateBody = this.#processBody(node);
|
|
2026
|
+
if (alternateBody == null ? void 0 : alternateBody.renderBody) {
|
|
2033
2027
|
const localBindings = getHoistSources(node);
|
|
2034
|
-
this.#writeChildren(node,
|
|
2028
|
+
this.#writeChildren(node, alternateBody.renderBody, true);
|
|
2035
2029
|
if (localBindings) {
|
|
2036
2030
|
this.#extractor.write("return {\nscope:");
|
|
2037
2031
|
this.#writeObjectKeys(localBindings);
|
|
@@ -2164,7 +2158,7 @@ constructor(_?: Return) {}
|
|
|
2164
2158
|
if (def) {
|
|
2165
2159
|
const importPath = resolveTagImport(this.#filename, def);
|
|
2166
2160
|
const renderer = (importPath == null ? void 0 : importPath.endsWith(".marko")) ? `renderTemplate(import("${importPath}"))` : def.html ? `renderNativeTag("${def.name}")` : "missingTag";
|
|
2167
|
-
if (!def.html &&
|
|
2161
|
+
if (!def.html && REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2168
2162
|
this.#extractor.write(
|
|
2169
2163
|
`${varShared("renderPreferLocal")}(
|
|
2170
2164
|
// @ts-expect-error We expect the compiler to error because we are checking if the tag is defined.
|
|
@@ -2174,7 +2168,7 @@ ${varShared(renderer)})`);
|
|
|
2174
2168
|
} else {
|
|
2175
2169
|
this.#extractor.write(varShared(renderer));
|
|
2176
2170
|
}
|
|
2177
|
-
} else if (
|
|
2171
|
+
} else if (REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2178
2172
|
this.#extractor.write(`${varShared("renderDynamicTag")}(
|
|
2179
2173
|
`).copy(tag.name).write("\n)");
|
|
2180
2174
|
} else {
|
|
@@ -2396,13 +2390,11 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2396
2390
|
}
|
|
2397
2391
|
if (dynamicAttrTagParents) {
|
|
2398
2392
|
this.#writeDynamicAttrTagParents(dynamicAttrTagParents);
|
|
2399
|
-
if (wasMerge)
|
|
2400
|
-
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2393
|
+
if (wasMerge) this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2401
2394
|
}
|
|
2402
2395
|
}
|
|
2403
2396
|
#writeStaticAttrTags(staticAttrTags, wasMerge) {
|
|
2404
|
-
if (!wasMerge)
|
|
2405
|
-
this.#extractor.write("...{");
|
|
2397
|
+
if (!wasMerge) this.#extractor.write("...{");
|
|
2406
2398
|
this.#extractor.write(
|
|
2407
2399
|
`[${varShared("never")}](){
|
|
2408
2400
|
const attrTags = ${varShared(
|
|
@@ -2418,27 +2410,27 @@ const attrTags = ${varShared(
|
|
|
2418
2410
|
}
|
|
2419
2411
|
}
|
|
2420
2412
|
this.#extractor.write("\n}");
|
|
2421
|
-
if (!wasMerge)
|
|
2422
|
-
this.#extractor.write("}");
|
|
2413
|
+
if (!wasMerge) this.#extractor.write("}");
|
|
2423
2414
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2424
2415
|
for (const nameText in staticAttrTags) {
|
|
2425
2416
|
const attrTag = staticAttrTags[nameText];
|
|
2426
2417
|
const attrTagDef = this.#lookup.getTag(nameText);
|
|
2427
|
-
const isRepeated = attrTag.length > 1
|
|
2418
|
+
const isRepeated = attrTag.length > 1;
|
|
2428
2419
|
const [firstAttrTag] = attrTag;
|
|
2429
2420
|
const name = (attrTagDef == null ? void 0 : attrTagDef.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
|
|
2430
2421
|
this.#extractor.write(`["${name}"`);
|
|
2431
2422
|
this.#writeTagNameComment(firstAttrTag);
|
|
2432
2423
|
this.#extractor.write("]: ");
|
|
2433
2424
|
if (isRepeated) {
|
|
2434
|
-
this.#extractor.write("
|
|
2425
|
+
this.#extractor.write(`${varShared("repeatedAttrTag")}(
|
|
2426
|
+
`);
|
|
2435
2427
|
}
|
|
2436
2428
|
for (const childNode of attrTag) {
|
|
2437
2429
|
this.#writeTagInputObject(childNode);
|
|
2438
2430
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2439
2431
|
}
|
|
2440
2432
|
if (isRepeated) {
|
|
2441
|
-
this.#extractor.write(`
|
|
2433
|
+
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2442
2434
|
}
|
|
2443
2435
|
}
|
|
2444
2436
|
}
|
|
@@ -2477,8 +2469,7 @@ const attrTags = ${varShared(
|
|
|
2477
2469
|
case "for": {
|
|
2478
2470
|
this.#extractor.write(`${varShared("forAttrTag")}({
|
|
2479
2471
|
`);
|
|
2480
|
-
if (!this.#writeAttrs(tag))
|
|
2481
|
-
this.#writeTagNameComment(tag);
|
|
2472
|
+
if (!this.#writeAttrs(tag)) this.#writeTagNameComment(tag);
|
|
2482
2473
|
this.#extractor.write("}, \n");
|
|
2483
2474
|
this.#writeComments(tag);
|
|
2484
2475
|
this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => (");
|
|
@@ -2488,12 +2479,11 @@ const attrTags = ${varShared(
|
|
|
2488
2479
|
}
|
|
2489
2480
|
case "while": {
|
|
2490
2481
|
this.#writeComments(tag);
|
|
2491
|
-
this.#extractor.write(
|
|
2492
|
-
`).copy(
|
|
2482
|
+
this.#extractor.write("((\n").copy(
|
|
2493
2483
|
this.#getRangeWithoutTrailingComma((_c = tag.args) == null ? void 0 : _c.value) || "undefined"
|
|
2494
|
-
).write("\n) ?
|
|
2484
|
+
).write("\n) ? ");
|
|
2495
2485
|
this.#writeDynamicAttrTagBody(tag);
|
|
2496
|
-
this.#extractor.write("
|
|
2486
|
+
this.#extractor.write(" : {})");
|
|
2497
2487
|
break;
|
|
2498
2488
|
}
|
|
2499
2489
|
}
|
|
@@ -2501,24 +2491,24 @@ const attrTags = ${varShared(
|
|
|
2501
2491
|
}
|
|
2502
2492
|
}
|
|
2503
2493
|
#writeTagInputObject(tag) {
|
|
2504
|
-
if (!tag.params)
|
|
2505
|
-
|
|
2494
|
+
if (!tag.params) this.#writeComments(tag);
|
|
2495
|
+
const body = this.#processBody(tag);
|
|
2496
|
+
let writeInputObj = true;
|
|
2506
2497
|
let hasInput = false;
|
|
2507
|
-
this.#extractor.write("{\n");
|
|
2508
2498
|
if (tag.args) {
|
|
2509
2499
|
hasInput = true;
|
|
2510
|
-
this.#extractor.
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2500
|
+
this.#extractor.copy(tag.args.value);
|
|
2501
|
+
if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
|
|
2502
|
+
this.#extractor.write(",\n{\n");
|
|
2503
|
+
} else {
|
|
2504
|
+
writeInputObj = false;
|
|
2505
|
+
}
|
|
2506
|
+
} else {
|
|
2507
|
+
this.#extractor.write("{\n");
|
|
2517
2508
|
}
|
|
2518
2509
|
if (this.#writeAttrs(tag)) {
|
|
2519
2510
|
hasInput = true;
|
|
2520
2511
|
}
|
|
2521
|
-
const body = this.#processBody(tag);
|
|
2522
2512
|
let hasRenderBody = false;
|
|
2523
2513
|
if (body) {
|
|
2524
2514
|
hasInput = true;
|
|
@@ -2564,7 +2554,9 @@ const attrTags = ${varShared(
|
|
|
2564
2554
|
if (!hasInput) {
|
|
2565
2555
|
this.#writeTagNameComment(tag);
|
|
2566
2556
|
}
|
|
2567
|
-
|
|
2557
|
+
if (writeInputObj) {
|
|
2558
|
+
this.#extractor.write("\n}");
|
|
2559
|
+
}
|
|
2568
2560
|
}
|
|
2569
2561
|
#writeObjectKeys(keys) {
|
|
2570
2562
|
this.#extractor.write("{");
|
|
@@ -2578,8 +2570,7 @@ const attrTags = ${varShared(
|
|
|
2578
2570
|
}
|
|
2579
2571
|
#copyWithMutationsReplaced(range) {
|
|
2580
2572
|
const mutations = this.#mutationOffsets;
|
|
2581
|
-
if (!mutations)
|
|
2582
|
-
return this.#extractor.copy(range);
|
|
2573
|
+
if (!mutations) return this.#extractor.copy(range);
|
|
2583
2574
|
const len = mutations.length;
|
|
2584
2575
|
let curOffset = range.start;
|
|
2585
2576
|
let minIndex = 0;
|
|
@@ -2629,8 +2620,7 @@ const attrTags = ${varShared(
|
|
|
2629
2620
|
#processBody(parent) {
|
|
2630
2621
|
var _a;
|
|
2631
2622
|
const { body } = parent;
|
|
2632
|
-
if (!body)
|
|
2633
|
-
return;
|
|
2623
|
+
if (!body) return;
|
|
2634
2624
|
const last = body.length - 1;
|
|
2635
2625
|
let renderBody;
|
|
2636
2626
|
let staticAttrTags;
|
|
@@ -2663,56 +2653,55 @@ const attrTags = ${varShared(
|
|
|
2663
2653
|
case "if": {
|
|
2664
2654
|
let alternates;
|
|
2665
2655
|
hasDynamicAttrTags ||= child.hasAttrTags;
|
|
2666
|
-
loop:
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2656
|
+
loop: while (i <= last) {
|
|
2657
|
+
const nextChild = body[i++];
|
|
2658
|
+
switch (nextChild.type) {
|
|
2659
|
+
case 17 /* Text */:
|
|
2660
|
+
if (this.#isEmptyText(nextChild)) {
|
|
2661
|
+
continue loop;
|
|
2662
|
+
} else {
|
|
2663
|
+
break;
|
|
2664
|
+
}
|
|
2665
|
+
case 1 /* Tag */:
|
|
2666
|
+
switch (nextChild.nameText) {
|
|
2667
|
+
case "else-if": {
|
|
2668
|
+
const alternate = {
|
|
2669
|
+
condition: this.#getRangeWithoutTrailingComma(
|
|
2670
|
+
(_a = nextChild.args) == null ? void 0 : _a.value
|
|
2671
|
+
) || this.#getAttrValue(nextChild, ATTR_UNAMED2),
|
|
2672
|
+
node: nextChild
|
|
2673
|
+
};
|
|
2674
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2675
|
+
if (alternates) {
|
|
2676
|
+
alternates.push(alternate);
|
|
2677
|
+
} else {
|
|
2678
|
+
alternates = [alternate];
|
|
2679
|
+
}
|
|
2672
2680
|
continue loop;
|
|
2673
|
-
} else {
|
|
2674
|
-
break;
|
|
2675
2681
|
}
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
if (alternates) {
|
|
2687
|
-
alternates.push(alternate);
|
|
2688
|
-
} else {
|
|
2689
|
-
alternates = [alternate];
|
|
2690
|
-
}
|
|
2691
|
-
continue loop;
|
|
2682
|
+
case "else": {
|
|
2683
|
+
const alternate = {
|
|
2684
|
+
condition: this.#getAttrValue(nextChild, "if"),
|
|
2685
|
+
node: nextChild
|
|
2686
|
+
};
|
|
2687
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2688
|
+
if (alternates) {
|
|
2689
|
+
alternates.push(alternate);
|
|
2690
|
+
} else {
|
|
2691
|
+
alternates = [alternate];
|
|
2692
2692
|
}
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
};
|
|
2698
|
-
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2699
|
-
if (alternates) {
|
|
2700
|
-
alternates.push(alternate);
|
|
2701
|
-
} else {
|
|
2702
|
-
alternates = [alternate];
|
|
2703
|
-
}
|
|
2704
|
-
if (alternate.condition) {
|
|
2705
|
-
continue loop;
|
|
2706
|
-
} else {
|
|
2707
|
-
break loop;
|
|
2708
|
-
}
|
|
2693
|
+
if (alternate.condition) {
|
|
2694
|
+
continue loop;
|
|
2695
|
+
} else {
|
|
2696
|
+
break loop;
|
|
2709
2697
|
}
|
|
2710
2698
|
}
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
i--;
|
|
2714
|
-
break;
|
|
2699
|
+
}
|
|
2700
|
+
break;
|
|
2715
2701
|
}
|
|
2702
|
+
i--;
|
|
2703
|
+
break;
|
|
2704
|
+
}
|
|
2716
2705
|
IF_TAG_ALTERNATES.set(child, alternates);
|
|
2717
2706
|
}
|
|
2718
2707
|
}
|
|
@@ -2780,8 +2769,7 @@ const attrTags = ${varShared(
|
|
|
2780
2769
|
}
|
|
2781
2770
|
}
|
|
2782
2771
|
#getRangeWithoutTrailingComma(range) {
|
|
2783
|
-
if (!range)
|
|
2784
|
-
return void 0;
|
|
2772
|
+
if (!range) return void 0;
|
|
2785
2773
|
const { start } = range;
|
|
2786
2774
|
let end = range.end - 1;
|
|
2787
2775
|
while (end >= start) {
|
|
@@ -2836,8 +2824,7 @@ const attrTags = ${varShared(
|
|
|
2836
2824
|
const code = this.#read(node);
|
|
2837
2825
|
code;
|
|
2838
2826
|
const info = this.#getJSDocInputTypeFromNode(node);
|
|
2839
|
-
if (info)
|
|
2840
|
-
return info;
|
|
2827
|
+
if (info) return info;
|
|
2841
2828
|
}
|
|
2842
2829
|
}
|
|
2843
2830
|
#getJSDocInputTypeFromNode(node) {
|
|
@@ -2872,8 +2859,7 @@ const attrTags = ${varShared(
|
|
|
2872
2859
|
const start = attr.name.start + 1;
|
|
2873
2860
|
const end = attr.name.end - 1;
|
|
2874
2861
|
for (let i = end; i-- > start; ) {
|
|
2875
|
-
if (this.#code.charAt(i) === ":")
|
|
2876
|
-
return i;
|
|
2862
|
+
if (this.#code.charAt(i) === ":") return i;
|
|
2877
2863
|
}
|
|
2878
2864
|
return false;
|
|
2879
2865
|
}
|
|
@@ -2965,8 +2951,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
2965
2951
|
var _a;
|
|
2966
2952
|
const config = getConfig(rootDir);
|
|
2967
2953
|
let typeLibs = config.cache.get(getTypeLibs);
|
|
2968
|
-
if (typeLibs)
|
|
2969
|
-
return typeLibs;
|
|
2954
|
+
if (typeLibs) return typeLibs;
|
|
2970
2955
|
const resolveTypeCompilerOptions = {
|
|
2971
2956
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
2972
2957
|
};
|
|
@@ -3011,8 +2996,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
3011
2996
|
return typeLibs;
|
|
3012
2997
|
}
|
|
3013
2998
|
function getScriptLang(fileName, defaultScriptLang, ts, host) {
|
|
3014
|
-
if (fileName.endsWith(".d.marko"))
|
|
3015
|
-
return "ts" /* ts */;
|
|
2999
|
+
if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
|
|
3016
3000
|
const dir = import_path2.default.dirname(fileName);
|
|
3017
3001
|
const config = getConfig(dir);
|
|
3018
3002
|
const cache = config.cache.get(getScriptLang);
|
|
@@ -3167,8 +3151,7 @@ __export(processors_exports, {
|
|
|
3167
3151
|
// src/util/get-ext.ts
|
|
3168
3152
|
function getExt(fileName) {
|
|
3169
3153
|
const extIndex = fileName.lastIndexOf(".");
|
|
3170
|
-
if (extIndex !== -1)
|
|
3171
|
-
return fileName.slice(extIndex);
|
|
3154
|
+
if (extIndex !== -1) return fileName.slice(extIndex);
|
|
3172
3155
|
}
|
|
3173
3156
|
|
|
3174
3157
|
// src/processors/marko.ts
|
|
@@ -3298,8 +3281,7 @@ var marko_default = {
|
|
|
3298
3281
|
statement,
|
|
3299
3282
|
sourceFile
|
|
3300
3283
|
);
|
|
3301
|
-
if (!/^(?:import|export) /.test(printed))
|
|
3302
|
-
code += "static ";
|
|
3284
|
+
if (!/^(?:import|export) /.test(printed)) code += "static ";
|
|
3303
3285
|
code += printed + nlChar;
|
|
3304
3286
|
}
|
|
3305
3287
|
if (componentImpl == null ? void 0 : componentImpl.members.length) {
|
|
@@ -3347,7 +3329,7 @@ var marko_default = {
|
|
|
3347
3329
|
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;
|
|
3348
3330
|
}
|
|
3349
3331
|
function isExportComponentType(statement) {
|
|
3350
|
-
return ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.length === 1 && statement.exportClause.elements[0].name.escapedText === "Component";
|
|
3332
|
+
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";
|
|
3351
3333
|
}
|
|
3352
3334
|
function isVariableStatementForName(statement, name) {
|
|
3353
3335
|
if (ts.isVariableStatement(statement)) {
|
|
@@ -3390,8 +3372,7 @@ function isHTMLTag(tag) {
|
|
|
3390
3372
|
return builtinTagsRegex.test(tag);
|
|
3391
3373
|
}
|
|
3392
3374
|
function getAttributeValueType(value) {
|
|
3393
|
-
if (value === void 0 || value[0] !== "=")
|
|
3394
|
-
return void 0;
|
|
3375
|
+
if (value === void 0 || value[0] !== "=") return void 0;
|
|
3395
3376
|
value = value.substring(1).trim();
|
|
3396
3377
|
switch (value) {
|
|
3397
3378
|
case "NaN":
|
|
@@ -3449,8 +3430,7 @@ var HTMLExtractor = class {
|
|
|
3449
3430
|
switch (node.type) {
|
|
3450
3431
|
case 16 /* AttrTag */:
|
|
3451
3432
|
(_a = node.body) == null ? void 0 : _a.forEach((child) => {
|
|
3452
|
-
if (this.#visitNode(child))
|
|
3453
|
-
hasDynamicBody = true;
|
|
3433
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3454
3434
|
});
|
|
3455
3435
|
break;
|
|
3456
3436
|
case 1 /* Tag */: {
|
|
@@ -3492,16 +3472,13 @@ var HTMLExtractor = class {
|
|
|
3492
3472
|
this.#extractor.copy(node.name);
|
|
3493
3473
|
this.#extractor.write(` data-marko-node-id="${id}"`);
|
|
3494
3474
|
(_a = node.attrs) == null ? void 0 : _a.forEach((attr) => {
|
|
3495
|
-
if (attr.type === 10 /* AttrNamed */)
|
|
3496
|
-
|
|
3497
|
-
else if (attr.type === 15 /* AttrSpread */)
|
|
3498
|
-
hasDynamicAttrs = true;
|
|
3475
|
+
if (attr.type === 10 /* AttrNamed */) this.#writeAttrNamed(attr);
|
|
3476
|
+
else if (attr.type === 15 /* AttrSpread */) hasDynamicAttrs = true;
|
|
3499
3477
|
});
|
|
3500
3478
|
this.#extractor.write(">");
|
|
3501
3479
|
if (!isVoidTag(node.nameText)) {
|
|
3502
3480
|
(_b = node.body) == null ? void 0 : _b.forEach((child) => {
|
|
3503
|
-
if (this.#visitNode(child))
|
|
3504
|
-
hasDynamicBody = true;
|
|
3481
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3505
3482
|
});
|
|
3506
3483
|
this.#extractor.write(`</${node.nameText}>`);
|
|
3507
3484
|
}
|
|
@@ -3530,8 +3507,7 @@ var HTMLExtractor = class {
|
|
|
3530
3507
|
}
|
|
3531
3508
|
const valueString = this.#read(attr.value);
|
|
3532
3509
|
const valueType = getAttributeValueType(valueString);
|
|
3533
|
-
if (valueType === void 0)
|
|
3534
|
-
return;
|
|
3510
|
+
if (valueType === void 0) return;
|
|
3535
3511
|
switch (valueType) {
|
|
3536
3512
|
case 0 /* True */:
|
|
3537
3513
|
break;
|