From 2927d3a9fe194d3d6357e6018014a4030aaa513b Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 12 Sep 2024 10:52:59 +0200 Subject: [PATCH 01/11] test: adds a snapshot test to demonstrate the issue Arrays of objects create definitions for all object keys contained --- snapshots/input/pure-js/src/main.js | 4 ++++ snapshots/output/pure-js/src/main.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/snapshots/input/pure-js/src/main.js b/snapshots/input/pure-js/src/main.js index f37303fc..7fad8284 100644 --- a/snapshots/input/pure-js/src/main.js +++ b/snapshots/input/pure-js/src/main.js @@ -47,3 +47,7 @@ function var_function_scope() { } print_fib(k) } + +function array_of_objects() { + [{ element: 0 }, { element: 1}] +} diff --git a/snapshots/output/pure-js/src/main.js b/snapshots/output/pure-js/src/main.js index 4d473a19..4f4d0449 100644 --- a/snapshots/output/pure-js/src/main.js +++ b/snapshots/output/pure-js/src/main.js @@ -97,3 +97,10 @@ function var_function_scope() { // ^ reference local 17 } +function array_of_objects() { +// ^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/array_of_objects(). + [{ element: 0 }, { element: 1}] +// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element0: +// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element1: +} + From 9571de477fc66e2bca0f9b556d4562ad1b27caed Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 23 Sep 2024 13:00:21 +0200 Subject: [PATCH 02/11] uses getContextualType to resolve property assignments to definition This follows the implementation I found in the TypeScript goToDefinition service https://github.com/microsoft/TypeScript/blob/88809467e8761e71483e2f4948ef411d8e447188/src/services/goToDefinition.ts#L307-L316 --- .tool-versions | 1 + .../input/syntax/src/property-assignment.ts | 4 ++ snapshots/output/syntax/src/destructuring.ts | 3 +- .../output/syntax/src/infer-relationship.ts | 23 ++++------ snapshots/output/syntax/src/inheritance.ts | 12 ++---- snapshots/output/syntax/src/interface.ts | 6 +-- .../output/syntax/src/property-assignment.ts | 9 ++++ .../output/syntax/src/structural-type.ts | 4 +- src/FileIndexer.ts | 43 +++++++++++++------ 9 files changed, 61 insertions(+), 44 deletions(-) diff --git a/.tool-versions b/.tool-versions index edd1509e..ec25181c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ nodejs 20.8.1 pnpm 8.9.2 +yarn 1.22.17 diff --git a/snapshots/input/syntax/src/property-assignment.ts b/snapshots/input/syntax/src/property-assignment.ts index c925faa3..d6f2d75b 100644 --- a/snapshots/input/syntax/src/property-assignment.ts +++ b/snapshots/input/syntax/src/property-assignment.ts @@ -5,3 +5,7 @@ export function shorthandPropertyAssignment() { const a = 'a' return { a } } +type A = { a: string } +export function typedPropertyAssignment(): A { + return { a: 'a' } +} diff --git a/snapshots/output/syntax/src/destructuring.ts b/snapshots/output/syntax/src/destructuring.ts index a1a9713f..eaeec0ac 100644 --- a/snapshots/output/syntax/src/destructuring.ts +++ b/snapshots/output/syntax/src/destructuring.ts @@ -8,8 +8,7 @@ interface Props { const props: Props = { a: 42 } // ^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/props. // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/Props# -// ^ definition syntax 1.0.0 src/`destructuring.ts`/a0: -// relationship implementation reference syntax 1.0.0 src/`destructuring.ts`/Props#a. +// ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. export function objectDestructuring(): number[] { // ^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/objectDestructuring(). diff --git a/snapshots/output/syntax/src/infer-relationship.ts b/snapshots/output/syntax/src/infer-relationship.ts index f6756e98..e748b3d5 100644 --- a/snapshots/output/syntax/src/infer-relationship.ts +++ b/snapshots/output/syntax/src/infer-relationship.ts @@ -22,8 +22,7 @@ export function returnStatement(): Configuration { // ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property0: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } for (let i = 0; i < 9; i++) { @@ -35,8 +34,7 @@ export function returnStatement(): Configuration { // ^ reference local 2 return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property1: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } } @@ -47,8 +45,7 @@ export function returnStatement(): Configuration { // ^ reference local 5 return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property2: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } } @@ -65,8 +62,7 @@ export function returnStatement(): Configuration { // ^ reference local 8 return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property3: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } } @@ -74,8 +70,7 @@ export function returnStatement(): Configuration { // ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property4: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } do { @@ -83,8 +78,7 @@ export function returnStatement(): Configuration { // ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). return { property: 41, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property5: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } } while (random() < 0) @@ -92,8 +86,7 @@ export function returnStatement(): Configuration { return { property: 42, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property6: -// relationship implementation reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. } } @@ -109,7 +102,7 @@ export function returnStatementInsideArgumentExpression(): Configuration[] { // ^^^^^^ reference local 12 return { property: incremented, -// ^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/property7: +// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. // ^^^^^^^^^^^ reference local 15 } }) diff --git a/snapshots/output/syntax/src/inheritance.ts b/snapshots/output/syntax/src/inheritance.ts index 3b4d0365..5bfeae7f 100644 --- a/snapshots/output/syntax/src/inheritance.ts +++ b/snapshots/output/syntax/src/inheritance.ts @@ -93,11 +93,9 @@ export const objectLiteralImplementation: Superinterface = { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/objectLiteralImplementation. // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface# property: 'property', -//^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/property0: -//relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. +//^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. interfaceMethod: (): string => { -//^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/interfaceMethod0: -//relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). +//^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). throw new Error('Function not implemented.') // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error# // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error. @@ -112,11 +110,9 @@ export function infersInterface(): void { consumesInterface({ //^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/consumesInterface(). interfaceMethod: (): string => 'inferred', -// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/interfaceMethod1: -// relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). property: 'inferred', -// ^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/property1: -// relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. }) } diff --git a/snapshots/output/syntax/src/interface.ts b/snapshots/output/syntax/src/interface.ts index 95efa958..82c95e69 100644 --- a/snapshots/output/syntax/src/interface.ts +++ b/snapshots/output/syntax/src/interface.ts @@ -17,8 +17,7 @@ export function newInterface(): Interface { // ^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface# return { property: 'a', -// ^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/property0: -// relationship implementation reference syntax 1.0.0 src/`interface.ts`/Interface#property. +// ^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#property. methodSignature(param: string): string { // ^^^^^^^^^^^^^^^ definition local 4 // relationship implementation reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). @@ -27,8 +26,7 @@ export function newInterface(): Interface { // ^^^^^ reference local 5 }, methodSignature2: (param: string): string => { -// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/methodSignature20: -// relationship implementation reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature2. +// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature2. // ^^^^^ definition local 7 return param // ^^^^^ reference local 7 diff --git a/snapshots/output/syntax/src/property-assignment.ts b/snapshots/output/syntax/src/property-assignment.ts index 9ce2af14..7745c9d0 100644 --- a/snapshots/output/syntax/src/property-assignment.ts +++ b/snapshots/output/syntax/src/property-assignment.ts @@ -13,4 +13,13 @@ export function shorthandPropertyAssignment() { // ^ definition syntax 1.0.0 src/`property-assignment.ts`/a1: // ^ reference local 2 } +type A = { a: string } +// ^ definition syntax 1.0.0 src/`property-assignment.ts`/A# +// ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. +export function typedPropertyAssignment(): A { +// ^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/typedPropertyAssignment(). +// ^ reference syntax 1.0.0 src/`property-assignment.ts`/A# + return { a: 'a' } +// ^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. +} diff --git a/snapshots/output/syntax/src/structural-type.ts b/snapshots/output/syntax/src/structural-type.ts index f0e6019d..31996ba1 100644 --- a/snapshots/output/syntax/src/structural-type.ts +++ b/snapshots/output/syntax/src/structural-type.ts @@ -15,7 +15,7 @@ export function foo(): Promise<{ member: number }> { // ^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# // ^^^^^^^ reference typescript 5.3.3 lib/`lib.es2018.promise.d.ts`/Promise# // ^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve(). -// ^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/member0: +// ^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/member0: } export function bar(): Promise { // ^^^ definition syntax 1.0.0 src/`structural-type.ts`/bar(). @@ -61,5 +61,5 @@ export type FeatureOptions = OptionsFlags // implicitly // type Fe export const fo: FeatureOptions = { darkMode: true } // ^^ definition syntax 1.0.0 src/`structural-type.ts`/fo. // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/FeatureOptions# -// ^^^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/darkMode0: +// ^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/FeatureFlags#typeLiteral13:darkMode. diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 3b7f0acb..2655dbec 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -150,22 +150,39 @@ export class FileIndexer { private visitSymbolOccurrence(node: ts.Node, sym: ts.Symbol): void { const range = Range.fromNode(node).toLsif() let role = 0 - const isDefinitionNode = isDefinition(node) + let isDefinitionNode = isDefinition(node) + let declarations: ts.Node[] = []; + if (ts.isPropertyAssignment(node.parent)) { + const contextualType = this.checker.getContextualType(node.parent.parent); + if (contextualType != null) { + const property = contextualType.getProperty(node.getText()); + if (property != null) { + const decls = property.getDeclarations() + if (decls != null && decls.length > 0) { + isDefinitionNode = false; + declarations = decls; + } + } + } + } + if (isDefinitionNode) { role |= scip.scip.SymbolRole.Definition } - const declarations = ts.isConstructorDeclaration(node) - ? [node] - : isDefinitionNode - ? // Don't emit ambiguous definition at definition-site. You can reproduce - // ambiguous results by triggering "Go to definition" in VS Code on `Conflict` - // in the example below: - // export const Conflict = 42 - // export interface Conflict {} - // ^^^^^^^^ "Go to definition" shows two results: const and interface. - // See https://github.com/sourcegraph/scip-typescript/pull/206 for more details. - [node.parent] - : sym?.declarations || [] + if (declarations.length === 0) { + declarations = ts.isConstructorDeclaration(node) + ? [node] + : isDefinitionNode + ? // Don't emit ambiguous definition at definition-site. You can reproduce + // ambiguous results by triggering "Go to definition" in VS Code on `Conflict` + // in the example below: + // export const Conflict = 42 + // export interface Conflict {} + // ^^^^^^^^ "Go to definition" shows two results: const and interface. + // See https://github.com/sourcegraph/scip-typescript/pull/206 for more details. + [node.parent] + : sym?.declarations || [] + } for (const declaration of declarations) { let scipSymbol = this.scipSymbol(declaration) From 625bf951a7f0238cf60128367a245b9f88ab8c00 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:00:18 +0200 Subject: [PATCH 03/11] uses in more places to get the type of object literals --- src/FileIndexer.ts | 88 ++++++++-------------------------------------- 1 file changed, 14 insertions(+), 74 deletions(-) diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 2655dbec..ffd5b6da 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -147,25 +147,22 @@ export class FileIndexer { return false } + private getDeclarationsForPropertyAssignment(node: ts.Node, sym: ts.Symbol): ts.Declaration[] | undefined { + if (!ts.isPropertyAssignment(node.parent)) { + return + } + // { symbol: .... } + // ^^^^^ this is symbol node we're pointing at + const contextualType = this.checker.getContextualType(node.parent.parent) + const property = contextualType?.getProperty(node.getText()) + return property?.getDeclarations() + } + private visitSymbolOccurrence(node: ts.Node, sym: ts.Symbol): void { const range = Range.fromNode(node).toLsif() let role = 0 - let isDefinitionNode = isDefinition(node) - let declarations: ts.Node[] = []; - if (ts.isPropertyAssignment(node.parent)) { - const contextualType = this.checker.getContextualType(node.parent.parent); - if (contextualType != null) { - const property = contextualType.getProperty(node.getText()); - if (property != null) { - const decls = property.getDeclarations() - if (decls != null && decls.length > 0) { - isDefinitionNode = false; - declarations = decls; - } - } - } - } - + let declarations: ts.Node[] = this.getDeclarationsForPropertyAssignment(node, sym) ?? []; + let isDefinitionNode = declarations.length == 0 && isDefinition(node); if (isDefinitionNode) { role |= scip.scip.SymbolRole.Definition } @@ -682,10 +679,7 @@ export class FileIndexer { onAncestor(declaration) } if (ts.isObjectLiteralExpression(declaration)) { - const tpe = this.inferredTypeOfObjectLiteral( - declaration.parent, - declaration - ) + const tpe = this.checker.getContextualType(declaration) ?? this.checker.getTypeAtLocation(declaration); for (const symbolDeclaration of tpe.symbol?.declarations || []) { loop(symbolDeclaration) } @@ -707,60 +701,6 @@ export class FileIndexer { } loop(node) } - - // Returns the "inferred" type of the provided object literal, where - // "inferred" is loosely defined as the type that is expected in the position - // where the object literal appears. For example, the object literal in - // `const x: SomeInterface = {y: 42}` has the inferred type `SomeInterface` - // even if `this.checker.getTypeAtLocation({y: 42})` does not return - // `SomeInterface`. The object literal could satisfy many types, but in this - // particular location must only satisfy `SomeInterface`. - private inferredTypeOfObjectLiteral( - node: ts.Node, - literal: ts.ObjectLiteralExpression - ): ts.Type { - if ( - ts.isIfStatement(node) || - ts.isForStatement(node) || - ts.isForInStatement(node) || - ts.isForOfStatement(node) || - ts.isWhileStatement(node) || - ts.isDoStatement(node) || - ts.isReturnStatement(node) || - ts.isBlock(node) - ) { - return this.inferredTypeOfObjectLiteral(node.parent, literal) - } - - if (ts.isVariableDeclaration(node)) { - // Example, return `SomeInterface` from `const x: SomeInterface = {y: 42}`. - return this.checker.getTypeAtLocation(node.name) - } - - if (ts.isFunctionLike(node)) { - const functionType = this.checker.getTypeAtLocation(node) - const callSignatures = functionType.getCallSignatures() - if (callSignatures.length > 0) { - return callSignatures[0].getReturnType() - } - } - - if (ts.isCallOrNewExpression(node)) { - // Example: return the type of the second parameter of `someMethod` from - // the expression `someMethod(someParameter, {y: 42})`. - const signature = this.checker.getResolvedSignature(node) - for (const [index, argument] of (node.arguments || []).entries()) { - if (argument === literal) { - const parameterSymbol = signature?.getParameters()[index] - if (parameterSymbol) { - return this.checker.getTypeOfSymbolAtLocation(parameterSymbol, node) - } - } - } - } - - return this.checker.getTypeAtLocation(literal) - } } function isAnonymousContainerOfSymbols(node: ts.Node): boolean { From bce1121e5b4b53dd0daedf01e2ff5ac29891c6fb Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:01:19 +0200 Subject: [PATCH 04/11] formatting --- snapshots/input/pure-js/src/main.js | 2 +- src/FileIndexer.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/snapshots/input/pure-js/src/main.js b/snapshots/input/pure-js/src/main.js index 7fad8284..d5adabe0 100644 --- a/snapshots/input/pure-js/src/main.js +++ b/snapshots/input/pure-js/src/main.js @@ -49,5 +49,5 @@ function var_function_scope() { } function array_of_objects() { - [{ element: 0 }, { element: 1}] + ;[{ element: 0 }, { element: 1 }] } diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index ffd5b6da..284d1356 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -147,7 +147,10 @@ export class FileIndexer { return false } - private getDeclarationsForPropertyAssignment(node: ts.Node, sym: ts.Symbol): ts.Declaration[] | undefined { + private getDeclarationsForPropertyAssignment( + node: ts.Node, + sym: ts.Symbol + ): ts.Declaration[] | undefined { if (!ts.isPropertyAssignment(node.parent)) { return } @@ -161,8 +164,9 @@ export class FileIndexer { private visitSymbolOccurrence(node: ts.Node, sym: ts.Symbol): void { const range = Range.fromNode(node).toLsif() let role = 0 - let declarations: ts.Node[] = this.getDeclarationsForPropertyAssignment(node, sym) ?? []; - let isDefinitionNode = declarations.length == 0 && isDefinition(node); + let declarations: ts.Node[] = + this.getDeclarationsForPropertyAssignment(node, sym) ?? [] + let isDefinitionNode = declarations.length == 0 && isDefinition(node) if (isDefinitionNode) { role |= scip.scip.SymbolRole.Definition } @@ -679,7 +683,9 @@ export class FileIndexer { onAncestor(declaration) } if (ts.isObjectLiteralExpression(declaration)) { - const tpe = this.checker.getContextualType(declaration) ?? this.checker.getTypeAtLocation(declaration); + const tpe = + this.checker.getContextualType(declaration) ?? + this.checker.getTypeAtLocation(declaration) for (const symbolDeclaration of tpe.symbol?.declarations || []) { loop(symbolDeclaration) } From 35fcb9afb0d83ee6f808c4a3a3586ccff10d0c64 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:04:05 +0200 Subject: [PATCH 05/11] fix tests --- snapshots/input/pure-js/src/main.js | 2 +- snapshots/output/pure-js/src/main.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/snapshots/input/pure-js/src/main.js b/snapshots/input/pure-js/src/main.js index d5adabe0..baa50eb6 100644 --- a/snapshots/input/pure-js/src/main.js +++ b/snapshots/input/pure-js/src/main.js @@ -49,5 +49,5 @@ function var_function_scope() { } function array_of_objects() { - ;[{ element: 0 }, { element: 1 }] + var a = [{ element: 0 }, { element: 1 }] } diff --git a/snapshots/output/pure-js/src/main.js b/snapshots/output/pure-js/src/main.js index 4f4d0449..95575188 100644 --- a/snapshots/output/pure-js/src/main.js +++ b/snapshots/output/pure-js/src/main.js @@ -99,8 +99,9 @@ function var_function_scope() { function array_of_objects() { // ^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/array_of_objects(). - [{ element: 0 }, { element: 1}] -// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element0: -// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element1: + var a = [{ element: 0 }, { element: 1 }] +// ^ definition local 20 +// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element0: +// ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element1: } From c096031a756cda449dc231d93be716f0f9fa4499 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:09:43 +0200 Subject: [PATCH 06/11] adds missing eslint dependencies without these `npm run eslint` wouldn't pass locally --- package.json | 8 ++- yarn.lock | 154 +++++++++++++++++++++++++-------------------------- 2 files changed, 82 insertions(+), 80 deletions(-) diff --git a/package.json b/package.json index 012b7a0f..ec370100 100644 --- a/package.json +++ b/package.json @@ -46,18 +46,20 @@ "@types/diff": "5.0.9", "@types/google-protobuf": "3.15.12", "@types/node": "20.10.5", - "ts-node": "^10.7.0", "@types/progress": "2.0.7", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", "diff": "^5.1.0", "eslint": "^8.57.0", + "eslint-plugin-etc": "^2.0.3", + "eslint-plugin-rxjs": "^5.0.3", "eslint-plugin-unicorn": "^55.0.0", "eslint-plugin-unused-imports": "^4.1.3", "pnpm": "8.12.1", "prettier": "3.3.2", + "ts-node": "^10.7.0", + "tsm": "^2.3.0", "typescript-eslint": "7.18.0", - "uvu": "^0.5.6", - "tsm": "^2.3.0" + "uvu": "^0.5.6" } } diff --git a/yarn.lock b/yarn.lock index 8c724bec..4f70c3fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -57,7 +57,7 @@ "@babel/helper-validator-identifier@^7.18.6", "@babel/helper-validator-identifier@^7.19.1", "@babel/helper-validator-identifier@^7.22.5", "@babel/helper-validator-identifier@^7.24.5": version "7.24.6" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.6.tgz#08bb6612b11bdec78f3feed3db196da682454a5e" + resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.6.tgz" integrity sha512-4yA7s865JHaqUdRbnaxarZREuPTHrjpDT+pXoAZ1yhyo6uFnIEpS8VMu16siFOHDpZNKYv5BObhsB//ycbICyw== "@babel/highlight@^7.18.6": @@ -125,7 +125,7 @@ "@cspotcode/source-map-support@^0.8.0": version "0.8.1" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + resolved "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz" integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== dependencies: "@jridgewell/trace-mapping" "0.3.9" @@ -178,12 +178,12 @@ "@eslint/js@8.57.0": version "8.57.0" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" + resolved "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== "@humanwhocodes/config-array@^0.11.14": version "0.11.14" - resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" + resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz" integrity sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg== dependencies: "@humanwhocodes/object-schema" "^2.0.2" @@ -197,7 +197,7 @@ "@humanwhocodes/object-schema@^2.0.2": version "2.0.2" - resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz#d9fae00a2d5cb40f92cfe64b47ad749fbc38f917" + resolved "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz" integrity sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw== "@jridgewell/gen-mapping@^0.3.2": @@ -253,12 +253,12 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@phenomnomnominal/tsquery@^4.0.0": - version "4.2.0" - resolved "https://registry.npmjs.org/@phenomnomnominal/tsquery/-/tsquery-4.2.0.tgz" - integrity sha512-hR2U3uVcrrdkuG30ItQ+uFDs4ncZAybxWG0OjTE8ptPzVoU7GVeXpy+vMU8zX9EbmjGeITPw/su5HjYQyAH8bA== +"@phenomnomnominal/tsquery@^5.0.0": + version "5.0.1" + resolved "https://registry.npmjs.org/@phenomnomnominal/tsquery/-/tsquery-5.0.1.tgz" + integrity sha512-3nVv+e2FQwsW8Aw6qTU6f+1rfcJ3hrcnvH/mu9i8YhxO+9sqbOfpL8m6PbET5+xKOlz/VSbp0RoYWYCtIsnmuA== dependencies: - esquery "^1.0.1" + esquery "^1.4.0" "@sourcegraph/eslint-config@0.37.1": version "0.37.1" @@ -293,22 +293,22 @@ "@tsconfig/node10@^1.0.7": version "1.0.9" - resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" + resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz" integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== "@tsconfig/node12@^1.0.7": version "1.0.11" - resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + resolved "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz" integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== "@tsconfig/node14@^1.0.0": version "1.0.3" - resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + resolved "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz" integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== "@tsconfig/node16@^1.0.2": version "1.0.4" - resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9" + resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz" integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA== "@types/diff@5.0.9": @@ -369,7 +369,7 @@ "@typescript-eslint/eslint-plugin@7.18.0", "@typescript-eslint/eslint-plugin@^7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz#b16d3cf3ee76bf572fdf511e79c248bdec619ea3" + resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz" integrity sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw== dependencies: "@eslint-community/regexpp" "^4.10.0" @@ -384,7 +384,7 @@ "@typescript-eslint/eslint-plugin@^6.9.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.21.0.tgz#30830c1ca81fd5f3c2714e524c4303e0194f9cd3" + resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.21.0.tgz" integrity sha512-oy9+hTPCUFpngkEZUSzbf9MxI65wbKFoQYsgPdILTfbUldp5ovUuphZVe4i30emU9M/kP+T64Di0mxl7dSw3MA== dependencies: "@eslint-community/regexpp" "^4.5.1" @@ -408,7 +408,7 @@ "@typescript-eslint/parser@7.18.0", "@typescript-eslint/parser@^7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.18.0.tgz#83928d0f1b7f4afa974098c64b5ce6f9051f96a0" + resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz" integrity sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg== dependencies: "@typescript-eslint/scope-manager" "7.18.0" @@ -419,7 +419,7 @@ "@typescript-eslint/parser@^6.9.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.21.0.tgz#af8fcf66feee2edc86bc5d1cf45e33b0630bf35b" + resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.21.0.tgz" integrity sha512-tbsV1jPne5CkFQCgPBcDOt30ItF7aJoZL997JSF7MhGQqOeT3svWRYxiqlfA5RUdlHN6Fi+EI9bxqbdyAUZjYQ== dependencies: "@typescript-eslint/scope-manager" "6.21.0" @@ -438,7 +438,7 @@ "@typescript-eslint/scope-manager@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz#ea8a9bfc8f1504a6ac5d59a6df308d3a0630a2b1" + resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz" integrity sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg== dependencies: "@typescript-eslint/types" "6.21.0" @@ -446,7 +446,7 @@ "@typescript-eslint/scope-manager@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz#c928e7a9fc2c0b3ed92ab3112c614d6bd9951c83" + resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz" integrity sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA== dependencies: "@typescript-eslint/types" "7.18.0" @@ -454,7 +454,7 @@ "@typescript-eslint/type-utils@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.21.0.tgz#6473281cfed4dacabe8004e8521cee0bd9d4c01e" + resolved "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.21.0.tgz" integrity sha512-rZQI7wHfao8qMX3Rd3xqeYSMCL3SoiSQLBATSiVKARdFGCYSRvmViieZjqc58jKgs8Y8i9YvVVhRbHSTA4VBag== dependencies: "@typescript-eslint/typescript-estree" "6.21.0" @@ -464,7 +464,7 @@ "@typescript-eslint/type-utils@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz#2165ffaee00b1fbbdd2d40aa85232dab6998f53b" + resolved "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz" integrity sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA== dependencies: "@typescript-eslint/typescript-estree" "7.18.0" @@ -479,12 +479,12 @@ "@typescript-eslint/types@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.21.0.tgz#205724c5123a8fef7ecd195075fa6e85bac3436d" + resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.21.0.tgz" integrity sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg== "@typescript-eslint/types@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.18.0.tgz#b90a57ccdea71797ffffa0321e744f379ec838c9" + resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz" integrity sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ== "@typescript-eslint/typescript-estree@5.40.0": @@ -502,7 +502,7 @@ "@typescript-eslint/typescript-estree@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz#c47ae7901db3b8bddc3ecd73daff2d0895688c46" + resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz" integrity sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ== dependencies: "@typescript-eslint/types" "6.21.0" @@ -516,7 +516,7 @@ "@typescript-eslint/typescript-estree@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz#b5868d486c51ce8f312309ba79bdb9f331b37931" + resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz" integrity sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA== dependencies: "@typescript-eslint/types" "7.18.0" @@ -543,7 +543,7 @@ "@typescript-eslint/utils@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.21.0.tgz#4714e7a6b39e773c1c8e97ec587f520840cd8134" + resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.21.0.tgz" integrity sha512-NfWVaC8HP9T8cbKQxHcsJBY5YE1O33+jpMwN45qzWWaPDZgLIbo12toGMWnmhvCpd3sIxkpDw3Wv1B3dYrbDQQ== dependencies: "@eslint-community/eslint-utils" "^4.4.0" @@ -556,7 +556,7 @@ "@typescript-eslint/utils@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.18.0.tgz#bca01cde77f95fc6a8d5b0dbcbfb3d6ca4be451f" + resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.18.0.tgz" integrity sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw== dependencies: "@eslint-community/eslint-utils" "^4.4.0" @@ -574,7 +574,7 @@ "@typescript-eslint/visitor-keys@6.21.0": version "6.21.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz#87a99d077aa507e20e238b11d56cc26ade45fe47" + resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz" integrity sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A== dependencies: "@typescript-eslint/types" "6.21.0" @@ -582,7 +582,7 @@ "@typescript-eslint/visitor-keys@7.18.0": version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz#0564629b6124d67607378d0f0332a0495b25e7d7" + resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz" integrity sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg== dependencies: "@typescript-eslint/types" "7.18.0" @@ -600,12 +600,12 @@ acorn-jsx@^5.3.2: acorn-walk@^8.1.1: version "8.3.1" - resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.1.tgz#2f10f5b69329d90ae18c58bf1fa8fccd8b959a43" + resolved "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.1.tgz" integrity sha512-TgUZgYvqZprrl7YldZNoa9OciCAyZR+Ejm9eXzKCmjsF5IKp/wgQ7Z/ZpjpGTIUPwrHQIcYeI8qDh4PsEwxMbw== acorn@^8.4.1, acorn@^8.9.0: version "8.11.3" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" + resolved "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz" integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== ajv@^6.12.4: @@ -644,7 +644,7 @@ are-docs-informative@^0.0.2: arg@^4.1.0: version "4.1.3" - resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + resolved "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz" integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== argparse@^2.0.1: @@ -735,7 +735,7 @@ brace-expansion@^1.1.7: brace-expansion@^2.0.1: version "2.0.1" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz" integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== dependencies: balanced-match "^1.0.0" @@ -749,7 +749,7 @@ braces@^3.0.2: browserslist@^4.23.0: version "4.23.0" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.0.tgz#8f3acc2bbe73af7213399430890f86c63a5674ab" + resolved "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz" integrity sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ== dependencies: caniuse-lite "^1.0.30001587" @@ -782,7 +782,7 @@ callsites@^3.0.0: caniuse-lite@^1.0.30001587: version "1.0.30001626" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001626.tgz#328623664a28493b4a9019af7ce03ea39fbe898c" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001626.tgz" integrity sha512-JRW7kAH8PFJzoPCJhLSHgDgKg5348hsQ68aqb+slnzuB5QFERv846oA/mRChmlLAOdEDeOkRn3ynb1gSFnjt3w== caseless@~0.12.0: @@ -879,7 +879,7 @@ concat-map@0.0.1: core-js-compat@^3.37.0: version "3.37.1" - resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.37.1.tgz#c844310c7852f4bdf49b8d339730b97e17ff09ee" + resolved "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.37.1.tgz" integrity sha512-9TNiImhKvQqSUkOvk/mMRZzOANTiEVC7WaBNhHcKM7x+/5E1l5NvsysR19zuDQScE8k+kfQXWRN3AtS/eOSHpg== dependencies: browserslist "^4.23.0" @@ -891,7 +891,7 @@ core-js-pure@^3.25.1: create-require@^1.1.0: version "1.1.1" - resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + resolved "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== cross-spawn@^7.0.2: @@ -954,7 +954,7 @@ dequal@^2.0.0: diff@^4.0.1: version "4.0.2" - resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== diff@^5.0.0, diff@^5.1.0: @@ -985,7 +985,7 @@ doctrine@^3.0.0: electron-to-chromium@^1.4.668: version "1.4.788" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.788.tgz#a3545959d5cfa0a266d3e551386c040be34e7e06" + resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.788.tgz" integrity sha512-ubp5+Ev/VV8KuRoWnfP2QF2Bg+O2ZFdb49DiiNbz2VmgkIqrnyYaqIOqj8A6K/3p1xV0QcU5hBQ1+BmB6ot1OA== emoji-regex@^8.0.0: @@ -1068,7 +1068,7 @@ esbuild-darwin-64@0.15.18: esbuild-darwin-arm64@0.15.18: version "0.15.18" - resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.18.tgz#b6dfc7799115a2917f35970bfbc93ae50256b337" + resolved "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.18.tgz" integrity sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA== esbuild-freebsd-64@0.15.18: @@ -1153,7 +1153,7 @@ esbuild-windows-arm64@0.15.18: esbuild@^0.15.16: version "0.15.18" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.18.tgz#ea894adaf3fbc036d32320a00d4d6e4978a2f36d" + resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.15.18.tgz" integrity sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q== optionalDependencies: "@esbuild/android-arm" "0.15.18" @@ -1200,9 +1200,9 @@ eslint-config-prettier@^9.0.0: integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== eslint-etc@^5.1.0: - version "5.2.0" - resolved "https://registry.npmjs.org/eslint-etc/-/eslint-etc-5.2.0.tgz" - integrity sha512-Gcm/NMa349FOXb1PEEfNMMyIANuorIc2/mI5Vfu1zENNsz+FBVhF62uY6gPUCigm/xDOc8JOnl+71WGnlzlDag== + version "5.2.1" + resolved "https://registry.npmjs.org/eslint-etc/-/eslint-etc-5.2.1.tgz" + integrity sha512-lFJBSiIURdqQKq9xJhvSJFyPA+VeTh5xvk24e8pxVL7bwLBtGF60C/KRkLTMrvCZ6DA3kbPuYhLWY0TZMlqTsg== dependencies: "@typescript-eslint/experimental-utils" "^5.0.0" tsutils "^3.17.1" @@ -1230,12 +1230,12 @@ eslint-plugin-ban@^1.4.0: dependencies: requireindex "~1.2.0" -eslint-plugin-etc@^2.0.2: - version "2.0.2" - resolved "https://registry.npmjs.org/eslint-plugin-etc/-/eslint-plugin-etc-2.0.2.tgz" - integrity sha512-g3b95LCdTCwZA8On9EICYL8m1NMWaiGfmNUd/ftZTeGZDXrwujKXUr+unYzqKjKFo1EbqJ31vt+Dqzrdm/sUcw== +eslint-plugin-etc@^2.0.2, eslint-plugin-etc@^2.0.3: + version "2.0.3" + resolved "https://registry.npmjs.org/eslint-plugin-etc/-/eslint-plugin-etc-2.0.3.tgz" + integrity sha512-o5RS/0YwtjlGKWjhKojgmm82gV1b4NQUuwk9zqjy9/EjxNFKKYCaF+0M7DkYBn44mJ6JYFZw3Ft249dkKuR1ew== dependencies: - "@phenomnomnominal/tsquery" "^4.0.0" + "@phenomnomnominal/tsquery" "^5.0.0" "@typescript-eslint/experimental-utils" "^5.0.0" eslint-etc "^5.1.0" requireindex "~1.2.0" @@ -1328,10 +1328,10 @@ eslint-plugin-react@^7.21.4: semver "^6.3.0" string.prototype.matchall "^4.0.7" -eslint-plugin-rxjs@^5.0.2: - version "5.0.2" - resolved "https://registry.npmjs.org/eslint-plugin-rxjs/-/eslint-plugin-rxjs-5.0.2.tgz" - integrity sha512-Q2wsEHWInhZ3uz5df+YbD4g/NPQqAeYHjJuEsxqgVS+XAsYCuVE2pj9kADdMFy4GsQy2jt7KP+TOrnq1i6bI5Q== +eslint-plugin-rxjs@^5.0.2, eslint-plugin-rxjs@^5.0.3: + version "5.0.3" + resolved "https://registry.npmjs.org/eslint-plugin-rxjs/-/eslint-plugin-rxjs-5.0.3.tgz" + integrity sha512-fcVkqLmYLRfRp+ShafjpUKuaZ+cw/sXAvM5dfSxiEr7M28QZ/NY7vaOr09FB4rSaZsQyLBnNPh5SL+4EgKjh8Q== dependencies: "@typescript-eslint/experimental-utils" "^5.0.0" common-tags "^1.8.0" @@ -1366,7 +1366,7 @@ eslint-plugin-unicorn@^48.0.0: eslint-plugin-unicorn@^55.0.0: version "55.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-55.0.0.tgz#e2aeb397914799895702480970e7d148df5bcc7b" + resolved "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-55.0.0.tgz" integrity sha512-n3AKiVpY2/uDcGrS3+QsYDkjPfaOrNrsfQxU9nt5nitd9KuvVXrfAvgCO9DYPSfap+Gqjw9EOrXIsBp5tlHZjA== dependencies: "@babel/helper-validator-identifier" "^7.24.5" @@ -1388,14 +1388,14 @@ eslint-plugin-unicorn@^55.0.0: eslint-plugin-unused-imports@^3.0.0: version "3.2.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.2.0.tgz#63a98c9ad5f622cd9f830f70bc77739f25ccfe0d" + resolved "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.2.0.tgz" integrity sha512-6uXyn6xdINEpxE1MtDjxQsyXB37lfyO2yKGVVgtD7WEWQGORSOZjgrD6hBhvGv4/SO+TOlS+UnC6JppRqbuwGQ== dependencies: eslint-rule-composer "^0.3.0" eslint-plugin-unused-imports@^4.1.3: version "4.1.3" - resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.3.tgz#079ef6f51914a981e657b3834935a6a417bf3f45" + resolved "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.3.tgz" integrity sha512-lqrNZIZjFMUr7P06eoKtQLwyVRibvG7N+LtfKtObYGizAAGrcqLkc3tDx+iAik2z7q0j/XI3ihjupIqxhFabFA== eslint-rule-composer@^0.3.0: @@ -1438,7 +1438,7 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4 eslint@^8.57.0: version "8.57.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.0.tgz#c786a6fd0e0b68941aaf624596fb987089195668" + resolved "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz" integrity sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ== dependencies: "@eslint-community/eslint-utils" "^4.2.0" @@ -1489,7 +1489,7 @@ espree@^9.6.0, espree@^9.6.1: acorn-jsx "^5.3.2" eslint-visitor-keys "^3.4.1" -esquery@^1.0.1, esquery@^1.4.2, esquery@^1.5.0: +esquery@^1.4.0, esquery@^1.4.2, esquery@^1.5.0: version "1.5.0" resolved "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz" integrity sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg== @@ -1681,7 +1681,7 @@ globals@^13.19.0: globals@^15.7.0: version "15.9.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-15.9.0.tgz#e9de01771091ffbc37db5714dab484f9f69ff399" + resolved "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz" integrity sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA== globby@^11.1.0: @@ -1754,7 +1754,7 @@ hosted-git-info@^2.1.4: ignore@^5.2.0, ignore@^5.2.4, ignore@^5.3.1: version "5.3.1" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" + resolved "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz" integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw== import-fresh@^3.2.1: @@ -2058,7 +2058,7 @@ loose-envify@^1.4.0: make-error@^1.1.1: version "1.3.6" - resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + resolved "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz" integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== merge2@^1.3.0, merge2@^1.4.1: @@ -2081,7 +2081,7 @@ min-indent@^1.0.0: minimatch@9.0.3: version "9.0.3" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz" integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg== dependencies: brace-expansion "^2.0.1" @@ -2095,7 +2095,7 @@ minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: minimatch@^9.0.4: version "9.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.4.tgz#8e49c731d1749cbec05050ee5145147b32496a51" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz" integrity sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw== dependencies: brace-expansion "^2.0.1" @@ -2326,12 +2326,12 @@ prelude-ls@^1.2.1: prettier@3.3.2: version "3.3.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.2.tgz#03ff86dc7c835f2d2559ee76876a3914cec4a90a" + resolved "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz" integrity sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA== pretty-ms@^7.0.1: version "7.0.1" - resolved "https://registry.yarnpkg.com/pretty-ms/-/pretty-ms-7.0.1.tgz#7d903eaab281f7d8e03c66f867e239dc32fb73e8" + resolved "https://registry.npmjs.org/pretty-ms/-/pretty-ms-7.0.1.tgz" integrity sha512-973driJZvxiGOQ5ONsFhOF/DtzPMOMtgC11kCpUrPGMTgqp2q/1gwzCquocrN33is0VZ5GFHXZYMM9l6h67v2Q== dependencies: parse-ms "^2.1.0" @@ -2511,7 +2511,7 @@ semver@^6.3.0: semver@^7.3.7, semver@^7.5.4, semver@^7.6.0, semver@^7.6.1: version "7.6.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" + resolved "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz" integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== shebang-command@^2.0.0: @@ -2682,12 +2682,12 @@ to-regex-range@^5.0.1: ts-api-utils@^1.0.1, ts-api-utils@^1.3.0: version "1.3.0" - resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.3.0.tgz#4b490e27129f1e8e686b45cc4ab63714dc60eea1" + resolved "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz" integrity sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ== ts-node@^10.7.0: version "10.9.2" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f" + resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz" integrity sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ== dependencies: "@cspotcode/source-map-support" "^0.8.0" @@ -2726,15 +2726,15 @@ tslib@^2.0.0: tsm@^2.3.0: version "2.3.0" - resolved "https://registry.yarnpkg.com/tsm/-/tsm-2.3.0.tgz#f1a2f21393ca58268ef54ba2246bee5528e2ec43" + resolved "https://registry.npmjs.org/tsm/-/tsm-2.3.0.tgz" integrity sha512-++0HFnmmR+gMpDtKTnW3XJ4yv9kVGi20n+NfyQWB9qwJvTaIWY9kBmzek2YUQK5APTQ/1DTrXmm4QtFPmW9Rzw== dependencies: esbuild "^0.15.16" tsutils-etc@^1.4.1: - version "1.4.1" - resolved "https://registry.npmjs.org/tsutils-etc/-/tsutils-etc-1.4.1.tgz" - integrity sha512-6UPYgc7OXcIW5tFxlsZF3OVSBvDInl/BkS3Xsu64YITXk7WrnWTVByKWPCThFDBp5gl5IGHOzGMdQuDCE7OL4g== + version "1.4.2" + resolved "https://registry.npmjs.org/tsutils-etc/-/tsutils-etc-1.4.2.tgz" + integrity sha512-2Dn5SxTDOu6YWDNKcx1xu2YUy6PUeKrWZB/x2cQ8vY2+iz3JRembKn/iZ0JLT1ZudGNwQQvtFX9AwvRHbXuPUg== dependencies: "@types/yargs" "^17.0.0" yargs "^17.0.0" @@ -2770,7 +2770,7 @@ type-fest@^0.8.1: typescript-eslint@7.18.0: version "7.18.0" - resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-7.18.0.tgz#e90d57649b2ad37a7475875fa3e834a6d9f61eb2" + resolved "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.18.0.tgz" integrity sha512-PonBkP603E3tt05lDkbOMyaxJjvKqQrXsnow72sVeOFINDE/qNmnnd+f9b4N+U7W6MXnnYyrhtmF2t08QWwUbA== dependencies: "@typescript-eslint/eslint-plugin" "7.18.0" @@ -2779,7 +2779,7 @@ typescript-eslint@7.18.0: typescript@^5.3.3: version "5.3.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + resolved "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz" integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== unbox-primitive@^1.0.2: @@ -2824,7 +2824,7 @@ uvu@^0.5.6: v8-compile-cache-lib@^3.0.1: version "3.0.1" - resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + resolved "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz" integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== validate-npm-package-license@^3.0.1: @@ -2892,7 +2892,7 @@ yargs@^17.0.0: yn@3.1.1: version "3.1.1" - resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + resolved "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz" integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== yocto-queue@^0.1.0: From b6f4920192f7c13e65a7381eb9794684d33a61f0 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:10:00 +0200 Subject: [PATCH 07/11] fix lints --- src/FileIndexer.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 284d1356..22a7fead 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -148,8 +148,7 @@ export class FileIndexer { } private getDeclarationsForPropertyAssignment( - node: ts.Node, - sym: ts.Symbol + node: ts.Node ): ts.Declaration[] | undefined { if (!ts.isPropertyAssignment(node.parent)) { return @@ -165,8 +164,8 @@ export class FileIndexer { const range = Range.fromNode(node).toLsif() let role = 0 let declarations: ts.Node[] = - this.getDeclarationsForPropertyAssignment(node, sym) ?? [] - let isDefinitionNode = declarations.length == 0 && isDefinition(node) + this.getDeclarationsForPropertyAssignment(node) ?? [] + const isDefinitionNode = declarations.length === 0 && isDefinition(node) if (isDefinitionNode) { role |= scip.scip.SymbolRole.Definition } From 950d671f04808441ca5a9dc3a3d9cd6cb8d7f516 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 10:14:22 +0200 Subject: [PATCH 08/11] adds a test showing the approach fails for quoted object properties --- snapshots/input/syntax/src/property-assignment.ts | 4 ++-- snapshots/output/syntax/src/property-assignment.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/snapshots/input/syntax/src/property-assignment.ts b/snapshots/input/syntax/src/property-assignment.ts index d6f2d75b..b56502b6 100644 --- a/snapshots/input/syntax/src/property-assignment.ts +++ b/snapshots/input/syntax/src/property-assignment.ts @@ -5,7 +5,7 @@ export function shorthandPropertyAssignment() { const a = 'a' return { a } } -type A = { a: string } +type A = { a: string, b : number } export function typedPropertyAssignment(): A { - return { a: 'a' } + return { a: 'a', "b": 10 } } diff --git a/snapshots/output/syntax/src/property-assignment.ts b/snapshots/output/syntax/src/property-assignment.ts index 7745c9d0..36d9c275 100644 --- a/snapshots/output/syntax/src/property-assignment.ts +++ b/snapshots/output/syntax/src/property-assignment.ts @@ -13,13 +13,15 @@ export function shorthandPropertyAssignment() { // ^ definition syntax 1.0.0 src/`property-assignment.ts`/a1: // ^ reference local 2 } -type A = { a: string } +type A = { a: string, b : number } // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A# // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. +// ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:b. export function typedPropertyAssignment(): A { // ^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/typedPropertyAssignment(). // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A# - return { a: 'a' } + return { a: 'a', "b": 10 } // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. +// ^^^ definition syntax 1.0.0 src/`property-assignment.ts`/`"b"0`: } From a7ad7bd788741c7c3c6a1f9d25c9f8023f3488d9 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 11:05:20 +0200 Subject: [PATCH 09/11] inlines definitions from the TS compiler to handle more cases --- .../input/syntax/src/property-assignment.ts | 3 +- snapshots/output/react/src/LoaderInput.tsx | 2 +- snapshots/output/syntax/src/interface.ts | 3 +- .../output/syntax/src/property-assignment.ts | 5 +- src/FileIndexer.ts | 17 ++-- src/TypeScriptInternal.ts | 86 +++++++++++++++++++ 6 files changed, 104 insertions(+), 12 deletions(-) diff --git a/snapshots/input/syntax/src/property-assignment.ts b/snapshots/input/syntax/src/property-assignment.ts index b56502b6..dca670ac 100644 --- a/snapshots/input/syntax/src/property-assignment.ts +++ b/snapshots/input/syntax/src/property-assignment.ts @@ -5,7 +5,8 @@ export function shorthandPropertyAssignment() { const a = 'a' return { a } } -type A = { a: string, b : number } +type A = { a: string; b: number } export function typedPropertyAssignment(): A { + // prettier-ignore return { a: 'a', "b": 10 } } diff --git a/snapshots/output/react/src/LoaderInput.tsx b/snapshots/output/react/src/LoaderInput.tsx index fba29323..fb7550f6 100644 --- a/snapshots/output/react/src/LoaderInput.tsx +++ b/snapshots/output/react/src/LoaderInput.tsx @@ -49,7 +49,7 @@ export const LoaderInput2: React.FunctionComponent = props => { return // ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput. // ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading. -// ^^^ reference local 10 +// ^^^ reference @types/react 18.2.39 `index.d.ts`/React/Attributes#key. // ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. // ^^^^^ reference local 6 // ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. diff --git a/snapshots/output/syntax/src/interface.ts b/snapshots/output/syntax/src/interface.ts index 82c95e69..3ea6368b 100644 --- a/snapshots/output/syntax/src/interface.ts +++ b/snapshots/output/syntax/src/interface.ts @@ -19,8 +19,7 @@ export function newInterface(): Interface { property: 'a', // ^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#property. methodSignature(param: string): string { -// ^^^^^^^^^^^^^^^ definition local 4 -// relationship implementation reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). // ^^^^^ definition local 5 return param // ^^^^^ reference local 5 diff --git a/snapshots/output/syntax/src/property-assignment.ts b/snapshots/output/syntax/src/property-assignment.ts index 36d9c275..ce5a8531 100644 --- a/snapshots/output/syntax/src/property-assignment.ts +++ b/snapshots/output/syntax/src/property-assignment.ts @@ -13,15 +13,16 @@ export function shorthandPropertyAssignment() { // ^ definition syntax 1.0.0 src/`property-assignment.ts`/a1: // ^ reference local 2 } -type A = { a: string, b : number } +type A = { a: string; b: number } // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A# // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:b. export function typedPropertyAssignment(): A { // ^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/typedPropertyAssignment(). // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A# + // prettier-ignore return { a: 'a', "b": 10 } // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. -// ^^^ definition syntax 1.0.0 src/`property-assignment.ts`/`"b"0`: +// ^^^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:b. } diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 22a7fead..a71d7192 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -150,14 +150,19 @@ export class FileIndexer { private getDeclarationsForPropertyAssignment( node: ts.Node ): ts.Declaration[] | undefined { - if (!ts.isPropertyAssignment(node.parent)) { + const objectElement = ts_inline.getContainingObjectLiteralElement(node) + if (!objectElement) { return } - // { symbol: .... } - // ^^^^^ this is symbol node we're pointing at - const contextualType = this.checker.getContextualType(node.parent.parent) - const property = contextualType?.getProperty(node.getText()) - return property?.getDeclarations() + const contextualType = this.checker.getContextualType(objectElement.parent) + if (contextualType === undefined) { + return + } + const symbol = ts_inline.getPropertySymbolFromContextualType( + objectElement, + contextualType + ) + return symbol?.getDeclarations() } private visitSymbolOccurrence(node: ts.Node, sym: ts.Symbol): void { diff --git a/src/TypeScriptInternal.ts b/src/TypeScriptInternal.ts index f2a250ad..5067350f 100644 --- a/src/TypeScriptInternal.ts +++ b/src/TypeScriptInternal.ts @@ -66,3 +66,89 @@ export function getTextOfJsxAttributeName(node: ts.JsxAttributeName): string { ? ts.idText(node) : `${ts.idText(node.namespace)}:${ts.idText(node.name)}` } + +type ObjectLiteralElementWithName = ts.ObjectLiteralElement & { + name: ts.PropertyName + parent: ts.ObjectLiteralExpression | ts.JsxAttributes +} +export function getContainingObjectLiteralElement( + node: ts.Node +): ObjectLiteralElementWithName | undefined { + const element = getContainingObjectLiteralElementWorker(node) + return element && + (ts.isObjectLiteralExpression(element.parent) || + ts.isJsxAttributes(element.parent)) + ? (element as ObjectLiteralElementWithName) + : undefined +} + +function getContainingObjectLiteralElementWorker( + node: ts.Node +): ts.ObjectLiteralElement | undefined { + switch (node.kind) { + case ts.SyntaxKind.StringLiteral: + case ts.SyntaxKind.NoSubstitutionTemplateLiteral: + case ts.SyntaxKind.NumericLiteral: { + if (node.parent.kind === ts.SyntaxKind.ComputedPropertyName) { + return ts.isObjectLiteralElement(node.parent.parent) + ? node.parent.parent + : undefined + } + // falls through + } + + case ts.SyntaxKind.Identifier: { + return ts.isObjectLiteralElement(node.parent) && + (node.parent.parent.kind === ts.SyntaxKind.ObjectLiteralExpression || + node.parent.parent.kind === ts.SyntaxKind.JsxAttributes) && + node.parent.name === node + ? node.parent + : undefined + } + } + return undefined +} + +export function getPropertySymbolFromContextualType( + node: ObjectLiteralElementWithName, + contextualType: ts.Type +): ts.Symbol | undefined { + const name = getNameFromPropertyName(node.name) + if (!name) { + return undefined + } + return contextualType.getProperty(name) +} + +export function getNameFromPropertyName( + name: ts.PropertyName +): string | undefined { + return name.kind === ts.SyntaxKind.ComputedPropertyName + ? // treat computed property names where expression is string/numeric literal as just string/numeric literal + isStringOrNumericLiteralLike(name.expression) + ? name.expression.text + : undefined + : ts.isPrivateIdentifier(name) + ? ts.idText(name) + : getTextOfIdentifierOrLiteral(name) +} + +export function isStringOrNumericLiteralLike( + node: ts.Node +): node is ts.StringLiteralLike | ts.NumericLiteral { + return ts.isStringLiteralLike(node) || ts.isNumericLiteral(node) +} + +export function getTextOfIdentifierOrLiteral( + node: ts.PropertyNameLiteral | ts.PrivateIdentifier +): string { + return ts.isMemberName(node) + ? ts.idText(node) + : ts.isJsxNamespacedName(node) + ? getTextOfJsxNamespacedName(node) + : node.text +} + +export function getTextOfJsxNamespacedName(node: ts.JsxNamespacedName): string { + return `${ts.idText(node.namespace)}:${ts.idText(node.name)}` +} From d235021a774100c90cb2dfc33ad8e43d440540ff Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 11:20:32 +0200 Subject: [PATCH 10/11] ports tests from #256 --- snapshots/input/syntax/src/decorators.ts | 12 ++ .../input/syntax/src/infer-relationship.ts | 60 ------- snapshots/input/syntax/src/inheritance.ts | 12 +- .../src/object-literals-arrow-function.ts | 35 ++++ .../src/object-literals-call-signatures.ts | 73 ++++++++ .../syntax/src/object-literals-nested.ts | 40 +++++ snapshots/input/syntax/src/object-literals.ts | 91 ++++++++++ snapshots/input/syntax/src/reusable-types.ts | 29 +++ snapshots/input/syntax/tsconfig.json | 3 +- snapshots/output/syntax/src/decorators.ts | 36 ++++ .../output/syntax/src/infer-relationship.ts | 110 ------------ snapshots/output/syntax/src/inheritance.ts | 38 ++-- .../src/object-literals-arrow-function.ts | 88 +++++++++ .../src/object-literals-call-signatures.ts | 158 ++++++++++++++++ .../syntax/src/object-literals-nested.ts | 69 +++++++ .../output/syntax/src/object-literals.ts | 169 ++++++++++++++++++ snapshots/output/syntax/src/reusable-types.ts | 67 +++++++ src/SnapshotTesting.ts | 2 +- 18 files changed, 881 insertions(+), 211 deletions(-) create mode 100644 snapshots/input/syntax/src/decorators.ts delete mode 100644 snapshots/input/syntax/src/infer-relationship.ts create mode 100644 snapshots/input/syntax/src/object-literals-arrow-function.ts create mode 100644 snapshots/input/syntax/src/object-literals-call-signatures.ts create mode 100644 snapshots/input/syntax/src/object-literals-nested.ts create mode 100644 snapshots/input/syntax/src/object-literals.ts create mode 100644 snapshots/input/syntax/src/reusable-types.ts create mode 100644 snapshots/output/syntax/src/decorators.ts delete mode 100644 snapshots/output/syntax/src/infer-relationship.ts create mode 100644 snapshots/output/syntax/src/object-literals-arrow-function.ts create mode 100644 snapshots/output/syntax/src/object-literals-call-signatures.ts create mode 100644 snapshots/output/syntax/src/object-literals-nested.ts create mode 100644 snapshots/output/syntax/src/object-literals.ts create mode 100644 snapshots/output/syntax/src/reusable-types.ts diff --git a/snapshots/input/syntax/src/decorators.ts b/snapshots/input/syntax/src/decorators.ts new file mode 100644 index 00000000..27937bcb --- /dev/null +++ b/snapshots/input/syntax/src/decorators.ts @@ -0,0 +1,12 @@ +import { Configuration } from './reusable-types' + +function MyDecorator(value: Configuration) { + return function (target: Function) { + console.log(`MyDecorator is called with value: ${value}`) + } +} + +@MyDecorator({ property: 42, property2: '42' }) +class MyClass { + //... +} diff --git a/snapshots/input/syntax/src/infer-relationship.ts b/snapshots/input/syntax/src/infer-relationship.ts deleted file mode 100644 index af9521a2..00000000 --- a/snapshots/input/syntax/src/infer-relationship.ts +++ /dev/null @@ -1,60 +0,0 @@ -interface Configuration { - property: number -} - -function random(): number { - return Math.random() -} -export function returnStatement(): Configuration { - if (random() > 0) { - return { - property: 41, - } - } - for (let i = 0; i < 9; i++) { - if (random() > i) { - return { - property: 41, - } - } - } - for (const i of [1, 2, 3]) { - if (random() > i) { - return { - property: 41, - } - } - } - for (const i in { '1': 2 }) { - if (random() > Number.parseInt(i)) { - return { - property: 41, - } - } - } - while (random() < 0) { - return { - property: 41, - } - } - do { - if (random() > 0) { - return { - property: 41, - } - } - } while (random() < 0) - - return { - property: 42, - } -} - -export function returnStatementInsideArgumentExpression(): Configuration[] { - return [1].map(number => { - const incremented = number + 1 - return { - property: incremented, - } - }) -} diff --git a/snapshots/input/syntax/src/inheritance.ts b/snapshots/input/syntax/src/inheritance.ts index ef57aa3e..f0ad8a86 100644 --- a/snapshots/input/syntax/src/inheritance.ts +++ b/snapshots/input/syntax/src/inheritance.ts @@ -1,9 +1,6 @@ +import { Superinterface } from './reusable-types' import { Overloader } from './overload' -export interface Superinterface { - property: string - interfaceMethod(): string -} export interface IntermediateSuperinterface extends Superinterface { intermediateInterfaceMethod(): string } @@ -43,10 +40,3 @@ export const objectLiteralImplementation: Superinterface = { throw new Error('Function not implemented.') }, } -export function consumesInterface(superInterface: Superinterface): void {} -export function infersInterface(): void { - consumesInterface({ - interfaceMethod: (): string => 'inferred', - property: 'inferred', - }) -} diff --git a/snapshots/input/syntax/src/object-literals-arrow-function.ts b/snapshots/input/syntax/src/object-literals-arrow-function.ts new file mode 100644 index 00000000..d914d42d --- /dev/null +++ b/snapshots/input/syntax/src/object-literals-arrow-function.ts @@ -0,0 +1,35 @@ +import { Option } from './reusable-types' + +interface Foobar { + foobar: number +} + +export function hasArrowFunctionParameter( + something: number, + fn: (foobar: Foobar) => Foobar +): Foobar { + return fn({ foobar: 42 + something }) +} + +export function consumesArrowFunction(): number { + return ( + hasArrowFunctionParameter(1, ({ foobar }) => ({ foobar: foobar + 1 })) + .foobar + + hasArrowFunctionParameter(2, foobar => ({ foobar: foobar.foobar + 2 })) + .foobar + ) +} + +export function genericArrow(): Foobar[] { + return [1].map(n => ({ foobar: n + 1 })) +} + +export function genericArrowOption(): Option[] { + return [1].map>(n => ({ value: { foobar: n + 1 } })) +} + +export function genericArrow2(): Foobar[] { + // navigation to `foobar` below does not work with tsserver or scip-java + // because `map` is missing an explicit `map` annotation. + return [1].map(n => ({ foobar: n + 1 })) +} diff --git a/snapshots/input/syntax/src/object-literals-call-signatures.ts b/snapshots/input/syntax/src/object-literals-call-signatures.ts new file mode 100644 index 00000000..3df73103 --- /dev/null +++ b/snapshots/input/syntax/src/object-literals-call-signatures.ts @@ -0,0 +1,73 @@ +import { + Configuration, + GenericClass, + GenericInterface, + Option, + Superinterface, +} from './reusable-types' + +export function consumesInterface(superInterface: Superinterface): void {} +export function consumesArray(superInterface: Superinterface[]): void {} +export function consumesGenericInterface( + genercInterface: GenericInterface +): void {} + +export function infersInterface(): void { + consumesInterface({ + interfaceMethod: (): string => 'inferred', + property: 'inferred', + }) + consumesArray([ + { + interfaceMethod: (): string => 'inferred', + property: 'inferred', + }, + ]) + consumesGenericInterface({ + interfaceMethod: (): string => 'inferred', + property: 123, + }) + consumesGenericInterface[]>({ + interfaceMethod: (): string => 'inferred', + property: [{ value: { property: 42, property2: '42' } }], + }) +} +export function returnStatementInsideArgumentExpression(): Configuration[] { + if (1 == 1) { + return [1].map((number: number): Configuration => { + const incremented = number + 1 + return { + property: incremented, + property2: incremented.toString(), + } + }) + } else { + return [1].map(number => { + const incremented = number + 1 + return { + property: incremented, + property2: incremented.toString(), + } + }) + } +} + +export function createGenericClass(): GenericClass { + return new GenericClass([{ property: 1, property2: '2' }]) +} + +export function handleGenericClass() { + return createGenericClass().map(({ property, property2 }) => ({ + property: property + 1, + property2: property2 + '1', + })) +} + +export function handleShorthand() { + const property = '42' + const interfaceMethod = (): string => 'inferred' + consumesInterface({ + interfaceMethod, + property, + }) +} diff --git a/snapshots/input/syntax/src/object-literals-nested.ts b/snapshots/input/syntax/src/object-literals-nested.ts new file mode 100644 index 00000000..6a8096ff --- /dev/null +++ b/snapshots/input/syntax/src/object-literals-nested.ts @@ -0,0 +1,40 @@ +import { Option } from './reusable-types' + +interface Address { + street: string + people: Person[] +} +interface Person { + name: string + address?: Address +} + +export function handleNestedObjectLiterals(): Person { + return { + name: 'John', + address: { + street: 'Oxford Street', + people: [ + { + name: 'Susan', + }, + ], + }, + } +} + +export function handleNestedTypeVariables(): Option { + return { + value: { + name: 'John', + address: { + street: 'Oxford Street', + people: [ + { + name: 'Susan', + }, + ], + }, + }, + } +} diff --git a/snapshots/input/syntax/src/object-literals.ts b/snapshots/input/syntax/src/object-literals.ts new file mode 100644 index 00000000..c9efaa38 --- /dev/null +++ b/snapshots/input/syntax/src/object-literals.ts @@ -0,0 +1,91 @@ +import { Configuration } from './reusable-types' + +function random(): number { + return Math.random() +} + +export function handleArrayLiteral(): Configuration[] { + return [ + { + property: 41, + property2: '41', + }, + ] +} + +export function returnStatement(): Configuration { + if (random() > 0) { + return { + property: 41, + property2: '41', + } + } + for (let i = 0; i < 9; i++) { + if (random() > i) { + return { + property: 41, + property2: '41', + } + } + } + for (const i of [1, 2, 3]) { + if (random() > i) { + return { + property: 41, + property2: '41', + } + } + } + for (const i in { '1': 2 }) { + if (random() > Number.parseInt(i)) { + return { + property: 41, + property2: '41', + } + } + } + while (random() < 0) { + return { + property: 41, + property2: '41', + } + } + do { + if (random() > 0) { + return { + property: 41, + property2: '41', + } + } + } while (random() < 0) + + return { + property: 42, + property2: '41', + } +} + +export function constDeclaration(): number[] { + var configuration1: Configuration = { + property: 1, + property2: '1', + } + configuration1 = { + property: 2, + property2: '2', + } + let configuration2: Configuration = { + property: 3, + property2: '3', + } + configuration2.property = configuration1.property + const configuration3: Configuration = { + property: 4, + property2: '4', + } + return [ + configuration1.property, + configuration2.property, + configuration3.property, + ] +} diff --git a/snapshots/input/syntax/src/reusable-types.ts b/snapshots/input/syntax/src/reusable-types.ts new file mode 100644 index 00000000..df961834 --- /dev/null +++ b/snapshots/input/syntax/src/reusable-types.ts @@ -0,0 +1,29 @@ +// Reusable types for other snapshot tests + +export interface Option { + value?: A +} + +export interface Numbers { + property: number +} +export interface Strings { + property2: string +} +export type Configuration = Numbers & Strings + +export class GenericClass { + constructor(public readonly values: A[]) {} + public map(fn: (a: A) => A): A[] { + return this.values.map(a => fn(a)) + } +} + +export interface Superinterface { + property: string + interfaceMethod(): string +} +export interface GenericInterface { + property: T + interfaceMethod(): string +} diff --git a/snapshots/input/syntax/tsconfig.json b/snapshots/input/syntax/tsconfig.json index 578d9f4d..bdfe08db 100644 --- a/snapshots/input/syntax/tsconfig.json +++ b/snapshots/input/syntax/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "outDir": "dist", - "target": "ES2015" + "target": "ES2015", + "experimentalDecorators": true } } diff --git a/snapshots/output/syntax/src/decorators.ts b/snapshots/output/syntax/src/decorators.ts new file mode 100644 index 00000000..288fab04 --- /dev/null +++ b/snapshots/output/syntax/src/decorators.ts @@ -0,0 +1,36 @@ +// < definition syntax 1.0.0 src/`decorators.ts`/ + +import { Configuration } from './reusable-types' +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ + +function MyDecorator(value: Configuration) { +// ^^^^^^^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyDecorator(). +// ^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyDecorator().(value) +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + return function (target: Function) { +// ^^^^^^ definition local 2 +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Function# +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Function. +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.core.d.ts`/Function# +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Function# + console.log(`MyDecorator is called with value: ${value}`) +// ^^^^^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/console. +// ^^^^^^^ reference @types/node 20.10.5 `globals.d.ts`/global/console. +// ^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console/ +// ^^^^^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/console. +// ^^^ reference typescript 5.3.3 lib/`lib.dom.d.ts`/Console#log(). +// ^^^ reference @types/node 20.10.5 `console.d.ts`/`"node:console"`/global/Console#log(). +// ^^^^^ reference syntax 1.0.0 src/`decorators.ts`/MyDecorator().(value) + } +} + +@MyDecorator({ property: 42, property2: '42' }) +//^^^^^^^^^^^ reference syntax 1.0.0 src/`decorators.ts`/MyDecorator(). +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +class MyClass { +// ^^^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyClass# + //... +} + diff --git a/snapshots/output/syntax/src/infer-relationship.ts b/snapshots/output/syntax/src/infer-relationship.ts deleted file mode 100644 index e748b3d5..00000000 --- a/snapshots/output/syntax/src/infer-relationship.ts +++ /dev/null @@ -1,110 +0,0 @@ -// < definition syntax 1.0.0 src/`infer-relationship.ts`/ - -interface Configuration { -// ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/Configuration# - property: number -//^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. -} - -function random(): number { -// ^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/random(). - return Math.random() -// ^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math# -// ^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math. -// ^^^^ reference typescript 5.3.3 lib/`lib.es2015.core.d.ts`/Math# -// ^^^^ reference typescript 5.3.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Math# -// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math#random(). -} -export function returnStatement(): Configuration { -// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/returnStatement(). -// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration# - if (random() > 0) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - for (let i = 0; i < 9; i++) { -// ^ definition local 2 -// ^ reference local 2 -// ^ reference local 2 - if (random() > i) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). -// ^ reference local 2 - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - } - for (const i of [1, 2, 3]) { -// ^ definition local 5 - if (random() > i) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). -// ^ reference local 5 - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - } - for (const i in { '1': 2 }) { -// ^ definition local 8 -// ^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/`'1'0`: - if (random() > Number.parseInt(i)) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). -// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number# -// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number. -// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number# -// ^^^^^^ reference typescript 5.3.3 lib/`lib.es2020.number.d.ts`/Number# -// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.core.d.ts`/NumberConstructor#parseInt(). -// ^ reference local 8 - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - } - while (random() < 0) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - do { - if (random() > 0) { -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). - return { - property: 41, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } - } - } while (random() < 0) -// ^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/random(). - - return { - property: 42, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. - } -} - -export function returnStatementInsideArgumentExpression(): Configuration[] { -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`infer-relationship.ts`/returnStatementInsideArgumentExpression(). -// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration# - return [1].map(number => { -// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). -// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration# -// ^^^^^^ definition local 12 - const incremented = number + 1 -// ^^^^^^^^^^^ definition local 15 -// ^^^^^^ reference local 12 - return { - property: incremented, -// ^^^^^^^^ reference syntax 1.0.0 src/`infer-relationship.ts`/Configuration#property. -// ^^^^^^^^^^^ reference local 15 - } - }) -} - diff --git a/snapshots/output/syntax/src/inheritance.ts b/snapshots/output/syntax/src/inheritance.ts index 5bfeae7f..208781b8 100644 --- a/snapshots/output/syntax/src/inheritance.ts +++ b/snapshots/output/syntax/src/inheritance.ts @@ -1,19 +1,15 @@ // < definition syntax 1.0.0 src/`inheritance.ts`/ +import { Superinterface } from './reusable-types' +// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ import { Overloader } from './overload' // ^^^^^^^^^^ reference syntax 1.0.0 src/`overload.d.ts`/Overloader# // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`overload.d.ts`/ -export interface Superinterface { -// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Superinterface# - property: string -//^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. - interfaceMethod(): string -//^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). -} export interface IntermediateSuperinterface extends Superinterface { // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface# -// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface# +// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# intermediateInterfaceMethod(): string //^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface#intermediateInterfaceMethod(). } @@ -39,8 +35,8 @@ export class Subclass // relationship implementation syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass# // relationship implementation syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface# // relationship implementation syntax 1.0.0 src/`inheritance.ts`/Superclass# -// relationship implementation syntax 1.0.0 src/`inheritance.ts`/Superinterface# // relationship implementation syntax 1.0.0 src/`overload.d.ts`/Overloader# +// relationship implementation syntax 1.0.0 src/`reusable-types.ts`/Superinterface# extends IntermediateSuperclass // ^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass# implements IntermediateSuperinterface, Overloader @@ -58,7 +54,7 @@ export class Subclass } property = 'property' //^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#property. -//relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. +//relationship implementation reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. public overrideMethod(): string { // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#overrideMethod(). // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#overrideMethod(). @@ -76,7 +72,7 @@ export class Subclass } public interfaceMethod(): string { // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#interfaceMethod(). -// relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). +// relationship implementation reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). throw new Error('Method not implemented.') // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error# // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error. @@ -91,28 +87,14 @@ export class Subclass } export const objectLiteralImplementation: Superinterface = { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/objectLiteralImplementation. -// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface# +// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# property: 'property', -//^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. +//^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. interfaceMethod: (): string => { -//^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). +//^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). throw new Error('Function not implemented.') // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error# // ^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Error. }, } -export function consumesInterface(superInterface: Superinterface): void {} -// ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/consumesInterface(). -// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/consumesInterface().(superInterface) -// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface# -export function infersInterface(): void { -// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/infersInterface(). - consumesInterface({ -//^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/consumesInterface(). - interfaceMethod: (): string => 'inferred', -// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#interfaceMethod(). - property: 'inferred', -// ^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superinterface#property. - }) -} diff --git a/snapshots/output/syntax/src/object-literals-arrow-function.ts b/snapshots/output/syntax/src/object-literals-arrow-function.ts new file mode 100644 index 00000000..3925372f --- /dev/null +++ b/snapshots/output/syntax/src/object-literals-arrow-function.ts @@ -0,0 +1,88 @@ +// < definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/ + +import { Option } from './reusable-types' +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ + +interface Foobar { +// ^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# + foobar: number +//^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +} + +export function hasArrowFunctionParameter( +// ^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). + something: number, +//^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(something) + fn: (foobar: Foobar) => Foobar +//^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(fn) +// ^^^^^^ definition local 1 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# +): Foobar { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# + return fn({ foobar: 42 + something }) +// ^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(fn) +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(something) +} + +export function consumesArrowFunction(): number { +// ^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/consumesArrowFunction(). + return ( + hasArrowFunctionParameter(1, ({ foobar }) => ({ foobar: foobar + 1 })) +// ^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). +// ^^^^^^ definition local 10 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^^^^^^ reference local 10 + .foobar + +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. + hasArrowFunctionParameter(2, foobar => ({ foobar: foobar.foobar + 2 })) +// ^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). +// ^^^^^^ definition local 14 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^^^^^^ reference local 14 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. + .foobar +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. + ) +} + +export function genericArrow(): Foobar[] { +// ^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrow(). +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# + return [1].map(n => ({ foobar: n + 1 })) +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# +// ^ definition local 18 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^ reference local 18 +} + +export function genericArrowOption(): Option[] { +// ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrowOption(). +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# + return [1].map>(n => ({ value: { foobar: n + 1 } })) +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# +// ^ definition local 22 +// ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. +// ^ reference local 22 +} + +export function genericArrow2(): Foobar[] { +// ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrow2(). +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# + // navigation to `foobar` below does not work with tsserver or scip-java + // because `map` is missing an explicit `map` annotation. + return [1].map(n => ({ foobar: n + 1 })) +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^ definition local 26 +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/foobar0: +// ^ reference local 26 +} + diff --git a/snapshots/output/syntax/src/object-literals-call-signatures.ts b/snapshots/output/syntax/src/object-literals-call-signatures.ts new file mode 100644 index 00000000..8c25f3a8 --- /dev/null +++ b/snapshots/output/syntax/src/object-literals-call-signatures.ts @@ -0,0 +1,158 @@ +// < definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/ + +import { + Configuration, +//^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + GenericClass, +//^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass# + GenericInterface, +//^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# + Option, +//^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# + Superinterface, +//^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# +} from './reusable-types' +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ + +export function consumesInterface(superInterface: Superinterface): void {} +// ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). +// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface().(superInterface) +// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# +export function consumesArray(superInterface: Superinterface[]): void {} +// ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray(). +// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray().(superInterface) +// ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# +export function consumesGenericInterface( +// ^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). +// ^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().[T] + genercInterface: GenericInterface +//^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().(genercInterface) +// ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# +// ^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().[T] +): void {} + +export function infersInterface(): void { +// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/infersInterface(). + consumesInterface({ +//^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). + interfaceMethod: (): string => 'inferred', +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). + property: 'inferred', +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. + }) + consumesArray([ +//^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray(). + { + interfaceMethod: (): string => 'inferred', +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). + property: 'inferred', +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. + }, + ]) + consumesGenericInterface({ +//^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). + interfaceMethod: (): string => 'inferred', +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). + property: 123, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. + }) + consumesGenericInterface[]>({ +//^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + interfaceMethod: (): string => 'inferred', +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). + property: [{ value: { property: 42, property2: '42' } }], +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. +// ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + }) +} +export function returnStatementInsideArgumentExpression(): Configuration[] { +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/returnStatementInsideArgumentExpression(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + if (1 == 1) { + return [1].map((number: number): Configuration => { +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^ definition local 3 +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + const incremented = number + 1 +// ^^^^^^^^^^^ definition local 6 +// ^^^^^^ reference local 3 + return { + property: incremented, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^^^ reference local 6 + property2: incremented.toString(), +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +// ^^^^^^^^^^^ reference local 6 +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number#toString(). + } + }) + } else { + return [1].map(number => { +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^ definition local 10 + const incremented = number + 1 +// ^^^^^^^^^^^ definition local 13 +// ^^^^^^ reference local 10 + return { + property: incremented, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^^^ reference local 13 + property2: incremented.toString(), +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +// ^^^^^^^^^^^ reference local 13 +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number#toString(). + } + }) + } +} + +export function createGenericClass(): GenericClass { +// ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/createGenericClass(). +// ^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass# +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + return new GenericClass([{ property: 1, property2: '2' }]) +// ^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +} + +export function handleGenericClass() { +// ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/handleGenericClass(). + return createGenericClass().map(({ property, property2 }) => ({ +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/createGenericClass(). +// ^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map(). +// ^^^^^^^^ definition local 19 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^ definition local 20 +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + property: property + 1, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^ reference local 19 + property2: property2 + '1', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +// ^^^^^^^^^ reference local 20 + })) +} + +export function handleShorthand() { +// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/handleShorthand(). + const property = '42' +// ^^^^^^^^ definition local 23 + const interfaceMethod = (): string => 'inferred' +// ^^^^^^^^^^^^^^^ definition local 26 + consumesInterface({ +//^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). + interfaceMethod, +// ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). + property, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. + }) +} + diff --git a/snapshots/output/syntax/src/object-literals-nested.ts b/snapshots/output/syntax/src/object-literals-nested.ts new file mode 100644 index 00000000..066beace --- /dev/null +++ b/snapshots/output/syntax/src/object-literals-nested.ts @@ -0,0 +1,69 @@ +// < definition syntax 1.0.0 src/`object-literals-nested.ts`/ + +import { Option } from './reusable-types' +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ + +interface Address { +// ^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address# + street: string +//^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. + people: Person[] +//^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# +} +interface Person { +// ^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person# + name: string +//^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. + address?: Address +//^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. +// ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address# +} + +export function handleNestedObjectLiterals(): Person { +// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/handleNestedObjectLiterals(). +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# + return { + name: 'John', +// ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. + address: { +// ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. + street: 'Oxford Street', +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. + people: [ +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. + { + name: 'Susan', +// ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. + }, + ], + }, + } +} + +export function handleNestedTypeVariables(): Option { +// ^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/handleNestedTypeVariables(). +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# + return { + value: { +// ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. + name: 'John', +// ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. + address: { +// ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. + street: 'Oxford Street', +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. + people: [ +// ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. + { + name: 'Susan', +// ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. + }, + ], + }, + }, + } +} + diff --git a/snapshots/output/syntax/src/object-literals.ts b/snapshots/output/syntax/src/object-literals.ts new file mode 100644 index 00000000..8e9d0f55 --- /dev/null +++ b/snapshots/output/syntax/src/object-literals.ts @@ -0,0 +1,169 @@ +// < definition syntax 1.0.0 src/`object-literals.ts`/ + +import { Configuration } from './reusable-types' +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ + +function random(): number { +// ^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/random(). + return Math.random() +// ^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math# +// ^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math. +// ^^^^ reference typescript 5.3.3 lib/`lib.es2015.core.d.ts`/Math# +// ^^^^ reference typescript 5.3.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Math# +// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Math#random(). +} + +export function handleArrayLiteral(): Configuration[] { +// ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/handleArrayLiteral(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + return [ + { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + }, + ] +} + +export function returnStatement(): Configuration { +// ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/returnStatement(). +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + if (random() > 0) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + for (let i = 0; i < 9; i++) { +// ^ definition local 2 +// ^ reference local 2 +// ^ reference local 2 + if (random() > i) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). +// ^ reference local 2 + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + } + for (const i of [1, 2, 3]) { +// ^ definition local 5 + if (random() > i) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). +// ^ reference local 5 + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + } + for (const i in { '1': 2 }) { +// ^ definition local 8 +// ^^^ definition syntax 1.0.0 src/`object-literals.ts`/`'1'0`: + if (random() > Number.parseInt(i)) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). +// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number# +// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number. +// ^^^^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Number# +// ^^^^^^ reference typescript 5.3.3 lib/`lib.es2020.number.d.ts`/Number# +// ^^^^^^^^ reference typescript 5.3.3 lib/`lib.es2015.core.d.ts`/NumberConstructor#parseInt(). +// ^ reference local 8 + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + } + while (random() < 0) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + do { + if (random() > 0) { +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). + return { + property: 41, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + } + } while (random() < 0) +// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). + + return { + property: 42, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '41', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } +} + +export function constDeclaration(): number[] { +// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/constDeclaration(). + var configuration1: Configuration = { +// ^^^^^^^^^^^^^^ definition local 11 +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + property: 1, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '1', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + configuration1 = { +//^^^^^^^^^^^^^^ reference local 11 + property: 2, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '2', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + let configuration2: Configuration = { +// ^^^^^^^^^^^^^^ definition local 14 +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + property: 3, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '3', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + configuration2.property = configuration1.property +//^^^^^^^^^^^^^^ reference local 14 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +// ^^^^^^^^^^^^^^ reference local 11 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + const configuration3: Configuration = { +// ^^^^^^^^^^^^^^ definition local 17 +// ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# + property: 4, +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + property2: '4', +// ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. + } + return [ + configuration1.property, +// ^^^^^^^^^^^^^^ reference local 11 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + configuration2.property, +// ^^^^^^^^^^^^^^ reference local 14 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + configuration3.property, +// ^^^^^^^^^^^^^^ reference local 17 +// ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. + ] +} + diff --git a/snapshots/output/syntax/src/reusable-types.ts b/snapshots/output/syntax/src/reusable-types.ts new file mode 100644 index 00000000..fab8984b --- /dev/null +++ b/snapshots/output/syntax/src/reusable-types.ts @@ -0,0 +1,67 @@ +// < definition syntax 1.0.0 src/`reusable-types.ts`/ + +// Reusable types for other snapshot tests + +export interface Option { +// ^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Option# +// ^ definition syntax 1.0.0 src/`reusable-types.ts`/Option#[A] + value?: A +//^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Option#value. +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#[A] +} + +export interface Numbers { +// ^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Numbers# + property: number +//^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. +} +export interface Strings { +// ^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Strings# + property2: string +//^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. +} +export type Configuration = Numbers & Strings +// ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Configuration# +// ^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers# +// ^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings# + +export class GenericClass { +// ^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass# +// ^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] + constructor(public readonly values: A[]) {} +//^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``(). +// ^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``().(values) +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] + public map(fn: (a: A) => A): A[] { +// ^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map(). +// ^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map().(fn) +// ^ definition local 1 +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] + return this.values.map(a => fn(a)) +// ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``().(values) +// ^^^ reference typescript 5.3.3 lib/`lib.es5.d.ts`/Array#map(). +// ^ definition local 5 +// ^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map().(fn) +// ^ reference local 5 + } +} + +export interface Superinterface { +// ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface# + property: string +//^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. + interfaceMethod(): string +//^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). +} +export interface GenericInterface { +// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# +// ^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#[T] + property: T +//^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. +// ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#[T] + interfaceMethod(): string +//^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). +} + diff --git a/src/SnapshotTesting.ts b/src/SnapshotTesting.ts index b04578f9..8b91023c 100644 --- a/src/SnapshotTesting.ts +++ b/src/SnapshotTesting.ts @@ -272,7 +272,7 @@ export function formatSnapshot( out.push(commentSyntax) const isStartOfLine = range.start.character === 0 - if (!isStartOfLine) { + if (!isStartOfLine && range.start.character > 2) { out.push(' '.repeat(range.start.character - 2)) } From 379bb3aa3f3e9155c230a85b0956a612da182341 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 30 Sep 2024 11:59:07 +0200 Subject: [PATCH 11/11] adds links to definitions of inlined functions --- src/TypeScriptInternal.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/TypeScriptInternal.ts b/src/TypeScriptInternal.ts index 5067350f..e0a2c6b7 100644 --- a/src/TypeScriptInternal.ts +++ b/src/TypeScriptInternal.ts @@ -67,10 +67,12 @@ export function getTextOfJsxAttributeName(node: ts.JsxAttributeName): string { : `${ts.idText(node.namespace)}:${ts.idText(node.name)}` } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3557 type ObjectLiteralElementWithName = ts.ObjectLiteralElement & { name: ts.PropertyName parent: ts.ObjectLiteralExpression | ts.JsxAttributes } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3534 export function getContainingObjectLiteralElement( node: ts.Node ): ObjectLiteralElementWithName | undefined { @@ -82,6 +84,7 @@ export function getContainingObjectLiteralElement( : undefined } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3538 function getContainingObjectLiteralElementWorker( node: ts.Node ): ts.ObjectLiteralElement | undefined { @@ -120,6 +123,7 @@ export function getPropertySymbolFromContextualType( return contextualType.getProperty(name) } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/utilities.ts?L2433 export function getNameFromPropertyName( name: ts.PropertyName ): string | undefined { @@ -133,12 +137,14 @@ export function getNameFromPropertyName( : getTextOfIdentifierOrLiteral(name) } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L5269 export function isStringOrNumericLiteralLike( node: ts.Node ): node is ts.StringLiteralLike | ts.NumericLiteral { return ts.isStringLiteralLike(node) || ts.isNumericLiteral(node) } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L5346 export function getTextOfIdentifierOrLiteral( node: ts.PropertyNameLiteral | ts.PrivateIdentifier ): string { @@ -149,6 +155,7 @@ export function getTextOfIdentifierOrLiteral( : node.text } +// https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L11012 export function getTextOfJsxNamespacedName(node: ts.JsxNamespacedName): string { return `${ts.idText(node.namespace)}:${ts.idText(node.name)}` }