@component-compass/ast-utils 0.1.7 → 0.1.9
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.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/parse5-guards.d.ts +5 -0
- package/dist/parse5-guards.js +12 -0
- package/dist/parse5-guards.js.map +1 -1
- package/package.json +3 -3
- package/dist/classify-import.d.ts +0 -33
- package/dist/classify-import.js +0 -84
- package/dist/classify-import.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export { isElement, hasChildren } from "./parse5-guards.js";
|
|
1
|
+
export { isElement, hasChildren, childNodesOf } from "./parse5-guards.js";
|
|
2
2
|
export { posixPath } from "./posix.js";
|
|
3
3
|
export { errorMessage, errorStack } from "./errors.js";
|
|
4
|
-
export { classifyImportOrigin } from "./classify-import.js";
|
|
5
|
-
export type { ImportOrigin, ClassifyOptions } from "./classify-import.js";
|
|
6
4
|
export { findEnclosingComponentBinding } from "./find-owner.js";
|
|
7
5
|
export type { EnclosingComponentBinding } from "./find-owner.js";
|
|
8
6
|
export { positionAt, getJSXName, isJSXElement, isJSXFragment, isJSXAttribute, isJSXSpreadAttribute, isCallExpression, isImportDeclaration, } from "./oxc-helpers.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { isElement, hasChildren } from "./parse5-guards.js";
|
|
1
|
+
export { isElement, hasChildren, childNodesOf } from "./parse5-guards.js";
|
|
2
2
|
export { posixPath } from "./posix.js";
|
|
3
3
|
export { errorMessage, errorStack } from "./errors.js";
|
|
4
|
-
export { classifyImportOrigin } from "./classify-import.js";
|
|
5
4
|
export { findEnclosingComponentBinding } from "./find-owner.js";
|
|
6
5
|
export { positionAt, getJSXName, isJSXElement, isJSXFragment, isJSXAttribute, isJSXSpreadAttribute, isCallExpression, isImportDeclaration, } from "./oxc-helpers.js";
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EACL,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/parse5-guards.d.ts
CHANGED
|
@@ -7,4 +7,9 @@ export declare function isElement(n: Node): n is Element;
|
|
|
7
7
|
export declare function hasChildren(n: Node): n is Node & {
|
|
8
8
|
childNodes: Node[];
|
|
9
9
|
};
|
|
10
|
+
/** parse5 template elements keep their children in `content` (an inert
|
|
11
|
+
* DocumentFragment per the HTML spec), not `childNodes`; every other node uses
|
|
12
|
+
* `childNodes`. Nodes with neither yield []. Single home for "where does a
|
|
13
|
+
* parse5 node keep its children" — call it, don't re-derive it. */
|
|
14
|
+
export declare function childNodesOf(n: Node): Node[];
|
|
10
15
|
export {};
|
package/dist/parse5-guards.js
CHANGED
|
@@ -8,4 +8,16 @@ export function hasChildren(n) {
|
|
|
8
8
|
return false;
|
|
9
9
|
return Array.isArray(n.childNodes);
|
|
10
10
|
}
|
|
11
|
+
/** parse5 template elements keep their children in `content` (an inert
|
|
12
|
+
* DocumentFragment per the HTML spec), not `childNodes`; every other node uses
|
|
13
|
+
* `childNodes`. Nodes with neither yield []. Single home for "where does a
|
|
14
|
+
* parse5 node keep its children" — call it, don't re-derive it. */
|
|
15
|
+
export function childNodesOf(n) {
|
|
16
|
+
if (isElement(n) && n.tagName === "template" && "content" in n) {
|
|
17
|
+
return n.content.childNodes;
|
|
18
|
+
}
|
|
19
|
+
if (hasChildren(n))
|
|
20
|
+
return n.childNodes;
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
11
23
|
//# sourceMappingURL=parse5-guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse5-guards.js","sourceRoot":"","sources":["../src/parse5-guards.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,CAAO;IAC/B,OAAO,SAAS,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,CAAO;IACjC,IAAI,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,KAAK,CAAC,OAAO,CAAE,CAA6B,CAAC,UAAU,CAAC,CAAC;AAClE,CAAC"}
|
|
1
|
+
{"version":3,"file":"parse5-guards.js","sourceRoot":"","sources":["../src/parse5-guards.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,CAAO;IAC/B,OAAO,SAAS,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,CAAO;IACjC,IAAI,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,KAAK,CAAC,OAAO,CAAE,CAA6B,CAAC,UAAU,CAAC,CAAC;AAClE,CAAC;AAKD;;;oEAGoE;AACpE,MAAM,UAAU,YAAY,CAAC,CAAO;IAClC,IAAI,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,KAAK,UAAU,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QAC/D,OAAQ,CAAqB,CAAC,OAAO,CAAC,UAAU,CAAC;IACnD,CAAC;IACD,IAAI,WAAW,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,UAAU,CAAC;IACxC,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@component-compass/ast-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Shared AST utilities for component-compass parsers and manifest plugins. Internal infrastructure.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"build": "tsc -p tsconfig.json",
|
|
21
21
|
"test": "vitest run --passWithNoTests",
|
|
22
22
|
"typecheck": "tsc --noEmit",
|
|
23
|
-
"lint": "biome lint src",
|
|
23
|
+
"lint": "biome lint src tests",
|
|
24
24
|
"clean": "rm -rf dist .turbo"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@component-compass/plugin-core": "0.1.
|
|
27
|
+
"@component-compass/plugin-core": "0.1.9",
|
|
28
28
|
"@oxc-project/types": "0.130.0",
|
|
29
29
|
"oxc-walker": "1.0.0",
|
|
30
30
|
"parse5": "8.0.1"
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ResolveImport } from "@component-compass/plugin-core";
|
|
2
|
-
export type ImportOrigin = {
|
|
3
|
-
type: "external";
|
|
4
|
-
package: string;
|
|
5
|
-
} | {
|
|
6
|
-
type: "local";
|
|
7
|
-
filePath: string;
|
|
8
|
-
} | {
|
|
9
|
-
type: "unresolved";
|
|
10
|
-
};
|
|
11
|
-
export type ClassifyOptions = {
|
|
12
|
-
repoRoot: string;
|
|
13
|
-
fromFile: string;
|
|
14
|
-
/**
|
|
15
|
-
* The shared `ResolveImport` from `cli/walker/resolve-import.ts`. Handles
|
|
16
|
-
* config aliases, tsconfig `paths`, and Node resolution in one layered
|
|
17
|
-
* pass. Required — there is no internal fallback.
|
|
18
|
-
*/
|
|
19
|
-
resolveImport: ResolveImport;
|
|
20
|
-
/**
|
|
21
|
-
* Names of packages known to belong to the scan's repo — workspace
|
|
22
|
-
* siblings (`workspaceGraph.packages[*].name`) plus declared deps from the
|
|
23
|
-
* root and workspace `package.json` files. When the resolver returns null,
|
|
24
|
-
* the specifier's package portion is matched against this set; a hit
|
|
25
|
-
* recovers external-package identity instead of marking the import
|
|
26
|
-
* unresolved. Necessary for yarn/pnpm workspaces where siblings live under
|
|
27
|
-
* `packages/*` but aren't symlinked into the root `node_modules`. Specs
|
|
28
|
-
* that don't parse to a known package name (e.g. `~/foo`, `@/x`) stay
|
|
29
|
-
* unresolved.
|
|
30
|
-
*/
|
|
31
|
-
knownPackageNames?: ReadonlySet<string>;
|
|
32
|
-
};
|
|
33
|
-
export declare function classifyImportOrigin(specifier: string, opts: ClassifyOptions): ImportOrigin;
|
package/dist/classify-import.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, relative, sep, dirname } from "node:path";
|
|
2
|
-
import { readFileSync, existsSync, realpathSync } from "node:fs";
|
|
3
|
-
import { posixPath } from "./posix.js";
|
|
4
|
-
export function classifyImportOrigin(specifier, opts) {
|
|
5
|
-
const resolved = opts.resolveImport(opts.fromFile, specifier);
|
|
6
|
-
if (!resolved) {
|
|
7
|
-
const pkg = packageNameFromSpecifier(specifier);
|
|
8
|
-
if (pkg && opts.knownPackageNames?.has(pkg)) {
|
|
9
|
-
return { type: "external", package: pkg };
|
|
10
|
-
}
|
|
11
|
-
return { type: "unresolved" };
|
|
12
|
-
}
|
|
13
|
-
const nodeModulesIdx = resolved.lastIndexOf(`${sep}node_modules${sep}`);
|
|
14
|
-
if (nodeModulesIdx >= 0) {
|
|
15
|
-
const pkg = packageOf(resolved);
|
|
16
|
-
if (!pkg)
|
|
17
|
-
return { type: "unresolved" };
|
|
18
|
-
return { type: "external", package: pkg };
|
|
19
|
-
}
|
|
20
|
-
if (!isAbsolute(resolved))
|
|
21
|
-
return { type: "unresolved" };
|
|
22
|
-
let repoRoot;
|
|
23
|
-
try {
|
|
24
|
-
repoRoot = realpathSync(opts.repoRoot);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
repoRoot = opts.repoRoot;
|
|
28
|
-
}
|
|
29
|
-
let realResolved;
|
|
30
|
-
try {
|
|
31
|
-
realResolved = realpathSync(resolved);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
realResolved = resolved;
|
|
35
|
-
}
|
|
36
|
-
const rel = relative(repoRoot, realResolved);
|
|
37
|
-
if (rel.startsWith("..") || isAbsolute(rel)) {
|
|
38
|
-
return { type: "unresolved" };
|
|
39
|
-
}
|
|
40
|
-
return { type: "local", filePath: posixPath(rel) };
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Parse a module specifier into its package-name portion. Returns null for
|
|
44
|
-
* specifiers that aren't shaped like a package import (relative paths,
|
|
45
|
-
* tsconfig/alias prefixes like `~/x`, `@/x`, `#x`, absolute paths).
|
|
46
|
-
* - `@scope/name` → `@scope/name`
|
|
47
|
-
* - `@scope/name/sub/path` → `@scope/name`
|
|
48
|
-
* - `lodash` → `lodash`
|
|
49
|
-
* - `lodash/fp/flow` → `lodash`
|
|
50
|
-
* - `./x`, `../x`, `/x` → null
|
|
51
|
-
* - `~/x`, `@/x`, `#alias` → null (scoped form requires `@scope/name`)
|
|
52
|
-
*/
|
|
53
|
-
function packageNameFromSpecifier(specifier) {
|
|
54
|
-
if (specifier.startsWith("@")) {
|
|
55
|
-
const slash1 = specifier.indexOf("/");
|
|
56
|
-
if (slash1 < 0)
|
|
57
|
-
return null;
|
|
58
|
-
const slash2 = specifier.indexOf("/", slash1 + 1);
|
|
59
|
-
return slash2 < 0 ? specifier : specifier.slice(0, slash2);
|
|
60
|
-
}
|
|
61
|
-
if (!/^[a-zA-Z]/.test(specifier))
|
|
62
|
-
return null;
|
|
63
|
-
const slash = specifier.indexOf("/");
|
|
64
|
-
return slash < 0 ? specifier : specifier.slice(0, slash);
|
|
65
|
-
}
|
|
66
|
-
function packageOf(absolute) {
|
|
67
|
-
let cursor = dirname(absolute);
|
|
68
|
-
while (cursor && cursor !== dirname(cursor)) {
|
|
69
|
-
const pkgJson = `${cursor}${sep}package.json`;
|
|
70
|
-
if (existsSync(pkgJson)) {
|
|
71
|
-
try {
|
|
72
|
-
const parsed = JSON.parse(readFileSync(pkgJson, "utf8"));
|
|
73
|
-
if (typeof parsed.name === "string" && parsed.name.length > 0)
|
|
74
|
-
return parsed.name;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
cursor = dirname(cursor);
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=classify-import.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"classify-import.js","sourceRoot":"","sources":["../src/classify-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA+BvC,MAAM,UAAU,oBAAoB,CAAC,SAAiB,EAAE,IAAqB;IAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,GAAG,IAAI,IAAI,CAAC,iBAAiB,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