@mnemonik/shared 7.144.2 → 7.145.1
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/ast/grammars.d.ts +6 -6
- package/dist/ast/grammars.d.ts.map +1 -1
- package/dist/ast/grammars.js +51 -10
- package/dist/ast/grammars.js.map +1 -1
- package/dist/sourceRedaction.d.ts.map +1 -1
- package/dist/sourceRedaction.js +743 -64
- package/dist/sourceRedaction.js.map +1 -1
- package/package.json +2 -1
- package/queries/clojure.tags.scm +1 -0
- package/queries/dart.tags.scm +3 -0
- package/queries/erlang.tags.scm +2 -0
- package/queries/graphql.tags.scm +3 -0
- package/queries/haskell.tags.scm +3 -0
- package/queries/julia.tags.scm +1 -0
- package/queries/kotlin.tags.scm +3 -0
- package/queries/ocaml.tags.scm +2 -0
- package/queries/ocaml_interface.tags.scm +1 -0
- package/queries/perl.tags.scm +2 -0
- package/queries/protobuf.tags.scm +5 -0
- package/queries/r.tags.scm +2 -0
- package/queries/zig.tags.scm +2 -0
- package/scripts/vendor-grammars.ts +586 -35
- package/src/ast/grammars.ts +51 -10
- package/src/sourceRedaction.ts +765 -12
- package/wasm/bash.wasm.gz +0 -0
- package/wasm/c-sharp.wasm.gz +0 -0
- package/wasm/c.wasm.gz +0 -0
- package/wasm/clojure.LICENSE +21 -0
- package/wasm/clojure.tags.scm +1 -0
- package/wasm/clojure.wasm.gz +0 -0
- package/wasm/cmake.wasm.gz +0 -0
- package/wasm/cpp.wasm.gz +0 -0
- package/wasm/dart.LICENSE +20 -0
- package/wasm/dart.tags.scm +3 -0
- package/wasm/dart.wasm.gz +0 -0
- package/wasm/elixir.wasm.gz +0 -0
- package/wasm/erlang.LICENSE +201 -0
- package/wasm/erlang.tags.scm +2 -0
- package/wasm/erlang.wasm.gz +0 -0
- package/wasm/go.wasm.gz +0 -0
- package/wasm/graphql.LICENSE +21 -0
- package/wasm/graphql.tags.scm +3 -0
- package/wasm/graphql.wasm.gz +0 -0
- package/wasm/groovy.wasm.gz +0 -0
- package/wasm/haskell.LICENSE +21 -0
- package/wasm/haskell.tags.scm +3 -0
- package/wasm/haskell.wasm.gz +0 -0
- package/wasm/java.wasm.gz +0 -0
- package/wasm/javascript.wasm.gz +0 -0
- package/wasm/julia.LICENSE +21 -0
- package/wasm/julia.tags.scm +1 -0
- package/wasm/julia.wasm.gz +0 -0
- package/wasm/kotlin.LICENSE +9 -0
- package/wasm/kotlin.tags.scm +3 -0
- package/wasm/kotlin.wasm.gz +0 -0
- package/wasm/lua.wasm.gz +0 -0
- package/wasm/nix.wasm.gz +0 -0
- package/wasm/objcpp.wasm.gz +0 -0
- package/wasm/ocaml.LICENSE +21 -0
- package/wasm/ocaml.tags.scm +2 -0
- package/wasm/ocaml.wasm.gz +0 -0
- package/wasm/ocaml_interface.LICENSE +21 -0
- package/wasm/ocaml_interface.tags.scm +1 -0
- package/wasm/ocaml_interface.wasm.gz +0 -0
- package/wasm/perl.LICENSE +7 -0
- package/wasm/perl.tags.scm +2 -0
- package/wasm/perl.wasm.gz +0 -0
- package/wasm/php.wasm.gz +0 -0
- package/wasm/powershell.wasm.gz +0 -0
- package/wasm/protobuf.LICENSE +21 -0
- package/wasm/protobuf.tags.scm +5 -0
- package/wasm/protobuf.wasm.gz +0 -0
- package/wasm/python.wasm.gz +0 -0
- package/wasm/r.LICENSE +9 -0
- package/wasm/r.tags.scm +2 -0
- package/wasm/r.wasm.gz +0 -0
- package/wasm/ruby.wasm.gz +0 -0
- package/wasm/rust.wasm.gz +0 -0
- package/wasm/scala.wasm.gz +0 -0
- package/wasm/solidity.wasm.gz +0 -0
- package/wasm/sql.wasm.gz +0 -0
- package/wasm/swift.wasm.gz +0 -0
- package/wasm/terraform.wasm.gz +0 -0
- package/wasm/tsx.wasm.gz +0 -0
- package/wasm/typescript.wasm.gz +0 -0
- package/wasm/zig.LICENSE +29 -0
- package/wasm/zig.tags.scm +2 -0
- package/wasm/zig.wasm.gz +0 -0
- package/wasm/bash.wasm +0 -0
- package/wasm/c-sharp.wasm +0 -0
- package/wasm/c.wasm +0 -0
- package/wasm/cmake.wasm +0 -0
- package/wasm/cpp.wasm +0 -0
- package/wasm/elixir.wasm +0 -0
- package/wasm/go.wasm +0 -0
- package/wasm/groovy.wasm +0 -0
- package/wasm/java.wasm +0 -0
- package/wasm/javascript.wasm +0 -0
- package/wasm/lua.wasm +0 -0
- package/wasm/nix.wasm +0 -0
- package/wasm/objcpp.wasm +0 -0
- package/wasm/php.wasm +0 -0
- package/wasm/powershell.wasm +0 -0
- package/wasm/python.wasm +0 -0
- package/wasm/ruby.wasm +0 -0
- package/wasm/rust.wasm +0 -0
- package/wasm/scala.wasm +0 -0
- package/wasm/solidity.wasm +0 -0
- package/wasm/sql.wasm +0 -0
- package/wasm/swift.wasm +0 -0
- package/wasm/terraform.wasm +0 -0
- package/wasm/tsx.wasm +0 -0
- package/wasm/typescript.wasm +0 -0
package/src/ast/grammars.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - it is quietly worse chunks, forever, with nothing in the logs. A caller that
|
|
9
9
|
* gets `unavailable` can fall back to the heuristic chunker AND say why.
|
|
10
10
|
*
|
|
11
|
-
* Artifacts are vendored, not installed: `packages/shared/wasm/<id>.wasm` plus
|
|
11
|
+
* Artifacts are vendored, not installed: `packages/shared/wasm/<id>.wasm.gz` plus
|
|
12
12
|
* the `<id>.tags.scm` tag queries, committed and published inside
|
|
13
13
|
* `@mnemonik/shared` (see `scripts/vendor-grammars.ts` for how they get there
|
|
14
14
|
* and why `npm pack` rather than devDependencies). A user's install therefore
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Two reports answer "what can this install do" and they are NOT
|
|
19
19
|
* interchangeable. `astArtifactReport` stats the vendored files and costs
|
|
20
|
-
* nothing; `astCapabilityReport` instantiates
|
|
21
|
-
* ms and ~75 MB of RSS that
|
|
22
|
-
* `Language.delete`. Startup
|
|
20
|
+
* nothing; `astCapabilityReport` instantiates every grammar. The original
|
|
21
|
+
* 18-grammar set cost ~690 ms and ~75 MB of RSS that was never returned because
|
|
22
|
+
* web-tree-sitter exposes no `Language.delete`. Startup uses the first; the second is for
|
|
23
23
|
* a diagnostic a human asked for. Grammars themselves load lazily, one per
|
|
24
24
|
* language, on the first file that needs one.
|
|
25
25
|
*
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
34
34
|
import { dirname, extname, join } from 'node:path';
|
|
35
35
|
import { fileURLToPath } from 'node:url';
|
|
36
|
+
import { gunzipSync } from 'node:zlib';
|
|
36
37
|
import { Language, Parser, Query, type Node } from 'web-tree-sitter';
|
|
37
38
|
import { warn } from '../logger.js';
|
|
38
39
|
|
|
@@ -62,6 +63,19 @@ const AST_LANGUAGE_ID_LIST = [
|
|
|
62
63
|
'terraform',
|
|
63
64
|
'nix',
|
|
64
65
|
'cmake',
|
|
66
|
+
'kotlin',
|
|
67
|
+
'dart',
|
|
68
|
+
'erlang',
|
|
69
|
+
'haskell',
|
|
70
|
+
'ocaml',
|
|
71
|
+
'ocaml_interface',
|
|
72
|
+
'clojure',
|
|
73
|
+
'julia',
|
|
74
|
+
'perl',
|
|
75
|
+
'r',
|
|
76
|
+
'zig',
|
|
77
|
+
'protobuf',
|
|
78
|
+
'graphql',
|
|
65
79
|
] as const;
|
|
66
80
|
|
|
67
81
|
/** A language this build can AST-parse. Exactly the vendored set, no aspirations. */
|
|
@@ -137,6 +151,19 @@ export const QUERY_CHAIN: Readonly<Record<AstLanguageId, readonly AstLanguageId[
|
|
|
137
151
|
terraform: ['terraform'],
|
|
138
152
|
nix: ['nix'],
|
|
139
153
|
cmake: ['cmake'],
|
|
154
|
+
kotlin: ['kotlin'],
|
|
155
|
+
dart: ['dart'],
|
|
156
|
+
erlang: ['erlang'],
|
|
157
|
+
haskell: ['haskell'],
|
|
158
|
+
ocaml: ['ocaml'],
|
|
159
|
+
ocaml_interface: ['ocaml_interface'],
|
|
160
|
+
clojure: ['clojure'],
|
|
161
|
+
julia: ['julia'],
|
|
162
|
+
perl: ['perl'],
|
|
163
|
+
r: ['r'],
|
|
164
|
+
zig: ['zig'],
|
|
165
|
+
protobuf: ['protobuf'],
|
|
166
|
+
graphql: ['graphql'],
|
|
140
167
|
};
|
|
141
168
|
|
|
142
169
|
/**
|
|
@@ -151,6 +178,7 @@ const EXTENSION_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
|
|
|
151
178
|
'.tsx': 'tsx',
|
|
152
179
|
'.m': 'objcpp',
|
|
153
180
|
'.mm': 'objcpp',
|
|
181
|
+
'.mli': 'ocaml_interface',
|
|
154
182
|
};
|
|
155
183
|
|
|
156
184
|
/** Upstream permits a bodyless else for highlighting across preprocessor boundaries. */
|
|
@@ -180,9 +208,8 @@ export function objcppSyntaxIssue(root: Node): string | null {
|
|
|
180
208
|
*
|
|
181
209
|
* Absences are deliberate answers, not gaps. `markdown` is missing because
|
|
182
210
|
* headers already are a document's semantic unit and 10,483 production chunks
|
|
183
|
-
* depend on `chunkMarkdown` keeping them; `
|
|
184
|
-
*
|
|
185
|
-
* `null` and the heuristic chunker takes over.
|
|
211
|
+
* depend on `chunkMarkdown` keeping them; `svelte` is absent because component
|
|
212
|
+
* parsing belongs to its adapter. Both resolve to `null` here.
|
|
186
213
|
*/
|
|
187
214
|
const LANGUAGE_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
|
|
188
215
|
typescript: 'typescript',
|
|
@@ -208,6 +235,20 @@ const LANGUAGE_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
|
|
|
208
235
|
terraform: 'terraform',
|
|
209
236
|
nix: 'nix',
|
|
210
237
|
cmake: 'cmake',
|
|
238
|
+
kotlin: 'kotlin',
|
|
239
|
+
dart: 'dart',
|
|
240
|
+
erlang: 'erlang',
|
|
241
|
+
haskell: 'haskell',
|
|
242
|
+
ocaml: 'ocaml',
|
|
243
|
+
clojure: 'clojure',
|
|
244
|
+
julia: 'julia',
|
|
245
|
+
perl: 'perl',
|
|
246
|
+
r: 'r',
|
|
247
|
+
zig: 'zig',
|
|
248
|
+
protobuf: 'protobuf',
|
|
249
|
+
graphql: 'graphql',
|
|
250
|
+
// Syntax reuse only: Starlark load/binding semantics belong to its own graph adapter.
|
|
251
|
+
starlark: 'python',
|
|
211
252
|
};
|
|
212
253
|
|
|
213
254
|
/** A loaded grammar plus its compiled query. Compiled once, reused per file. */
|
|
@@ -357,7 +398,7 @@ type ArtifactResolution =
|
|
|
357
398
|
| { unavailable: 'wasm_missing' | 'tags_query_missing'; detail: string };
|
|
358
399
|
|
|
359
400
|
function resolveArtifacts(id: AstLanguageId, artifactDir: string): ArtifactResolution {
|
|
360
|
-
const wasmPath = join(artifactDir, `${grammarArtifactBasename(id)}.wasm`);
|
|
401
|
+
const wasmPath = join(artifactDir, `${grammarArtifactBasename(id)}.wasm.gz`);
|
|
361
402
|
if (!isNonEmptyFile(wasmPath)) {
|
|
362
403
|
return { unavailable: 'wasm_missing', detail: `missing or empty grammar artifact ${wasmPath}` };
|
|
363
404
|
}
|
|
@@ -401,7 +442,7 @@ async function attemptLoad(id: AstLanguageId, artifactDir: string): Promise<Gram
|
|
|
401
442
|
let language: Language;
|
|
402
443
|
try {
|
|
403
444
|
await initParser();
|
|
404
|
-
language = await Language.load(wasmPath);
|
|
445
|
+
language = await Language.load(gunzipSync(readFileSync(wasmPath)));
|
|
405
446
|
} catch (err) {
|
|
406
447
|
// Presence is not loadability: tree-sitter-dart ships a 741 KB .wasm that
|
|
407
448
|
// Language.load rejects because the artifact predates the current wasm ABI.
|
|
@@ -503,7 +544,7 @@ export function astArtifactReport(artifactDir: string = WASM_DIR): {
|
|
|
503
544
|
*
|
|
504
545
|
* NOT free, and the cost is memory rather than only latency: measured on this
|
|
505
546
|
* checkout, ~690 ms and ~75 MB of RSS that is never given back. web-tree-sitter
|
|
506
|
-
* 0.26.11 exposes no `Language.delete` (see `attemptLoad`), so all
|
|
547
|
+
* 0.26.11 exposes no `Language.delete` (see `attemptLoad`), so all vendored grammars
|
|
507
548
|
* stay resident for the life of the process - including the fifteen a given repo
|
|
508
549
|
* has no files for. Caching makes the second call free; it does not make the
|
|
509
550
|
* first one cheap.
|