@domql/globusa 3.7.6
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 +67 -0
- package/dist/index.cjs +43608 -0
- package/dist/index.cjs.map +7 -0
- package/package.json +31 -0
- package/src/index.js +117 -0
- package/src/stringify.js +27 -0
- package/src/testcode.js +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @symbo.ls/globusa
|
|
2
|
+
|
|
3
|
+
Parses JavaScript source files and extracts global scope information for DOMQL components. Used by the serialization pipeline to identify module-scoped declarations (constants, functions, imports, mutable state) that component functions reference.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
### `parse(code: string)`
|
|
8
|
+
|
|
9
|
+
Takes a string of JavaScript code and returns:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
{
|
|
13
|
+
imports: [], // mitosis-style import objects
|
|
14
|
+
declarations: [], // strings of non-import/export code
|
|
15
|
+
exports: [], // strings of export statements
|
|
16
|
+
domqlComponents: [], // [ { name: string|null, code: string }, ... ]
|
|
17
|
+
linesExcludingImports: [], // all code lines except imports
|
|
18
|
+
identifiers: [] // strings of declared names at module scope
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Import object format
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
{ imports: { localName: 'exportedName' }, path: 'module-path' }
|
|
26
|
+
// e.g. import { createClient as sb } from '@supabase/supabase-js'
|
|
27
|
+
// → { imports: { sb: 'createClient' }, path: '@supabase/supabase-js' }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { parse } from '@symbo.ls/globusa'
|
|
34
|
+
|
|
35
|
+
const result = parse(`
|
|
36
|
+
import { supabase } from './supabase.js'
|
|
37
|
+
|
|
38
|
+
const SUPPORTED = ['en', 'ka', 'ru']
|
|
39
|
+
|
|
40
|
+
function detectBrowserLang() {
|
|
41
|
+
return SUPPORTED[0]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const MyComponent = {
|
|
45
|
+
onClick: (e, el) => el.scope.detectBrowserLang()
|
|
46
|
+
}
|
|
47
|
+
`)
|
|
48
|
+
|
|
49
|
+
result.imports // [{ imports: { supabase: 'supabase' }, path: './supabase.js' }]
|
|
50
|
+
result.identifiers // ['SUPPORTED', 'detectBrowserLang']
|
|
51
|
+
result.declarations // ['const SUPPORTED = [...]', 'function detectBrowserLang() { ... }']
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Role in serialization pipeline
|
|
55
|
+
|
|
56
|
+
When components are serialized for transport (push/publish), functions are stringified via `.toString()`. Module-scoped references (constants, helpers, imports) become free variables that break at `eval()` time.
|
|
57
|
+
|
|
58
|
+
Globusa parses the **original source** to identify these references, enabling the CLI to:
|
|
59
|
+
1. Extract them into `context.globalScope`
|
|
60
|
+
2. Rewrite function strings to use `el.scope.X` (globalScope is in the scope prototype chain)
|
|
61
|
+
3. Provide runtime resolution for external module dependencies
|
|
62
|
+
|
|
63
|
+
## Dependencies
|
|
64
|
+
|
|
65
|
+
- `@babel/parser` — JavaScript parsing
|
|
66
|
+
- `@babel/traverse` — AST traversal
|
|
67
|
+
- `@babel/types` — AST node type checks
|