@shrkcrft/structural-search 0.1.0-alpha.16 → 0.1.0-alpha.18

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.
@@ -27,12 +27,25 @@ export function matchPattern(node, pattern) {
27
27
  return false;
28
28
  }
29
29
  }
30
+ /**
31
+ * Compile a user-supplied regex defensively. An invalid pattern (e.g. an
32
+ * unbalanced `[`) returns null — treated as "no match" — instead of throwing
33
+ * and aborting the entire search walk over the project.
34
+ */
35
+ function compileRegex(source) {
36
+ try {
37
+ return new RegExp(source);
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
30
43
  function matchIdentifier(node, pat) {
31
44
  if (pat.name && pat.name !== '*' && node.text !== pat.name)
32
45
  return false;
33
46
  if (pat.nameRegex) {
34
- const re = new RegExp(pat.nameRegex);
35
- if (!re.test(node.text))
47
+ const re = compileRegex(pat.nameRegex);
48
+ if (!re || !re.test(node.text))
36
49
  return false;
37
50
  }
38
51
  return true;
@@ -41,8 +54,8 @@ function matchStringLiteral(node, pat) {
41
54
  if (pat.text !== undefined && node.text !== pat.text)
42
55
  return false;
43
56
  if (pat.textRegex) {
44
- const re = new RegExp(pat.textRegex);
45
- if (!re.test(node.text))
57
+ const re = compileRegex(pat.textRegex);
58
+ if (!re || !re.test(node.text))
46
59
  return false;
47
60
  }
48
61
  return true;
@@ -78,8 +91,8 @@ function matchImportDeclaration(node, pat) {
78
91
  if (pat.from !== undefined && spec !== pat.from)
79
92
  return false;
80
93
  if (pat.fromRegex) {
81
- const re = new RegExp(pat.fromRegex);
82
- if (!re.test(spec))
94
+ const re = compileRegex(pat.fromRegex);
95
+ if (!re || !re.test(spec))
83
96
  return false;
84
97
  }
85
98
  if (pat.sideEffectOnly === true) {
@@ -109,8 +122,8 @@ function matchClassDeclaration(node, pat) {
109
122
  if (pat.nameRegex) {
110
123
  if (!node.name)
111
124
  return false;
112
- const re = new RegExp(pat.nameRegex);
113
- if (!re.test(node.name.text))
125
+ const re = compileRegex(pat.nameRegex);
126
+ if (!re || !re.test(node.name.text))
114
127
  return false;
115
128
  }
116
129
  if (pat.hasDecoratorNamed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shrkcrft/structural-search",
3
- "version": "0.1.0-alpha.16",
3
+ "version": "0.1.0-alpha.18",
4
4
  "description": "SharkCraft structural search: declarative AST patterns for TypeScript codebases. Find call sites, decorators, classes, imports — preview-only by default; rewrite mode lands in Wave 8.",
5
5
  "license": "MIT",
6
6
  "author": "SharkCraft contributors",
@@ -44,7 +44,7 @@
44
44
  "typecheck": "tsc --noEmit -p tsconfig.json"
45
45
  },
46
46
  "dependencies": {
47
- "@shrkcrft/core": "^0.1.0-alpha.16",
47
+ "@shrkcrft/core": "^0.1.0-alpha.18",
48
48
  "typescript": "^5.5.0"
49
49
  },
50
50
  "publishConfig": {