@@ -3526,4 +3526,65 @@ fn process(opt: Option<User>) {
35263526 } ) ;
35273527 } ) ;
35283528
3529+ describe ( 'performance optimizations — coverage for new code paths' , ( ) => {
3530+ it ( 'fastStripNullable: passes through simple identifier without stripping' , ( ) => {
3531+ const tree = parse ( 'function f(user: User) { user.save(); }' , TypeScript . typescript ) ;
3532+ const typeEnv = buildTypeEnv ( tree , 'typescript' ) ;
3533+ // lookup exercises fastStripNullable — "User" has no | or ? markers
3534+ const callNode = tree . rootNode . descendantForIndex ( tree . rootNode . text . indexOf ( 'save' ) ) ;
3535+ expect ( typeEnv . lookup ( 'user' , callNode ) ) . toBe ( 'User' ) ;
3536+ } ) ;
3537+
3538+ it ( 'fastStripNullable: strips nullable union type via full stripNullable' , ( ) => {
3539+ const tree = parse ( 'function f(user: User | null) { user.save(); }' , TypeScript . typescript ) ;
3540+ const typeEnv = buildTypeEnv ( tree , 'typescript' ) ;
3541+ const callNode = tree . rootNode . descendantForIndex ( tree . rootNode . text . indexOf ( 'save' ) ) ;
3542+ expect ( typeEnv . lookup ( 'user' , callNode ) ) . toBe ( 'User' ) ;
3543+ } ) ;
3544+
3545+ it ( 'fastStripNullable: rejects bare nullable keyword' , ( ) => {
3546+ const tree = parse ( 'function f(x: null) { x.save(); }' , TypeScript . typescript ) ;
3547+ const typeEnv = buildTypeEnv ( tree , 'typescript' ) ;
3548+ const callNode = tree . rootNode . descendantForIndex ( tree . rootNode . text . indexOf ( 'save' ) ) ;
3549+ expect ( typeEnv . lookup ( 'x' , callNode ) ) . toBeUndefined ( ) ;
3550+ } ) ;
3551+
3552+ it ( 'fastStripNullable: strips optional type suffix' , ( ) => {
3553+ const tree = parse ( `
3554+ class Foo {
3555+ process(user: User) {
3556+ user.save();
3557+ }
3558+ }
3559+ ` , TypeScript . typescript ) ;
3560+ const typeEnv = buildTypeEnv ( tree , 'typescript' ) ;
3561+ const callNode = tree . rootNode . descendantForIndex ( tree . rootNode . text . indexOf ( 'save' ) ) ;
3562+ expect ( typeEnv . lookup ( 'user' , callNode ) ) . toBe ( 'User' ) ;
3563+ } ) ;
3564+
3565+ it ( 'SKIP_SUBTREE_TYPES: string literal subtrees do not affect type extraction' , ( ) => {
3566+ const tree = parse ( `
3567+ function f(user: User) {
3568+ const msg = "hello world this is a long string";
3569+ user.save();
3570+ }
3571+ ` , TypeScript . typescript ) ;
3572+ const { env } = buildTypeEnv ( tree , 'typescript' ) ;
3573+ expect ( flatGet ( env , 'user' ) ) . toBe ( 'User' ) ;
3574+ } ) ;
3575+
3576+ it ( 'interestingNodeTypes: non-declaration nodes skip extractTypeBinding' , ( ) => {
3577+ // Large code with many non-interesting nodes (binary expressions, calls, etc.)
3578+ const tree = parse ( `
3579+ function calculate(service: Service) {
3580+ const a = 1 + 2 + 3;
3581+ const b = true && false;
3582+ if (a > b) { service.run(); }
3583+ }
3584+ ` , TypeScript . typescript ) ;
3585+ const { env } = buildTypeEnv ( tree , 'typescript' ) ;
3586+ expect ( flatGet ( env , 'service' ) ) . toBe ( 'Service' ) ;
3587+ } ) ;
3588+ } ) ;
3589+
35293590} ) ;
0 commit comments