@@ -384,24 +384,46 @@ function visibleDeclarations(node, sf) {
384384 ts . isArrowFunction ( d . initializer ) || ts . isFunctionExpression ( d . initializer ) ;
385385 decls . set ( d . name . text , {
386386 text : `let ${ d . name . text } = ${ d . initializer . getText ( sf ) } ;` ,
387+ identifiers : identifiersIn ( d . initializer ) ,
387388 literal,
388389 fnLike,
389390 } ) ;
390391 }
391392 }
392393 } else if ( ts . isFunctionDeclaration ( s ) && s . name && ! decls . has ( s . name . text ) ) {
393- decls . set ( s . name . text , { text : s . getText ( sf ) , literal : false , fnLike : true } ) ;
394+ decls . set ( s . name . text , {
395+ text : s . getText ( sf ) , identifiers : identifiersIn ( s ) , literal : false , fnLike : true ,
396+ } ) ;
394397 }
395398 }
396399 }
397400 return decls ;
398401}
399402
400- const identifiersIn = ( src ) => {
403+ /**
404+ * Every identifier the CODE under `nodes` names — and nothing its TEXT says
405+ * (#30473, the twin of #29860 in `check-where-matcher-conformance`, hand-copied
406+ * for the independence reason above). Walked off the parsed tree, so a string
407+ * literal, a template literal's text between its `${…}` holes, a regular
408+ * expression and a comment contribute nothing, while an identifier inside a
409+ * `${…}` hole is code and is collected. Over-inclusive in one direction only: a
410+ * property name (`row.name`) is still an identifier node, and a name that
411+ * resolves to no same-file declaration is skipped by the lift.
412+ *
413+ * It used to be a word regex over the source text, so a double's refusal
414+ * message naming a sibling binding pulled that binding into the lift — and a
415+ * binding that closes over a factory parameter makes the lift throw, filing a
416+ * drivable double under whatever the retry loop can salvage.
417+ */
418+ function identifiersIn ( ...nodes ) {
401419 const out = new Set ( ) ;
402- for ( const m of src . matchAll ( / \b ( [ A - Z a - z _ $ ] [ A - Z a - z 0 - 9 _ $ ] * ) \b / g) ) out . add ( m [ 1 ] ) ;
420+ const visit = ( n ) => {
421+ if ( ts . isIdentifier ( n ) ) out . add ( n . text ) ;
422+ ts . forEachChild ( n , visit ) ;
423+ } ;
424+ for ( const n of nodes ) visit ( n ) ;
403425 return out ;
404- } ;
426+ }
405427
406428/** String literals in the body -- the object names a double may branch on. */
407429function stringLiteralsIn ( fnNode , sf ) {
@@ -468,6 +490,12 @@ export function discoverInSource(text, label) {
468490 line : line + 1 ,
469491 queryShaped : looksQueryShaped ( fn . body . getText ( sf ) ) ,
470492 source : expressionSourceOf ( fn , sf ) ,
493+ // What the lift follows: the code of exactly the text `source` carries.
494+ // A method lifts as `function (params) body`, so its own name is not in
495+ // it; an expression lifts whole.
496+ sourceIdentifiers : ts . isMethodDeclaration ( fn )
497+ ? identifiersIn ( ...fn . parameters , fn . body )
498+ : identifiersIn ( fn ) ,
471499 declarations : visibleDeclarations ( fn , sf ) ,
472500 objectNames : [ SYNTHETIC_OBJECT , ...stringLiteralsIn ( fn , sf ) ] ,
473501 } ) ;
@@ -506,7 +534,7 @@ function buildCallable(candidate, stubbed, stubClass) {
506534 const self = '__os_find' ;
507535 const skip = new Set ( stubbed ) ;
508536 const included = new Map ( ) ;
509- let frontier = identifiersIn ( candidate . source ) ;
537+ let frontier = candidate . sourceIdentifiers ;
510538 for ( let depth = 0 ; depth < 6 ; depth ++ ) {
511539 const next = new Set ( ) ;
512540 for ( const id of frontier ) {
@@ -516,7 +544,7 @@ function buildCallable(candidate, stubbed, stubClass) {
516544 if ( stubClass >= 1 && decl . literal ) { skip . add ( id ) ; continue ; }
517545 if ( stubClass >= 2 && ! decl . fnLike ) { skip . add ( id ) ; continue ; }
518546 included . set ( id , decl . text ) ;
519- for ( const x of identifiersIn ( decl . text ) ) next . add ( x ) ;
547+ for ( const x of decl . identifiers ) next . add ( x ) ;
520548 }
521549 if ( next . size === 0 ) break ;
522550 frontier = next ;
@@ -1113,6 +1141,49 @@ const ql = {
11131141 },
11141142};` ;
11151143
1144+ /**
1145+ * #30473: the lift reads identifiers from code, never from text. The refusal
1146+ * message names the sibling `openDriver`, an EXPORTED function: its source
1147+ * cannot sit inside the lift's function body (`export` is a syntax error there)
1148+ * and a function-like declaration is never stubbed, so a lift that follows the
1149+ * words of a template literal or a string cannot be built at any stub class and
1150+ * a conforming double reads UNJUDGED. The double never calls it.
1151+ */
1152+ const FIXTURE_TEXT_NAMES_SIBLING = `
1153+ export function openDriver(name: string) { return { name, version: '0.0.0' }; }
1154+ function makeQl(rows: any[]) {
1155+ return {
1156+ async find(object: string, opts: any) {
1157+ const where = opts?.where ?? {};
1158+ for (const k of Object.keys(where)) {
1159+ if (k.startsWith('$')) throw new Error(\`no openDriver here: operator \${k} is not implemented\`);
1160+ if (k === '') throw new Error('openDriver: an empty field name is not implemented');
1161+ }
1162+ const matched = rows.filter((r: any) => ${ MATCHER } );
1163+ return typeof opts?.limit === 'number' ? matched.slice(0, opts.limit) : matched;
1164+ },
1165+ };
1166+ }` ;
1167+
1168+ /**
1169+ * The other direction: a `${…}` hole IS code. The same-file helper `key` is
1170+ * named only inside a hole on the answering path, so a lift that stopped
1171+ * reading holes would leave it to the row stub and the control probe could not
1172+ * seat the double.
1173+ */
1174+ const FIXTURE_HOLE_NAMES_HELPER = `
1175+ const key = (k: string) => k;
1176+ function makeQl(rows: any[]) {
1177+ return {
1178+ async find(object: string, opts: any) {
1179+ const where = opts?.where ?? {};
1180+ const matched = rows.filter((r: any) =>
1181+ Object.entries(where).every(([k, v]) => (r as any)[\`\${key(k)}\`] === v));
1182+ return typeof opts?.limit === 'number' ? matched.slice(0, opts.limit) : matched;
1183+ },
1184+ };
1185+ }` ;
1186+
11161187async function judgeFixture ( src ) {
11171188 const found = discoverInSource ( src , 'fixture.test.ts' ) ;
11181189 const results = [ ] ;
@@ -1147,7 +1218,7 @@ const SELF_TEST_VERDICT = 'check-objectql-double-limit self-test reached its ver
11471218// not red. A battery BELOW its floor means cases stopped running; the remedy is
11481219// to find what stopped registering.
11491220const SELF_TEST_BATTERIES = Object . freeze ( {
1150- 'check-objectql-double-limit self-test' : 56 ,
1221+ 'check-objectql-double-limit self-test' : 63 ,
11511222} ) ;
11521223
11531224// DELETING an entry silences that battery's floor exactly as effectively as
@@ -1267,6 +1338,22 @@ async function selfTest() {
12671338 expect ( 'a module-scope-fixture double is judged, not dropped' ,
12681339 moduleFixture . r ?. verdict === 'BLIND' ) ;
12691340
1341+ // #30473: the lift reads identifiers from code, never from text.
1342+ const textNames = await one ( FIXTURE_TEXT_NAMES_SIBLING ) ;
1343+ expect ( 'a double beside text naming a sibling binding is discovered' , textNames . n === 1 ) ;
1344+ expect ( 'template-literal TEXT names no identifier: "openDriver" in the message is not collected' ,
1345+ textNames . found [ 0 ] ?. sourceIdentifiers ?. has ( 'openDriver' ) === false ) ;
1346+ expect ( 'nor does a plain string literal: its "implemented" is not collected either' ,
1347+ textNames . found [ 0 ] ?. sourceIdentifiers ?. has ( 'implemented' ) === false ) ;
1348+ expect ( 'a double beside text naming a sibling binding lifts and is CONFORMING, not UNJUDGED' ,
1349+ textNames . r ?. verdict === 'CONFORMING' ) ;
1350+ const holeNames = await one ( FIXTURE_HOLE_NAMES_HELPER ) ;
1351+ expect ( 'a double calling a helper inside a `${…}` hole is discovered' , holeNames . n === 1 ) ;
1352+ expect ( 'the helper named only inside the hole is collected' ,
1353+ holeNames . found [ 0 ] ?. sourceIdentifiers ?. has ( 'key' ) === true ) ;
1354+ expect ( 'so the hole-reading double lifts with its helper and is CONFORMING' ,
1355+ holeNames . r ?. verdict === 'CONFORMING' ) ;
1356+
12701357 // Reconciliation, ONE-SIDED (#26444): an increase is an error, a decrease is a report.
12711358 const fake = new Map ( [ [ 'a.test.ts' , { blind : 1 , wrong : 0 , unjudged : 0 , details : [ { line : 1 , result : { verdict : 'BLIND' } } ] } ] ] ) ;
12721359 expect ( 'an unbaselined blind double is an error' , reconcile ( fake , { } ) . length === 1 ) ;
@@ -1394,7 +1481,8 @@ async function selfTest() {
13941481 ' prove; the control probe drops a non-query `find`, one that never filters, and\n' +
13951482 ' one answering with rows of its own that it could read no evidence from;\n' +
13961483 ' a SHARED helper and a per-file copy grade identically; rows reached through a\n' +
1397- ' table map and through a module-scope fixture are both driven; the ledger\n' +
1484+ ' table map and through a module-scope fixture are both driven; the lift follows\n' +
1485+ ' identifiers its code names, never the words of its text; the ledger\n' +
13981486 ' reconciles one-sided (a decrease passes and is reported).' ,
13991487 ) ;
14001488
0 commit comments