Skip to content

Commit 292e678

Browse files
committed
Fixup of AST queries
1 parent e162191 commit 292e678

11 files changed

Lines changed: 30 additions & 38 deletions

‎.claude/skills/retire-add-ast-query/SKILL.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ Use ASTronomical syntax to navigate from the root to the version Literal, filter
164164

165165
Start simple, add anchors until the query is specific enough. Multiple queries in the array are OR'd — add a second entry for a different version era if the code structure changed across major versions.
166166

167+
**If two candidate queries end up nearly identical, stop and suspect an ASTronomical bug instead of writing both.** "Nearly identical" means the same filters/anchors, differing only in the terminal extraction step — e.g. one query ends in `/:value` and works against a plain string `Literal` (`x.version = "1.2.3"`), but a real-world build needs a second, otherwise-identical query ending in `/TemplateElement/:value/:cooked` because that build emits the version as a non-interpolated template literal instead (`` x.version = `1.2.3` ``). A `Literal` and a template literal with no `${}` are semantically the same string — the query *engine* should resolve either transparently, not every library's query author. Duplicating the query per literal-style is a local workaround that only fixes the one library, and this exact shape of gap tends to recur (react, react-dom, moment.js, and ua-parser-js all independently hit it in the same session because one bundler happened to prefer backtick strings).
168+
169+
When you notice this, don't add the duplicate to `jsrepository-ast.js`. Instead:
170+
1. Report the pattern to the user and propose fixing it in ASTronomical itself, at `/Users/erlend/code/github/RetireJS/ASTronomical` (a sibling checkout — confirm it exists before assuming the path).
171+
2. The fix belongs in `src/index.ts`'s attribute-resolution helpers (`getPrimitiveChildren` / `getPrimitiveChildrenOrNodePaths`) — add a fallback so a requested attribute (e.g. `value`) transparently resolves through the alternate AST shape, instead of requiring the query to spell out both shapes.
172+
3. Validate with the engine's own suite (`npm run typecheck && npm test` in the ASTronomical repo) before touching retire.js again, and confirm the *original* (single, non-duplicated) query now matches both shapes.
173+
4. Bumping ASTronomical's version, updating its `CHANGELOG.md`, publishing to npm, and bumping the dependency in `node/package.json` are all separate, more consequential steps (a published package affects every consumer, not just this repo) — check with the user before doing any of them rather than assuming the fix should ship immediately.
174+
167175
## Step 7 — Test the Query Locally
168176

169177
Create a test script:
@@ -233,7 +241,7 @@ node test-detection.js # full suite — catch any false positives intro
233241

234242
**Fixing failures:**
235243
- `validate` error: check `jsrepository-ast.js` syntax — it's a JS module, not JSON; look for unclosed template literals or missing commas
236-
- `Did not detect ... using ast`: query doesn't match that version — refine the query (back to Step 7) or add `allowAstMiss` for that version
244+
- `Did not detect ... using ast`: query doesn't match that version — refine the query (back to Step 7) or add `allowAstMiss` for that version. If the fix you're reaching for is "add a near-duplicate query that only changes how the final value is extracted," stop — see the callout in Step 6 about suspecting an ASTronomical engine gap instead.
237245
- `Detect multiple components using ast`: query is too broad — strengthen the anchor (back to Step 6)
238246

239247
## Step 11 — Report Results

‎node/package-lock.json‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎node/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"main": "./lib/retire.js",
1515
"dependencies": {
1616
"ansi-colors": "^4.1.1",
17-
"astronomical": "^3.0.0",
17+
"astronomical": "^3.2.0",
1818
"commander": "^10.0.1",
1919
"proxy-agent": "^6.4.0",
2020
"walkdir": "0.4.1",

‎repository/jsrepository-ast.js‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,16 @@ exports.queries = {
356356
/*
357357
Some bundlers (e.g. Vite/Rollup production builds) merge each module's
358358
assignments into a single comma-joined SequenceExpression and rename the
359-
CJS "exports" object to a short bundler-local identifier (e.g. `e`), and
360-
may emit the version as a template literal (backtick string) rather than
361-
a plain string Literal:
362-
e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=...,e.version=`19.2.7`
359+
CJS "exports" object to a short bundler-local identifier (e.g. `e`):
360+
e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=...,e.version="19.2.7"
363361
Match structurally on the assignment target object instead of the name.
364362
*/
365363
`//SequenceExpression[
366364
/AssignmentExpression[/:left/:property/:name == "__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE"]/:left/$:object ==
367365
/AssignmentExpression[/:left/:property/:name == "version"]/:left/$:object
368366
]/AssignmentExpression[
369367
/:left/:property/:name == "version"
370-
]/:right/TemplateElement/:value/:cooked`,
368+
]/$$:right/:value`,
371369
],
372370
react: [
373371
`//CallExpression[
@@ -388,13 +386,12 @@ exports.queries = {
388386
]/$$:right/:value`,
389387
/*
390388
React 19 renamed __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED to
391-
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE. The four
392-
queries below mirror the three patterns above (plus the react-dom-style
393-
SequenceExpression form) for the new name, covering: standalone CJS
394-
builds where "exports" is an undeclared free variable referenced by
395-
name (cdnjs minified, unpkg unminified), and bundler output where the
396-
exports object is a declared local/parameter with an arbitrary name and
397-
the version may be a template literal (Vite/Rollup production builds).
389+
__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE. The
390+
three queries below mirror the patterns above for the new name,
391+
covering: standalone CJS builds where "exports" is an undeclared free
392+
variable referenced by name (cdnjs minified, unpkg unminified), and
393+
bundler output where the exports object is a declared local/parameter
394+
with an arbitrary name (Vite/Rollup production builds).
398395
*/
399396
`//SequenceExpression[
400397
/AssignmentExpression/:left[/:object/:name == "exports" && /:property/:name == "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE"]
@@ -407,12 +404,6 @@ exports.queries = {
407404
]/AssignmentExpression[
408405
/:left/:property/:name == "version"
409406
]/$$:right/:value`,
410-
`//SequenceExpression[
411-
/AssignmentExpression[/:left/:property/:name == "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE"]/:left/$:object ==
412-
/AssignmentExpression[/:left/:property/:name == "version"]/:left/$:object
413-
]/AssignmentExpression[
414-
/:left/:property/:name == "version"
415-
]/:right/TemplateElement/:value/:cooked`,
416407
`/ExpressionStatement/AssignmentExpression[
417408
/MemberExpression/:property/:name == "version" &&
418409
/MemberExpression/:object/:name == "exports" &&

‎repository/jsrepository-v2.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6117,7 +6117,6 @@
61176117
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:$object == ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\" ]/$:object ]/$$:right/:value",
61186118
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
61196119
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value",
6120-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked",
61216120
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:object/:name == \"exports\" && ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" && /:object/:name == \"exports\" ] ]/$$:right/:value"
61226121
]
61236122
}
@@ -6240,7 +6239,7 @@
62406239
"//ObjectExpression[ /Property[/:key/:name == \"rendererPackageName\" && /:value/:value == \"react-dom\"] ]/Property[/:key/:name == \"version\"]/:value/:value",
62416240
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
62426241
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression [/:$object == ../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/$:object || /Identifier[ /:name == \"exports\" && ../../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/Identifier/:name == \"exports\" ] ] ]/$$:right/:value",
6243-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked"
6242+
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value"
62446243
]
62456244
}
62466245
},

‎repository/jsrepository-v3.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6217,7 +6217,6 @@
62176217
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:$object == ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\" ]/$:object ]/$$:right/:value",
62186218
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
62196219
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value",
6220-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked",
62216220
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:object/:name == \"exports\" && ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" && /:object/:name == \"exports\" ] ]/$$:right/:value"
62226221
]
62236222
}
@@ -6343,7 +6342,7 @@
63436342
"//ObjectExpression[ /Property[/:key/:name == \"rendererPackageName\" && /:value/:value == \"react-dom\"] ]/Property[/:key/:name == \"version\"]/:value/:value",
63446343
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
63456344
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression [/:$object == ../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/$:object || /Identifier[ /:name == \"exports\" && ../../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/Identifier/:name == \"exports\" ] ] ]/$$:right/:value",
6346-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked"
6345+
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value"
63476346
]
63486347
}
63496348
},

‎repository/jsrepository-v4.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6216,7 +6216,6 @@
62166216
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:$object == ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\" ]/$:object ]/$$:right/:value",
62176217
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
62186218
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value",
6219-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked",
62206219
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression/:object/:name == \"exports\" && ../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" && /:object/:name == \"exports\" ] ]/$$:right/:value"
62216220
]
62226221
}
@@ -6342,7 +6341,7 @@
63426341
"//ObjectExpression[ /Property[/:key/:name == \"rendererPackageName\" && /:value/:value == \"react-dom\"] ]/Property[/:key/:name == \"version\"]/:value/:value",
63436342
"//SequenceExpression[ /AssignmentExpression/:left[/:object/:name == \"exports\" && /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"] ]/AssignmentExpression[ /:left/:object/:name == \"exports\" && /:left/:property/:name == \"version\" ]/:right/:value",
63446343
"/ExpressionStatement/AssignmentExpression[ /MemberExpression/:property/:name == \"version\" && /MemberExpression [/:$object == ../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/$:object || /Identifier[ /:name == \"exports\" && ../../../../ExpressionStatement/AssignmentExpression/MemberExpression[ /:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\" ]/Identifier/:name == \"exports\" ] ] ]/$$:right/:value",
6345-
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/:right/TemplateElement/:value/:cooked"
6344+
"//SequenceExpression[ /AssignmentExpression[/:left/:property/:name == \"__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\"]/:left/$:object == /AssignmentExpression[/:left/:property/:name == \"version\"]/:left/$:object ]/AssignmentExpression[ /:left/:property/:name == \"version\" ]/$$:right/:value"
63466345
]
63476346
}
63486347
},

0 commit comments

Comments
 (0)