Skip to content

Shorthand property assignment missing local variable reference #440

@robbieh-noname

Description

@robbieh-noname

Bug Description

When a variable is passed as a shorthand property in an object literal, and the variable name matches the target type's property name, SCIP resolves the occurrence to the type definition's property (external symbol) instead of the local variable (local symbol).

This only occurs with shorthand syntax. Using explicit key: value syntax correctly emits both the external key reference and the local variable reference.

Reproduction

import { ApolloServer } from '@apollo/server';

const resolvers = {
  Query: {
    books: () => books,
    book(_: unknown, args: { id: number }) {
      return books[args.id];
    },
  },
  Mutation: {
    async addBook(_: unknown, args: { title: string; author: string }) {
      const newBook = { title: args.title, author: args.author };
      books.push(newBook);
      return newBook;
    },
  },
};

// Bug: `resolvers` resolves to ApolloServerOptions#resolvers (external)
// instead of the local `const resolvers` above
const server = new ApolloServer({ typeDefs, resolvers });

Steps to reproduce

  1. Index the project with scip-typescript
  2. Inspect the SCIP index - find the occurrence for resolvers inside new ApolloServer({ typeDefs, resolvers })
  3. The symbol points to ApolloServerOptions#resolvers (the type definition's property), not the local const resolvers

Confirmation

Confirmed by modifying the code and re-indexing:

Scenario Result
new ApolloServer({ typeDefs, resolvers }) - shorthand, name matches parameter Incorrect - resolves to external type properties only, no local variable reference emitted
new ApolloServer({ typeDefs, resolvers: resolvers }) - explicit key-value, same name Correct - key emits external type refs, value emits local resolvers. reference
Rename to resolvers1 + new ApolloServer({ typeDefs, resolvers1 }) Correct - no name collision, local variable resolved properly

SCIP index evidence

With explicit resolvers: resolvers at the constructor line:

# Key "resolvers" - external type property refs:
ApolloServerOptionsWithGateway#resolvers
ApolloServerOptionsWithSchema#resolvers
ApolloServerOptionsWithTypeDefs#resolvers

# Value "resolvers" - local variable ref:
src/index.ts/resolvers.

With shorthand { resolvers }, only the external type property refs are present - the local variable reference is missing entirely.

Expected behavior

Shorthand { resolvers } should produce the same occurrences as explicit resolvers: resolvers - both the external type property refs and the local variable ref.

Environment

  • scip-typescript v0.3.15
  • TypeScript 5.6.2

Possibly related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions