@symbo.ls/globusa
v3.14.764
Published
AST analysis of Symbols project files — splits a JS file into imports, exports, declarations, identifiers, and component object literals. Foundation for source-level audit and rewrite tooling.
Readme
@symbo.ls/globusa
AST analysis of Symbols project source files. Splits any .js file into:
ast— full babel AST (re-traversable without re-parsing)imports—[{ imports: { localName: importedName }, path }]exports— raw source slices of every top-level exportdeclarations— raw source slices of every non-import / non-export top-level statementlinesExcludingImports—declarations + exportsdomqlComponents—[{ name, code }]for everyexport const X = { ... }whose initializer is an object literalidentifiers— names of top-levelconst/let/var/functiondeclarationsdeclNodesByName—Map<name, node>for surgical re-traversal
Foundation for @symbo.ls/frank-audit (source-level audit + rewrite) and any tooling that needs to reason about the structure of a Symbols project file.
Usage
import { parse } from '@symbo.ls/globusa'
import fs from 'fs'
const source = fs.readFileSync('symbols/components/Card.js', 'utf8')
const result = parse(source)
// Walk every top-level identifier
for (const name of result.identifiers) {
const node = result.declNodesByName.get(name)
// ...
}
// Find every imported package
for (const imp of result.imports) {
console.log(imp.path, imp.imports)
}Origin
Forked from [email protected] by Nika Otiashvili. Vendored into the smbls monorepo at 3.14.0 for stability and to add the ast + declNodesByName exports needed by frank-audit.
