@ryuugg/stanza 0.1.1 → 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
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,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;
|