@dogsbay/literal 0.2.0-beta.153 → 0.2.0-beta.154
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 +29 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -623,11 +623,39 @@ class Evaluator {
|
|
|
623
623
|
}
|
|
624
624
|
i = this.skipBalanced(i);
|
|
625
625
|
if (this.is(i, ":"))
|
|
626
|
-
i = this.
|
|
626
|
+
i = this.skipReturnType(i + 1);
|
|
627
627
|
if (!this.is(i, "{"))
|
|
628
628
|
return -1;
|
|
629
629
|
return i + 1;
|
|
630
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* Past a function declaration's return type (`): Item[] {`), to the `{` of its body. The
|
|
633
|
+
* body's brace is the first `{` at depth 0 after a token that ends a type (a name, `]`, `)`, `}`,
|
|
634
|
+
* `>`); a `{` anywhere else opens an object type (`): { a: string } {`). Without this,
|
|
635
|
+
* `function sidebar(): DefaultTheme.SidebarItem[] { return […] }` (VitePress's own docs) was
|
|
636
|
+
* never read.
|
|
637
|
+
*/
|
|
638
|
+
skipReturnType(i) {
|
|
639
|
+
let depth = 0;
|
|
640
|
+
for (let first = true; i < this.toks.length; i++, first = false) {
|
|
641
|
+
const t = this.toks[i];
|
|
642
|
+
if (depth === 0 && t.kind === "punct" && t.text === "{" && !first) {
|
|
643
|
+
const prev = this.toks[i - 1];
|
|
644
|
+
if (prev.kind === "ident" || prev.kind === "str" || prev.kind === "num" || prev.kind === "template" || (prev.kind === "punct" && (prev.text === "]" || prev.text === ")" || prev.text === ">" || prev.text === "}")))
|
|
645
|
+
return i;
|
|
646
|
+
}
|
|
647
|
+
if (depth === 0 && t.kind === "punct" && (t.text === "=" || t.text === ";"))
|
|
648
|
+
return i;
|
|
649
|
+
if (t.kind === "punct" && (OPENERS[t.text] || t.text === "<"))
|
|
650
|
+
depth++;
|
|
651
|
+
else if (t.kind === "punct" && (CLOSERS.has(t.text) || t.text === ">")) {
|
|
652
|
+
if (depth === 0)
|
|
653
|
+
return i;
|
|
654
|
+
depth--;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return i;
|
|
658
|
+
}
|
|
631
659
|
/** Index just past the group opened at `i`. */
|
|
632
660
|
skipBalanced(i) {
|
|
633
661
|
if (!this.toks[i] || !OPENERS[this.toks[i].text])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/literal",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.154",
|
|
4
4
|
"description": "Read a JavaScript/TypeScript config module as data without running it: object and array literals, spreads, module-level constants, zero-argument helpers and wrapper calls; anything else is reported, never guessed. No Node, no dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|