@atscript/core 0.1.89 → 0.1.91
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.cjs +191 -138
- package/dist/index.d.ts +24 -1
- package/dist/index.mjs +192 -139
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1491,11 +1491,7 @@ function getRelFilterScope(owner) {
|
|
|
1491
1491
|
const unwound = doc.unwindType(typeName);
|
|
1492
1492
|
if (!unwound?.def) return [];
|
|
1493
1493
|
let def = doc.mergeIntersection(unwound.def);
|
|
1494
|
-
if (isInterface(def))
|
|
1495
|
-
const resolved = doc.resolveInterfaceExtends(def);
|
|
1496
|
-
if (resolved) def = resolved;
|
|
1497
|
-
else def = def.getDefinition() || def;
|
|
1498
|
-
}
|
|
1494
|
+
if (isInterface(def)) def = doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1499
1495
|
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1500
1496
|
return [];
|
|
1501
1497
|
}
|
|
@@ -1833,29 +1829,35 @@ var NodeIterator = class NodeIterator {
|
|
|
1833
1829
|
|
|
1834
1830
|
//#endregion
|
|
1835
1831
|
//#region packages/core/src/tokenizer/tokens/block.token.ts
|
|
1836
|
-
|
|
1832
|
+
/**
|
|
1833
|
+
* Builds a block node that opens on any key of `pairs` and closes on the
|
|
1834
|
+
* matching value; the opening character is kept as the token's `text`.
|
|
1835
|
+
*/ function createBlockToken(pairs) {
|
|
1836
|
+
const opening = Object.keys(pairs).map((c) => c.replace(/[\\^$.*+?()[\]{}|/-]/gu, "\\$&")).join("");
|
|
1837
|
+
return new _prostojs_parser.Node({
|
|
1838
|
+
name: "block",
|
|
1839
|
+
start: {
|
|
1840
|
+
token: new RegExp(`(?<text>[${opening}])`, "u"),
|
|
1841
|
+
omit: true
|
|
1842
|
+
},
|
|
1843
|
+
end: {
|
|
1844
|
+
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1845
|
+
omit: true
|
|
1846
|
+
},
|
|
1847
|
+
skip: /\s/u,
|
|
1848
|
+
eofClose: true,
|
|
1849
|
+
data: {
|
|
1850
|
+
type: "block",
|
|
1851
|
+
text: ""
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Block node
|
|
1857
|
+
*/ const BlockToken = createBlockToken({
|
|
1837
1858
|
"{": "}",
|
|
1838
1859
|
"(": ")",
|
|
1839
1860
|
"[": "]"
|
|
1840
|
-
};
|
|
1841
|
-
/**
|
|
1842
|
-
* Block node
|
|
1843
|
-
*/ const BlockToken = new _prostojs_parser.Node({
|
|
1844
|
-
name: "block",
|
|
1845
|
-
start: {
|
|
1846
|
-
token: RegExp("(?<text>[([{])", "u"),
|
|
1847
|
-
omit: true
|
|
1848
|
-
},
|
|
1849
|
-
end: {
|
|
1850
|
-
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1851
|
-
omit: true
|
|
1852
|
-
},
|
|
1853
|
-
skip: /\s/u,
|
|
1854
|
-
eofClose: true,
|
|
1855
|
-
data: {
|
|
1856
|
-
type: "block",
|
|
1857
|
-
text: ""
|
|
1858
|
-
}
|
|
1859
1861
|
});
|
|
1860
1862
|
|
|
1861
1863
|
//#endregion
|
|
@@ -1961,6 +1963,22 @@ const block$1 = new _prostojs_parser.Node({
|
|
|
1961
1963
|
}
|
|
1962
1964
|
});
|
|
1963
1965
|
|
|
1966
|
+
//#endregion
|
|
1967
|
+
//#region packages/core/src/tokenizer/tokens/query-block.token.ts
|
|
1968
|
+
/**
|
|
1969
|
+
* Query block node — parenthesized sub-expressions inside backtick queries.
|
|
1970
|
+
*
|
|
1971
|
+
* Same definition as `BlockToken` narrowed to `(`, so it produces the same
|
|
1972
|
+
* token shape (`type: 'block'`, `text: '('`) and every consumer keeps working,
|
|
1973
|
+
* but it recognizes `QueryOperatorToken` inside (see `tokens/index.ts`), which
|
|
1974
|
+
* makes `!=`, `>=`, `<=`, `>`, `<` work within parentheses — the generic block
|
|
1975
|
+
* only knows `PunctuationToken`, whose charset has no `<` / `>`.
|
|
1976
|
+
*
|
|
1977
|
+
* Only registered inside `QueryToken` (and itself, for nested parens) —
|
|
1978
|
+
* the generic `BlockToken` is left untouched so tokenization of `(`/`[`/`{`
|
|
1979
|
+
* outside queries does not change.
|
|
1980
|
+
*/ const QueryBlockToken = createBlockToken({ "(": ")" });
|
|
1981
|
+
|
|
1964
1982
|
//#endregion
|
|
1965
1983
|
//#region packages/core/src/tokenizer/tokens/query-operator.token.ts
|
|
1966
1984
|
/**
|
|
@@ -2076,6 +2094,7 @@ const tokens = {
|
|
|
2076
2094
|
text: TextToken,
|
|
2077
2095
|
regexp: RegExpToken,
|
|
2078
2096
|
query: QueryToken,
|
|
2097
|
+
queryBlock: QueryBlockToken,
|
|
2079
2098
|
root: void 0
|
|
2080
2099
|
};
|
|
2081
2100
|
const root = new _prostojs_parser.Node({
|
|
@@ -2095,7 +2114,14 @@ const root = new _prostojs_parser.Node({
|
|
|
2095
2114
|
});
|
|
2096
2115
|
tokens.root = root;
|
|
2097
2116
|
BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2098
|
-
QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2117
|
+
QueryToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2118
|
+
QueryBlockToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2119
|
+
/** 1-based parser position → 0-based VSCode position, shifted by `offset` characters. */ function toPos(p, offset = 0) {
|
|
2120
|
+
return {
|
|
2121
|
+
line: p.line - 1,
|
|
2122
|
+
character: p.column - 1 + offset
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2099
2125
|
/**
|
|
2100
2126
|
* Recursively extract TLexicalToken[] from a ParsedNode tree.
|
|
2101
2127
|
* Replaces the v0.5 mapContent('children', callback) + global loop.
|
|
@@ -2104,21 +2130,26 @@ QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToke
|
|
|
2104
2130
|
* line is 1-based, column is 1-based.
|
|
2105
2131
|
* VSCode expects 0-based line, 0-based character.
|
|
2106
2132
|
*/ function extractTokens(node) {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2133
|
+
const content = node.content;
|
|
2134
|
+
return content.map((item, index) => {
|
|
2135
|
+
if (typeof item === "string") {
|
|
2136
|
+
const prev = content[index - 1];
|
|
2137
|
+
const next = content[index + 1];
|
|
2138
|
+
const start = typeof prev === "object" ? prev.end : node.start;
|
|
2139
|
+
const end = typeof next === "object" ? next.start : node.end;
|
|
2140
|
+
return {
|
|
2141
|
+
type: "unknown",
|
|
2142
|
+
text: item,
|
|
2143
|
+
getRange: () => ({
|
|
2144
|
+
start: toPos(start),
|
|
2145
|
+
end: toPos(end)
|
|
2146
|
+
})
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2112
2149
|
const data = item.data;
|
|
2113
2150
|
data.getRange = () => ({
|
|
2114
|
-
start:
|
|
2115
|
-
|
|
2116
|
-
character: item.start.column - 1 + (data.startOffset ?? 0)
|
|
2117
|
-
},
|
|
2118
|
-
end: {
|
|
2119
|
-
line: item.end.line - 1,
|
|
2120
|
-
character: item.end.column - 1 + (data.endOffset ?? 0)
|
|
2121
|
-
}
|
|
2151
|
+
start: toPos(item.start, data.startOffset),
|
|
2152
|
+
end: toPos(item.end, data.endOffset)
|
|
2122
2153
|
});
|
|
2123
2154
|
data.children = extractTokens(item);
|
|
2124
2155
|
return data;
|
|
@@ -2401,43 +2432,42 @@ const VALUE_KEYWORDS = new Set([
|
|
|
2401
2432
|
"null",
|
|
2402
2433
|
"undefined"
|
|
2403
2434
|
]);
|
|
2435
|
+
const ZERO_RANGE = {
|
|
2436
|
+
start: {
|
|
2437
|
+
line: 0,
|
|
2438
|
+
character: 0
|
|
2439
|
+
},
|
|
2440
|
+
end: {
|
|
2441
|
+
line: 0,
|
|
2442
|
+
character: 0
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2404
2445
|
/**
|
|
2405
|
-
* Parse a backtick-delimited query expression
|
|
2446
|
+
* Parse a backtick-delimited query expression.
|
|
2447
|
+
*
|
|
2448
|
+
* `ni` iterates the query token's children and carries that token as its
|
|
2449
|
+
* `parent` — the range to blame when a diagnostic has no token of its own —
|
|
2450
|
+
* so fork it from the annotation iterator while the query token is current.
|
|
2406
2451
|
* Returns a SemanticQueryNode or undefined if the content is empty.
|
|
2407
|
-
*/ function parseQueryExpression(
|
|
2408
|
-
if (
|
|
2409
|
-
const
|
|
2410
|
-
ni.move();
|
|
2411
|
-
const expr = parseOrExpr(ni, messages);
|
|
2452
|
+
*/ function parseQueryExpression(ni, sourceToken) {
|
|
2453
|
+
if (!ni.$) return;
|
|
2454
|
+
const expr = parseOrExpr(ni);
|
|
2412
2455
|
if (!expr) return;
|
|
2413
|
-
if (ni.$)
|
|
2414
|
-
severity: 1,
|
|
2415
|
-
message: `Unexpected token in query expression: "${ni.$.text}"`,
|
|
2416
|
-
range: ni.$.getRange?.() ?? {
|
|
2417
|
-
start: {
|
|
2418
|
-
line: 0,
|
|
2419
|
-
character: 0
|
|
2420
|
-
},
|
|
2421
|
-
end: {
|
|
2422
|
-
line: 0,
|
|
2423
|
-
character: 0
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
});
|
|
2456
|
+
if (ni.$) pushError(ni, `Unexpected token in query expression: "${ni.$.text}"`);
|
|
2427
2457
|
const node = new SemanticQueryNode();
|
|
2428
2458
|
node.expression = expr;
|
|
2429
2459
|
node.sourceToken = sourceToken;
|
|
2430
2460
|
return node;
|
|
2431
2461
|
}
|
|
2432
|
-
function parseOrExpr(ni
|
|
2433
|
-
const left = parseAndExpr(ni
|
|
2462
|
+
function parseOrExpr(ni) {
|
|
2463
|
+
const left = parseAndExpr(ni);
|
|
2434
2464
|
if (!left) return;
|
|
2435
2465
|
const operands = [left];
|
|
2436
2466
|
while (ni.$?.type === "identifier" && ni.$.text === "or") {
|
|
2437
2467
|
ni.move();
|
|
2438
|
-
const right = parseAndExpr(ni
|
|
2468
|
+
const right = parseAndExpr(ni);
|
|
2439
2469
|
if (!right) {
|
|
2440
|
-
pushError(ni,
|
|
2470
|
+
pushError(ni, "Expected expression after \"or\"");
|
|
2441
2471
|
break;
|
|
2442
2472
|
}
|
|
2443
2473
|
operands.push(right);
|
|
@@ -2448,15 +2478,15 @@ function parseOrExpr(ni, messages) {
|
|
|
2448
2478
|
node.operands = operands;
|
|
2449
2479
|
return node;
|
|
2450
2480
|
}
|
|
2451
|
-
function parseAndExpr(ni
|
|
2452
|
-
const left = parseUnaryExpr(ni
|
|
2481
|
+
function parseAndExpr(ni) {
|
|
2482
|
+
const left = parseUnaryExpr(ni);
|
|
2453
2483
|
if (!left) return;
|
|
2454
2484
|
const operands = [left];
|
|
2455
2485
|
while (ni.$?.type === "identifier" && ni.$.text === "and") {
|
|
2456
2486
|
ni.move();
|
|
2457
|
-
const right = parseUnaryExpr(ni
|
|
2487
|
+
const right = parseUnaryExpr(ni);
|
|
2458
2488
|
if (!right) {
|
|
2459
|
-
pushError(ni,
|
|
2489
|
+
pushError(ni, "Expected expression after \"and\"");
|
|
2460
2490
|
break;
|
|
2461
2491
|
}
|
|
2462
2492
|
operands.push(right);
|
|
@@ -2467,12 +2497,12 @@ function parseAndExpr(ni, messages) {
|
|
|
2467
2497
|
node.operands = operands;
|
|
2468
2498
|
return node;
|
|
2469
2499
|
}
|
|
2470
|
-
function parseUnaryExpr(ni
|
|
2500
|
+
function parseUnaryExpr(ni) {
|
|
2471
2501
|
if (ni.$?.type === "identifier" && ni.$.text === "not") {
|
|
2472
2502
|
ni.move();
|
|
2473
|
-
const operand = parseUnaryExpr(ni
|
|
2503
|
+
const operand = parseUnaryExpr(ni);
|
|
2474
2504
|
if (!operand) {
|
|
2475
|
-
pushError(ni,
|
|
2505
|
+
pushError(ni, "Expected expression after \"not\"");
|
|
2476
2506
|
return;
|
|
2477
2507
|
}
|
|
2478
2508
|
const node = new SemanticQueryLogicalNode();
|
|
@@ -2481,29 +2511,27 @@ function parseUnaryExpr(ni, messages) {
|
|
|
2481
2511
|
return node;
|
|
2482
2512
|
}
|
|
2483
2513
|
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2484
|
-
const
|
|
2514
|
+
const subNi = ni.fork(ni.$.children || []);
|
|
2485
2515
|
ni.move();
|
|
2486
|
-
if (
|
|
2487
|
-
pushError(
|
|
2516
|
+
if (!subNi.$) {
|
|
2517
|
+
pushError(subNi, "Empty parenthesized expression");
|
|
2488
2518
|
return;
|
|
2489
2519
|
}
|
|
2490
|
-
const
|
|
2491
|
-
subNi
|
|
2492
|
-
const expr = parseOrExpr(subNi, messages);
|
|
2493
|
-
if (subNi.$) pushError(subNi, messages, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2520
|
+
const expr = parseOrExpr(subNi);
|
|
2521
|
+
if (subNi.$) pushError(subNi, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2494
2522
|
return expr;
|
|
2495
2523
|
}
|
|
2496
|
-
return parseComparison(ni
|
|
2524
|
+
return parseComparison(ni);
|
|
2497
2525
|
}
|
|
2498
|
-
function parseComparison(ni
|
|
2499
|
-
const left = parseFieldRef(ni
|
|
2526
|
+
function parseComparison(ni) {
|
|
2527
|
+
const left = parseFieldRef(ni);
|
|
2500
2528
|
if (!left) return;
|
|
2501
2529
|
if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
|
|
2502
2530
|
const opText = ni.$.text;
|
|
2503
2531
|
ni.move();
|
|
2504
|
-
const right = parseValueOrFieldRef(ni
|
|
2532
|
+
const right = parseValueOrFieldRef(ni);
|
|
2505
2533
|
if (!right) {
|
|
2506
|
-
pushError(ni,
|
|
2534
|
+
pushError(ni, `Expected value or field reference after "${opText}"`);
|
|
2507
2535
|
return;
|
|
2508
2536
|
}
|
|
2509
2537
|
const node = new SemanticQueryComparisonNode();
|
|
@@ -2516,7 +2544,7 @@ function parseComparison(ni, messages) {
|
|
|
2516
2544
|
const opText = ni.$.text;
|
|
2517
2545
|
if (opText === "in") {
|
|
2518
2546
|
ni.move();
|
|
2519
|
-
const right = parseValueList(ni
|
|
2547
|
+
const right = parseValueList(ni);
|
|
2520
2548
|
if (!right) return;
|
|
2521
2549
|
const node = new SemanticQueryComparisonNode();
|
|
2522
2550
|
node.left = left;
|
|
@@ -2526,9 +2554,9 @@ function parseComparison(ni, messages) {
|
|
|
2526
2554
|
}
|
|
2527
2555
|
if (opText === "matches") {
|
|
2528
2556
|
ni.move();
|
|
2529
|
-
const right = parseValueOrFieldRef(ni
|
|
2557
|
+
const right = parseValueOrFieldRef(ni);
|
|
2530
2558
|
if (!right) {
|
|
2531
|
-
pushError(ni,
|
|
2559
|
+
pushError(ni, "Expected value after \"matches\"");
|
|
2532
2560
|
return;
|
|
2533
2561
|
}
|
|
2534
2562
|
const node = new SemanticQueryComparisonNode();
|
|
@@ -2544,17 +2572,17 @@ function parseComparison(ni, messages) {
|
|
|
2544
2572
|
node.operator = "exists";
|
|
2545
2573
|
return node;
|
|
2546
2574
|
}
|
|
2547
|
-
if (opText === "not") return parseNotComparison(ni,
|
|
2548
|
-
pushError(ni,
|
|
2575
|
+
if (opText === "not") return parseNotComparison(ni, left);
|
|
2576
|
+
pushError(ni, `Unknown operator "${opText}"`);
|
|
2549
2577
|
return;
|
|
2550
2578
|
}
|
|
2551
|
-
pushError(ni,
|
|
2579
|
+
pushError(ni, "Expected operator after field reference");
|
|
2552
2580
|
}
|
|
2553
|
-
function parseNotComparison(ni,
|
|
2581
|
+
function parseNotComparison(ni, left) {
|
|
2554
2582
|
ni.move();
|
|
2555
2583
|
if (ni.$?.type === "identifier" && ni.$.text === "in") {
|
|
2556
2584
|
ni.move();
|
|
2557
|
-
const right = parseValueList(ni
|
|
2585
|
+
const right = parseValueList(ni);
|
|
2558
2586
|
if (!right) return;
|
|
2559
2587
|
const node = new SemanticQueryComparisonNode();
|
|
2560
2588
|
node.left = left;
|
|
@@ -2569,11 +2597,11 @@ function parseNotComparison(ni, messages, left) {
|
|
|
2569
2597
|
node.operator = "not exists";
|
|
2570
2598
|
return node;
|
|
2571
2599
|
}
|
|
2572
|
-
pushError(ni,
|
|
2600
|
+
pushError(ni, "Expected \"in\" or \"exists\" after \"not\"");
|
|
2573
2601
|
}
|
|
2574
|
-
function parseFieldRef(ni
|
|
2602
|
+
function parseFieldRef(ni) {
|
|
2575
2603
|
if (ni.$?.type !== "identifier") {
|
|
2576
|
-
pushError(ni,
|
|
2604
|
+
pushError(ni, "Expected field reference");
|
|
2577
2605
|
return;
|
|
2578
2606
|
}
|
|
2579
2607
|
const firstToken = new Token(ni.$);
|
|
@@ -2590,17 +2618,16 @@ function parseFieldRef(ni, messages) {
|
|
|
2590
2618
|
fieldText += `.${ni.$.text}`;
|
|
2591
2619
|
ni.move();
|
|
2592
2620
|
} else {
|
|
2593
|
-
pushError(ni,
|
|
2621
|
+
pushError(ni, "Expected identifier after \".\"");
|
|
2594
2622
|
break;
|
|
2595
2623
|
}
|
|
2596
2624
|
}
|
|
2597
2625
|
const node = new SemanticQueryFieldRefNode();
|
|
2598
2626
|
node.typeRef = firstToken;
|
|
2599
|
-
|
|
2600
|
-
else node.fieldRef = secondToken;
|
|
2627
|
+
node.fieldRef = fieldText === secondToken.text ? secondToken : secondToken.clone({ text: fieldText });
|
|
2601
2628
|
return node;
|
|
2602
2629
|
}
|
|
2603
|
-
pushError(ni,
|
|
2630
|
+
pushError(ni, "Expected identifier after \".\"");
|
|
2604
2631
|
const node = new SemanticQueryFieldRefNode();
|
|
2605
2632
|
node.fieldRef = firstToken;
|
|
2606
2633
|
return node;
|
|
@@ -2609,18 +2636,18 @@ function parseFieldRef(ni, messages) {
|
|
|
2609
2636
|
node.fieldRef = firstToken;
|
|
2610
2637
|
return node;
|
|
2611
2638
|
}
|
|
2612
|
-
function parseValueOrFieldRef(ni
|
|
2639
|
+
function parseValueOrFieldRef(ni) {
|
|
2613
2640
|
if (!ni.$) return;
|
|
2614
|
-
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni
|
|
2641
|
+
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni);
|
|
2615
2642
|
if (ni.$.type === "identifier") {
|
|
2616
|
-
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni
|
|
2617
|
-
return parseFieldRef(ni
|
|
2643
|
+
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni);
|
|
2644
|
+
return parseFieldRef(ni);
|
|
2618
2645
|
}
|
|
2619
|
-
pushError(ni,
|
|
2646
|
+
pushError(ni, "Expected value or field reference");
|
|
2620
2647
|
}
|
|
2621
|
-
function parseValue(ni
|
|
2648
|
+
function parseValue(ni) {
|
|
2622
2649
|
if (!ni.$) {
|
|
2623
|
-
pushError(ni,
|
|
2650
|
+
pushError(ni, "Expected value");
|
|
2624
2651
|
return;
|
|
2625
2652
|
}
|
|
2626
2653
|
const token = ni.$;
|
|
@@ -2630,48 +2657,42 @@ function parseValue(ni, messages) {
|
|
|
2630
2657
|
ni.move();
|
|
2631
2658
|
return node;
|
|
2632
2659
|
}
|
|
2633
|
-
pushError(ni,
|
|
2660
|
+
pushError(ni, `Unexpected token "${token.text}" where value expected`);
|
|
2634
2661
|
}
|
|
2635
|
-
function parseValueList(ni
|
|
2662
|
+
function parseValueList(ni) {
|
|
2636
2663
|
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2637
|
-
const
|
|
2664
|
+
const subNi = ni.fork(ni.$.children || []);
|
|
2638
2665
|
ni.move();
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
pushError(ni, messages, "Empty value list in \"in\" expression");
|
|
2666
|
+
if (!subNi.$) {
|
|
2667
|
+
pushError(subNi, "Empty value list in \"in\" expression");
|
|
2642
2668
|
return;
|
|
2643
2669
|
}
|
|
2644
|
-
const
|
|
2645
|
-
subNi
|
|
2646
|
-
const first = parseValue(subNi, messages);
|
|
2670
|
+
const values = [];
|
|
2671
|
+
const first = parseValue(subNi);
|
|
2647
2672
|
if (first) values.push(first);
|
|
2648
2673
|
while (subNi.$?.type === "punctuation" && subNi.$.text === ",") {
|
|
2649
2674
|
subNi.move();
|
|
2650
|
-
const v = parseValue(subNi
|
|
2675
|
+
const v = parseValue(subNi);
|
|
2651
2676
|
if (v) values.push(v);
|
|
2652
2677
|
}
|
|
2653
|
-
if (subNi.$) pushError(subNi,
|
|
2678
|
+
if (subNi.$) pushError(subNi, `Unexpected token in value list: "${subNi.$.text}"`);
|
|
2654
2679
|
const node = new SemanticQueryValueListNode();
|
|
2655
2680
|
node.values = values;
|
|
2656
2681
|
return node;
|
|
2657
2682
|
}
|
|
2658
|
-
pushError(ni,
|
|
2683
|
+
pushError(ni, "Expected parenthesized value list after \"in\"");
|
|
2659
2684
|
}
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
character: 0
|
|
2669
|
-
}
|
|
2670
|
-
};
|
|
2671
|
-
messages.push({
|
|
2685
|
+
/**
|
|
2686
|
+
* Range to blame for a diagnostic: the current token, else the enclosing
|
|
2687
|
+
* query token / "(...)" block the iterator was forked from.
|
|
2688
|
+
*/ function rangeOf(ni) {
|
|
2689
|
+
return ni.$?.getRange?.() ?? ni.parent?.getRange?.() ?? ZERO_RANGE;
|
|
2690
|
+
}
|
|
2691
|
+
function pushError(ni, message) {
|
|
2692
|
+
ni.messages.push({
|
|
2672
2693
|
severity: 1,
|
|
2673
2694
|
message,
|
|
2674
|
-
range
|
|
2695
|
+
range: rangeOf(ni)
|
|
2675
2696
|
});
|
|
2676
2697
|
}
|
|
2677
2698
|
|
|
@@ -2794,6 +2815,10 @@ function annotations() {
|
|
|
2794
2815
|
}
|
|
2795
2816
|
while (ni.satisfies(...opts.argument)) {
|
|
2796
2817
|
let argToken = new Token(ni.$);
|
|
2818
|
+
if (argToken.type === "query") {
|
|
2819
|
+
const queryNode = parseQueryExpression(ni.fork(argToken.children), argToken);
|
|
2820
|
+
if (queryNode) argToken.queryNode = queryNode;
|
|
2821
|
+
}
|
|
2797
2822
|
ni.accepted();
|
|
2798
2823
|
ni.move();
|
|
2799
2824
|
if (argToken.type === "identifier" && ![
|
|
@@ -2812,10 +2837,6 @@ function annotations() {
|
|
|
2812
2837
|
}
|
|
2813
2838
|
if (chainText !== argToken.text) argToken = argToken.clone({ text: chainText });
|
|
2814
2839
|
}
|
|
2815
|
-
if (argToken.type === "query") {
|
|
2816
|
-
const queryNode = parseQueryExpression(argToken.children, ni.messages, argToken);
|
|
2817
|
-
if (queryNode) argToken.queryNode = queryNode;
|
|
2818
|
-
}
|
|
2819
2840
|
addArgument(argToken);
|
|
2820
2841
|
if (ni.satisfies(opts.comma)) {
|
|
2821
2842
|
ni.accepted();
|
|
@@ -5379,6 +5400,7 @@ function _define_property(obj, key, value) {
|
|
|
5379
5400
|
else obj[key] = value;
|
|
5380
5401
|
return obj;
|
|
5381
5402
|
}
|
|
5403
|
+
/** Upper bound on concurrent file operations — macOS defaults `ulimit -n` to 256. */ const WRITE_CONCURRENCY = 32;
|
|
5382
5404
|
async function build(config) {
|
|
5383
5405
|
const rootDir = config.rootDir ? config.rootDir.startsWith("/") ? config.rootDir : path.default.join(process.cwd(), config.rootDir) : process.cwd();
|
|
5384
5406
|
config.rootDir = rootDir;
|
|
@@ -5428,12 +5450,20 @@ var BuildRepo = class {
|
|
|
5428
5450
|
}
|
|
5429
5451
|
return outFiles;
|
|
5430
5452
|
}
|
|
5431
|
-
|
|
5453
|
+
/**
|
|
5454
|
+
* Renders every document and writes the outputs to disk.
|
|
5455
|
+
*
|
|
5456
|
+
* Each write is awaited and atomic (temp file + rename), because a consumer
|
|
5457
|
+
* watching the output — a dev server, a type checker, another build — must
|
|
5458
|
+
* never observe a half-written file, and an un-awaited write can be
|
|
5459
|
+
* truncated when the process exits. Outputs whose content did not change
|
|
5460
|
+
* are not rewritten, so those watchers see no event for them.
|
|
5461
|
+
*/ async write(config, docs = this.docs) {
|
|
5432
5462
|
const outFiles = await this.generate(config, docs);
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5463
|
+
const targeted = outFiles.filter((o) => o.target);
|
|
5464
|
+
const dirs = new Set(targeted.map((o) => path.default.dirname(o.target)));
|
|
5465
|
+
await Promise.all(Array.from(dirs, (dir) => (0, fs_promises.mkdir)(dir, { recursive: true })));
|
|
5466
|
+
for (let i = 0; i < targeted.length; i += WRITE_CONCURRENCY) await Promise.all(targeted.slice(i, i + WRITE_CONCURRENCY).map((o) => writeIfChanged(o.target, o.content)));
|
|
5437
5467
|
return outFiles;
|
|
5438
5468
|
}
|
|
5439
5469
|
constructor(rootDir, repo, docs) {
|
|
@@ -5445,6 +5475,29 @@ var BuildRepo = class {
|
|
|
5445
5475
|
this.docs = docs;
|
|
5446
5476
|
}
|
|
5447
5477
|
};
|
|
5478
|
+
/**
|
|
5479
|
+
* Writes `content` to `target` unless the file already holds exactly that
|
|
5480
|
+
* content, so an unchanged output produces no filesystem event.
|
|
5481
|
+
*/ async function writeIfChanged(target, content) {
|
|
5482
|
+
if (await (0, fs_promises.readFile)(target, "utf8").catch(() => void 0) !== content) await writeFileAtomic(target, content);
|
|
5483
|
+
}
|
|
5484
|
+
let tmpSeq = 0;
|
|
5485
|
+
/**
|
|
5486
|
+
* Writes `content` to a sibling temp file and renames it over `target`, so the
|
|
5487
|
+
* target is either the old file or the new one — never a partial write.
|
|
5488
|
+
* The temp file is removed if anything goes wrong.
|
|
5489
|
+
*/ async function writeFileAtomic(target, content) {
|
|
5490
|
+
const tmp = `${target}.${process.pid}.${tmpSeq++}.tmp`;
|
|
5491
|
+
try {
|
|
5492
|
+
await (0, fs_promises.writeFile)(tmp, content);
|
|
5493
|
+
await (0, fs_promises.rename)(tmp, target);
|
|
5494
|
+
} catch (error) {
|
|
5495
|
+
try {
|
|
5496
|
+
await (0, fs_promises.rm)(tmp, { force: true });
|
|
5497
|
+
} catch {}
|
|
5498
|
+
throw error;
|
|
5499
|
+
}
|
|
5500
|
+
}
|
|
5448
5501
|
|
|
5449
5502
|
//#endregion
|
|
5450
5503
|
//#region packages/core/src/flatten.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -175,6 +175,15 @@ declare class BuildRepo {
|
|
|
175
175
|
getDoc(id: string): AtscriptDoc | undefined;
|
|
176
176
|
diagnostics(): Promise<Map<string, TMessages>>;
|
|
177
177
|
generate(config: TAtscriptConfigOutput, docs?: AtscriptDoc[]): Promise<TOutput[]>;
|
|
178
|
+
/**
|
|
179
|
+
* Renders every document and writes the outputs to disk.
|
|
180
|
+
*
|
|
181
|
+
* Each write is awaited and atomic (temp file + rename), because a consumer
|
|
182
|
+
* watching the output — a dev server, a type checker, another build — must
|
|
183
|
+
* never observe a half-written file, and an un-awaited write can be
|
|
184
|
+
* truncated when the process exits. Outputs whose content did not change
|
|
185
|
+
* are not rewritten, so those watchers see no event for them.
|
|
186
|
+
*/
|
|
178
187
|
write(config: TAtscriptConfigOutput, docs?: AtscriptDoc[]): Promise<TOutput[]>;
|
|
179
188
|
}
|
|
180
189
|
|
|
@@ -256,7 +265,7 @@ interface TAnnotationTokens {
|
|
|
256
265
|
}
|
|
257
266
|
type TPrimitiveAnnotationArg = string | number | boolean;
|
|
258
267
|
type TPrimitiveAnnotationArgs = Record<string, TPrimitiveAnnotationArg>;
|
|
259
|
-
type TPrimitiveAnnotationValue = boolean | string | number | TPrimitiveAnnotationArgs |
|
|
268
|
+
type TPrimitiveAnnotationValue = boolean | string | number | TPrimitiveAnnotationArgs | Array<TPrimitiveAnnotationArg | TPrimitiveAnnotationArgs>;
|
|
260
269
|
interface TPrimitiveBaseConfig {
|
|
261
270
|
type?: TPrimitiveTypeDef;
|
|
262
271
|
documentation?: string;
|
|
@@ -848,6 +857,20 @@ interface TAtscriptConfigInput {
|
|
|
848
857
|
include?: string[];
|
|
849
858
|
exclude?: string[];
|
|
850
859
|
db?: TDbConfig;
|
|
860
|
+
/**
|
|
861
|
+
* Extra Atscript models to include in `asc db sync` on top of the compiled
|
|
862
|
+
* `.as` files — typically models shipped by packages.
|
|
863
|
+
*
|
|
864
|
+
* The callback may return an array of annotated types, a module namespace
|
|
865
|
+
* object (`models: () => import('some-package/models')`), or a nested
|
|
866
|
+
* combination of both. Every export that `isAnnotatedType()` accepts and
|
|
867
|
+
* that carries `@db.table` or `@db.view` metadata is included, deduplicated
|
|
868
|
+
* by identity.
|
|
869
|
+
*
|
|
870
|
+
* Declared at the top level so it works with both the declarative and the
|
|
871
|
+
* function form of `db`.
|
|
872
|
+
*/
|
|
873
|
+
models?: () => unknown | Promise<unknown>;
|
|
851
874
|
}
|
|
852
875
|
interface TAtscriptConfigOutput {
|
|
853
876
|
format: TAtscriptRenderFormat;
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import path$1 from "path";
|
|
|
7
7
|
import { URL } from "url";
|
|
8
8
|
import { Node, printTree } from "@prostojs/parser";
|
|
9
9
|
import { defu } from "defu";
|
|
10
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
10
|
+
import { mkdir, readFile as readFile$1, rename, rm, writeFile } from "fs/promises";
|
|
11
11
|
import { glob } from "glob";
|
|
12
12
|
|
|
13
13
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
@@ -1460,11 +1460,7 @@ function getRelFilterScope(owner) {
|
|
|
1460
1460
|
const unwound = doc.unwindType(typeName);
|
|
1461
1461
|
if (!unwound?.def) return [];
|
|
1462
1462
|
let def = doc.mergeIntersection(unwound.def);
|
|
1463
|
-
if (isInterface(def))
|
|
1464
|
-
const resolved = doc.resolveInterfaceExtends(def);
|
|
1465
|
-
if (resolved) def = resolved;
|
|
1466
|
-
else def = def.getDefinition() || def;
|
|
1467
|
-
}
|
|
1463
|
+
if (isInterface(def)) def = doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
1468
1464
|
if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
|
|
1469
1465
|
return [];
|
|
1470
1466
|
}
|
|
@@ -1802,29 +1798,35 @@ var NodeIterator = class NodeIterator {
|
|
|
1802
1798
|
|
|
1803
1799
|
//#endregion
|
|
1804
1800
|
//#region packages/core/src/tokenizer/tokens/block.token.ts
|
|
1805
|
-
|
|
1801
|
+
/**
|
|
1802
|
+
* Builds a block node that opens on any key of `pairs` and closes on the
|
|
1803
|
+
* matching value; the opening character is kept as the token's `text`.
|
|
1804
|
+
*/ function createBlockToken(pairs) {
|
|
1805
|
+
const opening = Object.keys(pairs).map((c) => c.replace(/[\\^$.*+?()[\]{}|/-]/gu, "\\$&")).join("");
|
|
1806
|
+
return new Node({
|
|
1807
|
+
name: "block",
|
|
1808
|
+
start: {
|
|
1809
|
+
token: new RegExp(`(?<text>[${opening}])`, "u"),
|
|
1810
|
+
omit: true
|
|
1811
|
+
},
|
|
1812
|
+
end: {
|
|
1813
|
+
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1814
|
+
omit: true
|
|
1815
|
+
},
|
|
1816
|
+
skip: /\s/u,
|
|
1817
|
+
eofClose: true,
|
|
1818
|
+
data: {
|
|
1819
|
+
type: "block",
|
|
1820
|
+
text: ""
|
|
1821
|
+
}
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Block node
|
|
1826
|
+
*/ const BlockToken = createBlockToken({
|
|
1806
1827
|
"{": "}",
|
|
1807
1828
|
"(": ")",
|
|
1808
1829
|
"[": "]"
|
|
1809
|
-
};
|
|
1810
|
-
/**
|
|
1811
|
-
* Block node
|
|
1812
|
-
*/ const BlockToken = new Node({
|
|
1813
|
-
name: "block",
|
|
1814
|
-
start: {
|
|
1815
|
-
token: RegExp("(?<text>[([{])", "u"),
|
|
1816
|
-
omit: true
|
|
1817
|
-
},
|
|
1818
|
-
end: {
|
|
1819
|
-
token: (ctx) => pairs[ctx.node.data.text] || "",
|
|
1820
|
-
omit: true
|
|
1821
|
-
},
|
|
1822
|
-
skip: /\s/u,
|
|
1823
|
-
eofClose: true,
|
|
1824
|
-
data: {
|
|
1825
|
-
type: "block",
|
|
1826
|
-
text: ""
|
|
1827
|
-
}
|
|
1828
1830
|
});
|
|
1829
1831
|
|
|
1830
1832
|
//#endregion
|
|
@@ -1930,6 +1932,22 @@ const block$1 = new Node({
|
|
|
1930
1932
|
}
|
|
1931
1933
|
});
|
|
1932
1934
|
|
|
1935
|
+
//#endregion
|
|
1936
|
+
//#region packages/core/src/tokenizer/tokens/query-block.token.ts
|
|
1937
|
+
/**
|
|
1938
|
+
* Query block node — parenthesized sub-expressions inside backtick queries.
|
|
1939
|
+
*
|
|
1940
|
+
* Same definition as `BlockToken` narrowed to `(`, so it produces the same
|
|
1941
|
+
* token shape (`type: 'block'`, `text: '('`) and every consumer keeps working,
|
|
1942
|
+
* but it recognizes `QueryOperatorToken` inside (see `tokens/index.ts`), which
|
|
1943
|
+
* makes `!=`, `>=`, `<=`, `>`, `<` work within parentheses — the generic block
|
|
1944
|
+
* only knows `PunctuationToken`, whose charset has no `<` / `>`.
|
|
1945
|
+
*
|
|
1946
|
+
* Only registered inside `QueryToken` (and itself, for nested parens) —
|
|
1947
|
+
* the generic `BlockToken` is left untouched so tokenization of `(`/`[`/`{`
|
|
1948
|
+
* outside queries does not change.
|
|
1949
|
+
*/ const QueryBlockToken = createBlockToken({ "(": ")" });
|
|
1950
|
+
|
|
1933
1951
|
//#endregion
|
|
1934
1952
|
//#region packages/core/src/tokenizer/tokens/query-operator.token.ts
|
|
1935
1953
|
/**
|
|
@@ -2045,6 +2063,7 @@ const tokens = {
|
|
|
2045
2063
|
text: TextToken,
|
|
2046
2064
|
regexp: RegExpToken,
|
|
2047
2065
|
query: QueryToken,
|
|
2066
|
+
queryBlock: QueryBlockToken,
|
|
2048
2067
|
root: void 0
|
|
2049
2068
|
};
|
|
2050
2069
|
const root = new Node({
|
|
@@ -2064,7 +2083,14 @@ const root = new Node({
|
|
|
2064
2083
|
});
|
|
2065
2084
|
tokens.root = root;
|
|
2066
2085
|
BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2067
|
-
QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2086
|
+
QueryToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2087
|
+
QueryBlockToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
|
|
2088
|
+
/** 1-based parser position → 0-based VSCode position, shifted by `offset` characters. */ function toPos(p, offset = 0) {
|
|
2089
|
+
return {
|
|
2090
|
+
line: p.line - 1,
|
|
2091
|
+
character: p.column - 1 + offset
|
|
2092
|
+
};
|
|
2093
|
+
}
|
|
2068
2094
|
/**
|
|
2069
2095
|
* Recursively extract TLexicalToken[] from a ParsedNode tree.
|
|
2070
2096
|
* Replaces the v0.5 mapContent('children', callback) + global loop.
|
|
@@ -2073,21 +2099,26 @@ QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToke
|
|
|
2073
2099
|
* line is 1-based, column is 1-based.
|
|
2074
2100
|
* VSCode expects 0-based line, 0-based character.
|
|
2075
2101
|
*/ function extractTokens(node) {
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2102
|
+
const content = node.content;
|
|
2103
|
+
return content.map((item, index) => {
|
|
2104
|
+
if (typeof item === "string") {
|
|
2105
|
+
const prev = content[index - 1];
|
|
2106
|
+
const next = content[index + 1];
|
|
2107
|
+
const start = typeof prev === "object" ? prev.end : node.start;
|
|
2108
|
+
const end = typeof next === "object" ? next.start : node.end;
|
|
2109
|
+
return {
|
|
2110
|
+
type: "unknown",
|
|
2111
|
+
text: item,
|
|
2112
|
+
getRange: () => ({
|
|
2113
|
+
start: toPos(start),
|
|
2114
|
+
end: toPos(end)
|
|
2115
|
+
})
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2081
2118
|
const data = item.data;
|
|
2082
2119
|
data.getRange = () => ({
|
|
2083
|
-
start:
|
|
2084
|
-
|
|
2085
|
-
character: item.start.column - 1 + (data.startOffset ?? 0)
|
|
2086
|
-
},
|
|
2087
|
-
end: {
|
|
2088
|
-
line: item.end.line - 1,
|
|
2089
|
-
character: item.end.column - 1 + (data.endOffset ?? 0)
|
|
2090
|
-
}
|
|
2120
|
+
start: toPos(item.start, data.startOffset),
|
|
2121
|
+
end: toPos(item.end, data.endOffset)
|
|
2091
2122
|
});
|
|
2092
2123
|
data.children = extractTokens(item);
|
|
2093
2124
|
return data;
|
|
@@ -2370,43 +2401,42 @@ const VALUE_KEYWORDS = new Set([
|
|
|
2370
2401
|
"null",
|
|
2371
2402
|
"undefined"
|
|
2372
2403
|
]);
|
|
2404
|
+
const ZERO_RANGE = {
|
|
2405
|
+
start: {
|
|
2406
|
+
line: 0,
|
|
2407
|
+
character: 0
|
|
2408
|
+
},
|
|
2409
|
+
end: {
|
|
2410
|
+
line: 0,
|
|
2411
|
+
character: 0
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2373
2414
|
/**
|
|
2374
|
-
* Parse a backtick-delimited query expression
|
|
2415
|
+
* Parse a backtick-delimited query expression.
|
|
2416
|
+
*
|
|
2417
|
+
* `ni` iterates the query token's children and carries that token as its
|
|
2418
|
+
* `parent` — the range to blame when a diagnostic has no token of its own —
|
|
2419
|
+
* so fork it from the annotation iterator while the query token is current.
|
|
2375
2420
|
* Returns a SemanticQueryNode or undefined if the content is empty.
|
|
2376
|
-
*/ function parseQueryExpression(
|
|
2377
|
-
if (
|
|
2378
|
-
const
|
|
2379
|
-
ni.move();
|
|
2380
|
-
const expr = parseOrExpr(ni, messages);
|
|
2421
|
+
*/ function parseQueryExpression(ni, sourceToken) {
|
|
2422
|
+
if (!ni.$) return;
|
|
2423
|
+
const expr = parseOrExpr(ni);
|
|
2381
2424
|
if (!expr) return;
|
|
2382
|
-
if (ni.$)
|
|
2383
|
-
severity: 1,
|
|
2384
|
-
message: `Unexpected token in query expression: "${ni.$.text}"`,
|
|
2385
|
-
range: ni.$.getRange?.() ?? {
|
|
2386
|
-
start: {
|
|
2387
|
-
line: 0,
|
|
2388
|
-
character: 0
|
|
2389
|
-
},
|
|
2390
|
-
end: {
|
|
2391
|
-
line: 0,
|
|
2392
|
-
character: 0
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
});
|
|
2425
|
+
if (ni.$) pushError(ni, `Unexpected token in query expression: "${ni.$.text}"`);
|
|
2396
2426
|
const node = new SemanticQueryNode();
|
|
2397
2427
|
node.expression = expr;
|
|
2398
2428
|
node.sourceToken = sourceToken;
|
|
2399
2429
|
return node;
|
|
2400
2430
|
}
|
|
2401
|
-
function parseOrExpr(ni
|
|
2402
|
-
const left = parseAndExpr(ni
|
|
2431
|
+
function parseOrExpr(ni) {
|
|
2432
|
+
const left = parseAndExpr(ni);
|
|
2403
2433
|
if (!left) return;
|
|
2404
2434
|
const operands = [left];
|
|
2405
2435
|
while (ni.$?.type === "identifier" && ni.$.text === "or") {
|
|
2406
2436
|
ni.move();
|
|
2407
|
-
const right = parseAndExpr(ni
|
|
2437
|
+
const right = parseAndExpr(ni);
|
|
2408
2438
|
if (!right) {
|
|
2409
|
-
pushError(ni,
|
|
2439
|
+
pushError(ni, "Expected expression after \"or\"");
|
|
2410
2440
|
break;
|
|
2411
2441
|
}
|
|
2412
2442
|
operands.push(right);
|
|
@@ -2417,15 +2447,15 @@ function parseOrExpr(ni, messages) {
|
|
|
2417
2447
|
node.operands = operands;
|
|
2418
2448
|
return node;
|
|
2419
2449
|
}
|
|
2420
|
-
function parseAndExpr(ni
|
|
2421
|
-
const left = parseUnaryExpr(ni
|
|
2450
|
+
function parseAndExpr(ni) {
|
|
2451
|
+
const left = parseUnaryExpr(ni);
|
|
2422
2452
|
if (!left) return;
|
|
2423
2453
|
const operands = [left];
|
|
2424
2454
|
while (ni.$?.type === "identifier" && ni.$.text === "and") {
|
|
2425
2455
|
ni.move();
|
|
2426
|
-
const right = parseUnaryExpr(ni
|
|
2456
|
+
const right = parseUnaryExpr(ni);
|
|
2427
2457
|
if (!right) {
|
|
2428
|
-
pushError(ni,
|
|
2458
|
+
pushError(ni, "Expected expression after \"and\"");
|
|
2429
2459
|
break;
|
|
2430
2460
|
}
|
|
2431
2461
|
operands.push(right);
|
|
@@ -2436,12 +2466,12 @@ function parseAndExpr(ni, messages) {
|
|
|
2436
2466
|
node.operands = operands;
|
|
2437
2467
|
return node;
|
|
2438
2468
|
}
|
|
2439
|
-
function parseUnaryExpr(ni
|
|
2469
|
+
function parseUnaryExpr(ni) {
|
|
2440
2470
|
if (ni.$?.type === "identifier" && ni.$.text === "not") {
|
|
2441
2471
|
ni.move();
|
|
2442
|
-
const operand = parseUnaryExpr(ni
|
|
2472
|
+
const operand = parseUnaryExpr(ni);
|
|
2443
2473
|
if (!operand) {
|
|
2444
|
-
pushError(ni,
|
|
2474
|
+
pushError(ni, "Expected expression after \"not\"");
|
|
2445
2475
|
return;
|
|
2446
2476
|
}
|
|
2447
2477
|
const node = new SemanticQueryLogicalNode();
|
|
@@ -2450,29 +2480,27 @@ function parseUnaryExpr(ni, messages) {
|
|
|
2450
2480
|
return node;
|
|
2451
2481
|
}
|
|
2452
2482
|
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2453
|
-
const
|
|
2483
|
+
const subNi = ni.fork(ni.$.children || []);
|
|
2454
2484
|
ni.move();
|
|
2455
|
-
if (
|
|
2456
|
-
pushError(
|
|
2485
|
+
if (!subNi.$) {
|
|
2486
|
+
pushError(subNi, "Empty parenthesized expression");
|
|
2457
2487
|
return;
|
|
2458
2488
|
}
|
|
2459
|
-
const
|
|
2460
|
-
subNi
|
|
2461
|
-
const expr = parseOrExpr(subNi, messages);
|
|
2462
|
-
if (subNi.$) pushError(subNi, messages, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2489
|
+
const expr = parseOrExpr(subNi);
|
|
2490
|
+
if (subNi.$) pushError(subNi, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
|
|
2463
2491
|
return expr;
|
|
2464
2492
|
}
|
|
2465
|
-
return parseComparison(ni
|
|
2493
|
+
return parseComparison(ni);
|
|
2466
2494
|
}
|
|
2467
|
-
function parseComparison(ni
|
|
2468
|
-
const left = parseFieldRef(ni
|
|
2495
|
+
function parseComparison(ni) {
|
|
2496
|
+
const left = parseFieldRef(ni);
|
|
2469
2497
|
if (!left) return;
|
|
2470
2498
|
if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
|
|
2471
2499
|
const opText = ni.$.text;
|
|
2472
2500
|
ni.move();
|
|
2473
|
-
const right = parseValueOrFieldRef(ni
|
|
2501
|
+
const right = parseValueOrFieldRef(ni);
|
|
2474
2502
|
if (!right) {
|
|
2475
|
-
pushError(ni,
|
|
2503
|
+
pushError(ni, `Expected value or field reference after "${opText}"`);
|
|
2476
2504
|
return;
|
|
2477
2505
|
}
|
|
2478
2506
|
const node = new SemanticQueryComparisonNode();
|
|
@@ -2485,7 +2513,7 @@ function parseComparison(ni, messages) {
|
|
|
2485
2513
|
const opText = ni.$.text;
|
|
2486
2514
|
if (opText === "in") {
|
|
2487
2515
|
ni.move();
|
|
2488
|
-
const right = parseValueList(ni
|
|
2516
|
+
const right = parseValueList(ni);
|
|
2489
2517
|
if (!right) return;
|
|
2490
2518
|
const node = new SemanticQueryComparisonNode();
|
|
2491
2519
|
node.left = left;
|
|
@@ -2495,9 +2523,9 @@ function parseComparison(ni, messages) {
|
|
|
2495
2523
|
}
|
|
2496
2524
|
if (opText === "matches") {
|
|
2497
2525
|
ni.move();
|
|
2498
|
-
const right = parseValueOrFieldRef(ni
|
|
2526
|
+
const right = parseValueOrFieldRef(ni);
|
|
2499
2527
|
if (!right) {
|
|
2500
|
-
pushError(ni,
|
|
2528
|
+
pushError(ni, "Expected value after \"matches\"");
|
|
2501
2529
|
return;
|
|
2502
2530
|
}
|
|
2503
2531
|
const node = new SemanticQueryComparisonNode();
|
|
@@ -2513,17 +2541,17 @@ function parseComparison(ni, messages) {
|
|
|
2513
2541
|
node.operator = "exists";
|
|
2514
2542
|
return node;
|
|
2515
2543
|
}
|
|
2516
|
-
if (opText === "not") return parseNotComparison(ni,
|
|
2517
|
-
pushError(ni,
|
|
2544
|
+
if (opText === "not") return parseNotComparison(ni, left);
|
|
2545
|
+
pushError(ni, `Unknown operator "${opText}"`);
|
|
2518
2546
|
return;
|
|
2519
2547
|
}
|
|
2520
|
-
pushError(ni,
|
|
2548
|
+
pushError(ni, "Expected operator after field reference");
|
|
2521
2549
|
}
|
|
2522
|
-
function parseNotComparison(ni,
|
|
2550
|
+
function parseNotComparison(ni, left) {
|
|
2523
2551
|
ni.move();
|
|
2524
2552
|
if (ni.$?.type === "identifier" && ni.$.text === "in") {
|
|
2525
2553
|
ni.move();
|
|
2526
|
-
const right = parseValueList(ni
|
|
2554
|
+
const right = parseValueList(ni);
|
|
2527
2555
|
if (!right) return;
|
|
2528
2556
|
const node = new SemanticQueryComparisonNode();
|
|
2529
2557
|
node.left = left;
|
|
@@ -2538,11 +2566,11 @@ function parseNotComparison(ni, messages, left) {
|
|
|
2538
2566
|
node.operator = "not exists";
|
|
2539
2567
|
return node;
|
|
2540
2568
|
}
|
|
2541
|
-
pushError(ni,
|
|
2569
|
+
pushError(ni, "Expected \"in\" or \"exists\" after \"not\"");
|
|
2542
2570
|
}
|
|
2543
|
-
function parseFieldRef(ni
|
|
2571
|
+
function parseFieldRef(ni) {
|
|
2544
2572
|
if (ni.$?.type !== "identifier") {
|
|
2545
|
-
pushError(ni,
|
|
2573
|
+
pushError(ni, "Expected field reference");
|
|
2546
2574
|
return;
|
|
2547
2575
|
}
|
|
2548
2576
|
const firstToken = new Token(ni.$);
|
|
@@ -2559,17 +2587,16 @@ function parseFieldRef(ni, messages) {
|
|
|
2559
2587
|
fieldText += `.${ni.$.text}`;
|
|
2560
2588
|
ni.move();
|
|
2561
2589
|
} else {
|
|
2562
|
-
pushError(ni,
|
|
2590
|
+
pushError(ni, "Expected identifier after \".\"");
|
|
2563
2591
|
break;
|
|
2564
2592
|
}
|
|
2565
2593
|
}
|
|
2566
2594
|
const node = new SemanticQueryFieldRefNode();
|
|
2567
2595
|
node.typeRef = firstToken;
|
|
2568
|
-
|
|
2569
|
-
else node.fieldRef = secondToken;
|
|
2596
|
+
node.fieldRef = fieldText === secondToken.text ? secondToken : secondToken.clone({ text: fieldText });
|
|
2570
2597
|
return node;
|
|
2571
2598
|
}
|
|
2572
|
-
pushError(ni,
|
|
2599
|
+
pushError(ni, "Expected identifier after \".\"");
|
|
2573
2600
|
const node = new SemanticQueryFieldRefNode();
|
|
2574
2601
|
node.fieldRef = firstToken;
|
|
2575
2602
|
return node;
|
|
@@ -2578,18 +2605,18 @@ function parseFieldRef(ni, messages) {
|
|
|
2578
2605
|
node.fieldRef = firstToken;
|
|
2579
2606
|
return node;
|
|
2580
2607
|
}
|
|
2581
|
-
function parseValueOrFieldRef(ni
|
|
2608
|
+
function parseValueOrFieldRef(ni) {
|
|
2582
2609
|
if (!ni.$) return;
|
|
2583
|
-
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni
|
|
2610
|
+
if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni);
|
|
2584
2611
|
if (ni.$.type === "identifier") {
|
|
2585
|
-
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni
|
|
2586
|
-
return parseFieldRef(ni
|
|
2612
|
+
if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni);
|
|
2613
|
+
return parseFieldRef(ni);
|
|
2587
2614
|
}
|
|
2588
|
-
pushError(ni,
|
|
2615
|
+
pushError(ni, "Expected value or field reference");
|
|
2589
2616
|
}
|
|
2590
|
-
function parseValue(ni
|
|
2617
|
+
function parseValue(ni) {
|
|
2591
2618
|
if (!ni.$) {
|
|
2592
|
-
pushError(ni,
|
|
2619
|
+
pushError(ni, "Expected value");
|
|
2593
2620
|
return;
|
|
2594
2621
|
}
|
|
2595
2622
|
const token = ni.$;
|
|
@@ -2599,48 +2626,42 @@ function parseValue(ni, messages) {
|
|
|
2599
2626
|
ni.move();
|
|
2600
2627
|
return node;
|
|
2601
2628
|
}
|
|
2602
|
-
pushError(ni,
|
|
2629
|
+
pushError(ni, `Unexpected token "${token.text}" where value expected`);
|
|
2603
2630
|
}
|
|
2604
|
-
function parseValueList(ni
|
|
2631
|
+
function parseValueList(ni) {
|
|
2605
2632
|
if (ni.$?.type === "block" && ni.$.text === "(") {
|
|
2606
|
-
const
|
|
2633
|
+
const subNi = ni.fork(ni.$.children || []);
|
|
2607
2634
|
ni.move();
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
pushError(ni, messages, "Empty value list in \"in\" expression");
|
|
2635
|
+
if (!subNi.$) {
|
|
2636
|
+
pushError(subNi, "Empty value list in \"in\" expression");
|
|
2611
2637
|
return;
|
|
2612
2638
|
}
|
|
2613
|
-
const
|
|
2614
|
-
subNi
|
|
2615
|
-
const first = parseValue(subNi, messages);
|
|
2639
|
+
const values = [];
|
|
2640
|
+
const first = parseValue(subNi);
|
|
2616
2641
|
if (first) values.push(first);
|
|
2617
2642
|
while (subNi.$?.type === "punctuation" && subNi.$.text === ",") {
|
|
2618
2643
|
subNi.move();
|
|
2619
|
-
const v = parseValue(subNi
|
|
2644
|
+
const v = parseValue(subNi);
|
|
2620
2645
|
if (v) values.push(v);
|
|
2621
2646
|
}
|
|
2622
|
-
if (subNi.$) pushError(subNi,
|
|
2647
|
+
if (subNi.$) pushError(subNi, `Unexpected token in value list: "${subNi.$.text}"`);
|
|
2623
2648
|
const node = new SemanticQueryValueListNode();
|
|
2624
2649
|
node.values = values;
|
|
2625
2650
|
return node;
|
|
2626
2651
|
}
|
|
2627
|
-
pushError(ni,
|
|
2652
|
+
pushError(ni, "Expected parenthesized value list after \"in\"");
|
|
2628
2653
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
character: 0
|
|
2638
|
-
}
|
|
2639
|
-
};
|
|
2640
|
-
messages.push({
|
|
2654
|
+
/**
|
|
2655
|
+
* Range to blame for a diagnostic: the current token, else the enclosing
|
|
2656
|
+
* query token / "(...)" block the iterator was forked from.
|
|
2657
|
+
*/ function rangeOf(ni) {
|
|
2658
|
+
return ni.$?.getRange?.() ?? ni.parent?.getRange?.() ?? ZERO_RANGE;
|
|
2659
|
+
}
|
|
2660
|
+
function pushError(ni, message) {
|
|
2661
|
+
ni.messages.push({
|
|
2641
2662
|
severity: 1,
|
|
2642
2663
|
message,
|
|
2643
|
-
range
|
|
2664
|
+
range: rangeOf(ni)
|
|
2644
2665
|
});
|
|
2645
2666
|
}
|
|
2646
2667
|
|
|
@@ -2763,6 +2784,10 @@ function annotations() {
|
|
|
2763
2784
|
}
|
|
2764
2785
|
while (ni.satisfies(...opts.argument)) {
|
|
2765
2786
|
let argToken = new Token(ni.$);
|
|
2787
|
+
if (argToken.type === "query") {
|
|
2788
|
+
const queryNode = parseQueryExpression(ni.fork(argToken.children), argToken);
|
|
2789
|
+
if (queryNode) argToken.queryNode = queryNode;
|
|
2790
|
+
}
|
|
2766
2791
|
ni.accepted();
|
|
2767
2792
|
ni.move();
|
|
2768
2793
|
if (argToken.type === "identifier" && ![
|
|
@@ -2781,10 +2806,6 @@ function annotations() {
|
|
|
2781
2806
|
}
|
|
2782
2807
|
if (chainText !== argToken.text) argToken = argToken.clone({ text: chainText });
|
|
2783
2808
|
}
|
|
2784
|
-
if (argToken.type === "query") {
|
|
2785
|
-
const queryNode = parseQueryExpression(argToken.children, ni.messages, argToken);
|
|
2786
|
-
if (queryNode) argToken.queryNode = queryNode;
|
|
2787
|
-
}
|
|
2788
2809
|
addArgument(argToken);
|
|
2789
2810
|
if (ni.satisfies(opts.comma)) {
|
|
2790
2811
|
ni.accepted();
|
|
@@ -5348,6 +5369,7 @@ function _define_property(obj, key, value) {
|
|
|
5348
5369
|
else obj[key] = value;
|
|
5349
5370
|
return obj;
|
|
5350
5371
|
}
|
|
5372
|
+
/** Upper bound on concurrent file operations — macOS defaults `ulimit -n` to 256. */ const WRITE_CONCURRENCY = 32;
|
|
5351
5373
|
async function build(config) {
|
|
5352
5374
|
const rootDir = config.rootDir ? config.rootDir.startsWith("/") ? config.rootDir : path$1.join(process.cwd(), config.rootDir) : process.cwd();
|
|
5353
5375
|
config.rootDir = rootDir;
|
|
@@ -5397,12 +5419,20 @@ var BuildRepo = class {
|
|
|
5397
5419
|
}
|
|
5398
5420
|
return outFiles;
|
|
5399
5421
|
}
|
|
5400
|
-
|
|
5422
|
+
/**
|
|
5423
|
+
* Renders every document and writes the outputs to disk.
|
|
5424
|
+
*
|
|
5425
|
+
* Each write is awaited and atomic (temp file + rename), because a consumer
|
|
5426
|
+
* watching the output — a dev server, a type checker, another build — must
|
|
5427
|
+
* never observe a half-written file, and an un-awaited write can be
|
|
5428
|
+
* truncated when the process exits. Outputs whose content did not change
|
|
5429
|
+
* are not rewritten, so those watchers see no event for them.
|
|
5430
|
+
*/ async write(config, docs = this.docs) {
|
|
5401
5431
|
const outFiles = await this.generate(config, docs);
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5432
|
+
const targeted = outFiles.filter((o) => o.target);
|
|
5433
|
+
const dirs = new Set(targeted.map((o) => path$1.dirname(o.target)));
|
|
5434
|
+
await Promise.all(Array.from(dirs, (dir) => mkdir(dir, { recursive: true })));
|
|
5435
|
+
for (let i = 0; i < targeted.length; i += WRITE_CONCURRENCY) await Promise.all(targeted.slice(i, i + WRITE_CONCURRENCY).map((o) => writeIfChanged(o.target, o.content)));
|
|
5406
5436
|
return outFiles;
|
|
5407
5437
|
}
|
|
5408
5438
|
constructor(rootDir, repo, docs) {
|
|
@@ -5414,6 +5444,29 @@ var BuildRepo = class {
|
|
|
5414
5444
|
this.docs = docs;
|
|
5415
5445
|
}
|
|
5416
5446
|
};
|
|
5447
|
+
/**
|
|
5448
|
+
* Writes `content` to `target` unless the file already holds exactly that
|
|
5449
|
+
* content, so an unchanged output produces no filesystem event.
|
|
5450
|
+
*/ async function writeIfChanged(target, content) {
|
|
5451
|
+
if (await readFile$1(target, "utf8").catch(() => void 0) !== content) await writeFileAtomic(target, content);
|
|
5452
|
+
}
|
|
5453
|
+
let tmpSeq = 0;
|
|
5454
|
+
/**
|
|
5455
|
+
* Writes `content` to a sibling temp file and renames it over `target`, so the
|
|
5456
|
+
* target is either the old file or the new one — never a partial write.
|
|
5457
|
+
* The temp file is removed if anything goes wrong.
|
|
5458
|
+
*/ async function writeFileAtomic(target, content) {
|
|
5459
|
+
const tmp = `${target}.${process.pid}.${tmpSeq++}.tmp`;
|
|
5460
|
+
try {
|
|
5461
|
+
await writeFile(tmp, content);
|
|
5462
|
+
await rename(tmp, target);
|
|
5463
|
+
} catch (error) {
|
|
5464
|
+
try {
|
|
5465
|
+
await rm(tmp, { force: true });
|
|
5466
|
+
} catch {}
|
|
5467
|
+
throw error;
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5417
5470
|
|
|
5418
5471
|
//#endregion
|
|
5419
5472
|
//#region packages/core/src/flatten.ts
|