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
- Index the project with
scip-typescript
- Inspect the SCIP index - find the occurrence for
resolvers inside new ApolloServer({ typeDefs, resolvers })
- 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
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: valuesyntax correctly emits both the external key reference and the local variable reference.Reproduction
Steps to reproduce
scip-typescriptresolversinsidenew ApolloServer({ typeDefs, resolvers })ApolloServerOptions#resolvers(the type definition's property), not the localconst resolversConfirmation
Confirmed by modifying the code and re-indexing:
new ApolloServer({ typeDefs, resolvers })- shorthand, name matches parameternew ApolloServer({ typeDefs, resolvers: resolvers })- explicit key-value, same nameresolvers.referenceresolvers1+new ApolloServer({ typeDefs, resolvers1 })SCIP index evidence
With explicit
resolvers: resolversat the constructor line: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 explicitresolvers: resolvers- both the external type property refs and the local variable ref.Environment
scip-typescriptv0.3.15Possibly related
@Module({ imports })resolves toModuleMetadata#importsinstead of localimportsvariable). May share the same underlying cause in howShorthandPropertyAssignmentAST nodes are indexed.