@orkestrel/guide 0.0.22 → 0.0.23
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/src/core/index.cjs +33 -8
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +15 -5
- package/dist/src/core/index.d.ts +15 -5
- package/dist/src/core/index.js +33 -8
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +33 -8
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +33 -8
- package/dist/src/server/index.js.map +1 -1
- package/package.json +6 -6
package/dist/src/core/index.cjs
CHANGED
|
@@ -1246,7 +1246,14 @@ function extractHidden(source) {
|
|
|
1246
1246
|
}
|
|
1247
1247
|
/**
|
|
1248
1248
|
* Joins the declaration head starting at `start` into one space-separated
|
|
1249
|
-
* line, consuming lines until the first that ends with
|
|
1249
|
+
* line, consuming lines until the first that opens a body: one that ends with
|
|
1250
|
+
* `{`, or one that closes an empty body with `{}` or `{ }`.
|
|
1251
|
+
*
|
|
1252
|
+
* @remarks
|
|
1253
|
+
* A line ending with `{}` closes an empty body only when every angle, round,
|
|
1254
|
+
* and square bracket the head opened outside quoted text has closed; inside
|
|
1255
|
+
* one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
|
|
1256
|
+
* head that reaches the next column-zero `export` line opens no body.
|
|
1250
1257
|
*
|
|
1251
1258
|
* @param lines - The file's source lines
|
|
1252
1259
|
* @param start - The index of the head's first line
|
|
@@ -1255,6 +1262,7 @@ function extractHidden(source) {
|
|
|
1255
1262
|
* @example
|
|
1256
1263
|
* ```ts
|
|
1257
1264
|
* joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
|
|
1265
|
+
* joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
|
|
1258
1266
|
* ```
|
|
1259
1267
|
*/
|
|
1260
1268
|
function joinHead(lines, start) {
|
|
@@ -1262,8 +1270,15 @@ function joinHead(lines, start) {
|
|
|
1262
1270
|
for (let index = start; index < lines.length; index += 1) {
|
|
1263
1271
|
const line = lines[index];
|
|
1264
1272
|
if (line === void 0) break;
|
|
1265
|
-
|
|
1266
|
-
if (
|
|
1273
|
+
const text = line.trimEnd();
|
|
1274
|
+
if (index > start && text.startsWith("export ")) return void 0;
|
|
1275
|
+
parts.push(index === start ? text : text.trimStart());
|
|
1276
|
+
if (text.endsWith("{")) return {
|
|
1277
|
+
text: parts.join(" "),
|
|
1278
|
+
end: index
|
|
1279
|
+
};
|
|
1280
|
+
const bare = parts.join(" ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
|
|
1281
|
+
if ((bare.match(/</g)?.length ?? 0) <= (bare.match(/(?<!=)>/g)?.length ?? 0) && (bare.match(/\(/g)?.length ?? 0) <= (bare.match(/\)/g)?.length ?? 0) && (bare.match(/\[/g)?.length ?? 0) <= (bare.match(/\]/g)?.length ?? 0) && /\{\s*\}$/.test(text)) return {
|
|
1267
1282
|
text: parts.join(" "),
|
|
1268
1283
|
end: index
|
|
1269
1284
|
};
|
|
@@ -1304,12 +1319,14 @@ function escapeRegExp(value) {
|
|
|
1304
1319
|
* optional heritage clause between the identifier and the opening `{`; the identifier is the head's
|
|
1305
1320
|
* own run up to that list or clause, so it enters the key as literal text and no name reaches a
|
|
1306
1321
|
* `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
|
|
1307
|
-
* keeping JSDoc evidence intact
|
|
1322
|
+
* keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
|
|
1323
|
+
* records an empty body. Every balanced `<...>` span is removed from the head before its
|
|
1308
1324
|
* `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
|
|
1309
1325
|
* reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
|
|
1310
1326
|
* qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
|
|
1311
1327
|
* a column-zero close answers for that key: a head that opens none records nothing, and a later
|
|
1312
|
-
* head of a key already collected adds nothing
|
|
1328
|
+
* head of a key already collected adds nothing unless the earlier head recorded neither a body
|
|
1329
|
+
* nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
|
|
1313
1330
|
*
|
|
1314
1331
|
* @param source - The file's source text to read
|
|
1315
1332
|
* @returns One entry per collected declaration, keyed `${keyword} ${name}`
|
|
@@ -1323,7 +1340,7 @@ function escapeRegExp(value) {
|
|
|
1323
1340
|
function collectDeclarations(source) {
|
|
1324
1341
|
const declarations = /* @__PURE__ */ new Map();
|
|
1325
1342
|
const opener = /^export (?:class|interface) /;
|
|
1326
|
-
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{
|
|
1343
|
+
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
|
|
1327
1344
|
const lines = extractSourceLines(source);
|
|
1328
1345
|
const projected = lines.map((line) => line.code);
|
|
1329
1346
|
for (let index = 0; index < projected.length; index += 1) {
|
|
@@ -1336,14 +1353,22 @@ function collectDeclarations(source) {
|
|
|
1336
1353
|
const name = declared?.[2];
|
|
1337
1354
|
if (keyword === void 0 || name === void 0) continue;
|
|
1338
1355
|
const key = `${keyword} ${name}`;
|
|
1339
|
-
|
|
1356
|
+
const known = declarations.get(key);
|
|
1357
|
+
if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
|
|
1340
1358
|
let depth = 0;
|
|
1341
1359
|
let flat = "";
|
|
1342
|
-
for (const character of head.text.slice(`export ${key}`.length,
|
|
1360
|
+
for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
|
|
1343
1361
|
else if (character === ">") depth = Math.max(0, depth - 1);
|
|
1344
1362
|
else if (depth === 0) flat += character;
|
|
1345
1363
|
const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
|
|
1346
1364
|
const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(_orkestrel_contract.isNonEmptyString);
|
|
1365
|
+
if (head.text.endsWith("}")) {
|
|
1366
|
+
declarations.set(key, {
|
|
1367
|
+
body: [],
|
|
1368
|
+
bases
|
|
1369
|
+
});
|
|
1370
|
+
continue;
|
|
1371
|
+
}
|
|
1347
1372
|
for (let close = head.end + 1; close < projected.length; close += 1) {
|
|
1348
1373
|
if (projected[close] !== "}") continue;
|
|
1349
1374
|
declarations.set(key, {
|