@marko/language-tools 2.3.1 → 2.4.0
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 +108 -137
- package/dist/index.mjs +108 -141
- 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 };
|
|
@@ -1960,8 +1946,7 @@ constructor(_?: Return) {}
|
|
|
1960
1946
|
let renderId = this.#getRenderId(child);
|
|
1961
1947
|
if (!renderId && alternates) {
|
|
1962
1948
|
for (const { node } of alternates) {
|
|
1963
|
-
if (renderId = this.#getRenderId(node))
|
|
1964
|
-
break;
|
|
1949
|
+
if (renderId = this.#getRenderId(node)) break;
|
|
1965
1950
|
}
|
|
1966
1951
|
}
|
|
1967
1952
|
if (renderId) {
|
|
@@ -2132,7 +2117,7 @@ constructor(_?: Return) {}
|
|
|
2132
2117
|
if (def) {
|
|
2133
2118
|
const importPath = resolveTagImport(this.#filename, def);
|
|
2134
2119
|
const renderer = (importPath == null ? void 0 : importPath.endsWith(".marko")) ? `renderTemplate(import("${importPath}"))` : def.html ? `renderNativeTag("${def.name}")` : "missingTag";
|
|
2135
|
-
if (!def.html &&
|
|
2120
|
+
if (!def.html && REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2136
2121
|
this.#extractor.write(
|
|
2137
2122
|
`${varShared("renderPreferLocal")}(
|
|
2138
2123
|
// @ts-expect-error We expect the compiler to error because we are checking if the tag is defined.
|
|
@@ -2142,7 +2127,7 @@ ${varShared(renderer)})`);
|
|
|
2142
2127
|
} else {
|
|
2143
2128
|
this.#extractor.write(varShared(renderer));
|
|
2144
2129
|
}
|
|
2145
|
-
} else if (
|
|
2130
|
+
} else if (REG_TAG_NAME_IDENTIFIER.test(tagName)) {
|
|
2146
2131
|
this.#extractor.write(`${varShared("renderDynamicTag")}(
|
|
2147
2132
|
`).copy(tag.name).write("\n)");
|
|
2148
2133
|
} else {
|
|
@@ -2364,13 +2349,11 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
|
|
|
2364
2349
|
}
|
|
2365
2350
|
if (dynamicAttrTagParents) {
|
|
2366
2351
|
this.#writeDynamicAttrTagParents(dynamicAttrTagParents);
|
|
2367
|
-
if (wasMerge)
|
|
2368
|
-
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2352
|
+
if (wasMerge) this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2369
2353
|
}
|
|
2370
2354
|
}
|
|
2371
2355
|
#writeStaticAttrTags(staticAttrTags, wasMerge) {
|
|
2372
|
-
if (!wasMerge)
|
|
2373
|
-
this.#extractor.write("...{");
|
|
2356
|
+
if (!wasMerge) this.#extractor.write("...{");
|
|
2374
2357
|
this.#extractor.write(
|
|
2375
2358
|
`[${varShared("never")}](){
|
|
2376
2359
|
const attrTags = ${varShared(
|
|
@@ -2386,27 +2369,27 @@ const attrTags = ${varShared(
|
|
|
2386
2369
|
}
|
|
2387
2370
|
}
|
|
2388
2371
|
this.#extractor.write("\n}");
|
|
2389
|
-
if (!wasMerge)
|
|
2390
|
-
this.#extractor.write("}");
|
|
2372
|
+
if (!wasMerge) this.#extractor.write("}");
|
|
2391
2373
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2392
2374
|
for (const nameText in staticAttrTags) {
|
|
2393
2375
|
const attrTag = staticAttrTags[nameText];
|
|
2394
2376
|
const attrTagDef = this.#lookup.getTag(nameText);
|
|
2395
|
-
const isRepeated = attrTag.length > 1
|
|
2377
|
+
const isRepeated = attrTag.length > 1;
|
|
2396
2378
|
const [firstAttrTag] = attrTag;
|
|
2397
2379
|
const name = (attrTagDef == null ? void 0 : attrTagDef.targetProperty) || nameText.slice(nameText.lastIndexOf(":") + 1);
|
|
2398
2380
|
this.#extractor.write(`["${name}"`);
|
|
2399
2381
|
this.#writeTagNameComment(firstAttrTag);
|
|
2400
2382
|
this.#extractor.write("]: ");
|
|
2401
2383
|
if (isRepeated) {
|
|
2402
|
-
this.#extractor.write("
|
|
2384
|
+
this.#extractor.write(`${varShared("repeatedAttrTag")}(
|
|
2385
|
+
`);
|
|
2403
2386
|
}
|
|
2404
2387
|
for (const childNode of attrTag) {
|
|
2405
2388
|
this.#writeTagInputObject(childNode);
|
|
2406
2389
|
this.#extractor.write(SEP_COMMA_NEW_LINE);
|
|
2407
2390
|
}
|
|
2408
2391
|
if (isRepeated) {
|
|
2409
|
-
this.#extractor.write(`
|
|
2392
|
+
this.#extractor.write(`)${SEP_COMMA_NEW_LINE}`);
|
|
2410
2393
|
}
|
|
2411
2394
|
}
|
|
2412
2395
|
}
|
|
@@ -2445,8 +2428,7 @@ const attrTags = ${varShared(
|
|
|
2445
2428
|
case "for": {
|
|
2446
2429
|
this.#extractor.write(`${varShared("forAttrTag")}({
|
|
2447
2430
|
`);
|
|
2448
|
-
if (!this.#writeAttrs(tag))
|
|
2449
|
-
this.#writeTagNameComment(tag);
|
|
2431
|
+
if (!this.#writeAttrs(tag)) this.#writeTagNameComment(tag);
|
|
2450
2432
|
this.#extractor.write("}, \n");
|
|
2451
2433
|
this.#writeComments(tag);
|
|
2452
2434
|
this.#extractor.copy(tag.typeParams).write("(\n").copy((_b = tag.params) == null ? void 0 : _b.value).write("\n) => (");
|
|
@@ -2456,12 +2438,11 @@ const attrTags = ${varShared(
|
|
|
2456
2438
|
}
|
|
2457
2439
|
case "while": {
|
|
2458
2440
|
this.#writeComments(tag);
|
|
2459
|
-
this.#extractor.write(
|
|
2460
|
-
`).copy(
|
|
2441
|
+
this.#extractor.write("((\n").copy(
|
|
2461
2442
|
this.#getRangeWithoutTrailingComma((_c = tag.args) == null ? void 0 : _c.value) || "undefined"
|
|
2462
|
-
).write("\n) ?
|
|
2443
|
+
).write("\n) ? ");
|
|
2463
2444
|
this.#writeDynamicAttrTagBody(tag);
|
|
2464
|
-
this.#extractor.write("
|
|
2445
|
+
this.#extractor.write(" : {})");
|
|
2465
2446
|
break;
|
|
2466
2447
|
}
|
|
2467
2448
|
}
|
|
@@ -2469,24 +2450,24 @@ const attrTags = ${varShared(
|
|
|
2469
2450
|
}
|
|
2470
2451
|
}
|
|
2471
2452
|
#writeTagInputObject(tag) {
|
|
2472
|
-
if (!tag.params)
|
|
2473
|
-
|
|
2453
|
+
if (!tag.params) this.#writeComments(tag);
|
|
2454
|
+
const body = this.#processBody(tag);
|
|
2455
|
+
let writeInputObj = true;
|
|
2474
2456
|
let hasInput = false;
|
|
2475
|
-
this.#extractor.write("{\n");
|
|
2476
2457
|
if (tag.args) {
|
|
2477
2458
|
hasInput = true;
|
|
2478
|
-
this.#extractor.
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2459
|
+
this.#extractor.copy(tag.args.value);
|
|
2460
|
+
if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
|
|
2461
|
+
this.#extractor.write(",\n{\n");
|
|
2462
|
+
} else {
|
|
2463
|
+
writeInputObj = false;
|
|
2464
|
+
}
|
|
2465
|
+
} else {
|
|
2466
|
+
this.#extractor.write("{\n");
|
|
2485
2467
|
}
|
|
2486
2468
|
if (this.#writeAttrs(tag)) {
|
|
2487
2469
|
hasInput = true;
|
|
2488
2470
|
}
|
|
2489
|
-
const body = this.#processBody(tag);
|
|
2490
2471
|
let hasRenderBody = false;
|
|
2491
2472
|
if (body) {
|
|
2492
2473
|
hasInput = true;
|
|
@@ -2532,7 +2513,9 @@ const attrTags = ${varShared(
|
|
|
2532
2513
|
if (!hasInput) {
|
|
2533
2514
|
this.#writeTagNameComment(tag);
|
|
2534
2515
|
}
|
|
2535
|
-
|
|
2516
|
+
if (writeInputObj) {
|
|
2517
|
+
this.#extractor.write("\n}");
|
|
2518
|
+
}
|
|
2536
2519
|
}
|
|
2537
2520
|
#writeObjectKeys(keys) {
|
|
2538
2521
|
this.#extractor.write("{");
|
|
@@ -2546,8 +2529,7 @@ const attrTags = ${varShared(
|
|
|
2546
2529
|
}
|
|
2547
2530
|
#copyWithMutationsReplaced(range) {
|
|
2548
2531
|
const mutations = this.#mutationOffsets;
|
|
2549
|
-
if (!mutations)
|
|
2550
|
-
return this.#extractor.copy(range);
|
|
2532
|
+
if (!mutations) return this.#extractor.copy(range);
|
|
2551
2533
|
const len = mutations.length;
|
|
2552
2534
|
let curOffset = range.start;
|
|
2553
2535
|
let minIndex = 0;
|
|
@@ -2597,8 +2579,7 @@ const attrTags = ${varShared(
|
|
|
2597
2579
|
#processBody(parent) {
|
|
2598
2580
|
var _a;
|
|
2599
2581
|
const { body } = parent;
|
|
2600
|
-
if (!body)
|
|
2601
|
-
return;
|
|
2582
|
+
if (!body) return;
|
|
2602
2583
|
const last = body.length - 1;
|
|
2603
2584
|
let renderBody;
|
|
2604
2585
|
let staticAttrTags;
|
|
@@ -2631,56 +2612,55 @@ const attrTags = ${varShared(
|
|
|
2631
2612
|
case "if": {
|
|
2632
2613
|
let alternates;
|
|
2633
2614
|
hasDynamicAttrTags ||= child.hasAttrTags;
|
|
2634
|
-
loop:
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2615
|
+
loop: while (i <= last) {
|
|
2616
|
+
const nextChild = body[i++];
|
|
2617
|
+
switch (nextChild.type) {
|
|
2618
|
+
case 17 /* Text */:
|
|
2619
|
+
if (this.#isEmptyText(nextChild)) {
|
|
2620
|
+
continue loop;
|
|
2621
|
+
} else {
|
|
2622
|
+
break;
|
|
2623
|
+
}
|
|
2624
|
+
case 1 /* Tag */:
|
|
2625
|
+
switch (nextChild.nameText) {
|
|
2626
|
+
case "else-if": {
|
|
2627
|
+
const alternate = {
|
|
2628
|
+
condition: this.#getRangeWithoutTrailingComma(
|
|
2629
|
+
(_a = nextChild.args) == null ? void 0 : _a.value
|
|
2630
|
+
) || this.#getAttrValue(nextChild, ATTR_UNAMED2),
|
|
2631
|
+
node: nextChild
|
|
2632
|
+
};
|
|
2633
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2634
|
+
if (alternates) {
|
|
2635
|
+
alternates.push(alternate);
|
|
2636
|
+
} else {
|
|
2637
|
+
alternates = [alternate];
|
|
2638
|
+
}
|
|
2640
2639
|
continue loop;
|
|
2641
|
-
} else {
|
|
2642
|
-
break;
|
|
2643
2640
|
}
|
|
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;
|
|
2641
|
+
case "else": {
|
|
2642
|
+
const alternate = {
|
|
2643
|
+
condition: this.#getAttrValue(nextChild, "if"),
|
|
2644
|
+
node: nextChild
|
|
2645
|
+
};
|
|
2646
|
+
hasDynamicAttrTags ||= nextChild.hasAttrTags;
|
|
2647
|
+
if (alternates) {
|
|
2648
|
+
alternates.push(alternate);
|
|
2649
|
+
} else {
|
|
2650
|
+
alternates = [alternate];
|
|
2660
2651
|
}
|
|
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
|
-
}
|
|
2652
|
+
if (alternate.condition) {
|
|
2653
|
+
continue loop;
|
|
2654
|
+
} else {
|
|
2655
|
+
break loop;
|
|
2677
2656
|
}
|
|
2678
2657
|
}
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
i--;
|
|
2682
|
-
break;
|
|
2658
|
+
}
|
|
2659
|
+
break;
|
|
2683
2660
|
}
|
|
2661
|
+
i--;
|
|
2662
|
+
break;
|
|
2663
|
+
}
|
|
2684
2664
|
IF_TAG_ALTERNATES.set(child, alternates);
|
|
2685
2665
|
}
|
|
2686
2666
|
}
|
|
@@ -2748,8 +2728,7 @@ const attrTags = ${varShared(
|
|
|
2748
2728
|
}
|
|
2749
2729
|
}
|
|
2750
2730
|
#getRangeWithoutTrailingComma(range) {
|
|
2751
|
-
if (!range)
|
|
2752
|
-
return void 0;
|
|
2731
|
+
if (!range) return void 0;
|
|
2753
2732
|
const { start } = range;
|
|
2754
2733
|
let end = range.end - 1;
|
|
2755
2734
|
while (end >= start) {
|
|
@@ -2804,8 +2783,7 @@ const attrTags = ${varShared(
|
|
|
2804
2783
|
const code = this.#read(node);
|
|
2805
2784
|
code;
|
|
2806
2785
|
const info = this.#getJSDocInputTypeFromNode(node);
|
|
2807
|
-
if (info)
|
|
2808
|
-
return info;
|
|
2786
|
+
if (info) return info;
|
|
2809
2787
|
}
|
|
2810
2788
|
}
|
|
2811
2789
|
#getJSDocInputTypeFromNode(node) {
|
|
@@ -2840,8 +2818,7 @@ const attrTags = ${varShared(
|
|
|
2840
2818
|
const start = attr.name.start + 1;
|
|
2841
2819
|
const end = attr.name.end - 1;
|
|
2842
2820
|
for (let i = end; i-- > start; ) {
|
|
2843
|
-
if (this.#code.charAt(i) === ":")
|
|
2844
|
-
return i;
|
|
2821
|
+
if (this.#code.charAt(i) === ":") return i;
|
|
2845
2822
|
}
|
|
2846
2823
|
return false;
|
|
2847
2824
|
}
|
|
@@ -2933,8 +2910,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
2933
2910
|
var _a;
|
|
2934
2911
|
const config = getConfig(rootDir);
|
|
2935
2912
|
let typeLibs = config.cache.get(getTypeLibs);
|
|
2936
|
-
if (typeLibs)
|
|
2937
|
-
return typeLibs;
|
|
2913
|
+
if (typeLibs) return typeLibs;
|
|
2938
2914
|
const resolveTypeCompilerOptions = {
|
|
2939
2915
|
moduleResolution: ts.ModuleResolutionKind.Bundler
|
|
2940
2916
|
};
|
|
@@ -2979,8 +2955,7 @@ function getTypeLibs(rootDir, ts, host) {
|
|
|
2979
2955
|
return typeLibs;
|
|
2980
2956
|
}
|
|
2981
2957
|
function getScriptLang(fileName, defaultScriptLang, ts, host) {
|
|
2982
|
-
if (fileName.endsWith(".d.marko"))
|
|
2983
|
-
return "ts" /* ts */;
|
|
2958
|
+
if (fileName.endsWith(".d.marko")) return "ts" /* ts */;
|
|
2984
2959
|
const dir = path2.dirname(fileName);
|
|
2985
2960
|
const config = getConfig(dir);
|
|
2986
2961
|
const cache = config.cache.get(getScriptLang);
|
|
@@ -3135,8 +3110,7 @@ __export(processors_exports, {
|
|
|
3135
3110
|
// src/util/get-ext.ts
|
|
3136
3111
|
function getExt(fileName) {
|
|
3137
3112
|
const extIndex = fileName.lastIndexOf(".");
|
|
3138
|
-
if (extIndex !== -1)
|
|
3139
|
-
return fileName.slice(extIndex);
|
|
3113
|
+
if (extIndex !== -1) return fileName.slice(extIndex);
|
|
3140
3114
|
}
|
|
3141
3115
|
|
|
3142
3116
|
// src/processors/marko.ts
|
|
@@ -3266,8 +3240,7 @@ var marko_default = {
|
|
|
3266
3240
|
statement,
|
|
3267
3241
|
sourceFile
|
|
3268
3242
|
);
|
|
3269
|
-
if (!/^(?:import|export) /.test(printed))
|
|
3270
|
-
code += "static ";
|
|
3243
|
+
if (!/^(?:import|export) /.test(printed)) code += "static ";
|
|
3271
3244
|
code += printed + nlChar;
|
|
3272
3245
|
}
|
|
3273
3246
|
if (componentImpl == null ? void 0 : componentImpl.members.length) {
|
|
@@ -3315,7 +3288,7 @@ var marko_default = {
|
|
|
3315
3288
|
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
3289
|
}
|
|
3317
3290
|
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";
|
|
3291
|
+
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
3292
|
}
|
|
3320
3293
|
function isVariableStatementForName(statement, name) {
|
|
3321
3294
|
if (ts.isVariableStatement(statement)) {
|
|
@@ -3358,8 +3331,7 @@ function isHTMLTag(tag) {
|
|
|
3358
3331
|
return builtinTagsRegex.test(tag);
|
|
3359
3332
|
}
|
|
3360
3333
|
function getAttributeValueType(value) {
|
|
3361
|
-
if (value === void 0 || value[0] !== "=")
|
|
3362
|
-
return void 0;
|
|
3334
|
+
if (value === void 0 || value[0] !== "=") return void 0;
|
|
3363
3335
|
value = value.substring(1).trim();
|
|
3364
3336
|
switch (value) {
|
|
3365
3337
|
case "NaN":
|
|
@@ -3417,8 +3389,7 @@ var HTMLExtractor = class {
|
|
|
3417
3389
|
switch (node.type) {
|
|
3418
3390
|
case 16 /* AttrTag */:
|
|
3419
3391
|
(_a = node.body) == null ? void 0 : _a.forEach((child) => {
|
|
3420
|
-
if (this.#visitNode(child))
|
|
3421
|
-
hasDynamicBody = true;
|
|
3392
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3422
3393
|
});
|
|
3423
3394
|
break;
|
|
3424
3395
|
case 1 /* Tag */: {
|
|
@@ -3460,16 +3431,13 @@ var HTMLExtractor = class {
|
|
|
3460
3431
|
this.#extractor.copy(node.name);
|
|
3461
3432
|
this.#extractor.write(` data-marko-node-id="${id}"`);
|
|
3462
3433
|
(_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;
|
|
3434
|
+
if (attr.type === 10 /* AttrNamed */) this.#writeAttrNamed(attr);
|
|
3435
|
+
else if (attr.type === 15 /* AttrSpread */) hasDynamicAttrs = true;
|
|
3467
3436
|
});
|
|
3468
3437
|
this.#extractor.write(">");
|
|
3469
3438
|
if (!isVoidTag(node.nameText)) {
|
|
3470
3439
|
(_b = node.body) == null ? void 0 : _b.forEach((child) => {
|
|
3471
|
-
if (this.#visitNode(child))
|
|
3472
|
-
hasDynamicBody = true;
|
|
3440
|
+
if (this.#visitNode(child)) hasDynamicBody = true;
|
|
3473
3441
|
});
|
|
3474
3442
|
this.#extractor.write(`</${node.nameText}>`);
|
|
3475
3443
|
}
|
|
@@ -3498,8 +3466,7 @@ var HTMLExtractor = class {
|
|
|
3498
3466
|
}
|
|
3499
3467
|
const valueString = this.#read(attr.value);
|
|
3500
3468
|
const valueType = getAttributeValueType(valueString);
|
|
3501
|
-
if (valueType === void 0)
|
|
3502
|
-
return;
|
|
3469
|
+
if (valueType === void 0) return;
|
|
3503
3470
|
switch (valueType) {
|
|
3504
3471
|
case 0 /* True */:
|
|
3505
3472
|
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;
|