@ryuugg/stanza 0.1.0 → 0.1.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuugg/stanza",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "An opinionated code formatter for TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formatter",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"check": "oxlint && oxfmt --check",
|
|
43
43
|
"check:fix": "oxlint --fix && oxfmt",
|
|
44
44
|
"self-check": "bun run src/cli.ts --check src scripts tests/*.ts",
|
|
45
|
+
"tegami": "bun scripts/tegami.ts",
|
|
45
46
|
"test": "bun test --parallel",
|
|
46
47
|
"typecheck": "tsc --noEmit"
|
|
47
48
|
},
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"@types/bun": "latest",
|
|
53
54
|
"oxfmt": "^0.70.0",
|
|
54
55
|
"oxlint": "^1.85.0",
|
|
56
|
+
"tegami": "^1.5.0",
|
|
55
57
|
"typescript": "5"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
package/src/languages/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ const entries: Entry[] = [javascript];
|
|
|
6
6
|
const byExtension = new Map(
|
|
7
7
|
entries.flatMap((entry) => entry.extensions.map((extension) => [extension, entry] as const)),
|
|
8
8
|
);
|
|
9
|
+
export const extensions = [...byExtension.keys()];
|
|
9
10
|
|
|
10
11
|
export function entryFor(path: string): Entry | undefined {
|
|
11
12
|
return byExtension.get(extname(path));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { visitorKeys, type Node } from "oxc-parser";
|
|
2
|
+
import type { Path } from "../../engine/model.ts";
|
|
2
3
|
|
|
3
4
|
function isNode(value: unknown): value is Node {
|
|
4
5
|
return (
|
|
@@ -149,6 +150,21 @@ export function declared(node: Node): string[] {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
export function jsxElementPath(node: Node): Path | undefined {
|
|
154
|
+
if (node.type === "JSXIdentifier") return /^[a-z]|-/.test(node.name) ? undefined : [node.name];
|
|
155
|
+
if (node.type !== "JSXMemberExpression") return undefined;
|
|
156
|
+
|
|
157
|
+
const segments = [node.property.name];
|
|
158
|
+
|
|
159
|
+
let head = node.object;
|
|
160
|
+
while (head.type === "JSXMemberExpression") {
|
|
161
|
+
segments.push(head.property.name);
|
|
162
|
+
head = head.object;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return [head.name, ...segments.reverse()];
|
|
166
|
+
}
|
|
167
|
+
|
|
152
168
|
export function* references(root: Node, names: Set<string>): Generator<string> {
|
|
153
169
|
const stack = [{ node: root, names, binding: false }];
|
|
154
170
|
while (stack.length > 0) {
|
|
@@ -168,6 +184,11 @@ export function* references(root: Node, names: Set<string>): Generator<string> {
|
|
|
168
184
|
|
|
169
185
|
if (visible.size === 0) continue;
|
|
170
186
|
|
|
187
|
+
if (node.type === "JSXOpeningElement") {
|
|
188
|
+
const path = jsxElementPath(node.name);
|
|
189
|
+
if (!binding && path && visible.has(path[0])) yield path[0];
|
|
190
|
+
}
|
|
191
|
+
|
|
171
192
|
const next = children(node);
|
|
172
193
|
for (let index = next.length - 1; index >= 0; index--) {
|
|
173
194
|
const [key, child] = next[index]!;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Entry } from "../language.ts";
|
|
2
2
|
|
|
3
|
+
const extensions = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
4
|
+
const generatedSuffixes = [
|
|
5
|
+
...extensions.map((extension) => `.gen${extension}`),
|
|
6
|
+
...extensions
|
|
7
|
+
.filter((extension) => extension.endsWith("js"))
|
|
8
|
+
.map((extension) => `.min${extension}`),
|
|
9
|
+
];
|
|
10
|
+
|
|
3
11
|
const directories = new Set([
|
|
4
12
|
"node_modules",
|
|
5
13
|
"dist",
|
|
@@ -13,12 +21,7 @@ const directories = new Set([
|
|
|
13
21
|
]);
|
|
14
22
|
|
|
15
23
|
function generatedName(name: string): boolean {
|
|
16
|
-
return (
|
|
17
|
-
name.endsWith(".gen.ts") ||
|
|
18
|
-
name.endsWith(".gen.tsx") ||
|
|
19
|
-
name.includes(".generated.") ||
|
|
20
|
-
name.endsWith(".min.js")
|
|
21
|
-
);
|
|
24
|
+
return name.includes(".generated.") || generatedSuffixes.some((suffix) => name.endsWith(suffix));
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
function skipsName(name: string, keepGenerated: boolean): boolean {
|
|
@@ -32,7 +35,7 @@ function skipsName(name: string, keepGenerated: boolean): boolean {
|
|
|
32
35
|
|
|
33
36
|
export const entry: Entry = {
|
|
34
37
|
id: "javascript",
|
|
35
|
-
extensions
|
|
38
|
+
extensions,
|
|
36
39
|
directories,
|
|
37
40
|
skipsName,
|
|
38
41
|
load: () => (require("./index.ts") as typeof import("./index.ts")).language,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Node, Statement, SwitchCase } from "oxc-parser";
|
|
2
|
-
import { boundNames, children, declared, references } from "./ast.ts";
|
|
2
|
+
import { boundNames, children, declared, jsxElementPath, references } from "./ast.ts";
|
|
3
3
|
import { lineAt, source } from "../../engine/doc.ts";
|
|
4
4
|
import type { Binding, Doc, Item, Kind, Path } from "../../engine/model.ts";
|
|
5
5
|
import type { Layout } from "../language.ts";
|
|
@@ -120,6 +120,16 @@ function readsPath(doc: Doc, root: Node, path: Path): boolean {
|
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
if (node.type === "JSXOpeningElement") {
|
|
124
|
+
const elementPath = jsxElementPath(node.name);
|
|
125
|
+
if (
|
|
126
|
+
elementPath &&
|
|
127
|
+
elementPath.length >= path.length &&
|
|
128
|
+
path.every((segment, index) => elementPath[index] === segment)
|
|
129
|
+
)
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
123
133
|
if (node.type !== "MemberExpression") {
|
|
124
134
|
for (const [, child] of children(node).toReversed()) stack.push(child);
|
|
125
135
|
continue;
|