@mnemonik/shared 7.142.0 → 7.144.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.
Files changed (66) hide show
  1. package/dist/ast/astChunker.d.ts.map +1 -1
  2. package/dist/ast/astChunker.js +6 -1
  3. package/dist/ast/astChunker.js.map +1 -1
  4. package/dist/ast/grammars.d.ts +4 -2
  5. package/dist/ast/grammars.d.ts.map +1 -1
  6. package/dist/ast/grammars.js +47 -1
  7. package/dist/ast/grammars.js.map +1 -1
  8. package/dist/codeScanner.d.ts +6 -0
  9. package/dist/codeScanner.d.ts.map +1 -1
  10. package/dist/codeScanner.js +12 -0
  11. package/dist/codeScanner.js.map +1 -1
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +3 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/sourceRedaction.d.ts.map +1 -1
  17. package/dist/sourceRedaction.js +1013 -21
  18. package/dist/sourceRedaction.js.map +1 -1
  19. package/dist/vueSource.d.ts +17 -0
  20. package/dist/vueSource.d.ts.map +1 -0
  21. package/dist/vueSource.js +63 -0
  22. package/dist/vueSource.js.map +1 -0
  23. package/package.json +3 -1
  24. package/queries/cmake.tags.scm +6 -0
  25. package/queries/nix.tags.scm +4 -0
  26. package/queries/objcpp.tags.scm +4 -0
  27. package/queries/sql.tags.scm +5 -0
  28. package/queries/swift.tags.scm +11 -0
  29. package/queries/terraform.tags.scm +8 -0
  30. package/scripts/jsx-bare-ampersand.patch +61 -0
  31. package/scripts/vendor-grammars.ts +731 -37
  32. package/src/ast/astChunker.ts +10 -1
  33. package/src/ast/grammars.ts +44 -2
  34. package/src/codeScanner.ts +12 -0
  35. package/src/index.ts +7 -0
  36. package/src/sourceRedaction.ts +1099 -21
  37. package/src/vueSource.ts +77 -0
  38. package/wasm/bash.wasm +0 -0
  39. package/wasm/cmake.LICENSE +21 -0
  40. package/wasm/cmake.tags.scm +6 -0
  41. package/wasm/cmake.wasm +0 -0
  42. package/wasm/cpp.LICENSE +21 -0
  43. package/wasm/cpp.wasm +0 -0
  44. package/wasm/groovy.LICENSE +25 -0
  45. package/wasm/groovy.wasm +0 -0
  46. package/wasm/javascript.wasm +0 -0
  47. package/wasm/lua.LICENSE +21 -0
  48. package/wasm/lua.tags.scm +36 -0
  49. package/wasm/lua.wasm +0 -0
  50. package/wasm/nix.LICENSE +21 -0
  51. package/wasm/nix.tags.scm +4 -0
  52. package/wasm/nix.wasm +0 -0
  53. package/wasm/objcpp.LICENSE +28 -0
  54. package/wasm/objcpp.tags.scm +4 -0
  55. package/wasm/objcpp.wasm +0 -0
  56. package/wasm/sql.LICENSE +21 -0
  57. package/wasm/sql.tags.scm +5 -0
  58. package/wasm/sql.wasm +0 -0
  59. package/wasm/swift.LICENSE +21 -0
  60. package/wasm/swift.tags.scm +11 -0
  61. package/wasm/swift.wasm +0 -0
  62. package/wasm/terraform.LICENSE +201 -0
  63. package/wasm/terraform.tags.scm +8 -0
  64. package/wasm/terraform.wasm +0 -0
  65. package/wasm/tsx.wasm +0 -0
  66. package/wasm/typescript.wasm +0 -0
@@ -57,7 +57,12 @@
57
57
 
58
58
  import type { Node, Query, Tree } from 'web-tree-sitter';
59
59
  import { Parser } from 'web-tree-sitter';
60
- import { loadGrammar, type AstLanguageId, type GrammarBinding } from './grammars.js';
60
+ import {
61
+ loadGrammar,
62
+ objcppSyntaxIssue,
63
+ type AstLanguageId,
64
+ type GrammarBinding,
65
+ } from './grammars.js';
61
66
 
62
67
  export interface AstChunk {
63
68
  /** Verbatim contiguous source: exactly the lines `startLine..endLine`. */
@@ -298,6 +303,10 @@ export async function chunkWithAst(
298
303
  const parseMs = performance.now() - startedAt;
299
304
 
300
305
  try {
306
+ if (languageId === 'objcpp') {
307
+ const issue = objcppSyntaxIssue(tree.rootNode);
308
+ if (issue) return { unsupported: 'parse_failed', detail: issue };
309
+ }
301
310
  const lines = content.split('\n');
302
311
  // A trailing newline TERMINATES the last line, it does not open a new one,
303
312
  // but `split` yields a phantom '' for it. Dropping it here - before
@@ -33,7 +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 { Language, Parser, Query } from 'web-tree-sitter';
36
+ import { Language, Parser, Query, type Node } from 'web-tree-sitter';
37
37
  import { warn } from '../logger.js';
38
38
 
39
39
  const AST_LANGUAGE_ID_LIST = [
@@ -45,6 +45,7 @@ const AST_LANGUAGE_ID_LIST = [
45
45
  'java',
46
46
  'c',
47
47
  'cpp',
48
+ 'objcpp',
48
49
  'csharp',
49
50
  'ruby',
50
51
  'php',
@@ -55,6 +56,12 @@ const AST_LANGUAGE_ID_LIST = [
55
56
  'bash',
56
57
  'groovy',
57
58
  'powershell',
59
+ 'swift',
60
+ 'sql',
61
+ 'lua',
62
+ 'terraform',
63
+ 'nix',
64
+ 'cmake',
58
65
  ] as const;
59
66
 
60
67
  /** A language this build can AST-parse. Exactly the vendored set, no aspirations. */
@@ -113,6 +120,7 @@ export const QUERY_CHAIN: Readonly<Record<AstLanguageId, readonly AstLanguageId[
113
120
  java: ['java'],
114
121
  c: ['c'],
115
122
  cpp: ['c', 'cpp'],
123
+ objcpp: ['objcpp'],
116
124
  csharp: ['csharp'],
117
125
  ruby: ['ruby'],
118
126
  php: ['php'],
@@ -123,6 +131,12 @@ export const QUERY_CHAIN: Readonly<Record<AstLanguageId, readonly AstLanguageId[
123
131
  bash: ['bash'],
124
132
  groovy: ['groovy'],
125
133
  powershell: ['powershell'],
134
+ swift: ['swift'],
135
+ sql: ['sql'],
136
+ lua: ['lua'],
137
+ terraform: ['terraform'],
138
+ nix: ['nix'],
139
+ cmake: ['cmake'],
126
140
  };
127
141
 
128
142
  /**
@@ -135,8 +149,30 @@ export const QUERY_CHAIN: Readonly<Record<AstLanguageId, readonly AstLanguageId[
135
149
  */
136
150
  const EXTENSION_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
137
151
  '.tsx': 'tsx',
152
+ '.m': 'objcpp',
153
+ '.mm': 'objcpp',
138
154
  };
139
155
 
156
+ /** Upstream permits a bodyless else for highlighting across preprocessor boundaries. */
157
+ export function objcppSyntaxIssue(root: Node): string | null {
158
+ if (root.hasError) return 'Objective-C++ contains ERROR or MISSING nodes';
159
+ const cursor = root.walk();
160
+ try {
161
+ for (;;) {
162
+ const node = cursor.currentNode;
163
+ if (node.type === 'else_clause' && node.namedChildCount === 0)
164
+ return 'Objective-C++ else clause has no body; conditional-source recovery is not admitted';
165
+ if (cursor.gotoFirstChild()) continue;
166
+ for (;;) {
167
+ if (cursor.gotoNextSibling()) break;
168
+ if (!cursor.gotoParent()) return null;
169
+ }
170
+ }
171
+ } finally {
172
+ cursor.delete();
173
+ }
174
+ }
175
+
140
176
  /**
141
177
  * Scanner language string -> grammar. Keyed on what `languageForExtension`
142
178
  * actually returns, so this table and the extension table cannot disagree about
@@ -144,7 +180,7 @@ const EXTENSION_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
144
180
  *
145
181
  * Absences are deliberate answers, not gaps. `markdown` is missing because
146
182
  * headers already are a document's semantic unit and 10,483 production chunks
147
- * depend on `chunkMarkdown` keeping them; `kotlin`, `swift`, `dart` and friends
183
+ * depend on `chunkMarkdown` keeping them; `kotlin`, `dart` and friends
148
184
  * are missing because no loadable grammar is vendored yet. Both resolve to
149
185
  * `null` and the heuristic chunker takes over.
150
186
  */
@@ -166,6 +202,12 @@ const LANGUAGE_GRAMMARS: Readonly<Record<string, AstLanguageId>> = {
166
202
  shell: 'bash',
167
203
  groovy: 'groovy',
168
204
  powershell: 'powershell',
205
+ swift: 'swift',
206
+ sql: 'sql',
207
+ lua: 'lua',
208
+ terraform: 'terraform',
209
+ nix: 'nix',
210
+ cmake: 'cmake',
169
211
  };
170
212
 
171
213
  /** A loaded grammar plus its compiled query. Compiled once, reused per file. */
@@ -532,6 +532,7 @@ const EXTENSION_LANGUAGES: Readonly<Record<string, string>> = {
532
532
  * preference) need the same answer without constructing a scanner.
533
533
  */
534
534
  export function languageForExtension(filePathOrExt: string): string {
535
+ if (isCmakeListsPath(filePathOrExt)) return 'cmake';
535
536
  // `extname` FIRST. A dotfile that carries a real extension ('.eslintrc.js',
536
537
  // '.mocharc.cjs', '.prettierrc.ts') starts with '.' and contains no '/', so
537
538
  // a bare-extension-first reading swallowed the whole name and answered
@@ -563,6 +564,13 @@ export function languageForExtension(filePathOrExt: string): string {
563
564
  const isMigrationSqlAuthorityPath = (posixRelPath: string): boolean =>
564
565
  /^migrations\/.*\.sql$/.test(posixRelPath);
565
566
 
567
+ /** Content-only build authority, shared by scanner collection and server admission. */
568
+ export const XCODE_AUTHORITY_PATH = /(?:^|\/)[^/]+\.xcodeproj\/project\.pbxproj$|\.xcconfig$/;
569
+ export const isXcodeAuthorityPath = (path: string): boolean => XCODE_AUTHORITY_PATH.test(path);
570
+ /** Exact CMake build entrypoint; ordinary .txt files remain outside collection. */
571
+ export const CMAKE_LISTS_PATH = /(?:^|\/)CMakeLists\.txt$/;
572
+ export const isCmakeListsPath = (path: string): boolean => CMAKE_LISTS_PATH.test(path);
573
+
566
574
  /**
567
575
  * Predicates for paths whose verbatim content is ALREADY shipped by
568
576
  * `collectAuthorityFiles` and that carry no additional value as embedded code
@@ -582,6 +590,8 @@ const isMigrationSqlAuthorityPath = (posixRelPath: string): boolean =>
582
590
  */
583
591
  const AUTHORITY_ONLY_PATH_PREDICATES: readonly ((posixRelPath: string) => boolean)[] = [
584
592
  isMigrationSqlAuthorityPath,
593
+ isXcodeAuthorityPath,
594
+ isCmakeListsPath,
585
595
  ];
586
596
 
587
597
  /**
@@ -627,6 +637,8 @@ export const AUTHORITY_FILE_MATCHERS: Array<(relPath: string) => boolean> = [
627
637
  // `AUTHORITY_ONLY_PATH_PREDICATES` by reference, not by a copied regex, so
628
638
  // collection and the chunking exclusion cannot disagree.
629
639
  isMigrationSqlAuthorityPath,
640
+ isXcodeAuthorityPath,
641
+ isCmakeListsPath,
630
642
  ];
631
643
 
632
644
  /**
package/src/index.ts CHANGED
@@ -26,6 +26,10 @@ export {
26
26
  isFixturePath,
27
27
  isSecretFile,
28
28
  isAuthorityOnlyPath,
29
+ XCODE_AUTHORITY_PATH,
30
+ isXcodeAuthorityPath,
31
+ isCmakeListsPath,
32
+ CMAKE_LISTS_PATH,
29
33
  isCursorRulePath,
30
34
  logAstCapabilityOnce,
31
35
  type CodeChunk,
@@ -75,6 +79,7 @@ export {
75
79
  loadGrammar,
76
80
  loadedGrammarIds,
77
81
  resolveAstLanguage,
82
+ objcppSyntaxIssue,
78
83
  type AstLanguageId,
79
84
  type GrammarBinding,
80
85
  type GrammarLoad,
@@ -175,3 +180,5 @@ export {
175
180
  } from './systemdControl.js';
176
181
 
177
182
  export { pidIsScanner } from './scannerPid.js';
183
+
184
+ export { parseVueSource, walkVueTemplate, VUE_FIDELITY_MARKER } from './vueSource.js';