sveast 0.1.0 → 0.2.0
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/README.md +12 -1
- package/index.d.ts +1203 -673
- package/index.js +1 -64
- package/package.json +1 -1
- package/parse-module.js +1 -0
- package/parse.js +2 -0
- package/shared-6xjb6x65.js +64 -0
package/README.md
CHANGED
|
@@ -56,7 +56,18 @@ Parses a JavaScript or TypeScript module, such as a `.ts` file a component impor
|
|
|
56
56
|
|
|
57
57
|
### Types
|
|
58
58
|
|
|
59
|
-
`AST` is svelte's `AST` namespace (`AST.Root`, `AST.RegularElement`, `AST.CSS.Rule`, ...),
|
|
59
|
+
`AST` is svelte's `AST` namespace (`AST.Root`, `AST.RegularElement`, `AST.CSS.Rule`, ...), corrected to match what the parser returns: `name_loc` and a comment's `loc` are optional, `Root.instance`/`module` are absent rather than `null` when there's no such `<script>`, `Root.js` is declared, and every directive has `modifiers`. `ParseOptions` is exported too.
|
|
60
|
+
|
|
61
|
+
The estree node types are exported as well (`Program`, `Node`, `Statement`, `Expression`, `Identifier`, ...), so you don't need `@types/estree`. They're estree's, plus what the parser adds: `start`/`end` on every node, and the TypeScript plugin's nodes (`TSInterfaceDeclaration`, `TSTypeAnnotation`, `TSTypeReference`, ...; `TSNode` is their union) and fields (`typeAnnotation`, `typeParameters`, `typeArguments`, `returnType`, `importKind`/`exportKind`, ...). The TypeScript nodes are in the `Statement`, `Declaration` and `Expression` unions, so checking `node.type` narrows to them.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { parseModule, type TSInterfaceDeclaration } from "sveast";
|
|
65
|
+
|
|
66
|
+
const interfaces: TSInterfaceDeclaration[] = [];
|
|
67
|
+
for (const node of parseModule(source, { typescript: true }).body) {
|
|
68
|
+
if (node.type === "TSInterfaceDeclaration") interfaces.push(node);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
60
71
|
|
|
61
72
|
## Recipes
|
|
62
73
|
|