├── .dockerignore ├── .eslintrc.js ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── labeler.yml └── workflows │ ├── ci.yml │ ├── labeler.yml │ ├── pr-auditor.yml │ ├── release.yml │ └── scip.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .tool-versions ├── .vscode ├── launch.json └── settings.json ├── Development.md ├── Dockerfile ├── LICENSE ├── README.md ├── dev ├── bump-version ├── lenient-n.sh ├── lenient-npm.sh └── lenient-yarn.sh ├── package.json ├── renovate.json ├── snapshots ├── inferTsConfig │ ├── js-project │ │ └── hello.js │ └── ts-project │ │ ├── hello.js │ │ └── hello.ts ├── input │ ├── enclosing-ranges-ts │ │ ├── index.ts │ │ ├── package.json │ │ └── tsconfig.json │ ├── enclosing-ranges │ │ ├── package.json │ │ ├── range.js │ │ └── tsconfig.json │ ├── invalid-package-json │ │ ├── package.json │ │ ├── packages │ │ │ ├── a │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── a.ts │ │ │ │ └── tsconfig.json │ │ │ └── b │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ └── b.ts │ │ │ │ └── tsconfig.json │ │ ├── pnpm-lock.yaml │ │ ├── pnpm-workspace.yaml │ │ └── tsconfig.json │ ├── multi-project │ │ ├── package.json │ │ ├── packages │ │ │ ├── a │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── index.ts │ │ │ │ └── tsconfig.json │ │ │ ├── b │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── b.ts │ │ │ │ ├── tsconfig.json │ │ │ │ └── tsconfig.tsbuildinfo │ │ │ └── tsconfig.base.json │ │ ├── tsconfig.json │ │ ├── tsconfig.packages.json │ │ └── yarn.lock │ ├── pnpm-workspaces │ │ ├── package.json │ │ ├── packages │ │ │ ├── a │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ └── a.ts │ │ │ │ └── tsconfig.json │ │ │ └── b │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ └── b.ts │ │ │ │ ├── tsconfig.json │ │ │ │ └── tsconfig.tsbuildinfo │ │ ├── pnpm-lock.yaml │ │ ├── pnpm-workspace.yaml │ │ └── tsconfig.json │ ├── pure-js │ │ ├── package.json │ │ └── src │ │ │ └── main.js │ ├── react │ │ ├── package.json │ │ ├── src │ │ │ ├── LoaderInput.tsx │ │ │ ├── MyTSXElement.tsx │ │ │ └── UseMyTSXElement.tsx │ │ └── tsconfig.json │ └── syntax │ │ ├── dump.svg │ │ ├── package.json │ │ ├── src │ │ ├── ClassWithPrivate.ts │ │ ├── accessors.ts │ │ ├── class.ts │ │ ├── conflicting-const-interface.ts │ │ ├── constructor.ts │ │ ├── decorators.ts │ │ ├── destructuring.ts │ │ ├── enum.ts │ │ ├── function.ts │ │ ├── import.ts │ │ ├── inheritance.ts │ │ ├── interface.ts │ │ ├── issue-45.d.ts │ │ ├── local.ts │ │ ├── module.d.ts │ │ ├── namespace.ts │ │ ├── object-literals-arrow-function.ts │ │ ├── object-literals-call-signatures.ts │ │ ├── object-literals-nested.ts │ │ ├── object-literals.ts │ │ ├── overload.d.ts │ │ ├── property-assignment-reference.ts │ │ ├── property-assignment.ts │ │ ├── reusable-types.ts │ │ ├── string-literals.ts │ │ ├── structural-type.ts │ │ ├── type-alias.ts │ │ ├── type-parameter.ts │ │ ├── typings.d.ts │ │ └── typings.ts │ │ ├── tsconfig.json │ │ └── yarn.lock ├── output │ ├── enclosing-ranges-ts │ │ └── index.ts │ ├── enclosing-ranges │ │ └── range.js │ ├── invalid-package-json │ │ └── packages │ │ │ └── a │ │ │ └── src │ │ │ └── a.ts │ ├── multi-project │ │ └── packages │ │ │ ├── a │ │ │ └── src │ │ │ │ └── index.ts │ │ │ └── b │ │ │ └── src │ │ │ └── b.ts │ ├── pnpm-workspaces │ │ └── packages │ │ │ ├── a │ │ │ └── src │ │ │ │ └── a.ts │ │ │ └── b │ │ │ └── src │ │ │ └── b.ts │ ├── pure-js │ │ └── src │ │ │ └── main.js │ ├── react │ │ └── src │ │ │ ├── LoaderInput.tsx │ │ │ ├── MyTSXElement.tsx │ │ │ └── UseMyTSXElement.tsx │ └── syntax │ │ └── src │ │ ├── ClassWithPrivate.ts │ │ ├── accessors.ts │ │ ├── class.ts │ │ ├── conflicting-const-interface.ts │ │ ├── constructor.ts │ │ ├── decorators.ts │ │ ├── destructuring.ts │ │ ├── enum.ts │ │ ├── function.ts │ │ ├── import.ts │ │ ├── inheritance.ts │ │ ├── interface.ts │ │ ├── issue-45.d.ts │ │ ├── local.ts │ │ ├── module.d.ts │ │ ├── namespace.ts │ │ ├── object-literals-arrow-function.ts │ │ ├── object-literals-call-signatures.ts │ │ ├── object-literals-nested.ts │ │ ├── object-literals.ts │ │ ├── overload.d.ts │ │ ├── property-assignment-reference.ts │ │ ├── property-assignment.ts │ │ ├── reusable-types.ts │ │ ├── string-literals.ts │ │ ├── structural-type.ts │ │ ├── type-alias.ts │ │ ├── type-parameter.ts │ │ └── typings.ts ├── package.json └── yarn.lock ├── src ├── .gitattributes ├── CommandLineOptions.test.ts ├── CommandLineOptions.ts ├── Counter.ts ├── Descriptor.ts ├── FileIndexer.ts ├── Input.ts ├── Packages.ts ├── Position.ts ├── ProjectIndexer.test.ts ├── ProjectIndexer.ts ├── Range.ts ├── ScipSymbol.ts ├── SnapshotTesting.ts ├── TypeScriptInternal.ts ├── inferTsconfig.test.ts ├── inferTsconfig.ts ├── main.test.ts ├── main.ts ├── parseHumanByteSizeIntoNumber.test.ts ├── parseHumanByteSizeIntoNumber.ts └── scip.ts ├── tsconfig.json └── yarn.lock /.dockerignore: -------------------------------------------------------------------------------- 1 | **/.git 2 | node_modules 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: '@sourcegraph/eslint-config', 3 | env: { 4 | browser: true, 5 | node: true, 6 | }, 7 | parserOptions: { 8 | project: 'tsconfig.json', 9 | }, 10 | ignorePatterns: ['temp', 'scip.ts', 'snapshots'], 11 | rules: { 12 | 'no-sync': 'off', 13 | 'jsdoc/check-indentation': 'off', 14 | 'class-methods-use-this': 'error', 15 | }, 16 | } 17 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Test plan 2 | 3 | 10 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | team/graph: 2 | - '/.*/' 3 | graph/scip-typescript: 4 | - '/.*/' 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | node-version: [18.x, 20.x] # NOTE: Keep in sync with README. 13 | # See Node.js release schedule: https://nodejs.org/en/about/previous-releases 14 | # - v18 EOL: Apr 30 2025 15 | # - v20 EOL: Apr 30 2026 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Use Node.js ${{ matrix.node-version }} 19 | uses: actions/setup-node@v3 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | - run: yarn install 23 | - run: npm run test 24 | lint: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@v3 28 | - run: yarn install 29 | - run: yarn run prettier-check 30 | - run: yarn run eslint 31 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: 'Issue Labeler' 2 | on: 3 | issues: 4 | types: [opened, edited] 5 | 6 | permissions: 7 | issues: write 8 | contents: read 9 | 10 | jobs: 11 | triage: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: github/issue-labeler@v3.4 15 | with: 16 | configuration-path: .github/labeler.yml 17 | enable-versioned-regex: 0 18 | repo-token: ${{ github.token }} 19 | -------------------------------------------------------------------------------- /.github/workflows/pr-auditor.yml: -------------------------------------------------------------------------------- 1 | # See https://docs.sourcegraph.com/dev/background-information/ci#pr-auditor 2 | name: pr-auditor 3 | on: 4 | pull_request_target: 5 | types: [closed, edited, opened, synchronize, ready_for_review] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | check-pr: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | with: 14 | repository: 'sourcegraph/devx-service' 15 | token: ${{ secrets.PR_AUDITOR_TOKEN }} 16 | - uses: actions/setup-go@v4 17 | with: { go-version: '1.22' } 18 | 19 | - run: 'go run ./cmd/pr-auditor' 20 | env: 21 | GITHUB_EVENT_PATH: ${{ env.GITHUB_EVENT_PATH }} 22 | GITHUB_TOKEN: ${{ secrets.PR_AUDITOR_TOKEN }} 23 | GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} 24 | report_failure: 25 | needs: check-pr 26 | if: ${{ failure() }} 27 | uses: sourcegraph/workflows/.github/workflows/report-job-failure.yml@main 28 | secrets: inherit 29 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | branches: 8 | - main 9 | 10 | jobs: 11 | release-image: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: docker/setup-buildx-action@v2 16 | - uses: actions/setup-node@v3 17 | with: 18 | node-version: 20 19 | registry-url: 'https://registry.npmjs.org' 20 | - run: yarn install 21 | - run: yarn run build 22 | - run: du -h dist/src/main.js 23 | - run: npm publish --access public 24 | if: startsWith(github.ref, 'refs/tags/v') 25 | env: 26 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 27 | - run: echo "PATCH=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV 28 | - run: echo "MINOR=${PATCH%.*}" >> $GITHUB_ENV 29 | - run: echo "MAJOR=${MINOR%.*}" >> $GITHUB_ENV 30 | - name: Login to DockerHub 31 | uses: docker/login-action@v2 32 | with: 33 | username: ${{ secrets.DOCKER_USERNAME }} 34 | password: ${{ secrets.DOCKER_PASSWORD }} 35 | - name: Build and push snapshot 36 | if: github.ref == 'refs/heads/main' 37 | uses: docker/build-push-action@v3 38 | with: 39 | push: true 40 | tags: | 41 | sourcegraph/scip-typescript:latest-snapshot 42 | - name: Build and push tag 43 | if: startsWith(github.ref, 'refs/tags/v') 44 | uses: docker/build-push-action@v3 45 | with: 46 | push: true 47 | tags: | 48 | sourcegraph/scip-typescript:latest 49 | sourcegraph/scip-typescript:${{ env.PATCH }} 50 | sourcegraph/scip-typescript:${{ env.MINOR }} 51 | sourcegraph/scip-typescript:${{ env.MAJOR }} 52 | -------------------------------------------------------------------------------- /.github/workflows/scip.yml: -------------------------------------------------------------------------------- 1 | name: 'Upload SCIP to Sourcegraph' 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - run: yarn install 13 | - run: yarn global add tsx @sourcegraph/src 14 | - run: tsx src/main.ts index 15 | 16 | - name: Upload SCIP to Cloud 17 | run: src code-intel upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress 18 | env: 19 | SRC_ENDPOINT: https://sourcegraph.com/ 20 | SRC_ACCESS_TOKEN: ${{ secrets.SRC_ACCESS_TOKEN_DOTCOM }} 21 | 22 | - name: Upload SCIP to S2 23 | run: src code-intel upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress 24 | env: 25 | SRC_ENDPOINT: https://sourcegraph.sourcegraph.com/ 26 | SRC_ACCESS_TOKEN: ${{ secrets.SRC_ACCESS_TOKEN_S2 }} 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .eslintcache 4 | yarn-error.log 5 | snapshots/output/**/*.scip 6 | tsconfig.tsbuildinfo 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | src/scip.ts 4 | snapshots/output 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "trailingComma": "es5", 4 | "singleQuote": true, 5 | "useTabs": false, 6 | "arrowParens": "avoid" 7 | } 8 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs 20.17.0 2 | pnpm 9.11.0 3 | yarn 1.22.22 4 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Debug Tests", 8 | "runtimeExecutable": "npm", 9 | "runtimeArgs": ["run", "test"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /Development.md: -------------------------------------------------------------------------------- 1 | # Developing scip-typescript 2 | 3 | Please note that the yarn version used by CI is `v1.22.19` - you should use this version as well to prevent lockfile conflicts. 4 | 5 | ## References 6 | 7 | - VS Code is a good reference point for the "correct" behavior 8 | for code navigation functionality. 9 | - Keep a local checkout of Microsoft/TypeScript for checking out code examples. 10 | Most TypeScript APIs are lacking in documentation, 11 | so reading the code is the best way to understand how things work. 12 | 13 | ## Running tests 14 | 15 | ```sh 16 | # Run snapshot tests 17 | npm run test 18 | # Update snapshot test outputs 19 | npm run update-snapshots 20 | ``` 21 | 22 | ## Debugging 23 | 24 | ### Print debugging 25 | 26 | For print debugging, you can print types using: 27 | 28 | ```typescript 29 | checker.typeToString(type) 30 | ``` 31 | 32 | TODO: Document how to print the AST for a file 33 | 34 | TODO: Document how to print an individual AST node 35 | 36 | ## Skipping files/test for local development 37 | 38 | Search for the query `"Uncomment below if you want to skip` to find places where 39 | you can uncomment code to skip tests/files for a faster edit/test/debug feedback 40 | loop during local development. 41 | 42 | ## Snapshotting arbitrary projects 43 | 44 | ```sh 45 | cd /path/to/dir 46 | DIR=/path/to/scip-typescript "$DIR/node_modules/.bin/tsx" "$DIR/src/main.ts" index # add --yarn-workspaces if applicable 47 | lsif-typed index.scip > dump.lsif # from github.com/sourcegraph/sourcegraph/lib/codeintel/tools/lsif-typed 48 | lsif-java snapshot-lsif # from github.com/sourcegraph/lsif-java 49 | ``` 50 | 51 | ## Publishing a release 52 | 53 | First, make sure you are on the main branch and have no dirty changes. 54 | 55 | Next, run the `dev/bump-version` script to bump the version in package.json and 56 | push a git tag to trigger a CI job. 57 | 58 | ``` 59 | ./dev/bump-version VERSION_TO_RELEASE 60 | # example: ./dev/bump-version 2.3.1 61 | ``` 62 | 63 | Once the release job has finished, create a GitHub release 64 | https://github.com/sourcegraph/scip-typescript/releases/new 65 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # When updating the version of the base container, please use the 2 | # SHA256 listed under 'Index digest' on Docker Hub, 3 | # not the 'Manifest digest'. 4 | # 5 | # This ensures that when pulling the container, Docker will detect 6 | # the platform and pull the correct image (if it exists) 7 | # 8 | # Alternate way of determining the Index digest using the docker CLI. 9 | # 10 | # $ docker buildx imagetools inspect node:22.12.0-slim 11 | # Name: docker.io/library/node:22.12.0-slim 12 | # MediaType: application/vnd.oci.image.index.v1+json 13 | # Digest: sha256:a4b757cd491c7f0b57f57951f35f4e85b7e1ad54dbffca4cf9af0725e1650cd8 14 | # And use this digest in FROM 15 | ARG base_sha=a4b757cd491c7f0b57f57951f35f4e85b7e1ad54dbffca4cf9af0725e1650cd8 16 | 17 | FROM node:22.12.0-slim@sha256:${base_sha} 18 | 19 | ENV NODE_OPTIONS=--max-old-space-size=4096 20 | 21 | RUN apt update && \ 22 | apt install -y git bash curl ca-certificates python3 make build-essential automake autoconf curl && \ 23 | rm -rf /var/lib/apt/lists/* && \ 24 | npm install -g n yarn pnpm --force 25 | 26 | WORKDIR /app 27 | 28 | COPY . . 29 | RUN npm install && npm run build && npm install -g . 30 | 31 | WORKDIR /src 32 | 33 | RUN mv /usr/local/bin/yarn /usr/local/bin/actual-yarn 34 | COPY ./dev/lenient-yarn.sh /usr/local/bin/yarn 35 | 36 | RUN mv /usr/local/bin/npm /usr/local/bin/actual-npm 37 | COPY ./dev/lenient-npm.sh /usr/local/bin/npm 38 | 39 | RUN mv /usr/local/bin/n /usr/local/bin/actual-n 40 | COPY ./dev/lenient-n.sh /usr/local/bin/n 41 | 42 | ENTRYPOINT ["scip-typescript"] 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # scip-typescript 2 | 3 | [SCIP](https://github.com/sourcegraph/scip) indexer for TypeScript and JavaScript. 4 | 5 | ## Quick start 6 | 7 | ### Installation 8 | 9 | ```sh 10 | npm install -g @sourcegraph/scip-typescript 11 | ``` 12 | 13 | Currently, Node v18, Node v20 are supported. 14 | 15 | ### Indexing a TypeScript project 16 | 17 | Navigate to the project root, containing `tsconfig.json`. 18 | 19 | ```sh 20 | npm install # or yarn install 21 | scip-typescript index 22 | ``` 23 | 24 | ### Indexing a JavaScript project 25 | 26 | Navigate to the project root, containing `package.json`. 27 | 28 | ```sh 29 | npm install # or yarn install 30 | scip-typescript index --infer-tsconfig 31 | ``` 32 | 33 | To improve the quality of indexing results for JavaScript, 34 | consider adding `@types/*` packages as `devDependencies` in `package.json`. 35 | 36 | ### Index a TypeScript project using Yarn workspaces 37 | 38 | Navigate to the project root, containing `package.json`. 39 | 40 | ```sh 41 | yarn install 42 | 43 | scip-typescript index --yarn-workspaces 44 | ``` 45 | 46 | ### Index a TypeScript project using pnpm workspaces 47 | 48 | Navigate to the project root, containing `package.json`. 49 | 50 | ```sh 51 | pnpm install 52 | 53 | scip-typescript index --pnpm-workspaces 54 | ``` 55 | 56 | ### Indexing in CI 57 | 58 | Add the following run steps to your CI pipeline: 59 | 60 | ```sh 61 | npm install -g @sourcegraph/scip-typescript @sourcegraph/src 62 | npm install # or yarn install 63 | scip-typescript index 64 | # Upload index with any necessary tokens (shown here using GitHub workflow syntax) 65 | src lsif upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress 66 | ``` 67 | 68 | For more examples, see the 69 | [Sourcegraph docs](https://docs.sourcegraph.com/code_intelligence/how-to/index_a_typescript_and_javascript_repository). 70 | 71 | ### Troubleshooting stalled progress 72 | 73 | If `scip-typescript index` is not showing progress, try running it again with 74 | the `--progress-bar` flag. The progress bar prints out the current file being 75 | indexed that could reveal details why progress is stalling. The progress bar 76 | is disabled by default because it prints out a lot of noise in CI logs, and 77 | the most common environment to run scip-typescript is in CI. 78 | 79 | ### Dealing with out of memory issues (OOM) 80 | 81 | You may experience OOM issues when indexing large codebases 82 | 83 | ``` 84 | <--- JS stacktrace ---> 85 | 86 | FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 87 | 1: 0xb7b150 node::Abort() [node] 88 | 2: 0xa8c89a [node] 89 | 3: 0xd62ea0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 90 | 4: 0xd63247 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 91 | 5: 0xf40945 [node] 92 | 6: 0xf52e2d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 93 | ... 94 | ``` 95 | 96 | To fix this problem, try one of the following steps: 97 | 98 | - Add `--no-global-caches` to the index command like this `scip-typescript 99 | index --no-global-caches REST_OF_THE_COMMAND`. By default, scip-typescript 100 | caches symbol indexing across TypeScript projects to speed up indexing. This 101 | cache increases the memory footprint, which can cause OOM. Disabling this cache 102 | slows down indexing but reduces the memory footprint. 103 | - Increase memory to the Node.js process by running scip-typescript like this 104 | `node --max-old-space-size=16000 "$(which scip-typescript)" index REST_OF_COMMAND`. 105 | Replace 16000 with an even larger number if your computer has bigger RAM. 106 | 107 | ## Migrating from lsif-node 108 | 109 | Before creating scip-typescript, we used another TypeScript indexer called 110 | [lsif-node](https://github.com/sourcegraph/lsif-node). We recommend migrating 111 | to scip-typescript if you are using lsif-node. 112 | 113 | Follow the steps below to migrate from lsif-node to scip-typescript: 114 | 115 | - Replace usages of the `lsif-tsc -p ARGUMENTS` command with `scip-typescript index ARGUMENTS`. 116 | - Upgrade to the latest version of the `src` command-line interface, which you 117 | can install via `yarn global add @sourcegraph/src`. It’s okay if the version 118 | of your `src` command-line interface does not match the version of your 119 | Sourcegraph instance. 120 | 121 | ## Contributing 122 | 123 | See [Development.md](./Development.md) for docs on how to work on this project. 124 | 125 | Contributors should follow the [Sourcegraph Community Code of Conduct](https://handbook.sourcegraph.com/company-info-and-process/community/code_of_conduct/). 126 | -------------------------------------------------------------------------------- /dev/bump-version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eux 3 | 4 | # Assert that current branch is main 5 | git rev-parse --abbrev-ref HEAD | grep -q main 6 | 7 | # Assert that there are no uncommitted changes 8 | git diff-index --quiet HEAD -- 9 | 10 | NEW_VERSION="$1" 11 | if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 12 | echo "You need to specify a version number in the format X.Y.Z" 13 | exit 1 14 | fi 15 | 16 | echo "Updating package.json." 17 | yarn version --no-git-tag-version --new-version "$NEW_VERSION" 18 | git commit -am "Release v$NEW_VERSION." --allow-empty 19 | 20 | # Commit and tag new version 21 | VERSION_TAG="v$NEW_VERSION" 22 | git add . 23 | git commit -m "Bump version to $VERSION_TAG" --allow-empty 24 | git push origin main 25 | git tag -af "$VERSION_TAG" -m "Version $NEW_VERSION" 26 | git push -f origin "$VERSION_TAG" 27 | -------------------------------------------------------------------------------- /dev/lenient-n.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eux 3 | 4 | /usr/local/bin/actual-n "$@" || echo "scip-typescript: ignoring n auto failure, will try to auto-index the project with the pre-installed node version" 5 | -------------------------------------------------------------------------------- /dev/lenient-npm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eux 3 | 4 | 5 | if [ $# -gt 0 ] && [ "$1" == "install" ]; then 6 | /usr/local/bin/actual-npm "$@" || echo "scip-typescript: ignoring npm install failure, will try to auto-index the project with partial dependency information" 7 | else 8 | /usr/local/bin/actual-npm "$@" 9 | fi 10 | -------------------------------------------------------------------------------- /dev/lenient-yarn.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eux 3 | 4 | ADDITIONAL_ARGS="--ignore-engines" 5 | if [ "$(/usr/local/bin/actual-yarn --version | cut -d'.' -f1)" -gt 1 ]; then 6 | ADDITIONAL_ARGS="" 7 | fi 8 | 9 | if [ $# -gt 1 ] && [ "$1" == "install" ]; then 10 | /usr/local/bin/actual-yarn $ADDITIONAL_ARGS "$@" || echo "scip-typescript: ignoring yarn install failure, will try to auto-index the project with partial dependency information" 11 | else 12 | /usr/local/bin/actual-yarn $ADDITIONAL_ARGS "$@" 13 | fi 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sourcegraph/scip-typescript", 3 | "version": "v0.3.15", 4 | "description": "SCIP indexer for TypeScript and JavaScript", 5 | "publisher": "sourcegraph", 6 | "bin": "dist/src/main.js", 7 | "main": "./dist/src/main.js", 8 | "scripts": { 9 | "prettier": "prettier --write --list-different '**/*.{ts,js?(on),md,yml}'", 10 | "prettier-check": "prettier --check '**/*.{ts,js?(on),md,yml}'", 11 | "tslint": "tslint -p tsconfig.json --format stylish", 12 | "eslint": "eslint --cache '**/*.ts?(x)'", 13 | "build": "node ./node_modules/typescript/bin/tsc -b .", 14 | "test": "uvu -r tsm --ignore dist", 15 | "update-snapshots": "uvu -r tsm --ignore dist --update-snapshots", 16 | "prepare": "cd snapshots && yarn && cd input/multi-project && yarn && cd ../pnpm-workspaces && pnpm install" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/sourcegraph/scip-typescript.git" 21 | }, 22 | "keywords": [ 23 | "scip", 24 | "typescript", 25 | "compiler", 26 | "javascript", 27 | "indexer" 28 | ], 29 | "author": "Code Intelligence at Sourcegraph", 30 | "license": "Apache-2.0", 31 | "bugs": { 32 | "url": "https://github.com/sourcegraph/scip-typescript/issues" 33 | }, 34 | "homepage": "https://github.com/sourcegraph/scip-typescript#readme", 35 | "dependencies": { 36 | "commander": "^12.1.0", 37 | "google-protobuf": "^3.21.4", 38 | "progress": "^2.0.3", 39 | "typescript": "^5.6.2" 40 | }, 41 | "devDependencies": { 42 | "@sourcegraph/eslint-config": "0.37.1", 43 | "@sourcegraph/prettierrc": "3.0.3", 44 | "@sourcegraph/tsconfig": "4.0.1", 45 | "@types/diff": "7.0.1", 46 | "@types/google-protobuf": "3.15.12", 47 | "@types/node": "20.16.10", 48 | "@types/progress": "2.0.7", 49 | "@typescript-eslint/eslint-plugin": "^7.18.0", 50 | "@typescript-eslint/parser": "^7.18.0", 51 | "diff": "7.0.0", 52 | "eslint": "^8.57.1", 53 | "eslint-plugin-etc": "^2.0.3", 54 | "eslint-plugin-rxjs": "^5.0.3", 55 | "eslint-plugin-unicorn": "^55.0.0", 56 | "eslint-plugin-unused-imports": "^4.1.4", 57 | "pnpm": "9.11.0", 58 | "prettier": "3.5.3", 59 | "tsm": "^2.3.0", 60 | "tsx": "^4.19.1", 61 | "typescript-eslint": "7.18.0", 62 | "uvu": "^0.5.6" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/renovate", 3 | "extends": ["github>sourcegraph/renovate-config"], 4 | "reviewers": [] 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/inferTsConfig/js-project/hello.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/scip-typescript/000e34ae226d4d343e803d1e26e23ea4ddca2256/snapshots/inferTsConfig/js-project/hello.js -------------------------------------------------------------------------------- /snapshots/inferTsConfig/ts-project/hello.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/scip-typescript/000e34ae226d4d343e803d1e26e23ea4ddca2256/snapshots/inferTsConfig/ts-project/hello.js -------------------------------------------------------------------------------- /snapshots/inferTsConfig/ts-project/hello.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcegraph/scip-typescript/000e34ae226d4d343e803d1e26e23ea4ddca2256/snapshots/inferTsConfig/ts-project/hello.ts -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges-ts/index.ts: -------------------------------------------------------------------------------- 1 | // format-options: showRanges 2 | 3 | interface Foo { 4 | bar: string 5 | test: () => void 6 | } 7 | 8 | interface Single { 9 | t: T 10 | } 11 | 12 | enum SimpleEnum { 13 | Case1, 14 | Case2, 15 | } 16 | 17 | type SimpleTypeAlias = SimpleEnum 18 | 19 | type ComplexTypeAlias = Single> 20 | -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enclosing-ranges-ts", 3 | "version": "1.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enclosing-ranges", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges/range.js: -------------------------------------------------------------------------------- 1 | // format-options: showRanges 2 | 3 | const test = () => { 4 | const a = 'a' 5 | const b = 'b' 6 | 7 | return a + b 8 | } 9 | 10 | function test2() { 11 | const a = 'a' 12 | const b = 'b' 13 | 14 | return a + b 15 | } 16 | 17 | class Test { 18 | constructor() { 19 | const a = 'a' 20 | const b = 'b' 21 | 22 | return a + b 23 | } 24 | 25 | test() { 26 | const a = 'a' 27 | const b = 'b' 28 | 29 | return a + b 30 | } 31 | 32 | static test() { 33 | const a = 'a' 34 | const b = 'b' 35 | 36 | return a + b 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /snapshots/input/enclosing-ranges/tsconfig.json: -------------------------------------------------------------------------------- 1 | { "compilerOptions": { "allowJs": true } } 2 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "invalid-package-json", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "private": true, 12 | "packageManager": "pnpm@7.20.0" 13 | } 14 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/a", 3 | "description": "Example TS/JS project", 4 | "main": "src/a.ts", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "author": "", 9 | "license": "ISC" 10 | } 11 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/a/src/a.ts: -------------------------------------------------------------------------------- 1 | export function a(): string { 2 | return '' 3 | } 4 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/a/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": ".", 6 | "outDir": "dist" 7 | }, 8 | "include": ["src/*"] 9 | } 10 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Example TS/JS project", 3 | "main": "src/b.ts", 4 | "scripts": { 5 | "test": "echo \"Error: no test specified\" && exit 1" 6 | }, 7 | "author": "", 8 | "license": "ISC", 9 | "dependencies": { 10 | "@example/a": "1.0.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/b/src/b.ts: -------------------------------------------------------------------------------- 1 | import { a } from '@example/a' 2 | 3 | export function b() { 4 | return a() 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/packages/b/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": "./src", 6 | "sourceRoot": "src", 7 | "outDir": "dist" 8 | }, 9 | "include": ["src/*"], 10 | "references": [{ "path": "../a" }] 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: 5.4 2 | 3 | importers: 4 | 5 | .: 6 | specifiers: {} 7 | 8 | packages/a: 9 | specifiers: {} 10 | 11 | packages/b: 12 | specifiers: 13 | '@example/a': 1.0.0 14 | dependencies: 15 | '@example/a': link:../a 16 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/*' 3 | -------------------------------------------------------------------------------- /snapshots/input/invalid-package-json/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@sourcegraph/tsconfig", 3 | "compilerOptions": { 4 | "target": "es2020", 5 | "module": "commonjs", 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "esModuleInterop": true, 9 | "lib": ["esnext", "dom", "dom.iterable"], 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "skipLibCheck": true, 14 | "skipDefaultLibCheck": true, 15 | "noErrorTruncation": true, 16 | "importHelpers": true, 17 | "resolveJsonModule": true, 18 | "composite": true, 19 | "outDir": "out", 20 | "rootDir": "." 21 | }, 22 | "include": [], 23 | "exclude": ["out", "node_modules", "dist"] 24 | } 25 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multi-project", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "workspaces": [ 11 | "packages/*" 12 | ], 13 | "license": "ISC", 14 | "private": true 15 | } 16 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/a", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/a/src/index.ts: -------------------------------------------------------------------------------- 1 | // format-options: showDocs 2 | 3 | export function a(): string { 4 | return '' 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/a/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": ".", 6 | "outDir": "dist", 7 | "paths": { 8 | "@example/a/src/*": ["src/*"] 9 | } 10 | }, 11 | "include": ["src/*"] 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/b", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/b/src/b.ts: -------------------------------------------------------------------------------- 1 | import { a } from '@example/a/src' 2 | 3 | export function b() { 4 | return a() 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/b/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": "./src", 6 | "sourceRoot": "src", 7 | "outDir": "dist" 8 | }, 9 | "include": ["src/*"], 10 | "references": [{ "path": "../a" }] 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/packages/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "composite": true, 5 | "declaration": true, 6 | "declarationMap": true, 7 | "paths": { 8 | "a": ["packages/a/src"], 9 | "b": ["packages/b/src"] 10 | }, 11 | "outDir": "dist" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@sourcegraph/tsconfig", 3 | "compilerOptions": { 4 | "target": "es2020", 5 | "module": "commonjs", 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "esModuleInterop": true, 9 | "lib": ["esnext", "dom", "dom.iterable"], 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "skipLibCheck": true, 14 | "skipDefaultLibCheck": true, 15 | "noErrorTruncation": true, 16 | "importHelpers": true, 17 | "resolveJsonModule": true, 18 | "composite": true, 19 | "outDir": "out", 20 | "rootDir": "." 21 | }, 22 | "include": [], 23 | "exclude": ["out", "node_modules", "dist"] 24 | } 25 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/tsconfig.packages.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { 5 | "path": "./packages/a" 6 | }, 7 | { 8 | "path": "./packages/b" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/multi-project/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pnpm-workspaces", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "private": true, 12 | "packageManager": "pnpm@7.20.0" 13 | } 14 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/a", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/a.ts", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/a/src/a.ts: -------------------------------------------------------------------------------- 1 | export function a(): string { 2 | return '' 3 | } 4 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/a/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": ".", 6 | "outDir": "dist" 7 | }, 8 | "include": ["src/*"] 9 | } 10 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/b", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/b.ts", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@example/a": "1.0.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/b/src/b.ts: -------------------------------------------------------------------------------- 1 | import { a } from '@example/a' 2 | 3 | export function b() { 4 | return a() 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/packages/b/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "baseUrl": "./src", 6 | "sourceRoot": "src", 7 | "outDir": "dist" 8 | }, 9 | "include": ["src/*"], 10 | "references": [{ "path": "../a" }] 11 | } 12 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '9.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | importers: 8 | 9 | .: {} 10 | 11 | packages/a: {} 12 | 13 | packages/b: 14 | dependencies: 15 | '@example/a': 16 | specifier: 1.0.0 17 | version: link:../a 18 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/*' 3 | -------------------------------------------------------------------------------- /snapshots/input/pnpm-workspaces/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@sourcegraph/tsconfig", 3 | "compilerOptions": { 4 | "target": "es2020", 5 | "module": "commonjs", 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "esModuleInterop": true, 9 | "lib": ["esnext", "dom", "dom.iterable"], 10 | "sourceMap": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "skipLibCheck": true, 14 | "skipDefaultLibCheck": true, 15 | "noErrorTruncation": true, 16 | "importHelpers": true, 17 | "resolveJsonModule": true, 18 | "composite": true, 19 | "outDir": "out", 20 | "rootDir": "." 21 | }, 22 | "include": [], 23 | "exclude": ["out", "node_modules", "dist"] 24 | } 25 | -------------------------------------------------------------------------------- /snapshots/input/pure-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pure-js", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "private": true 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/pure-js/src/main.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | if (n <= 1) { 3 | return 0 4 | } 5 | return fib(n - 1) + fib(n - 2) 6 | } 7 | 8 | function print_fib(a) { 9 | console.log(fib(a)) 10 | } 11 | 12 | var y = 'Hello' 13 | function capture() { 14 | return y 15 | } 16 | const capture_lambda = () => { 17 | return y 18 | } 19 | 20 | for (var i = 0; i <= 10; i++) {} 21 | 22 | for (const x of [1, 2, 3]) { 23 | } 24 | 25 | var a = 0 26 | var a = 1 27 | print_fib(a) 28 | 29 | function forever() { 30 | return forever() 31 | } 32 | 33 | function use_before_def() { 34 | print_fib(n) 35 | var n = 10 36 | 37 | if (forever()) { 38 | var m = 10 39 | } 40 | print_fib(m) 41 | } 42 | 43 | function var_function_scope() { 44 | var k = 0 45 | if (forever()) { 46 | var k = 1 47 | } 48 | print_fib(k) 49 | } 50 | 51 | function array_of_objects() { 52 | var a = [{ element: 0 }, { element: 1 }] 53 | } 54 | -------------------------------------------------------------------------------- /snapshots/input/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-example", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "private": true 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/react/src/LoaderInput.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | /** Takes loading prop, input component as child */ 4 | interface Props { 5 | loading: boolean 6 | children: React.ReactNode 7 | } 8 | 9 | export const LoaderInput: React.FunctionComponent = ({ 10 | loading, 11 | children, 12 | }) => ( 13 |
14 | {children} 15 | {loading &&

spinner

} 16 |
17 | ) 18 | 19 | export const LoaderInput2: React.FunctionComponent = props => { 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /snapshots/input/react/src/MyTSXElement.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export interface MyProps {} 4 | 5 | export const MyTSXElement: React.FunctionComponent = ({}) => (

) -------------------------------------------------------------------------------- /snapshots/input/react/src/UseMyTSXElement.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import { MyProps, MyTSXElement } from "./MyTSXElement"; 4 | 5 | export const _: React.FunctionComponent = 6 | ({}) => () -------------------------------------------------------------------------------- /snapshots/input/react/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react", 4 | "esModuleInterop": true, 5 | "outDir": "dist" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /snapshots/input/syntax/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "syntax", 3 | "version": "1.0.0", 4 | "description": "Example TS/JS project", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "private": true 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/ClassWithPrivate.ts: -------------------------------------------------------------------------------- 1 | export class ClassWithPrivate { 2 | #privateField 3 | #privateFieldWithInitializer = 42 4 | 5 | #privateMethod() { 6 | this.#privateField = 'private field' 7 | return this.#privateField 8 | } 9 | 10 | static #privateStaticField 11 | static #privateStaticFieldWithInitializer = 42 12 | 13 | static #privateStaticMethod() {} 14 | public publicMethod(): any[] { 15 | return [ 16 | this.#privateField, 17 | this.#privateFieldWithInitializer, 18 | this.#privateMethod(), 19 | ClassWithPrivate.#privateStaticMethod(), 20 | ClassWithPrivate.#privateStaticField, 21 | ClassWithPrivate.#privateStaticFieldWithInitializer, 22 | ] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/accessors.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | _length: number = 0 3 | get length(): number { 4 | return this._length 5 | } 6 | set length(value: number) { 7 | this._length = value 8 | } 9 | 10 | _capacity: number = 0 11 | get capacity(): number { 12 | return this._capacity 13 | } 14 | } 15 | 16 | export class D { 17 | _length: number = 0 18 | public get length(): number { 19 | return this._length 20 | } 21 | public set length(value: number) { 22 | this._length = value 23 | } 24 | 25 | _capacity: number = 0 26 | public get capacity(): number { 27 | return this._capacity 28 | } 29 | private set capacity(value: number) { 30 | this._capacity = value 31 | } 32 | public unsafeSetCapacity(value: number): void { 33 | this.capacity = value 34 | } 35 | } 36 | 37 | function g(_: number): void {} 38 | 39 | function f() { 40 | const c = new C() 41 | c.length = 10 42 | g(c.length) 43 | g(c.capacity) 44 | g(c.length) 45 | 46 | const d = new D() 47 | d.length = 0 48 | g(d.length) 49 | g(d.capacity) 50 | g(D.length) 51 | } 52 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/class.ts: -------------------------------------------------------------------------------- 1 | export class Class { 2 | public classProperty: string 3 | constructor(constructorParam: string) { 4 | this.classProperty = constructorParam 5 | } 6 | public method(methodParam: string): string { 7 | return this.privateMethod(methodParam) 8 | } 9 | public static staticMethod(methodParam: string): string { 10 | return methodParam 11 | } 12 | private privateMethod(methodParam: string): string { 13 | return methodParam 14 | } 15 | } 16 | 17 | export function newClass(param: string): string { 18 | const instance = new Class(param).classProperty 19 | const instance2 = Class.staticMethod(param) 20 | return instance + instance2 21 | } 22 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/conflicting-const-interface.ts: -------------------------------------------------------------------------------- 1 | export const ConflictingConst = 42 2 | export interface ConflictingConst {} 3 | export class ImplementsConflictingConst implements ConflictingConst {} 4 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/constructor.ts: -------------------------------------------------------------------------------- 1 | namespace Yay { 2 | export class SuperConstructor { 3 | constructor(public readonly property: number) {} 4 | } 5 | 6 | export namespace Woo { 7 | export class MyClass { 8 | constructor() {} 9 | } 10 | } 11 | } 12 | 13 | export class SuperConstructor2 { 14 | constructor(public readonly property: number) {} 15 | } 16 | 17 | export function useConstructor(): Yay.SuperConstructor { 18 | return new Yay.SuperConstructor(10) 19 | } 20 | 21 | export function useConstructor2(): SuperConstructor2 { 22 | return new SuperConstructor2(10) 23 | } 24 | 25 | export function useConstructor3(): Yay.Woo.MyClass { 26 | return new Yay.Woo.MyClass() 27 | } 28 | 29 | export class NoConstructor { 30 | property: number 31 | } 32 | 33 | export function useNoConstructor() { 34 | return new NoConstructor() 35 | } 36 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/decorators.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from './reusable-types' 2 | 3 | function MyDecorator(value: Configuration) { 4 | return function (target: Function) { 5 | console.log(`MyDecorator is called with value: ${value}`) 6 | } 7 | } 8 | 9 | @MyDecorator({ property: 42, property2: '42' }) 10 | class MyClass { 11 | //... 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/destructuring.ts: -------------------------------------------------------------------------------- 1 | interface Props { 2 | a: number 3 | } 4 | const props: Props = { a: 42 } 5 | 6 | export function objectDestructuring(): number[] { 7 | const { a: b } = props 8 | return [props].map(({ a }) => a + b) 9 | } 10 | 11 | export function arrayDestructuring(): number[] { 12 | const [b] = [props] 13 | return [[b]].map(([a]) => a.a) 14 | } 15 | 16 | export function nestedDestructuring(): number[] { 17 | const [[b]] = [[props]] 18 | return [[props]].map(([{ a }]) => a + b.a) 19 | } 20 | 21 | export function forLoopObjectDestructuring(): number { 22 | for (const { a } of [props]) { 23 | return a 24 | } 25 | return 1 26 | } 27 | 28 | export function forLoopArrayDestructuring(): number { 29 | for (const [{ a }] of [[props]]) { 30 | return a 31 | } 32 | return 1 33 | } 34 | 35 | export function parameterDestructuring({ a }: Props): number { 36 | return a 37 | } 38 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/enum.ts: -------------------------------------------------------------------------------- 1 | export enum Enum { 2 | A, 3 | B, 4 | } 5 | 6 | export function newEnum(): Enum { 7 | return Enum.A 8 | } 9 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/function.ts: -------------------------------------------------------------------------------- 1 | export function newFunction(): void {} 2 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/import.ts: -------------------------------------------------------------------------------- 1 | import * as namespace from './namespace' 2 | import { Class } from './class' 3 | import { Enum } from './enum' 4 | import { newFunction } from './function' 5 | import { newInterface as renamedInterface } from './interface' 6 | 7 | export function useEverything(): string { 8 | return ( 9 | new Class('a').classProperty + 10 | renamedInterface().methodSignature('a') + 11 | Enum[Enum.A] + 12 | newFunction() + 13 | namespace.a.value 14 | ) 15 | } 16 | 17 | export function dynamicImport(): Promise { 18 | return import('./function').then(c => c.newFunction()) 19 | } 20 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/inheritance.ts: -------------------------------------------------------------------------------- 1 | import { Superinterface } from './reusable-types' 2 | import { Overloader } from './overload' 3 | 4 | export interface IntermediateSuperinterface extends Superinterface { 5 | intermediateInterfaceMethod(): string 6 | } 7 | export abstract class Superclass { 8 | public abstract overrideMethod(): string 9 | } 10 | export abstract class IntermediateSuperclass extends Superclass { 11 | public override overrideMethod(): string { 12 | return 'this will get overridden' 13 | } 14 | public abstract intermediateOverrideMethod(): string 15 | } 16 | export class Subclass 17 | extends IntermediateSuperclass 18 | implements IntermediateSuperinterface, Overloader 19 | { 20 | public onLiteral(param: any): void { 21 | throw new Error('Method not implemented.' + param) 22 | } 23 | property = 'property' 24 | public overrideMethod(): string { 25 | throw new Error('Method not implemented.') 26 | } 27 | public intermediateOverrideMethod(): string { 28 | throw new Error('Method not implemented.') 29 | } 30 | public interfaceMethod(): string { 31 | throw new Error('Method not implemented.') 32 | } 33 | public intermediateInterfaceMethod(): string { 34 | throw new Error('Method not implemented.') 35 | } 36 | } 37 | export const objectLiteralImplementation: Superinterface = { 38 | property: 'property', 39 | interfaceMethod: (): string => { 40 | throw new Error('Function not implemented.') 41 | }, 42 | } 43 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/interface.ts: -------------------------------------------------------------------------------- 1 | export interface Interface { 2 | property: string 3 | methodSignature(param: string): string 4 | methodSignature2: (param: string) => string 5 | } 6 | 7 | export function newInterface(): Interface { 8 | return { 9 | property: 'a', 10 | methodSignature(param: string): string { 11 | return param 12 | }, 13 | methodSignature2: (param: string): string => { 14 | return param 15 | }, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/issue-45.d.ts: -------------------------------------------------------------------------------- 1 | export namespace example { 2 | class Server { 3 | // This overloaded method reproduces the following issue https://github.com/sourcegraph/scip-typescript/issues/45 4 | addListener(name: 'a'): void 5 | addListener(name: 'b'): void 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/local.ts: -------------------------------------------------------------------------------- 1 | export function local(): string { 2 | const a = 'a' 3 | let b = a 4 | var c = b, 5 | c2 = b 6 | for (let d = 0; d < c.length; d++) { 7 | c += d 8 | c2 += c.length 9 | } 10 | return [c, c2].reduce((previousValue, currentValue, currentIndex) => { 11 | return previousValue + currentValue + currentIndex 12 | }) 13 | } 14 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/module.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'a:b' { 2 | function hello(): string 3 | } 4 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/namespace.ts: -------------------------------------------------------------------------------- 1 | export declare namespace a { 2 | function hello(): string 3 | interface Interface { 4 | hello: string 5 | } 6 | var i: Interface 7 | export const value = 1 8 | } 9 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/object-literals-arrow-function.ts: -------------------------------------------------------------------------------- 1 | import { Option } from './reusable-types' 2 | 3 | interface Foobar { 4 | foobar: number 5 | } 6 | 7 | export function hasArrowFunctionParameter( 8 | something: number, 9 | fn: (foobar: Foobar) => Foobar 10 | ): Foobar { 11 | return fn({ foobar: 42 + something }) 12 | } 13 | 14 | export function consumesArrowFunction(): number { 15 | return ( 16 | hasArrowFunctionParameter(1, ({ foobar }) => ({ foobar: foobar + 1 })) 17 | .foobar + 18 | hasArrowFunctionParameter(2, foobar => ({ foobar: foobar.foobar + 2 })) 19 | .foobar 20 | ) 21 | } 22 | 23 | export function genericArrow(): Foobar[] { 24 | return [1].map(n => ({ foobar: n + 1 })) 25 | } 26 | 27 | export function genericArrowOption(): Option[] { 28 | return [1].map>(n => ({ value: { foobar: n + 1 } })) 29 | } 30 | 31 | export function genericArrow2(): Foobar[] { 32 | // navigation to `foobar` below does not work with tsserver or scip-java 33 | // because `map` is missing an explicit `map` annotation. 34 | return [1].map(n => ({ foobar: n + 1 })) 35 | } 36 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/object-literals-call-signatures.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Configuration, 3 | GenericClass, 4 | GenericInterface, 5 | Option, 6 | Superinterface, 7 | } from './reusable-types' 8 | 9 | export function consumesInterface(superInterface: Superinterface): void {} 10 | export function consumesArray(superInterface: Superinterface[]): void {} 11 | export function consumesGenericInterface( 12 | genercInterface: GenericInterface 13 | ): void {} 14 | 15 | export function infersInterface(): void { 16 | consumesInterface({ 17 | interfaceMethod: (): string => 'inferred', 18 | property: 'inferred', 19 | }) 20 | consumesArray([ 21 | { 22 | interfaceMethod: (): string => 'inferred', 23 | property: 'inferred', 24 | }, 25 | ]) 26 | consumesGenericInterface({ 27 | interfaceMethod: (): string => 'inferred', 28 | property: 123, 29 | }) 30 | consumesGenericInterface[]>({ 31 | interfaceMethod: (): string => 'inferred', 32 | property: [{ value: { property: 42, property2: '42' } }], 33 | }) 34 | } 35 | export function returnStatementInsideArgumentExpression(): Configuration[] { 36 | if (1 == 1) { 37 | return [1].map((number: number): Configuration => { 38 | const incremented = number + 1 39 | return { 40 | property: incremented, 41 | property2: incremented.toString(), 42 | } 43 | }) 44 | } else { 45 | return [1].map(number => { 46 | const incremented = number + 1 47 | return { 48 | property: incremented, 49 | property2: incremented.toString(), 50 | } 51 | }) 52 | } 53 | } 54 | 55 | export function createGenericClass(): GenericClass { 56 | return new GenericClass([{ property: 1, property2: '2' }]) 57 | } 58 | 59 | export function handleGenericClass() { 60 | return createGenericClass().map(({ property, property2 }) => ({ 61 | property: property + 1, 62 | property2: property2 + '1', 63 | })) 64 | } 65 | 66 | export function handleShorthand() { 67 | const property = '42' 68 | const interfaceMethod = (): string => 'inferred' 69 | consumesInterface({ 70 | interfaceMethod, 71 | property, 72 | }) 73 | } 74 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/object-literals-nested.ts: -------------------------------------------------------------------------------- 1 | import { Option } from './reusable-types' 2 | 3 | interface Address { 4 | street: string 5 | people: Person[] 6 | } 7 | interface Person { 8 | name: string 9 | address?: Address 10 | } 11 | 12 | export function handleNestedObjectLiterals(): Person { 13 | return { 14 | name: 'John', 15 | address: { 16 | street: 'Oxford Street', 17 | people: [ 18 | { 19 | name: 'Susan', 20 | }, 21 | ], 22 | }, 23 | } 24 | } 25 | 26 | export function handleNestedTypeVariables(): Option { 27 | return { 28 | value: { 29 | name: 'John', 30 | address: { 31 | street: 'Oxford Street', 32 | people: [ 33 | { 34 | name: 'Susan', 35 | }, 36 | ], 37 | }, 38 | }, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/object-literals.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from './reusable-types' 2 | 3 | function random(): number { 4 | return Math.random() 5 | } 6 | 7 | export function handleArrayLiteral(): Configuration[] { 8 | return [ 9 | { 10 | property: 41, 11 | property2: '41', 12 | }, 13 | ] 14 | } 15 | 16 | export function returnStatement(): Configuration { 17 | if (random() > 0) { 18 | return { 19 | property: 41, 20 | property2: '41', 21 | } 22 | } 23 | for (let i = 0; i < 9; i++) { 24 | if (random() > i) { 25 | return { 26 | property: 41, 27 | property2: '41', 28 | } 29 | } 30 | } 31 | for (const i of [1, 2, 3]) { 32 | if (random() > i) { 33 | return { 34 | property: 41, 35 | property2: '41', 36 | } 37 | } 38 | } 39 | for (const i in { '1': 2 }) { 40 | if (random() > Number.parseInt(i)) { 41 | return { 42 | property: 41, 43 | property2: '41', 44 | } 45 | } 46 | } 47 | while (random() < 0) { 48 | return { 49 | property: 41, 50 | property2: '41', 51 | } 52 | } 53 | do { 54 | if (random() > 0) { 55 | return { 56 | property: 41, 57 | property2: '41', 58 | } 59 | } 60 | } while (random() < 0) 61 | 62 | return { 63 | property: 42, 64 | property2: '41', 65 | } 66 | } 67 | 68 | export function constDeclaration(): number[] { 69 | var configuration1: Configuration = { 70 | property: 1, 71 | property2: '1', 72 | } 73 | configuration1 = { 74 | property: 2, 75 | property2: '2', 76 | } 77 | let configuration2: Configuration = { 78 | property: 3, 79 | property2: '3', 80 | } 81 | configuration2.property = configuration1.property 82 | const configuration3: Configuration = { 83 | property: 4, 84 | property2: '4', 85 | } 86 | return [ 87 | configuration1.property, 88 | configuration2.property, 89 | configuration3.property, 90 | ] 91 | } 92 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/overload.d.ts: -------------------------------------------------------------------------------- 1 | export interface Overloader { 2 | onLiteral(param: 'a'): void 3 | onLiteral(param: 'b'): void 4 | } 5 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/property-assignment-reference.ts: -------------------------------------------------------------------------------- 1 | import { 2 | propertyAssignment, 3 | shorthandPropertyAssignment, 4 | } from './property-assignment' 5 | 6 | export function run(): string { 7 | return propertyAssignment().a + shorthandPropertyAssignment().a 8 | } 9 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/property-assignment.ts: -------------------------------------------------------------------------------- 1 | export function propertyAssignment() { 2 | return { a: 'a' } 3 | } 4 | export function shorthandPropertyAssignment() { 5 | const a = 'a' 6 | return { a } 7 | } 8 | type A = { a: string; b: number } 9 | export function typedPropertyAssignment(): A { 10 | // prettier-ignore 11 | return { a: 'a', "b": 10 } 12 | } 13 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/reusable-types.ts: -------------------------------------------------------------------------------- 1 | // Reusable types for other snapshot tests 2 | 3 | export interface Option { 4 | value?: A 5 | } 6 | 7 | export interface Numbers { 8 | property: number 9 | } 10 | export interface Strings { 11 | property2: string 12 | } 13 | export type Configuration = Numbers & Strings 14 | 15 | export class GenericClass { 16 | constructor(public readonly values: A[]) {} 17 | public map(fn: (a: A) => A): A[] { 18 | return this.values.map(a => fn(a)) 19 | } 20 | } 21 | 22 | export interface Superinterface { 23 | property: string 24 | interfaceMethod(): string 25 | } 26 | export interface GenericInterface { 27 | property: T 28 | interfaceMethod(): string 29 | } 30 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/string-literals.ts: -------------------------------------------------------------------------------- 1 | interface SomeInterface { 2 | a: number 3 | b: number 4 | c: number 5 | } 6 | // "Go to definition" does not work for the 'a', 'b' and 'c' string literals 7 | // below when using tsserver so it's fine that scip-typescript does not emit 8 | // occurrences here either. 9 | export type OmitInterface = Omit 10 | export type PickInterface = Pick 11 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/structural-type.ts: -------------------------------------------------------------------------------- 1 | export function foo(): Promise<{ member: number }> { 2 | return Promise.resolve({ member: 42 }) 3 | } 4 | export function bar(): Promise { 5 | return foo().then(x => x.member) 6 | } 7 | export function bar2(): Promise { 8 | return foo().then(({ member }) => member) 9 | } 10 | 11 | type OptionsFlags = { [Property in keyof Type]: boolean } 12 | type FeatureFlags = { darkMode: () => void } 13 | export type FeatureOptions = OptionsFlags // implicitly // type FeatureOptions = { // darkMode: boolean; // } const fo: FeatureOptions = { darkMode: true }; // ^ go to def 14 | export const fo: FeatureOptions = { darkMode: true } 15 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/type-alias.ts: -------------------------------------------------------------------------------- 1 | type S = string 2 | 3 | const s: S = '' 4 | 5 | class C { 6 | t: T 7 | } 8 | type Cstring = C 9 | 10 | const cs: Cstring = new C() 11 | 12 | class D { 13 | t: T 14 | u: U 15 | } 16 | type DT = D // partially specialized 17 | type DU = D> // recursive! 18 | 19 | const dt: DT = new D() 20 | const du: DU = new D() 21 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/type-parameter.ts: -------------------------------------------------------------------------------- 1 | export function typeParameter(parameter: A, parameter2: B): [A, B] { 2 | return [parameter, parameter2] 3 | } 4 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare var window: Window & typeof globalThis 2 | interface Window { 3 | process: any 4 | require: any 5 | } 6 | -------------------------------------------------------------------------------- /snapshots/input/syntax/src/typings.ts: -------------------------------------------------------------------------------- 1 | export function process() { 2 | return window.process 3 | } 4 | -------------------------------------------------------------------------------- /snapshots/input/syntax/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "target": "ES2015", 5 | "experimentalDecorators": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /snapshots/input/syntax/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /snapshots/output/enclosing-ranges-ts/index.ts: -------------------------------------------------------------------------------- 1 | // < definition enclosing-ranges-ts 1.0.0 `index.ts`/ 2 | 3 | // format-options: showRanges 4 | 5 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Foo# 6 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/ 7 | interface Foo { 8 | // ^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo# 9 | bar: string 10 | //^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#bar. 11 | test: () => void 12 | //^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Foo#test. 13 | } 14 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Foo# 15 | 16 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Single# 17 | interface Single { 18 | // ^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single# 19 | // ^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T] 20 | t: T 21 | //^ definition enclosing-ranges-ts 1.0.0 `index.ts`/Single#t. 22 | // ^ reference enclosing-ranges-ts 1.0.0 `index.ts`/Single#[T] 23 | } 24 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/Single# 25 | 26 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum# 27 | enum SimpleEnum { 28 | // ^^^^^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum# 29 | Case1, 30 | //^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum#Case1. 31 | Case2, 32 | //^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum#Case2. 33 | } 34 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum# 35 | 36 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/SimpleTypeAlias# 37 | type SimpleTypeAlias = SimpleEnum 38 | // ^^^^^^^^^^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/SimpleTypeAlias# 39 | // ^^^^^^^^^^ reference enclosing-ranges-ts 1.0.0 `index.ts`/SimpleEnum# 40 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/SimpleTypeAlias# 41 | 42 | // < start enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias# 43 | type ComplexTypeAlias = Single> 44 | // ^^^^^^^^^^^^^^^^ definition enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias# 45 | // ^ definition enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias#[T] 46 | // ^^^^^^ reference enclosing-ranges-ts 1.0.0 `index.ts`/Single# 47 | // ^^^^^^ reference enclosing-ranges-ts 1.0.0 `index.ts`/Single# 48 | // ^ reference enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias#[T] 49 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/ComplexTypeAlias# 50 | 51 | // < end enclosing_range enclosing-ranges-ts 1.0.0 `index.ts`/ 52 | -------------------------------------------------------------------------------- /snapshots/output/enclosing-ranges/range.js: -------------------------------------------------------------------------------- 1 | // < definition enclosing-ranges 0.0.1 `range.js`/ 2 | 3 | // format-options: showRanges 4 | 5 | // < start enclosing_range enclosing-ranges 0.0.1 `range.js`/ 6 | // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/test. 7 | const test = () => { 8 | // ^^^^ definition enclosing-ranges 0.0.1 `range.js`/test. 9 | const a = 'a' 10 | // ^ definition local 2 11 | const b = 'b' 12 | // ^ definition local 5 13 | 14 | return a + b 15 | // ^ reference local 2 16 | // ^ reference local 5 17 | } 18 | // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/test. 19 | 20 | // < start enclosing_range enclosing-ranges 0.0.1 `range.js`/test2(). 21 | function test2() { 22 | // ^^^^^ definition enclosing-ranges 0.0.1 `range.js`/test2(). 23 | const a = 'a' 24 | // ^ definition local 8 25 | const b = 'b' 26 | // ^ definition local 11 27 | 28 | return a + b 29 | // ^ reference local 8 30 | // ^ reference local 11 31 | } 32 | // < end enclosing_range enclosing-ranges 0.0.1 `range.js`/test2(). 33 | 34 | // < start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test# 35 | class Test { 36 | // ^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test# 37 | // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#``(). 38 | constructor() { 39 | //^^^^^^^^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#``(). 40 | const a = 'a' 41 | // ^ definition local 14 42 | const b = 'b' 43 | // ^ definition local 17 44 | 45 | return a + b 46 | // ^ reference local 14 47 | // ^ reference local 17 48 | } 49 | // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#``(). 50 | 51 | // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test(). 52 | test() { 53 | //^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#test(). 54 | const a = 'a' 55 | // ^ definition local 20 56 | const b = 'b' 57 | // ^ definition local 23 58 | 59 | return a + b 60 | // ^ reference local 20 61 | // ^ reference local 23 62 | } 63 | // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test(). 64 | 65 | // ⌄ start enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test(). 66 | static test() { 67 | // ^^^^ definition enclosing-ranges 0.0.1 `range.js`/Test#test(). 68 | const a = 'a' 69 | // ^ definition local 26 70 | const b = 'b' 71 | // ^ definition local 29 72 | 73 | return a + b 74 | // ^ reference local 26 75 | // ^ reference local 29 76 | } 77 | // ^ end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test#test(). 78 | } 79 | // < end enclosing_range enclosing-ranges 0.0.1 `range.js`/Test# 80 | 81 | // < end enclosing_range enclosing-ranges 0.0.1 `range.js`/ 82 | -------------------------------------------------------------------------------- /snapshots/output/invalid-package-json/packages/a/src/a.ts: -------------------------------------------------------------------------------- 1 | // < definition @example/a HEAD src/`a.ts`/ 2 | 3 | export function a(): string { 4 | // ^ definition @example/a HEAD src/`a.ts`/a(). 5 | return '' 6 | } 7 | 8 | -------------------------------------------------------------------------------- /snapshots/output/multi-project/packages/a/src/index.ts: -------------------------------------------------------------------------------- 1 | // < definition @example/a 1.0.0 src/`index.ts`/ 2 | //documentation ```ts 3 | // > module "index.ts" 4 | // > ``` 5 | 6 | // format-options: showDocs 7 | 8 | export function a(): string { 9 | // ^ definition @example/a 1.0.0 src/`index.ts`/a(). 10 | // documentation ```ts 11 | // > function a(): string 12 | // > ``` 13 | return '' 14 | } 15 | 16 | -------------------------------------------------------------------------------- /snapshots/output/multi-project/packages/b/src/b.ts: -------------------------------------------------------------------------------- 1 | // < definition @example/b 1.0.0 src/`b.ts`/ 2 | 3 | import { a } from '@example/a/src' 4 | // ^ reference @example/a 1.0.0 src/`index.ts`/a(). 5 | // ^^^^^^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/ 6 | 7 | export function b() { 8 | // ^ definition @example/b 1.0.0 src/`b.ts`/b(). 9 | return a() 10 | // ^ reference @example/a 1.0.0 src/`index.ts`/a(). 11 | } 12 | 13 | -------------------------------------------------------------------------------- /snapshots/output/pnpm-workspaces/packages/a/src/a.ts: -------------------------------------------------------------------------------- 1 | // < definition @example/a 1.0.0 src/`a.ts`/ 2 | 3 | export function a(): string { 4 | // ^ definition @example/a 1.0.0 src/`a.ts`/a(). 5 | return '' 6 | } 7 | 8 | -------------------------------------------------------------------------------- /snapshots/output/pnpm-workspaces/packages/b/src/b.ts: -------------------------------------------------------------------------------- 1 | // < definition @example/b 1.0.0 src/`b.ts`/ 2 | 3 | import { a } from '@example/a' 4 | // ^ reference @example/a 1.0.0 src/`a.ts`/a(). 5 | // ^^^^^^^^^^^^ reference @example/a 1.0.0 src/`a.ts`/ 6 | 7 | export function b() { 8 | // ^ definition @example/b 1.0.0 src/`b.ts`/b(). 9 | return a() 10 | // ^ reference @example/a 1.0.0 src/`a.ts`/a(). 11 | } 12 | 13 | -------------------------------------------------------------------------------- /snapshots/output/pure-js/src/main.js: -------------------------------------------------------------------------------- 1 | // < definition pure-js 1.0.0 src/`main.js`/ 2 | 3 | function fib(n) { 4 | // ^^^ definition pure-js 1.0.0 src/`main.js`/fib(). 5 | // ^ definition pure-js 1.0.0 src/`main.js`/fib().(n) 6 | if (n <= 1) { 7 | // ^ reference pure-js 1.0.0 src/`main.js`/fib().(n) 8 | return 0 9 | } 10 | return fib(n - 1) + fib(n - 2) 11 | // ^^^ reference pure-js 1.0.0 src/`main.js`/fib(). 12 | // ^ reference pure-js 1.0.0 src/`main.js`/fib().(n) 13 | // ^^^ reference pure-js 1.0.0 src/`main.js`/fib(). 14 | // ^ reference pure-js 1.0.0 src/`main.js`/fib().(n) 15 | } 16 | 17 | function print_fib(a) { 18 | // ^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/print_fib(). 19 | // ^ definition pure-js 1.0.0 src/`main.js`/print_fib().(a) 20 | console.log(fib(a)) 21 | //^^^^^^^ reference typescript 5.6.2 lib/`lib.dom.d.ts`/console. 22 | //^^^^^^^ reference @types/node 20.16.10 `globals.d.ts`/global/console. 23 | //^^^^^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/console/ 24 | //^^^^^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/console. 25 | // ^^^ reference typescript 5.6.2 lib/`lib.dom.d.ts`/Console#log(). 26 | // ^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/Console#log(). 27 | // ^^^ reference pure-js 1.0.0 src/`main.js`/fib(). 28 | // ^ reference pure-js 1.0.0 src/`main.js`/print_fib().(a) 29 | } 30 | 31 | var y = 'Hello' 32 | // ^ definition pure-js 1.0.0 src/`main.js`/y. 33 | function capture() { 34 | // ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/capture(). 35 | return y 36 | // ^ reference pure-js 1.0.0 src/`main.js`/y. 37 | } 38 | const capture_lambda = () => { 39 | // ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/capture_lambda. 40 | return y 41 | // ^ reference pure-js 1.0.0 src/`main.js`/y. 42 | } 43 | 44 | for (var i = 0; i <= 10; i++) {} 45 | // ^ definition local 2 46 | // ^ reference local 2 47 | // ^ reference local 2 48 | 49 | for (const x of [1, 2, 3]) { 50 | // ^ definition local 5 51 | } 52 | 53 | var a = 0 54 | // ^ definition pure-js 1.0.0 src/`main.js`/a. 55 | var a = 1 56 | // ^ definition pure-js 1.0.0 src/`main.js`/a. 57 | print_fib(a) 58 | //^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib(). 59 | // ^ reference pure-js 1.0.0 src/`main.js`/a. 60 | 61 | function forever() { 62 | // ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/forever(). 63 | return forever() 64 | // ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever(). 65 | } 66 | 67 | function use_before_def() { 68 | // ^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/use_before_def(). 69 | print_fib(n) 70 | //^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib(). 71 | // ^ reference local 8 72 | var n = 10 73 | // ^ definition local 8 74 | 75 | if (forever()) { 76 | // ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever(). 77 | var m = 10 78 | // ^ definition local 11 79 | } 80 | print_fib(m) 81 | //^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib(). 82 | // ^ reference local 11 83 | } 84 | 85 | function var_function_scope() { 86 | // ^^^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/var_function_scope(). 87 | var k = 0 88 | // ^ definition local 14 89 | if (forever()) { 90 | // ^^^^^^^ reference pure-js 1.0.0 src/`main.js`/forever(). 91 | var k = 1 92 | // ^ definition local 17 93 | } 94 | print_fib(k) 95 | //^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib(). 96 | // ^ reference local 14 97 | // ^ reference local 17 98 | } 99 | 100 | function array_of_objects() { 101 | // ^^^^^^^^^^^^^^^^ definition pure-js 1.0.0 src/`main.js`/array_of_objects(). 102 | var a = [{ element: 0 }, { element: 1 }] 103 | // ^ definition local 20 104 | // ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element0: 105 | // ^^^^^^^ definition pure-js 1.0.0 src/`main.js`/element1: 106 | } 107 | 108 | -------------------------------------------------------------------------------- /snapshots/output/react/src/LoaderInput.tsx: -------------------------------------------------------------------------------- 1 | // < definition react-example 1.0.0 src/`LoaderInput.tsx`/ 2 | 3 | import React from 'react' 4 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 5 | // ^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/ 6 | 7 | /** Takes loading prop, input component as child */ 8 | interface Props { 9 | // ^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props# 10 | loading: boolean 11 | //^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading. 12 | children: React.ReactNode 13 | //^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. 14 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 15 | // ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ReactNode# 16 | } 17 | 18 | export const LoaderInput: React.FunctionComponent = ({ 19 | // ^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput. 20 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 21 | // ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent# 22 | // ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props# 23 | loading, 24 | //^^^^^^^ definition local 3 25 | //^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading. 26 | children, 27 | //^^^^^^^^ definition local 4 28 | //^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. 29 | }) => ( 30 |
31 | // ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div. 32 | // ^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/HTMLAttributes#className. 33 | {children} 34 | // ^^^^^^^^ reference local 4 35 | {loading &&

spinner

} 36 | // ^^^^^^^ reference local 3 37 | // ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p. 38 | // ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p. 39 |
40 | // ^^^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#div. 41 | ) 42 | 43 | export const LoaderInput2: React.FunctionComponent = props => { 44 | // ^^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput2. 45 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 46 | // ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent# 47 | // ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props# 48 | // ^^^^^ definition local 6 49 | return 50 | // ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput. 51 | // ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading. 52 | // ^^^ reference @types/react 18.2.39 `index.d.ts`/React/Attributes#key. 53 | // ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. 54 | // ^^^^^ reference local 6 55 | // ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children. 56 | } 57 | 58 | -------------------------------------------------------------------------------- /snapshots/output/react/src/MyTSXElement.tsx: -------------------------------------------------------------------------------- 1 | // < definition react-example 1.0.0 src/`MyTSXElement.tsx`/ 2 | 3 | import React from 'react' 4 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 5 | // ^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/ 6 | 7 | export interface MyProps {} 8 | // ^^^^^^^ definition react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps# 9 | 10 | export const MyTSXElement: React.FunctionComponent = ({}) => (

) 11 | // ^^^^^^^^^^^^ definition react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement. 12 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 13 | // ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent# 14 | // ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps# 15 | // ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p. 16 | // ^ reference @types/react 18.2.39 `index.d.ts`/global/JSX/IntrinsicElements#p. 17 | -------------------------------------------------------------------------------- /snapshots/output/react/src/UseMyTSXElement.tsx: -------------------------------------------------------------------------------- 1 | // < definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/ 2 | 3 | import React from "react"; 4 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 5 | // ^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/ 6 | 7 | import { MyProps, MyTSXElement } from "./MyTSXElement"; 8 | // ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps# 9 | // ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement. 10 | // ^^^^^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/ 11 | 12 | export const _: React.FunctionComponent = 13 | // ^ definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/_. 14 | // ^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/ 15 | // ^^^^^^^^^^^^^^^^^ reference @types/react 18.2.39 `index.d.ts`/React/FunctionComponent# 16 | // ^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyProps# 17 | ({}) => () 18 | // ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement. 19 | // ^^^^^^^^^^^^ reference react-example 1.0.0 src/`MyTSXElement.tsx`/MyTSXElement. 20 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/ClassWithPrivate.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ 2 | 3 | export class ClassWithPrivate { 4 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate# 5 | #privateField 6 | //^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`. 7 | #privateFieldWithInitializer = 42 8 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateFieldWithInitializer`. 9 | 10 | #privateMethod() { 11 | //^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateMethod`(). 12 | this.#privateField = 'private field' 13 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`. 14 | return this.#privateField 15 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`. 16 | } 17 | 18 | static #privateStaticField 19 | // ^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticField`. 20 | static #privateStaticFieldWithInitializer = 42 21 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticFieldWithInitializer`. 22 | 23 | static #privateStaticMethod() {} 24 | // ^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticMethod`(). 25 | public publicMethod(): any[] { 26 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#publicMethod(). 27 | return [ 28 | this.#privateField, 29 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateField`. 30 | this.#privateFieldWithInitializer, 31 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateFieldWithInitializer`. 32 | this.#privateMethod(), 33 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateMethod`(). 34 | ClassWithPrivate.#privateStaticMethod(), 35 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate# 36 | // ^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticMethod`(). 37 | ClassWithPrivate.#privateStaticField, 38 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate# 39 | // ^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticField`. 40 | ClassWithPrivate.#privateStaticFieldWithInitializer, 41 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate# 42 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`ClassWithPrivate.ts`/ClassWithPrivate#`#privateStaticFieldWithInitializer`. 43 | ] 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/accessors.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`accessors.ts`/ 2 | 3 | class C { 4 | // ^ definition syntax 1.0.0 src/`accessors.ts`/C# 5 | _length: number = 0 6 | //^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#_length. 7 | get length(): number { 8 | // ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`length`(). 9 | return this._length 10 | // ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#_length. 11 | } 12 | set length(value: number) { 13 | // ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`length`(). 14 | // ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`length`().(value) 15 | this._length = value 16 | // ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#_length. 17 | // ^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`().(value) 18 | } 19 | 20 | _capacity: number = 0 21 | //^^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#_capacity. 22 | get capacity(): number { 23 | // ^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/C#`capacity`(). 24 | return this._capacity 25 | // ^^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#_capacity. 26 | } 27 | } 28 | 29 | export class D { 30 | // ^ definition syntax 1.0.0 src/`accessors.ts`/D# 31 | _length: number = 0 32 | //^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#_length. 33 | public get length(): number { 34 | // ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`length`(). 35 | return this._length 36 | // ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_length. 37 | } 38 | public set length(value: number) { 39 | // ^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`length`(). 40 | // ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`length`().(value) 41 | this._length = value 42 | // ^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_length. 43 | // ^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`length`().(value) 44 | } 45 | 46 | _capacity: number = 0 47 | //^^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#_capacity. 48 | public get capacity(): number { 49 | // ^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 50 | return this._capacity 51 | // ^^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_capacity. 52 | } 53 | private set capacity(value: number) { 54 | // ^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 55 | // ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#`capacity`().(value) 56 | this._capacity = value 57 | // ^^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#_capacity. 58 | // ^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`capacity`().(value) 59 | } 60 | public unsafeSetCapacity(value: number): void { 61 | // ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#unsafeSetCapacity(). 62 | // ^^^^^ definition syntax 1.0.0 src/`accessors.ts`/D#unsafeSetCapacity().(value) 63 | this.capacity = value 64 | // ^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 65 | // ^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 66 | // ^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#unsafeSetCapacity().(value) 67 | } 68 | } 69 | 70 | function g(_: number): void {} 71 | // ^ definition syntax 1.0.0 src/`accessors.ts`/g(). 72 | // ^ definition syntax 1.0.0 src/`accessors.ts`/g().(_) 73 | 74 | function f() { 75 | // ^ definition syntax 1.0.0 src/`accessors.ts`/f(). 76 | const c = new C() 77 | // ^ definition local 2 78 | // ^ reference syntax 1.0.0 src/`accessors.ts`/C# 79 | c.length = 10 80 | //^ reference local 2 81 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 82 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 83 | g(c.length) 84 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 85 | // ^ reference local 2 86 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 87 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 88 | g(c.capacity) 89 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 90 | // ^ reference local 2 91 | // ^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`capacity`(). 92 | g(c.length) 93 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 94 | // ^ reference local 2 95 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 96 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/C#`length`(). 97 | 98 | const d = new D() 99 | // ^ definition local 5 100 | // ^ reference syntax 1.0.0 src/`accessors.ts`/D# 101 | d.length = 0 102 | //^ reference local 5 103 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`length`(). 104 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`length`(). 105 | g(d.length) 106 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 107 | // ^ reference local 5 108 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`length`(). 109 | // ^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`length`(). 110 | g(d.capacity) 111 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 112 | // ^ reference local 5 113 | // ^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 114 | // ^^^^^^^^ reference syntax 1.0.0 src/`accessors.ts`/D#`capacity`(). 115 | g(D.length) 116 | //^ reference syntax 1.0.0 src/`accessors.ts`/g(). 117 | // ^ reference syntax 1.0.0 src/`accessors.ts`/D# 118 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Function#length. 119 | } 120 | 121 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/class.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`class.ts`/ 2 | 3 | export class Class { 4 | // ^^^^^ definition syntax 1.0.0 src/`class.ts`/Class# 5 | public classProperty: string 6 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#classProperty. 7 | constructor(constructorParam: string) { 8 | //^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#``(). 9 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#``().(constructorParam) 10 | this.classProperty = constructorParam 11 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#classProperty. 12 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#``().(constructorParam) 13 | } 14 | public method(methodParam: string): string { 15 | // ^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#method(). 16 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#method().(methodParam) 17 | return this.privateMethod(methodParam) 18 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#privateMethod(). 19 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#method().(methodParam) 20 | } 21 | public static staticMethod(methodParam: string): string { 22 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#staticMethod(). 23 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#staticMethod().(methodParam) 24 | return methodParam 25 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#staticMethod().(methodParam) 26 | } 27 | private privateMethod(methodParam: string): string { 28 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#privateMethod(). 29 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/Class#privateMethod().(methodParam) 30 | return methodParam 31 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#privateMethod().(methodParam) 32 | } 33 | } 34 | 35 | export function newClass(param: string): string { 36 | // ^^^^^^^^ definition syntax 1.0.0 src/`class.ts`/newClass(). 37 | // ^^^^^ definition syntax 1.0.0 src/`class.ts`/newClass().(param) 38 | const instance = new Class(param).classProperty 39 | // ^^^^^^^^ definition local 2 40 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#``(). 41 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/newClass().(param) 42 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#classProperty. 43 | const instance2 = Class.staticMethod(param) 44 | // ^^^^^^^^^ definition local 5 45 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class# 46 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#staticMethod(). 47 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/newClass().(param) 48 | return instance + instance2 49 | // ^^^^^^^^ reference local 2 50 | // ^^^^^^^^^ reference local 5 51 | } 52 | 53 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/conflicting-const-interface.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ 2 | 3 | export const ConflictingConst = 42 4 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst. 5 | export interface ConflictingConst {} 6 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst# 7 | export class ImplementsConflictingConst implements ConflictingConst {} 8 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ImplementsConflictingConst# 9 | // relationship implementation syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst# 10 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst. 11 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst# 12 | 13 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/constructor.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`constructor.ts`/ 2 | 3 | namespace Yay { 4 | // ^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/ 5 | export class SuperConstructor { 6 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor# 7 | constructor(public readonly property: number) {} 8 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#``(). 9 | // ^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#``().(property) 10 | } 11 | 12 | export namespace Woo { 13 | // ^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/Woo/ 14 | export class MyClass { 15 | // ^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/Woo/MyClass# 16 | constructor() {} 17 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/Yay/Woo/MyClass#``(). 18 | } 19 | } 20 | } 21 | 22 | export class SuperConstructor2 { 23 | // ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2# 24 | constructor(public readonly property: number) {} 25 | //^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#``(). 26 | // ^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#``().(property) 27 | } 28 | 29 | export function useConstructor(): Yay.SuperConstructor { 30 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/useConstructor(). 31 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/ 32 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor# 33 | return new Yay.SuperConstructor(10) 34 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/ 35 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/SuperConstructor#``(). 36 | } 37 | 38 | export function useConstructor2(): SuperConstructor2 { 39 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/useConstructor2(). 40 | // ^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/SuperConstructor2# 41 | return new SuperConstructor2(10) 42 | // ^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/SuperConstructor2#``(). 43 | } 44 | 45 | export function useConstructor3(): Yay.Woo.MyClass { 46 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/useConstructor3(). 47 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/ 48 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/Woo/ 49 | // ^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/Woo/MyClass# 50 | return new Yay.Woo.MyClass() 51 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/ 52 | // ^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/Woo/ 53 | // ^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/Yay/Woo/MyClass#``(). 54 | } 55 | 56 | export class NoConstructor { 57 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/NoConstructor# 58 | property: number 59 | //^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/NoConstructor#property. 60 | } 61 | 62 | export function useNoConstructor() { 63 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`constructor.ts`/useNoConstructor(). 64 | return new NoConstructor() 65 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`constructor.ts`/NoConstructor# 66 | } 67 | 68 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/decorators.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`decorators.ts`/ 2 | 3 | import { Configuration } from './reusable-types' 4 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 5 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 6 | 7 | function MyDecorator(value: Configuration) { 8 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyDecorator(). 9 | // ^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyDecorator().(value) 10 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 11 | return function (target: Function) { 12 | // ^^^^^^ definition local 2 13 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Function# 14 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Function. 15 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.core.d.ts`/Function# 16 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Function# 17 | console.log(`MyDecorator is called with value: ${value}`) 18 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.dom.d.ts`/console. 19 | // ^^^^^^^ reference @types/node 20.16.10 `globals.d.ts`/global/console. 20 | // ^^^^^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/console/ 21 | // ^^^^^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/console. 22 | // ^^^ reference typescript 5.6.2 lib/`lib.dom.d.ts`/Console#log(). 23 | // ^^^ reference @types/node 20.16.10 `console.d.ts`/`"node:console"`/global/Console#log(). 24 | // ^^^^^ reference syntax 1.0.0 src/`decorators.ts`/MyDecorator().(value) 25 | } 26 | } 27 | 28 | @MyDecorator({ property: 42, property2: '42' }) 29 | //^^^^^^^^^^^ reference syntax 1.0.0 src/`decorators.ts`/MyDecorator(). 30 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 31 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 32 | class MyClass { 33 | // ^^^^^^^ definition syntax 1.0.0 src/`decorators.ts`/MyClass# 34 | //... 35 | } 36 | 37 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/destructuring.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`destructuring.ts`/ 2 | 3 | interface Props { 4 | // ^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/Props# 5 | a: number 6 | //^ definition syntax 1.0.0 src/`destructuring.ts`/Props#a. 7 | } 8 | const props: Props = { a: 42 } 9 | // ^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/props. 10 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/Props# 11 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 12 | 13 | export function objectDestructuring(): number[] { 14 | // ^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/objectDestructuring(). 15 | const { a: b } = props 16 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 17 | // ^ definition local 4 18 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 19 | return [props].map(({ a }) => a + b) 20 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 21 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 22 | // ^ definition local 10 23 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 24 | // ^ reference local 10 25 | // ^ reference local 4 26 | } 27 | 28 | export function arrayDestructuring(): number[] { 29 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/arrayDestructuring(). 30 | const [b] = [props] 31 | // ^ definition local 15 32 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 33 | return [[b]].map(([a]) => a.a) 34 | // ^ reference local 15 35 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 36 | // ^ definition local 21 37 | // ^ reference local 21 38 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 39 | } 40 | 41 | export function nestedDestructuring(): number[] { 42 | // ^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/nestedDestructuring(). 43 | const [[b]] = [[props]] 44 | // ^ definition local 28 45 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 46 | return [[props]].map(([{ a }]) => a + b.a) 47 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 48 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 49 | // ^ definition local 36 50 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 51 | // ^ reference local 36 52 | // ^ reference local 28 53 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 54 | } 55 | 56 | export function forLoopObjectDestructuring(): number { 57 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/forLoopObjectDestructuring(). 58 | for (const { a } of [props]) { 59 | // ^ definition local 41 60 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 61 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 62 | return a 63 | // ^ reference local 41 64 | } 65 | return 1 66 | } 67 | 68 | export function forLoopArrayDestructuring(): number { 69 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/forLoopArrayDestructuring(). 70 | for (const [{ a }] of [[props]]) { 71 | // ^ definition local 48 72 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 73 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/props. 74 | return a 75 | // ^ reference local 48 76 | } 77 | return 1 78 | } 79 | 80 | export function parameterDestructuring({ a }: Props): number { 81 | // ^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`destructuring.ts`/parameterDestructuring(). 82 | // ^ definition local 50 83 | // ^ reference syntax 1.0.0 src/`destructuring.ts`/Props#a. 84 | // ^^^^^ reference syntax 1.0.0 src/`destructuring.ts`/Props# 85 | return a 86 | // ^ reference local 50 87 | } 88 | 89 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/enum.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`enum.ts`/ 2 | 3 | export enum Enum { 4 | // ^^^^ definition syntax 1.0.0 src/`enum.ts`/Enum# 5 | A, 6 | //^ definition syntax 1.0.0 src/`enum.ts`/Enum#A. 7 | B, 8 | //^ definition syntax 1.0.0 src/`enum.ts`/Enum#B. 9 | } 10 | 11 | export function newEnum(): Enum { 12 | // ^^^^^^^ definition syntax 1.0.0 src/`enum.ts`/newEnum(). 13 | // ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum# 14 | return Enum.A 15 | // ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum# 16 | // ^ reference syntax 1.0.0 src/`enum.ts`/Enum#A. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/function.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`function.ts`/ 2 | 3 | export function newFunction(): void {} 4 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`function.ts`/newFunction(). 5 | 6 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/import.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`import.ts`/ 2 | 3 | import * as namespace from './namespace' 4 | // ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/ 5 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/ 6 | import { Class } from './class' 7 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class# 8 | // ^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/ 9 | import { Enum } from './enum' 10 | // ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum# 11 | // ^^^^^^^^ reference syntax 1.0.0 src/`enum.ts`/ 12 | import { newFunction } from './function' 13 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/newFunction(). 14 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/ 15 | import { newInterface as renamedInterface } from './interface' 16 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/newInterface(). 17 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/newInterface(). 18 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/ 19 | 20 | export function useEverything(): string { 21 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`import.ts`/useEverything(). 22 | return ( 23 | new Class('a').classProperty + 24 | // ^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#``(). 25 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`class.ts`/Class#classProperty. 26 | renamedInterface().methodSignature('a') + 27 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/newInterface(). 28 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). 29 | Enum[Enum.A] + 30 | // ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum# 31 | // ^^^^ reference syntax 1.0.0 src/`enum.ts`/Enum# 32 | // ^ reference syntax 1.0.0 src/`enum.ts`/Enum#A. 33 | newFunction() + 34 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/newFunction(). 35 | namespace.a.value 36 | // ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/ 37 | // ^ reference syntax 1.0.0 src/`namespace.ts`/a/ 38 | // ^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/value. 39 | ) 40 | } 41 | 42 | export function dynamicImport(): Promise { 43 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`import.ts`/dynamicImport(). 44 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise# 45 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.iterable.d.ts`/Promise# 46 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/Promise. 47 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# 48 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2018.promise.d.ts`/Promise# 49 | return import('./function').then(c => c.newFunction()) 50 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/ 51 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise#then(). 52 | // ^ definition local 3 53 | // ^ reference local 3 54 | // ^^^^^^^^^^^ reference syntax 1.0.0 src/`function.ts`/newFunction(). 55 | } 56 | 57 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/inheritance.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`inheritance.ts`/ 2 | 3 | import { Superinterface } from './reusable-types' 4 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 5 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 6 | import { Overloader } from './overload' 7 | // ^^^^^^^^^^ reference syntax 1.0.0 src/`overload.d.ts`/Overloader# 8 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`overload.d.ts`/ 9 | 10 | export interface IntermediateSuperinterface extends Superinterface { 11 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface# 12 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 13 | intermediateInterfaceMethod(): string 14 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface#intermediateInterfaceMethod(). 15 | } 16 | export abstract class Superclass { 17 | // ^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Superclass# 18 | public abstract overrideMethod(): string 19 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Superclass#overrideMethod(). 20 | } 21 | export abstract class IntermediateSuperclass extends Superclass { 22 | // ^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass# 23 | // relationship implementation syntax 1.0.0 src/`inheritance.ts`/Superclass# 24 | // ^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Superclass# 25 | public override overrideMethod(): string { 26 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#overrideMethod(). 27 | // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superclass#overrideMethod(). 28 | return 'this will get overridden' 29 | } 30 | public abstract intermediateOverrideMethod(): string 31 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#intermediateOverrideMethod(). 32 | } 33 | export class Subclass 34 | // ^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass# 35 | // relationship implementation syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass# 36 | // relationship implementation syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface# 37 | // relationship implementation syntax 1.0.0 src/`inheritance.ts`/Superclass# 38 | // relationship implementation syntax 1.0.0 src/`overload.d.ts`/Overloader# 39 | // relationship implementation syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 40 | extends IntermediateSuperclass 41 | // ^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass# 42 | implements IntermediateSuperinterface, Overloader 43 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface# 44 | // ^^^^^^^^^^ reference syntax 1.0.0 src/`overload.d.ts`/Overloader# 45 | { 46 | public onLiteral(param: any): void { 47 | // ^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#onLiteral(). 48 | // relationship implementation reference syntax 1.0.0 src/`overload.d.ts`/Overloader#onLiteral(). 49 | // ^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#onLiteral().(param) 50 | throw new Error('Method not implemented.' + param) 51 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 52 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 53 | // ^^^^^ reference syntax 1.0.0 src/`inheritance.ts`/Subclass#onLiteral().(param) 54 | } 55 | property = 'property' 56 | //^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#property. 57 | //relationship implementation reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 58 | public overrideMethod(): string { 59 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#overrideMethod(). 60 | // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#overrideMethod(). 61 | // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/Superclass#overrideMethod(). 62 | throw new Error('Method not implemented.') 63 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 64 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 65 | } 66 | public intermediateOverrideMethod(): string { 67 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#intermediateOverrideMethod(). 68 | // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#intermediateOverrideMethod(). 69 | throw new Error('Method not implemented.') 70 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 71 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 72 | } 73 | public interfaceMethod(): string { 74 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#interfaceMethod(). 75 | // relationship implementation reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 76 | throw new Error('Method not implemented.') 77 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 78 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 79 | } 80 | public intermediateInterfaceMethod(): string { 81 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#intermediateInterfaceMethod(). 82 | // relationship implementation reference syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperinterface#intermediateInterfaceMethod(). 83 | throw new Error('Method not implemented.') 84 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 85 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 86 | } 87 | } 88 | export const objectLiteralImplementation: Superinterface = { 89 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/objectLiteralImplementation. 90 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 91 | property: 'property', 92 | //^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 93 | interfaceMethod: (): string => { 94 | //^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 95 | throw new Error('Function not implemented.') 96 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error# 97 | // ^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Error. 98 | }, 99 | } 100 | 101 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/interface.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`interface.ts`/ 2 | 3 | export interface Interface { 4 | // ^^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/Interface# 5 | property: string 6 | //^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/Interface#property. 7 | methodSignature(param: string): string 8 | //^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). 9 | // ^^^^^ definition syntax 1.0.0 src/`interface.ts`/Interface#methodSignature().(param) 10 | methodSignature2: (param: string) => string 11 | //^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/Interface#methodSignature2. 12 | // ^^^^^ definition local 1 13 | } 14 | 15 | export function newInterface(): Interface { 16 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`interface.ts`/newInterface(). 17 | // ^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface# 18 | return { 19 | property: 'a', 20 | // ^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#property. 21 | methodSignature(param: string): string { 22 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature(). 23 | // ^^^^^ definition local 5 24 | return param 25 | // ^^^^^ reference local 5 26 | }, 27 | methodSignature2: (param: string): string => { 28 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`interface.ts`/Interface#methodSignature2. 29 | // ^^^^^ definition local 7 30 | return param 31 | // ^^^^^ reference local 7 32 | }, 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/issue-45.d.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`issue-45.d.ts`/ 2 | 3 | export namespace example { 4 | // ^^^^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/ 5 | class Server { 6 | // ^^^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/Server# 7 | // This overloaded method reproduces the following issue https://github.com/sourcegraph/scip-typescript/issues/45 8 | addListener(name: 'a'): void 9 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/Server#addListener(). 10 | // ^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/Server#addListener().(name) 11 | addListener(name: 'b'): void 12 | // ^^^^^^^^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/Server#addListener(). 13 | // ^^^^ definition syntax 1.0.0 src/`issue-45.d.ts`/example/Server#addListener().(name) 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/local.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`local.ts`/ 2 | 3 | export function local(): string { 4 | // ^^^^^ definition syntax 1.0.0 src/`local.ts`/local(). 5 | const a = 'a' 6 | // ^ definition local 2 7 | let b = a 8 | // ^ definition local 5 9 | // ^ reference local 2 10 | var c = b, 11 | // ^ definition local 8 12 | // ^ reference local 5 13 | c2 = b 14 | // ^^ definition local 9 15 | // ^ reference local 5 16 | for (let d = 0; d < c.length; d++) { 17 | // ^ definition local 12 18 | // ^ reference local 12 19 | // ^ reference local 8 20 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/String#length. 21 | // ^ reference local 12 22 | c += d 23 | // ^ reference local 8 24 | // ^ reference local 12 25 | c2 += c.length 26 | // ^^ reference local 9 27 | // ^ reference local 8 28 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/String#length. 29 | } 30 | return [c, c2].reduce((previousValue, currentValue, currentIndex) => { 31 | // ^ reference local 8 32 | // ^^ reference local 9 33 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#reduce(). 34 | // ^^^^^^^^^^^^^ definition local 16 35 | // ^^^^^^^^^^^^ definition local 17 36 | // ^^^^^^^^^^^^ definition local 18 37 | return previousValue + currentValue + currentIndex 38 | // ^^^^^^^^^^^^^ reference local 16 39 | // ^^^^^^^^^^^^ reference local 17 40 | // ^^^^^^^^^^^^ reference local 18 41 | }) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/module.d.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`module.d.ts`/ 2 | 3 | declare module 'a:b' { 4 | // ^^^^^ definition syntax 1.0.0 src/`module.d.ts`/`'a:b'`/ 5 | function hello(): string 6 | // ^^^^^ definition syntax 1.0.0 src/`module.d.ts`/`'a:b'`/hello(). 7 | } 8 | 9 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/namespace.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`namespace.ts`/ 2 | 3 | export declare namespace a { 4 | // ^ definition syntax 1.0.0 src/`namespace.ts`/a/ 5 | function hello(): string 6 | // ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/hello(). 7 | interface Interface { 8 | // ^^^^^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface# 9 | hello: string 10 | // ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/Interface#hello. 11 | } 12 | var i: Interface 13 | // ^ definition syntax 1.0.0 src/`namespace.ts`/a/i. 14 | // ^^^^^^^^^ reference syntax 1.0.0 src/`namespace.ts`/a/Interface# 15 | export const value = 1 16 | // ^^^^^ definition syntax 1.0.0 src/`namespace.ts`/a/value. 17 | } 18 | 19 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/object-literals-arrow-function.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/ 2 | 3 | import { Option } from './reusable-types' 4 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 5 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 6 | 7 | interface Foobar { 8 | // ^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 9 | foobar: number 10 | //^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 11 | } 12 | 13 | export function hasArrowFunctionParameter( 14 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). 15 | something: number, 16 | //^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(something) 17 | fn: (foobar: Foobar) => Foobar 18 | //^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(fn) 19 | // ^^^^^^ definition local 1 20 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 21 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 22 | ): Foobar { 23 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 24 | return fn({ foobar: 42 + something }) 25 | // ^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(fn) 26 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 27 | // ^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter().(something) 28 | } 29 | 30 | export function consumesArrowFunction(): number { 31 | // ^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/consumesArrowFunction(). 32 | return ( 33 | hasArrowFunctionParameter(1, ({ foobar }) => ({ foobar: foobar + 1 })) 34 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). 35 | // ^^^^^^ definition local 10 36 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 37 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 38 | // ^^^^^^ reference local 10 39 | .foobar + 40 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 41 | hasArrowFunctionParameter(2, foobar => ({ foobar: foobar.foobar + 2 })) 42 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/hasArrowFunctionParameter(). 43 | // ^^^^^^ definition local 14 44 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 45 | // ^^^^^^ reference local 14 46 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 47 | .foobar 48 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 49 | ) 50 | } 51 | 52 | export function genericArrow(): Foobar[] { 53 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrow(). 54 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 55 | return [1].map(n => ({ foobar: n + 1 })) 56 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 57 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 58 | // ^ definition local 18 59 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 60 | // ^ reference local 18 61 | } 62 | 63 | export function genericArrowOption(): Option[] { 64 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrowOption(). 65 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 66 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 67 | return [1].map>(n => ({ value: { foobar: n + 1 } })) 68 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 69 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 70 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 71 | // ^ definition local 22 72 | // ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. 73 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar#foobar. 74 | // ^ reference local 22 75 | } 76 | 77 | export function genericArrow2(): Foobar[] { 78 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/genericArrow2(). 79 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/Foobar# 80 | // navigation to `foobar` below does not work with tsserver or scip-java 81 | // because `map` is missing an explicit `map` annotation. 82 | return [1].map(n => ({ foobar: n + 1 })) 83 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 84 | // ^ definition local 26 85 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/foobar0: 86 | // ^ reference local 26 87 | } 88 | 89 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/object-literals-call-signatures.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/ 2 | 3 | import { 4 | Configuration, 5 | //^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 6 | GenericClass, 7 | //^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass# 8 | GenericInterface, 9 | //^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# 10 | Option, 11 | //^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 12 | Superinterface, 13 | //^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 14 | } from './reusable-types' 15 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 16 | 17 | export function consumesInterface(superInterface: Superinterface): void {} 18 | // ^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). 19 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface().(superInterface) 20 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 21 | export function consumesArray(superInterface: Superinterface[]): void {} 22 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray(). 23 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray().(superInterface) 24 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 25 | export function consumesGenericInterface( 26 | // ^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). 27 | // ^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().[T] 28 | genercInterface: GenericInterface 29 | //^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().(genercInterface) 30 | // ^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# 31 | // ^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface().[T] 32 | ): void {} 33 | 34 | export function infersInterface(): void { 35 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/infersInterface(). 36 | consumesInterface({ 37 | //^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). 38 | interfaceMethod: (): string => 'inferred', 39 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 40 | property: 'inferred', 41 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 42 | }) 43 | consumesArray([ 44 | //^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesArray(). 45 | { 46 | interfaceMethod: (): string => 'inferred', 47 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 48 | property: 'inferred', 49 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 50 | }, 51 | ]) 52 | consumesGenericInterface({ 53 | //^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). 54 | interfaceMethod: (): string => 'inferred', 55 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). 56 | property: 123, 57 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. 58 | }) 59 | consumesGenericInterface[]>({ 60 | //^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesGenericInterface(). 61 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 62 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 63 | interfaceMethod: (): string => 'inferred', 64 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). 65 | property: [{ value: { property: 42, property2: '42' } }], 66 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. 67 | // ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. 68 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 69 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 70 | }) 71 | } 72 | export function returnStatementInsideArgumentExpression(): Configuration[] { 73 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/returnStatementInsideArgumentExpression(). 74 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 75 | if (1 == 1) { 76 | return [1].map((number: number): Configuration => { 77 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 78 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 79 | // ^^^^^^ definition local 3 80 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 81 | const incremented = number + 1 82 | // ^^^^^^^^^^^ definition local 6 83 | // ^^^^^^ reference local 3 84 | return { 85 | property: incremented, 86 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 87 | // ^^^^^^^^^^^ reference local 6 88 | property2: incremented.toString(), 89 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 90 | // ^^^^^^^^^^^ reference local 6 91 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Number#toString(). 92 | } 93 | }) 94 | } else { 95 | return [1].map(number => { 96 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 97 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 98 | // ^^^^^^ definition local 10 99 | const incremented = number + 1 100 | // ^^^^^^^^^^^ definition local 13 101 | // ^^^^^^ reference local 10 102 | return { 103 | property: incremented, 104 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 105 | // ^^^^^^^^^^^ reference local 13 106 | property2: incremented.toString(), 107 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 108 | // ^^^^^^^^^^^ reference local 13 109 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Number#toString(). 110 | } 111 | }) 112 | } 113 | } 114 | 115 | export function createGenericClass(): GenericClass { 116 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/createGenericClass(). 117 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass# 118 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 119 | return new GenericClass([{ property: 1, property2: '2' }]) 120 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``(). 121 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 122 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 123 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 124 | } 125 | 126 | export function handleGenericClass() { 127 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/handleGenericClass(). 128 | return createGenericClass().map(({ property, property2 }) => ({ 129 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/createGenericClass(). 130 | // ^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map(). 131 | // ^^^^^^^^ definition local 19 132 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 133 | // ^^^^^^^^^ definition local 20 134 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 135 | property: property + 1, 136 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 137 | // ^^^^^^^^ reference local 19 138 | property2: property2 + '1', 139 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 140 | // ^^^^^^^^^ reference local 20 141 | })) 142 | } 143 | 144 | export function handleShorthand() { 145 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/handleShorthand(). 146 | const property = '42' 147 | // ^^^^^^^^ definition local 23 148 | const interfaceMethod = (): string => 'inferred' 149 | // ^^^^^^^^^^^^^^^ definition local 26 150 | consumesInterface({ 151 | //^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`object-literals-call-signatures.ts`/consumesInterface(). 152 | interfaceMethod, 153 | // ^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 154 | property, 155 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 156 | }) 157 | } 158 | 159 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/object-literals-nested.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`object-literals-nested.ts`/ 2 | 3 | import { Option } from './reusable-types' 4 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 5 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 6 | 7 | interface Address { 8 | // ^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address# 9 | street: string 10 | //^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. 11 | people: Person[] 12 | //^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. 13 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# 14 | } 15 | interface Person { 16 | // ^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person# 17 | name: string 18 | //^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. 19 | address?: Address 20 | //^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. 21 | // ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address# 22 | } 23 | 24 | export function handleNestedObjectLiterals(): Person { 25 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/handleNestedObjectLiterals(). 26 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# 27 | return { 28 | name: 'John', 29 | // ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. 30 | address: { 31 | // ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. 32 | street: 'Oxford Street', 33 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. 34 | people: [ 35 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. 36 | { 37 | name: 'Susan', 38 | // ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. 39 | }, 40 | ], 41 | }, 42 | } 43 | } 44 | 45 | export function handleNestedTypeVariables(): Option { 46 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals-nested.ts`/handleNestedTypeVariables(). 47 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option# 48 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person# 49 | return { 50 | value: { 51 | // ^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#value. 52 | name: 'John', 53 | // ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. 54 | address: { 55 | // ^^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#address. 56 | street: 'Oxford Street', 57 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#street. 58 | people: [ 59 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Address#people. 60 | { 61 | name: 'Susan', 62 | // ^^^^ reference syntax 1.0.0 src/`object-literals-nested.ts`/Person#name. 63 | }, 64 | ], 65 | }, 66 | }, 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/object-literals.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`object-literals.ts`/ 2 | 3 | import { Configuration } from './reusable-types' 4 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 5 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/ 6 | 7 | function random(): number { 8 | // ^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/random(). 9 | return Math.random() 10 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Math# 11 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Math. 12 | // ^^^^ reference typescript 5.6.2 lib/`lib.es2015.core.d.ts`/Math# 13 | // ^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Math# 14 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Math#random(). 15 | } 16 | 17 | export function handleArrayLiteral(): Configuration[] { 18 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/handleArrayLiteral(). 19 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 20 | return [ 21 | { 22 | property: 41, 23 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 24 | property2: '41', 25 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 26 | }, 27 | ] 28 | } 29 | 30 | export function returnStatement(): Configuration { 31 | // ^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/returnStatement(). 32 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 33 | if (random() > 0) { 34 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 35 | return { 36 | property: 41, 37 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 38 | property2: '41', 39 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 40 | } 41 | } 42 | for (let i = 0; i < 9; i++) { 43 | // ^ definition local 2 44 | // ^ reference local 2 45 | // ^ reference local 2 46 | if (random() > i) { 47 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 48 | // ^ reference local 2 49 | return { 50 | property: 41, 51 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 52 | property2: '41', 53 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 54 | } 55 | } 56 | } 57 | for (const i of [1, 2, 3]) { 58 | // ^ definition local 5 59 | if (random() > i) { 60 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 61 | // ^ reference local 5 62 | return { 63 | property: 41, 64 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 65 | property2: '41', 66 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 67 | } 68 | } 69 | } 70 | for (const i in { '1': 2 }) { 71 | // ^ definition local 8 72 | // ^^^ definition syntax 1.0.0 src/`object-literals.ts`/`'1'0`: 73 | if (random() > Number.parseInt(i)) { 74 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 75 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Number# 76 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Number. 77 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Number# 78 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.es2020.number.d.ts`/Number# 79 | // ^^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.core.d.ts`/NumberConstructor#parseInt(). 80 | // ^ reference local 8 81 | return { 82 | property: 41, 83 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 84 | property2: '41', 85 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 86 | } 87 | } 88 | } 89 | while (random() < 0) { 90 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 91 | return { 92 | property: 41, 93 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 94 | property2: '41', 95 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 96 | } 97 | } 98 | do { 99 | if (random() > 0) { 100 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 101 | return { 102 | property: 41, 103 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 104 | property2: '41', 105 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 106 | } 107 | } 108 | } while (random() < 0) 109 | // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). 110 | 111 | return { 112 | property: 42, 113 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 114 | property2: '41', 115 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 116 | } 117 | } 118 | 119 | export function constDeclaration(): number[] { 120 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`object-literals.ts`/constDeclaration(). 121 | var configuration1: Configuration = { 122 | // ^^^^^^^^^^^^^^ definition local 11 123 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 124 | property: 1, 125 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 126 | property2: '1', 127 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 128 | } 129 | configuration1 = { 130 | //^^^^^^^^^^^^^^ reference local 11 131 | property: 2, 132 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 133 | property2: '2', 134 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 135 | } 136 | let configuration2: Configuration = { 137 | // ^^^^^^^^^^^^^^ definition local 14 138 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 139 | property: 3, 140 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 141 | property2: '3', 142 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 143 | } 144 | configuration2.property = configuration1.property 145 | //^^^^^^^^^^^^^^ reference local 14 146 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 147 | // ^^^^^^^^^^^^^^ reference local 11 148 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 149 | const configuration3: Configuration = { 150 | // ^^^^^^^^^^^^^^ definition local 17 151 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Configuration# 152 | property: 4, 153 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 154 | property2: '4', 155 | // ^^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 156 | } 157 | return [ 158 | configuration1.property, 159 | // ^^^^^^^^^^^^^^ reference local 11 160 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 161 | configuration2.property, 162 | // ^^^^^^^^^^^^^^ reference local 14 163 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 164 | configuration3.property, 165 | // ^^^^^^^^^^^^^^ reference local 17 166 | // ^^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 167 | ] 168 | } 169 | 170 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/overload.d.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`overload.d.ts`/ 2 | 3 | export interface Overloader { 4 | // ^^^^^^^^^^ definition syntax 1.0.0 src/`overload.d.ts`/Overloader# 5 | onLiteral(param: 'a'): void 6 | //^^^^^^^^^ definition syntax 1.0.0 src/`overload.d.ts`/Overloader#onLiteral(). 7 | // ^^^^^ definition syntax 1.0.0 src/`overload.d.ts`/Overloader#onLiteral().(param) 8 | onLiteral(param: 'b'): void 9 | //^^^^^^^^^ definition syntax 1.0.0 src/`overload.d.ts`/Overloader#onLiteral(). 10 | // ^^^^^ definition syntax 1.0.0 src/`overload.d.ts`/Overloader#onLiteral().(param) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/property-assignment-reference.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`property-assignment-reference.ts`/ 2 | 3 | import { 4 | propertyAssignment, 5 | //^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`property-assignment.ts`/propertyAssignment(). 6 | shorthandPropertyAssignment, 7 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`property-assignment.ts`/shorthandPropertyAssignment(). 8 | } from './property-assignment' 9 | // ^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`property-assignment.ts`/ 10 | 11 | export function run(): string { 12 | // ^^^ definition syntax 1.0.0 src/`property-assignment-reference.ts`/run(). 13 | return propertyAssignment().a + shorthandPropertyAssignment().a 14 | // ^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`property-assignment.ts`/propertyAssignment(). 15 | // ^ reference syntax 1.0.0 src/`property-assignment.ts`/a0: 16 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`property-assignment.ts`/shorthandPropertyAssignment(). 17 | // ^ reference syntax 1.0.0 src/`property-assignment.ts`/a1: 18 | } 19 | 20 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/property-assignment.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`property-assignment.ts`/ 2 | 3 | export function propertyAssignment() { 4 | // ^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/propertyAssignment(). 5 | return { a: 'a' } 6 | // ^ definition syntax 1.0.0 src/`property-assignment.ts`/a0: 7 | } 8 | export function shorthandPropertyAssignment() { 9 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/shorthandPropertyAssignment(). 10 | const a = 'a' 11 | // ^ definition local 2 12 | return { a } 13 | // ^ definition syntax 1.0.0 src/`property-assignment.ts`/a1: 14 | // ^ reference local 2 15 | } 16 | type A = { a: string; b: number } 17 | // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A# 18 | // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. 19 | // ^ definition syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:b. 20 | export function typedPropertyAssignment(): A { 21 | // ^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`property-assignment.ts`/typedPropertyAssignment(). 22 | // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A# 23 | // prettier-ignore 24 | return { a: 'a', "b": 10 } 25 | // ^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:a. 26 | // ^^^ reference syntax 1.0.0 src/`property-assignment.ts`/A#typeLiteral3:b. 27 | } 28 | 29 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/reusable-types.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`reusable-types.ts`/ 2 | 3 | // Reusable types for other snapshot tests 4 | 5 | export interface Option
{ 6 | // ^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Option# 7 | // ^ definition syntax 1.0.0 src/`reusable-types.ts`/Option#[A] 8 | value?: A 9 | //^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Option#value. 10 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/Option#[A] 11 | } 12 | 13 | export interface Numbers { 14 | // ^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Numbers# 15 | property: number 16 | //^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Numbers#property. 17 | } 18 | export interface Strings { 19 | // ^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Strings# 20 | property2: string 21 | //^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Strings#property2. 22 | } 23 | export type Configuration = Numbers & Strings 24 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Configuration# 25 | // ^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Numbers# 26 | // ^^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/Strings# 27 | 28 | export class GenericClass { 29 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass# 30 | // ^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] 31 | constructor(public readonly values: A[]) {} 32 | //^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``(). 33 | // ^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``().(values) 34 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] 35 | public map(fn: (a: A) => A): A[] { 36 | // ^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map(). 37 | // ^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map().(fn) 38 | // ^ definition local 1 39 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] 40 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] 41 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#[A] 42 | return this.values.map(a => fn(a)) 43 | // ^^^^^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#``().(values) 44 | // ^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Array#map(). 45 | // ^ definition local 5 46 | // ^^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericClass#map().(fn) 47 | // ^ reference local 5 48 | } 49 | } 50 | 51 | export interface Superinterface { 52 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface# 53 | property: string 54 | //^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface#property. 55 | interfaceMethod(): string 56 | //^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/Superinterface#interfaceMethod(). 57 | } 58 | export interface GenericInterface { 59 | // ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface# 60 | // ^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#[T] 61 | property: T 62 | //^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#property. 63 | // ^ reference syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#[T] 64 | interfaceMethod(): string 65 | //^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`reusable-types.ts`/GenericInterface#interfaceMethod(). 66 | } 67 | 68 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/string-literals.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`string-literals.ts`/ 2 | 3 | interface SomeInterface { 4 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`string-literals.ts`/SomeInterface# 5 | a: number 6 | //^ definition syntax 1.0.0 src/`string-literals.ts`/SomeInterface#a. 7 | b: number 8 | //^ definition syntax 1.0.0 src/`string-literals.ts`/SomeInterface#b. 9 | c: number 10 | //^ definition syntax 1.0.0 src/`string-literals.ts`/SomeInterface#c. 11 | } 12 | // "Go to definition" does not work for the 'a', 'b' and 'c' string literals 13 | // below when using tsserver so it's fine that scip-typescript does not emit 14 | // occurrences here either. 15 | export type OmitInterface = Omit 16 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`string-literals.ts`/OmitInterface# 17 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Omit# 18 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`string-literals.ts`/SomeInterface# 19 | export type PickInterface = Pick 20 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`string-literals.ts`/PickInterface# 21 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Pick# 22 | // ^^^^^^^^^^^^^ reference syntax 1.0.0 src/`string-literals.ts`/SomeInterface# 23 | 24 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/structural-type.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`structural-type.ts`/ 2 | 3 | export function foo(): Promise<{ member: number }> { 4 | // ^^^ definition syntax 1.0.0 src/`structural-type.ts`/foo(). 5 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise# 6 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.iterable.d.ts`/Promise# 7 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/Promise. 8 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# 9 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2018.promise.d.ts`/Promise# 10 | // ^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/foo().Promise:typeLiteral0:member. 11 | return Promise.resolve({ member: 42 }) 12 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise# 13 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.iterable.d.ts`/Promise# 14 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/Promise. 15 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# 16 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2018.promise.d.ts`/Promise# 17 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve(). 18 | // ^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/member0: 19 | } 20 | export function bar(): Promise { 21 | // ^^^ definition syntax 1.0.0 src/`structural-type.ts`/bar(). 22 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise# 23 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.iterable.d.ts`/Promise# 24 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/Promise. 25 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# 26 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2018.promise.d.ts`/Promise# 27 | return foo().then(x => x.member) 28 | // ^^^ reference syntax 1.0.0 src/`structural-type.ts`/foo(). 29 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise#then(). 30 | // ^ definition local 4 31 | // ^ reference local 4 32 | // ^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/foo().Promise:typeLiteral0:member. 33 | } 34 | export function bar2(): Promise { 35 | // ^^^^ definition syntax 1.0.0 src/`structural-type.ts`/bar2(). 36 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise# 37 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.iterable.d.ts`/Promise# 38 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.promise.d.ts`/Promise. 39 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# 40 | // ^^^^^^^ reference typescript 5.6.2 lib/`lib.es2018.promise.d.ts`/Promise# 41 | return foo().then(({ member }) => member) 42 | // ^^^ reference syntax 1.0.0 src/`structural-type.ts`/foo(). 43 | // ^^^^ reference typescript 5.6.2 lib/`lib.es5.d.ts`/Promise#then(). 44 | // ^^^^^^ definition local 10 45 | // ^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/foo().Promise:typeLiteral0:member. 46 | // ^^^^^^ reference local 10 47 | } 48 | 49 | type OptionsFlags = { [Property in keyof Type]: boolean } 50 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/OptionsFlags# 51 | // ^^^^ definition syntax 1.0.0 src/`structural-type.ts`/OptionsFlags#[Type] 52 | // ^^^^^^^^ definition local 12 53 | // ^^^^ reference syntax 1.0.0 src/`structural-type.ts`/OptionsFlags#[Type] 54 | type FeatureFlags = { darkMode: () => void } 55 | // ^^^^^^^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/FeatureFlags# 56 | // ^^^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/FeatureFlags#typeLiteral13:darkMode. 57 | export type FeatureOptions = OptionsFlags // implicitly // type FeatureOptions = { // darkMode: boolean; // } const fo: FeatureOptions = { darkMode: true }; // ^ go to def 58 | // ^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/FeatureOptions# 59 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/OptionsFlags# 60 | // ^^^^^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/FeatureFlags# 61 | export const fo: FeatureOptions = { darkMode: true } 62 | // ^^ definition syntax 1.0.0 src/`structural-type.ts`/fo. 63 | // ^^^^^^^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/FeatureOptions# 64 | // ^^^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/FeatureFlags#typeLiteral13:darkMode. 65 | 66 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/type-alias.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`type-alias.ts`/ 2 | 3 | type S = string 4 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/S# 5 | 6 | const s: S = '' 7 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/s. 8 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/S# 9 | 10 | class C { 11 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/C# 12 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/C#[T] 13 | t: T 14 | //^ definition syntax 1.0.0 src/`type-alias.ts`/C#t. 15 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/C#[T] 16 | } 17 | type Cstring = C 18 | // ^^^^^^^ definition syntax 1.0.0 src/`type-alias.ts`/Cstring# 19 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/C# 20 | 21 | const cs: Cstring = new C() 22 | // ^^ definition syntax 1.0.0 src/`type-alias.ts`/cs. 23 | // ^^^^^^^ reference syntax 1.0.0 src/`type-alias.ts`/Cstring# 24 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/C# 25 | 26 | class D { 27 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/D# 28 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/D#[T] 29 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/D#[U] 30 | t: T 31 | //^ definition syntax 1.0.0 src/`type-alias.ts`/D#t. 32 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D#[T] 33 | u: U 34 | //^ definition syntax 1.0.0 src/`type-alias.ts`/D#u. 35 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D#[U] 36 | } 37 | type DT = D // partially specialized 38 | // ^^ definition syntax 1.0.0 src/`type-alias.ts`/DT# 39 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/DT#[T] 40 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D# 41 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/DT#[T] 42 | type DU = D> // recursive! 43 | // ^^ definition syntax 1.0.0 src/`type-alias.ts`/DU# 44 | // ^ definition syntax 1.0.0 src/`type-alias.ts`/DU#[U] 45 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D# 46 | // ^^ reference syntax 1.0.0 src/`type-alias.ts`/DU# 47 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/DU#[U] 48 | 49 | const dt: DT = new D() 50 | // ^^ definition syntax 1.0.0 src/`type-alias.ts`/dt. 51 | // ^^ reference syntax 1.0.0 src/`type-alias.ts`/DT# 52 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D# 53 | const du: DU = new D() 54 | // ^^ definition syntax 1.0.0 src/`type-alias.ts`/du. 55 | // ^^ reference syntax 1.0.0 src/`type-alias.ts`/DU# 56 | // ^ reference syntax 1.0.0 src/`type-alias.ts`/D# 57 | 58 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/type-parameter.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`type-parameter.ts`/ 2 | 3 | export function typeParameter(parameter: A, parameter2: B): [A, B] { 4 | // ^^^^^^^^^^^^^ definition syntax 1.0.0 src/`type-parameter.ts`/typeParameter(). 5 | // ^ definition syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[A] 6 | // ^ definition syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[B] 7 | // ^^^^^^^^^ definition syntax 1.0.0 src/`type-parameter.ts`/typeParameter().(parameter) 8 | // ^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[A] 9 | // ^^^^^^^^^^ definition syntax 1.0.0 src/`type-parameter.ts`/typeParameter().(parameter2) 10 | // ^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[B] 11 | // ^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[A] 12 | // ^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().[B] 13 | return [parameter, parameter2] 14 | // ^^^^^^^^^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().(parameter) 15 | // ^^^^^^^^^^ reference syntax 1.0.0 src/`type-parameter.ts`/typeParameter().(parameter2) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /snapshots/output/syntax/src/typings.ts: -------------------------------------------------------------------------------- 1 | // < definition syntax 1.0.0 src/`typings.ts`/ 2 | 3 | export function process() { 4 | // ^^^^^^^ definition syntax 1.0.0 src/`typings.ts`/process(). 5 | return window.process 6 | // ^^^^^^ reference typescript 5.6.2 lib/`lib.dom.d.ts`/window. 7 | // ^^^^^^^ reference @types/node 20.16.10 `globals.d.ts`/global/process. 8 | // ^^^^^^^ reference @types/node 20.16.10 `process.d.ts`/`"process"`/global/process. 9 | } 10 | 11 | -------------------------------------------------------------------------------- /snapshots/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "snapshots", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "private": true, 7 | "workspaces": [ 8 | "input/*" 9 | ], 10 | "dependencies": { 11 | "react": "18.0.0", 12 | "@sourcegraph/tsconfig": "4.0.1" 13 | }, 14 | "devDependencies": { 15 | "@types/react": "18.2.39" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /snapshots/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@sourcegraph/tsconfig@4.0.1": 6 | version "4.0.1" 7 | resolved "https://registry.yarnpkg.com/@sourcegraph/tsconfig/-/tsconfig-4.0.1.tgz#5965ec41771d2ac5b23b6e0d919cee3e70485840" 8 | integrity sha512-G/xsejsR84G5dj3kHJ7svKBo9E5tWl96rUHKP94Y2UDtA7BzUhAYbieM+b9ZUpIRt66h3+MlYbG5HK4UI2zDzw== 9 | 10 | "@types/prop-types@*": 11 | version "15.7.4" 12 | resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" 13 | integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== 14 | 15 | "@types/react@18.2.39": 16 | version "18.2.39" 17 | resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.39.tgz#744bee99e053ad61fe74eb8b897f3ab5b19a7e25" 18 | integrity sha512-Oiw+ppED6IremMInLV4HXGbfbG6GyziY3kqAwJYOR0PNbkYDmLWQA3a95EhdSmamsvbkJN96ZNN+YD+fGjzSBA== 19 | dependencies: 20 | "@types/prop-types" "*" 21 | "@types/scheduler" "*" 22 | csstype "^3.0.2" 23 | 24 | "@types/scheduler@*": 25 | version "0.16.2" 26 | resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" 27 | integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== 28 | 29 | csstype@^3.0.2: 30 | version "3.0.11" 31 | resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.11.tgz#d66700c5eacfac1940deb4e3ee5642792d85cd33" 32 | integrity sha512-sa6P2wJ+CAbgyy4KFssIb/JNMLxFvKF1pCYCSXS8ZMuqZnMsrxqI2E5sPyoTpxoPU/gVZMzr2zjOfg8GIZOMsw== 33 | 34 | "js-tokens@^3.0.0 || ^4.0.0": 35 | version "4.0.0" 36 | resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" 37 | integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== 38 | 39 | loose-envify@^1.1.0: 40 | version "1.4.0" 41 | resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" 42 | integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== 43 | dependencies: 44 | js-tokens "^3.0.0 || ^4.0.0" 45 | 46 | react@18.0.0: 47 | version "18.0.0" 48 | resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96" 49 | integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A== 50 | dependencies: 51 | loose-envify "^1.1.0" 52 | -------------------------------------------------------------------------------- /src/.gitattributes: -------------------------------------------------------------------------------- 1 | scip.ts linguist-generated=true 2 | -------------------------------------------------------------------------------- /src/CommandLineOptions.test.ts: -------------------------------------------------------------------------------- 1 | import { test } from 'uvu' 2 | import * as assert from 'uvu/assert' 3 | 4 | import { mainCommand, MultiProjectOptions } from './CommandLineOptions' 5 | 6 | function checkIndexParser( 7 | args: string[], 8 | expectedOptions: Partial, 9 | expectedProjects?: string[] 10 | ): void { 11 | test(args.join(' '), () => { 12 | let isAssertionTriggered = false 13 | const actualArguments = ['node', 'scip-typescript.js', 'index', ...args] 14 | mainCommand((projects, options) => { 15 | assert.equal(options, { ...options, ...expectedOptions }) 16 | if (expectedProjects) { 17 | assert.equal(projects, expectedProjects) 18 | } 19 | isAssertionTriggered = true 20 | }).parse(actualArguments) 21 | assert.ok(isAssertionTriggered) 22 | }) 23 | } 24 | 25 | // defaults 26 | checkIndexParser([], { 27 | cwd: process.cwd(), 28 | inferTsconfig: false, 29 | output: 'index.scip', 30 | yarnWorkspaces: false, 31 | }) 32 | 33 | checkIndexParser(['--cwd', 'qux'], { cwd: 'qux' }) 34 | checkIndexParser(['--yarn-workspaces'], { yarnWorkspaces: true }) 35 | checkIndexParser(['--pnpm-workspaces'], { pnpmWorkspaces: true }) 36 | checkIndexParser(['--infer-tsconfig'], { inferTsconfig: true }) 37 | checkIndexParser(['--no-progress-bar'], { progressBar: false }) 38 | checkIndexParser(['--progress-bar'], { progressBar: true }) 39 | checkIndexParser(['--no-global-caches'], { globalCaches: false }) 40 | 41 | test.run() 42 | -------------------------------------------------------------------------------- /src/CommandLineOptions.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander' 2 | import ts from 'typescript' 3 | 4 | import packageJson from '../package.json' 5 | 6 | import { parseHumanByteSizeIntoNumber } from './parseHumanByteSizeIntoNumber' 7 | import * as scip from './scip' 8 | 9 | /** Configuration options to index a multi-project workspace. */ 10 | export interface MultiProjectOptions { 11 | inferTsconfig: boolean 12 | progressBar: boolean 13 | yarnWorkspaces: boolean 14 | yarnBerryWorkspaces: boolean 15 | pnpmWorkspaces: boolean 16 | globalCaches: boolean 17 | maxFileByteSize?: string 18 | maxFileByteSizeNumber?: number 19 | cwd: string 20 | output: string 21 | indexedProjects: Set 22 | } 23 | 24 | /** Configuration options to index a single TypeScript project. */ 25 | export interface ProjectOptions extends MultiProjectOptions { 26 | projectRoot: string 27 | projectDisplayName: string 28 | writeIndex: (index: scip.scip.Index) => void 29 | } 30 | 31 | /** Cached values */ 32 | export interface GlobalCache { 33 | sources: Map< 34 | string, 35 | [ts.SourceFile | undefined, ts.ScriptTarget | ts.CreateSourceFileOptions] 36 | > 37 | parsedCommandLines: Map 38 | } 39 | 40 | export function mainCommand( 41 | indexAction: (projects: string[], options: MultiProjectOptions) => void 42 | ): Command { 43 | const command = new Command() 44 | command 45 | .name('scip-typescript') 46 | .version(packageJson.version) 47 | .description( 48 | 'SCIP indexer for TypeScript and JavaScript\nFor usage examples, see https://github.com/sourcegraph/scip-typescript/blob/main/README.md' 49 | ) 50 | command 51 | .command('index') 52 | .option('--cwd ', 'the working directory', process.cwd()) 53 | .option('--pnpm-workspaces', 'whether to index all pnpm workspaces', false) 54 | .option('--yarn-workspaces', 'whether to index all yarn workspaces', false) 55 | .option( 56 | '--yarn-berry-workspaces', 57 | '(deprecated) use --yarn-workspaces instead', 58 | false 59 | ) 60 | .option( 61 | '--infer-tsconfig', 62 | "whether to infer the tsconfig.json file, if it's missing", 63 | false 64 | ) 65 | .option('--output ', 'path to the output file', 'index.scip') 66 | .option('--progress-bar', 'whether to enable a rich progress bar') 67 | .option('--no-progress-bar', 'whether to disable the rich progress bar') 68 | .option( 69 | '--no-global-caches', 70 | 'whether to disable global caches between TypeScript projects' 71 | ) 72 | .option( 73 | '--max-file-byte-size ', 74 | 'skip files that have a larger byte size than the provided value. Supported formats: 1kb, 1mb, 1gb.', 75 | '1mb' 76 | ) 77 | .argument('[projects...]') 78 | .action((parsedProjects, parsedOptions) => { 79 | const options = parsedOptions as MultiProjectOptions 80 | 81 | // Parse and validate human-provided --max-file-byte-size value 82 | options.maxFileByteSizeNumber = parseHumanByteSizeIntoNumber( 83 | options.maxFileByteSize ?? '1mb' 84 | ) 85 | if (isNaN(options.maxFileByteSizeNumber)) { 86 | console.error( 87 | `invalid byte size '${options.maxFileByteSize}'. To fix this problem, change the value of the flag --max-file-byte-size to use a valid byte size format: 1kb, 1mb, 1gb.` 88 | ) 89 | process.exitCode = 1 90 | return 91 | } 92 | 93 | indexAction(parsedProjects as string[], options) 94 | }) 95 | return command 96 | } 97 | -------------------------------------------------------------------------------- /src/Counter.ts: -------------------------------------------------------------------------------- 1 | export class Counter { 2 | private n = -1 3 | public next(): number { 4 | this.n++ 5 | return this.n 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/Descriptor.ts: -------------------------------------------------------------------------------- 1 | import * as scip from './scip' 2 | 3 | type Descriptor = scip.scip.Descriptor 4 | const Descriptor = scip.scip.Descriptor 5 | type Suffix = scip.scip.Descriptor.Suffix 6 | const Suffix = scip.scip.Descriptor.Suffix 7 | 8 | export function packageDescriptor(name: string): Descriptor { 9 | return new Descriptor({ name, suffix: Suffix.Namespace }) 10 | } 11 | 12 | export function typeDescriptor(name: string): Descriptor { 13 | return new Descriptor({ name, suffix: Suffix.Type }) 14 | } 15 | 16 | export function termDescriptor(name: string): Descriptor { 17 | return new Descriptor({ name, suffix: Suffix.Term }) 18 | } 19 | 20 | export function metaDescriptor(name: string): Descriptor { 21 | return new Descriptor({ name, suffix: Suffix.Meta }) 22 | } 23 | 24 | export function methodDescriptor(name: string): Descriptor { 25 | return new Descriptor({ name, suffix: Suffix.Method }) 26 | } 27 | 28 | export function parameterDescriptor(name: string): Descriptor { 29 | return new Descriptor({ name, suffix: Suffix.Parameter }) 30 | } 31 | 32 | export function typeParameterDescriptor(name: string): Descriptor { 33 | return new Descriptor({ name, suffix: Suffix.TypeParameter }) 34 | } 35 | 36 | export function descriptorString(desc: Descriptor): string { 37 | switch (desc.suffix) { 38 | case Suffix.Namespace: { 39 | return escapedName(desc) + '/' 40 | } 41 | case Suffix.Type: { 42 | return escapedName(desc) + '#' 43 | } 44 | case Suffix.Term: { 45 | return escapedName(desc) + '.' 46 | } 47 | case Suffix.Meta: { 48 | return escapedName(desc) + ':' 49 | } 50 | case Suffix.Method: { 51 | return escapedName(desc) + '(' + (desc.disambiguator || '') + ').' 52 | } 53 | case Suffix.Parameter: { 54 | return '(' + escapedName(desc) + ')' 55 | } 56 | case Suffix.TypeParameter: { 57 | return '[' + escapedName(desc) + ']' 58 | } 59 | default: { 60 | throw new Error(`unknown descriptor suffix: ${desc.suffix}`) 61 | } 62 | } 63 | } 64 | 65 | function escapedName(desc: Descriptor): string { 66 | if (!desc.name) { 67 | return '' 68 | } 69 | if (isSimpleIdentifier(desc.name)) { 70 | return desc.name 71 | } 72 | return '`' + desc.name.replaceAll('`', '``') + '`' 73 | } 74 | 75 | // Returns true if this name does not need to be backtick escaped 76 | function isSimpleIdentifier(name: string): boolean { 77 | return /^[\w$+-]+$/i.test(name) 78 | } 79 | -------------------------------------------------------------------------------- /src/Input.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | 3 | import { Range } from './Range' 4 | 5 | export class Input { 6 | public lines: string[] 7 | constructor( 8 | public readonly path: string, 9 | public readonly text: string 10 | ) { 11 | this.lines = text.split('\n') 12 | } 13 | 14 | public static fromFile(path: string): Input { 15 | return new Input(path, fs.readFileSync(path).toString()) 16 | } 17 | /** 18 | * For debugingg purposes, formats the source file with carets ^ to underline 19 | * the range. For example, when given the range enclosing the `hello` 20 | * identifier. 21 | * ``` 22 | * src/hello.ts:LINE:CHARACTER 23 | * const hello = 42 24 | * ^^^^^ 25 | * ``` 26 | * @param range the range to highlight 27 | * @param diagnostic optional message to include with the formatted string 28 | */ 29 | public format(range: Range, diagnostic?: string): string { 30 | const line = this.lines[range.start.line] 31 | const indent = ' '.repeat(range.start.character) 32 | const length = range.isSingleLine() 33 | ? range.end.character - range.start.character 34 | : line.length - range.start.character 35 | const carets = length < 0 ? '' : '^'.repeat(length) 36 | const multilineSuffix = range.isSingleLine() 37 | ? '' 38 | : ` ${range.end.line}:${range.end.character}` 39 | const message = diagnostic ? ' ' + diagnostic : '' 40 | return `${this.path}:${range.start.line}:${range.start.character}${message}\n${line}\n${indent}${carets}${multilineSuffix}` 41 | } 42 | public log(range: Range): void { 43 | console.log(this.format(range)) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Packages.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import path from 'path' 3 | 4 | import { packageDescriptor } from './Descriptor' 5 | import { ScipSymbol } from './ScipSymbol' 6 | 7 | export class Packages { 8 | constructor(public readonly projectRoot: string) {} 9 | private cache: Map = new Map() 10 | public symbol(filePath: string): ScipSymbol { 11 | if (path.normalize(filePath).replaceAll('\\', '/') !== filePath) { 12 | throw new Error( 13 | `unexpected error: path.normalize('${filePath}') !== ${filePath}` 14 | ) 15 | } 16 | const fromCache = this.cache.get(filePath) 17 | if (fromCache) { 18 | return fromCache 19 | } 20 | const packageJsonPath = path.join(filePath, 'package.json') 21 | try { 22 | if ( 23 | fs.existsSync(packageJsonPath) && 24 | fs.lstatSync(packageJsonPath).isFile() 25 | ) { 26 | const packageJsonText = fs.readFileSync(packageJsonPath).toString() 27 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment 28 | const packageJson = JSON.parse(packageJsonText) 29 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access 30 | const name = packageJson.name 31 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access 32 | const version = packageJson.version 33 | if (typeof name === 'string' && typeof version === 'string') { 34 | return this.cached(filePath, ScipSymbol.package(name, version)) 35 | } 36 | if (typeof name === 'string') { 37 | // The version field is missing so we fallback to `"HEAD"` 38 | return this.cached(filePath, ScipSymbol.package(name, 'HEAD')) 39 | } 40 | // Fallback to an anonymous package because we found a package.json but 41 | // were unable to parse the name and version. 42 | return this.cached(filePath, ScipSymbol.anonymousPackage()) 43 | } 44 | } catch (error) { 45 | console.error(`error parsing ${packageJsonPath}`, error) 46 | return this.cached(filePath, ScipSymbol.anonymousPackage()) 47 | } 48 | 49 | if (filePath === this.projectRoot) { 50 | // Don't look for package.json in a parent directory of the root. 51 | return this.cached(filePath, ScipSymbol.anonymousPackage()) 52 | } 53 | 54 | const dirname = path.dirname(filePath) 55 | if (dirname === filePath) { 56 | // Avoid infinite recursion when `path.dirname(path) === path` 57 | return this.cached(filePath, ScipSymbol.anonymousPackage()) 58 | } 59 | 60 | const owner = this.symbol(dirname) 61 | return this.cached( 62 | filePath, 63 | ScipSymbol.global(owner, packageDescriptor(path.basename(filePath))) 64 | ) 65 | } 66 | 67 | private cached(filePath: string, sym: ScipSymbol): ScipSymbol { 68 | this.cache.set(filePath, sym) 69 | return sym 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Position.ts: -------------------------------------------------------------------------------- 1 | export class Position { 2 | /** 3 | * @param line 0-based line number 4 | * @param character 0-based character (or column) number 5 | */ 6 | constructor( 7 | public readonly line: number, 8 | public readonly character: number 9 | ) {} 10 | public compare(other: Position): number { 11 | if (this.line !== other.line) { 12 | return this.line - other.line 13 | } 14 | return this.character - other.character 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/ProjectIndexer.test.ts: -------------------------------------------------------------------------------- 1 | import { test } from 'uvu' 2 | import * as assert from 'uvu/assert' 3 | 4 | import { prettyMilliseconds } from './ProjectIndexer' 5 | 6 | function minute(x: number): number { 7 | return x * 60 * 1000 8 | } 9 | function second(x: number): number { 10 | return x * 1000 11 | } 12 | 13 | test('prettyMilliseconds', () => { 14 | assert.is(prettyMilliseconds(0), '0ms') 15 | assert.is(prettyMilliseconds(1), '1ms') 16 | assert.is(prettyMilliseconds(second(1)), '1s 0ms') 17 | assert.is(prettyMilliseconds(second(1) + 300), '1s 300ms') 18 | assert.is(prettyMilliseconds(second(2)), '2s 0ms') 19 | assert.is(prettyMilliseconds(second(5)), '5s 0ms') 20 | assert.is(prettyMilliseconds(minute(1)), '1m 0s 0ms') 21 | assert.is(prettyMilliseconds(minute(2)), '2m 0s 0ms') 22 | assert.is(prettyMilliseconds(minute(5)), '5m 0s 0ms') 23 | assert.is(prettyMilliseconds(minute(60)), '60m 0s 0ms') 24 | assert.is(prettyMilliseconds(minute(5) + second(8) + 999), '5m 8s 999ms') 25 | }) 26 | 27 | test.run() 28 | -------------------------------------------------------------------------------- /src/ProjectIndexer.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | 3 | import ProgressBar from 'progress' 4 | import * as ts from 'typescript' 5 | 6 | import { GlobalCache, ProjectOptions } from './CommandLineOptions' 7 | import { FileIndexer } from './FileIndexer' 8 | import { Input } from './Input' 9 | import { Packages } from './Packages' 10 | import * as scip from './scip' 11 | import { ScipSymbol } from './ScipSymbol' 12 | 13 | function createCompilerHost( 14 | cache: GlobalCache, 15 | compilerOptions: ts.CompilerOptions, 16 | projectOptions: ProjectOptions 17 | ): ts.CompilerHost { 18 | const host = ts.createCompilerHost(compilerOptions) 19 | if (!projectOptions.globalCaches) { 20 | return host 21 | } 22 | const hostCopy = { ...host } 23 | host.getParsedCommandLine = (fileName: string) => { 24 | if (!hostCopy.getParsedCommandLine) { 25 | return undefined 26 | } 27 | const fromCache = cache.parsedCommandLines.get(fileName) 28 | if (fromCache !== undefined) { 29 | return fromCache 30 | } 31 | const result = hostCopy.getParsedCommandLine(fileName) 32 | if (result !== undefined) { 33 | // Don't cache undefined results even if they could be cached 34 | // theoretically. The big performance gains from this cache come from 35 | // caching non-undefined results. 36 | cache.parsedCommandLines.set(fileName, result) 37 | } 38 | return result 39 | } 40 | host.getSourceFile = ( 41 | fileName, 42 | languageVersion, 43 | onError, 44 | shouldCreateNewSourceFile 45 | ) => { 46 | const fromCache = cache.sources.get(fileName) 47 | if (fromCache !== undefined) { 48 | const [sourceFile, cachedLanguageVersion] = fromCache 49 | if (isSameLanguageVersion(languageVersion, cachedLanguageVersion)) { 50 | return sourceFile 51 | } 52 | } 53 | const result = hostCopy.getSourceFile( 54 | fileName, 55 | languageVersion, 56 | onError, 57 | shouldCreateNewSourceFile 58 | ) 59 | if (result !== undefined) { 60 | // Don't cache undefined results even if they could be cached 61 | // theoretically. The big performance gains from this cache come from 62 | // caching non-undefined results. 63 | cache.sources.set(fileName, [result, languageVersion]) 64 | } 65 | return result 66 | } 67 | return host 68 | } 69 | 70 | export class ProjectIndexer { 71 | private program: ts.Program 72 | private checker: ts.TypeChecker 73 | private symbolCache: Map = new Map() 74 | private hasConstructor: Map = new Map() 75 | private packages: Packages 76 | constructor( 77 | public readonly config: ts.ParsedCommandLine, 78 | public readonly options: ProjectOptions, 79 | cache: GlobalCache 80 | ) { 81 | const host = createCompilerHost(cache, config.options, options) 82 | this.program = ts.createProgram(config.fileNames, config.options, host) 83 | this.checker = this.program.getTypeChecker() 84 | this.packages = new Packages(options.projectRoot) 85 | } 86 | public index(): void { 87 | const startTimestamp = Date.now() 88 | const sourceFiles = this.program.getSourceFiles() 89 | 90 | const filesToIndex: ts.SourceFile[] = [] 91 | // Visit every sourceFile in the program 92 | for (const sourceFile of sourceFiles) { 93 | const includes = this.config.fileNames.includes(sourceFile.fileName) 94 | if (!includes) { 95 | continue 96 | } 97 | filesToIndex.push(sourceFile) 98 | } 99 | 100 | if (filesToIndex.length === 0) { 101 | throw new Error( 102 | `no indexable files in project '${this.options.projectDisplayName}'` 103 | ) 104 | } 105 | 106 | const jobs: ProgressBar | undefined = this.options.progressBar 107 | ? new ProgressBar( 108 | ` ${this.options.projectDisplayName} [:bar] :current/:total :title`, 109 | { 110 | total: filesToIndex.length, 111 | renderThrottle: 100, 112 | incomplete: '_', 113 | complete: '#', 114 | width: 20, 115 | clear: true, 116 | stream: process.stderr, 117 | } 118 | ) 119 | : undefined 120 | let lastWrite = startTimestamp 121 | for (const [index, sourceFile] of filesToIndex.entries()) { 122 | const title = path.relative(this.options.cwd, sourceFile.fileName) 123 | jobs?.tick({ title }) 124 | if (!this.options.progressBar) { 125 | const now = Date.now() 126 | const elapsed = now - lastWrite 127 | if (elapsed > 1000 && index > 2) { 128 | lastWrite = now 129 | process.stdout.write('.') 130 | } 131 | } 132 | const document = new scip.scip.Document({ 133 | relative_path: path.relative(this.options.cwd, sourceFile.fileName), 134 | occurrences: [], 135 | }) 136 | const input = new Input(sourceFile.fileName, sourceFile.getText()) 137 | const visitor = new FileIndexer( 138 | this.checker, 139 | this.options, 140 | input, 141 | document, 142 | this.symbolCache, 143 | this.hasConstructor, 144 | this.packages, 145 | sourceFile 146 | ) 147 | try { 148 | visitor.index() 149 | } catch (error) { 150 | console.error( 151 | `unexpected error indexing project root '${this.options.cwd}'`, 152 | error 153 | ) 154 | } 155 | if (visitor.document.occurrences.length > 0) { 156 | this.options.writeIndex( 157 | new scip.scip.Index({ 158 | documents: [visitor.document], 159 | }) 160 | ) 161 | } 162 | } 163 | jobs?.terminate() 164 | const elapsed = Date.now() - startTimestamp 165 | if (!this.options.progressBar && lastWrite > startTimestamp) { 166 | process.stdout.write('\n') 167 | } 168 | console.log( 169 | `+ ${this.options.projectDisplayName} (${prettyMilliseconds(elapsed)})` 170 | ) 171 | } 172 | } 173 | 174 | export function prettyMilliseconds(milliseconds: number): string { 175 | let ms = Math.floor(milliseconds) 176 | let result = '' 177 | if (ms >= 1000 * 60) { 178 | const minutes = Math.floor(ms / (1000 * 60)) 179 | if (minutes !== 0) { 180 | result += `${minutes}m ` 181 | ms -= minutes * 1000 * 60 182 | } 183 | } 184 | if (result !== '' || ms >= 1000) { 185 | const seconds = Math.floor(ms / 1000) 186 | result += `${seconds}s ` 187 | ms -= seconds * 1000 188 | } 189 | result += `${ms}ms` 190 | return result.trim() 191 | } 192 | 193 | function isSameLanguageVersion( 194 | a: ts.ScriptTarget | ts.CreateSourceFileOptions, 195 | b: ts.ScriptTarget | ts.CreateSourceFileOptions 196 | ): boolean { 197 | if (typeof a === 'number' && typeof b === 'number') { 198 | return a === b 199 | } 200 | if (typeof a === 'number' || typeof b === 'number') { 201 | // Different shape: one is ts.ScriptTarget, the other is 202 | // ts.CreateSourceFileOptions 203 | return false 204 | } 205 | return ( 206 | a.languageVersion === b.languageVersion && 207 | a.impliedNodeFormat === b.impliedNodeFormat 208 | // Ignore setExternalModuleIndicator even if that increases the risk of a 209 | // false positive. A local experiment revealed that we never get a cache hit 210 | // if we compare setExternalModuleIndicator since it's function with a 211 | // unique reference on every `CompilerHost.getSourceFile` callback. 212 | ) 213 | } 214 | -------------------------------------------------------------------------------- /src/Range.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { Position } from './Position' 4 | 5 | export class Range { 6 | constructor( 7 | public readonly start: Position, 8 | public readonly end: Position 9 | ) {} 10 | public compare(other: Range): number { 11 | const byStart = this.start.compare(other.start) 12 | if (byStart !== 0) { 13 | return byStart 14 | } 15 | return this.end.compare(other.end) 16 | } 17 | public toLsif(): number[] { 18 | if (this.isSingleLine()) { 19 | return [this.start.line, this.start.character, this.end.character] 20 | } 21 | return [ 22 | this.start.line, 23 | this.start.character, 24 | this.end.line, 25 | this.end.character, 26 | ] 27 | } 28 | public static fromLsif(range: number[]): Range { 29 | const endLine = range.length === 3 ? range[0] : range[2] 30 | const endCharacter = range.length === 3 ? range[2] : range[3] 31 | return new Range( 32 | new Position(range[0], range[1]), 33 | new Position(endLine, endCharacter) 34 | ) 35 | } 36 | 37 | public static fromNode(node: ts.Node): Range { 38 | const sourceFile = node.getSourceFile() 39 | const start = sourceFile.getLineAndCharacterOfPosition(node.getStart()) 40 | const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd()) 41 | return new Range( 42 | new Position(start.line, start.character), 43 | new Position(end.line, end.character) 44 | ) 45 | } 46 | 47 | public isSingleLine(): boolean { 48 | return this.start.line === this.end.line 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/ScipSymbol.ts: -------------------------------------------------------------------------------- 1 | import { descriptorString } from './Descriptor' 2 | import * as scip from './scip' 3 | 4 | export class ScipSymbol { 5 | private constructor(public readonly value: string) {} 6 | 7 | public isEmpty(): boolean { 8 | return this.value === '' 9 | } 10 | 11 | public isLocal(): boolean { 12 | return this.value.startsWith('local ') 13 | } 14 | 15 | public static local(counter: number): ScipSymbol { 16 | return new ScipSymbol(`local ${counter}`) 17 | } 18 | 19 | public static empty(): ScipSymbol { 20 | return new ScipSymbol('') 21 | } 22 | 23 | public static package(name: string, version: string): ScipSymbol { 24 | return new ScipSymbol(`scip-typescript npm ${name} ${version} `) 25 | } 26 | 27 | public static anonymousPackage(): ScipSymbol { 28 | return ScipSymbol.package('.', '.') 29 | } 30 | 31 | public static global( 32 | owner: ScipSymbol, 33 | descriptor: scip.scip.Descriptor 34 | ): ScipSymbol { 35 | return new ScipSymbol(owner.value + descriptorString(descriptor)) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/SnapshotTesting.ts: -------------------------------------------------------------------------------- 1 | import { Input } from './Input' 2 | import { Range } from './Range' 3 | import { scip } from './scip' 4 | 5 | const stripIndexerPrefix = 'scip-typescript npm ' 6 | const commentSyntax = '//' 7 | const formatOptionsPrefix = '// format-options:' 8 | 9 | function getSymbolTable( 10 | doc: scip.Document 11 | ): Map { 12 | const symbolTable = new Map() 13 | for (const symbol of doc.symbols) { 14 | symbolTable.set(symbol.symbol, symbol) 15 | } 16 | return symbolTable 17 | } 18 | 19 | function parseOptions(lines: string[]): { 20 | showDocs: boolean 21 | showRanges: boolean 22 | } { 23 | const formatOptions = { 24 | showDocs: false, 25 | showRanges: false, 26 | } 27 | 28 | for (const line of lines) { 29 | if (!line.startsWith(formatOptionsPrefix)) { 30 | continue 31 | } 32 | 33 | const options = line.slice(formatOptionsPrefix.length).trim().split(',') 34 | 35 | for (const option of options) { 36 | const optionName = option.trim() 37 | 38 | if (!(optionName in formatOptions)) { 39 | throw new Error(`Invalid format option: ${optionName}`) 40 | } 41 | 42 | formatOptions[optionName as keyof typeof formatOptions] = true 43 | } 44 | 45 | break 46 | } 47 | 48 | return formatOptions 49 | } 50 | 51 | function symbolNameForSnapshot(fullName: string): string { 52 | return fullName.startsWith(stripIndexerPrefix) 53 | ? fullName.slice(stripIndexerPrefix.length) 54 | : fullName 55 | } 56 | 57 | export function formatSnapshot( 58 | input: Input, 59 | doc: scip.Document, 60 | externalSymbols: scip.SymbolInformation[] = [] 61 | ): string { 62 | const out: string[] = [] 63 | const symbolTable = getSymbolTable(doc) 64 | 65 | const externalSymbolTable: Map = new Map() 66 | for (const externalSymbol of externalSymbols) { 67 | externalSymbolTable.set(externalSymbol.symbol, externalSymbol) 68 | } 69 | 70 | const enclosingRanges: { range: Range; symbol: string }[] = [] 71 | const symbolsWithDefinitions: Set = new Set() 72 | 73 | const formatOptions = parseOptions(input.lines) 74 | 75 | for (const occurrence of doc.occurrences) { 76 | const isDefinition = 77 | (occurrence.symbol_roles & scip.SymbolRole.Definition) > 0 78 | if (isDefinition) { 79 | symbolsWithDefinitions.add(occurrence.symbol) 80 | } 81 | 82 | if (formatOptions.showRanges && occurrence.enclosing_range.length > 0) { 83 | enclosingRanges.push({ 84 | range: Range.fromLsif(occurrence.enclosing_range), 85 | symbol: occurrence.symbol, 86 | }) 87 | } 88 | } 89 | 90 | enclosingRanges.sort(enclosingRangesByLine) 91 | 92 | const enclosingRangeStarts: (typeof enclosingRanges)[number][][] = Array.from( 93 | new Array(input.lines.length), 94 | () => [] 95 | ) 96 | const enclosingRangeEnds: (typeof enclosingRanges)[number][][] = Array.from( 97 | new Array(input.lines.length), 98 | () => [] 99 | ) 100 | 101 | for (const enclosingRange of enclosingRanges) { 102 | enclosingRangeStarts[enclosingRange.range.start.line].push(enclosingRange) 103 | enclosingRangeEnds[enclosingRange.range.end.line].unshift(enclosingRange) 104 | } 105 | 106 | const emittedDocstrings: Set = new Set() 107 | const pushDoc = ( 108 | range: Range, 109 | symbol: string, 110 | isDefinition: boolean, 111 | isStartOfLine: boolean 112 | ): void => { 113 | // Only emit docstrings once 114 | if (emittedDocstrings.has(symbol)) { 115 | out.push('\n') 116 | return 117 | } 118 | 119 | // Only definitions OR symbols without a definition should be emitted 120 | if (!isDefinition && symbolsWithDefinitions.has(symbol)) { 121 | out.push('\n') 122 | return 123 | } 124 | 125 | emittedDocstrings.add(symbol) 126 | 127 | let prefix = '\n' + commentSyntax 128 | if (!isStartOfLine) { 129 | prefix += ' '.repeat(range.start.character - 2) 130 | } 131 | 132 | const pushOneDoc = (docs: string[], external: boolean): void => { 133 | if (!formatOptions.showDocs) { 134 | return 135 | } 136 | 137 | for (const documentation of docs) { 138 | for (const [idx, line] of documentation.split('\n').entries()) { 139 | out.push(prefix) 140 | if (idx === 0) { 141 | if (external) { 142 | out.push('external ') 143 | } 144 | out.push('documentation ') 145 | } else { 146 | out.push(' > ') 147 | } 148 | out.push(line.slice(0, 40)) 149 | if (line.length > 40) { 150 | out.push('...') 151 | } 152 | } 153 | } 154 | } 155 | 156 | const pushOneRelationship = (relationships: scip.Relationship[]): void => { 157 | relationships.sort((a, b) => a.symbol.localeCompare(b.symbol)) 158 | 159 | for (const relationship of relationships) { 160 | out.push(prefix) 161 | out.push('relationship') 162 | if (relationship.is_implementation) { 163 | out.push(' implementation') 164 | } 165 | if (relationship.is_reference) { 166 | out.push(' reference') 167 | } 168 | if (relationship.is_type_definition) { 169 | out.push(' type_definition') 170 | } 171 | out.push(' ' + symbolNameForSnapshot(relationship.symbol)) 172 | } 173 | } 174 | 175 | const externalSymbol = externalSymbolTable.get(symbol) 176 | if (externalSymbol) { 177 | pushOneDoc(externalSymbol.documentation, true) 178 | pushOneRelationship(externalSymbol.relationships) 179 | } else { 180 | const info = symbolTable.get(symbol) 181 | if (info) { 182 | pushOneDoc(info.documentation, false) 183 | pushOneRelationship(info.relationships) 184 | } 185 | } 186 | out.push('\n') 187 | } 188 | 189 | const pushEnclosingRange = ( 190 | enclosingRange: { 191 | range: Range 192 | symbol: string 193 | }, 194 | end: boolean = false 195 | ): void => { 196 | if (!formatOptions.showRanges) { 197 | return 198 | } 199 | 200 | out.push(commentSyntax) 201 | out.push(' '.repeat(Math.max(1, enclosingRange.range.start.character - 2))) 202 | 203 | if (enclosingRange.range.start.character < 2) { 204 | out.push('<') 205 | } else if (end) { 206 | out.push('^') 207 | } else { 208 | out.push('⌄') 209 | } 210 | 211 | if (end) { 212 | out.push(' end ') 213 | } else { 214 | out.push(' start ') 215 | } 216 | out.push('enclosing_range ') 217 | out.push(symbolNameForSnapshot(enclosingRange.symbol)) 218 | out.push('\n') 219 | } 220 | 221 | doc.occurrences.sort(occurrencesByLine) 222 | let occurrenceIndex = 0 223 | 224 | for (const [lineNumber, line] of input.lines.entries()) { 225 | // Write 0,0 items ABOVE the first line. 226 | // This is the only case where we would need to do this. 227 | if (occurrenceIndex === 0) { 228 | const occurrence = doc.occurrences[occurrenceIndex] 229 | const range = Range.fromLsif(occurrence.range) 230 | 231 | // This is essentially a "file-based" item. 232 | // This guarantees that this sits above everything else in the file. 233 | if (range.start.character === 0 && range.end.character === 0) { 234 | const isDefinition = 235 | (occurrence.symbol_roles & scip.SymbolRole.Definition) > 0 236 | out.push(commentSyntax) 237 | out.push(' < ') 238 | out.push(isDefinition ? 'definition' : 'reference') 239 | out.push(' ') 240 | out.push(symbolNameForSnapshot(occurrence.symbol)) 241 | pushDoc(range, occurrence.symbol, isDefinition, true) 242 | out.push('\n') 243 | 244 | occurrenceIndex++ 245 | } 246 | } 247 | 248 | // Check if any enclosing ranges start on this line 249 | for (const enclosingRange of enclosingRangeStarts[lineNumber]) { 250 | pushEnclosingRange(enclosingRange) 251 | } 252 | 253 | out.push('') 254 | out.push(line) 255 | out.push('\n') 256 | while ( 257 | occurrenceIndex < doc.occurrences.length && 258 | doc.occurrences[occurrenceIndex].range[0] === lineNumber 259 | ) { 260 | const occurrence = doc.occurrences[occurrenceIndex] 261 | occurrenceIndex++ 262 | 263 | if (occurrence.symbol === undefined) { 264 | continue 265 | } 266 | 267 | if (occurrence.range.length > 3) { 268 | throw new Error('not yet implemented, multi-line ranges') 269 | } 270 | 271 | const range = Range.fromLsif(occurrence.range) 272 | 273 | out.push(commentSyntax) 274 | const isStartOfLine = range.start.character === 0 275 | if (!isStartOfLine && range.start.character > 2) { 276 | out.push(' '.repeat(range.start.character - 2)) 277 | } 278 | 279 | let modifier = 0 280 | if (isStartOfLine) { 281 | modifier = 1 282 | } 283 | 284 | const caretLength = range.end.character - range.start.character - modifier 285 | if (caretLength < 0) { 286 | throw new Error(input.format(range, 'negative length occurrence!')) 287 | } 288 | out.push('^'.repeat(caretLength)) 289 | out.push(' ') 290 | const isDefinition = 291 | (occurrence.symbol_roles & scip.SymbolRole.Definition) > 0 292 | out.push(isDefinition ? 'definition' : 'reference') 293 | out.push(' ') 294 | const symbol = symbolNameForSnapshot(occurrence.symbol) 295 | out.push(symbol.replace('\n', '|')) 296 | 297 | pushDoc(range, occurrence.symbol, isDefinition, isStartOfLine) 298 | } 299 | 300 | // Check if any enclosing ranges end on this line 301 | for (const enclosingRange of enclosingRangeEnds[lineNumber]) { 302 | pushEnclosingRange(enclosingRange, true) 303 | } 304 | } 305 | return out.join('') 306 | } 307 | 308 | function occurrencesByLine(a: scip.Occurrence, b: scip.Occurrence): number { 309 | return Range.fromLsif(a.range).compare(Range.fromLsif(b.range)) 310 | } 311 | 312 | function enclosingRangesByLine( 313 | a: { range: Range; symbol: string }, 314 | b: { range: Range; symbol: string } 315 | ): number { 316 | // Return the range that starts first, and if they start at the same line, the one that ends last (enclosing). 317 | const rangeCompare = a.range.compare(b.range) 318 | 319 | if (rangeCompare !== 0) { 320 | return rangeCompare 321 | } 322 | 323 | return b.range.end.line - a.range.end.line 324 | } 325 | -------------------------------------------------------------------------------- /src/TypeScriptInternal.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | // Functions in this file are based directly off corresponding functions 4 | // in the TypeScript codebase. 5 | 6 | export function shouldSkipAlias(node: ts.Node): boolean { 7 | switch (node.kind) { 8 | case ts.SyntaxKind.ImportClause: 9 | case ts.SyntaxKind.ImportEqualsDeclaration: { 10 | // TODO: How do we test this code path? 11 | return true 12 | } 13 | case ts.SyntaxKind.ImportSpecifier: { 14 | return node.parent.kind === ts.SyntaxKind.NamedImports 15 | } 16 | case ts.SyntaxKind.BindingElement: 17 | case ts.SyntaxKind.VariableDeclaration: { 18 | // TODO: How do we test this code path? 19 | return ( 20 | isInJSFile(node) && 21 | isVariableDeclarationInitializedToBareOrAccessedRequire(node) 22 | ) 23 | } 24 | default: { 25 | return false 26 | } 27 | } 28 | } 29 | 30 | function isInJSFile(node: ts.Node): boolean { 31 | return !!(node.flags & ts.NodeFlags.JavaScriptFile) 32 | } 33 | 34 | function isVariableDeclarationInitializedToBareOrAccessedRequire( 35 | node: ts.Node 36 | ): boolean { 37 | if (node.kind === ts.SyntaxKind.BindingElement) { 38 | node = node.parent.parent 39 | } 40 | return isVariableDeclaration(node) && !!node.initializer 41 | // FIXME: This requires inlining a bunch of more definitions. 42 | // ts.isRequireCall(allowAccessedRequire ? ts.getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true); 43 | } 44 | 45 | function isVariableDeclaration(node: ts.Node): node is ts.VariableDeclaration { 46 | return node.kind === ts.SyntaxKind.VariableDeclaration 47 | } 48 | export function isParameter(sym: ts.Symbol): boolean { 49 | // based on isFirstDeclarationOfSymbolParameter 50 | const declaration = sym.declarations?.[0] 51 | return !!ts.findAncestor(declaration, (node: ts.Node): boolean | 'quit' => 52 | ts.isParameter(node) 53 | ? true 54 | : ts.isBindingElement(node) || 55 | ts.isObjectBindingPattern(node) || 56 | ts.isArrayBindingPattern(node) 57 | ? false 58 | : 'quit' 59 | ) 60 | } 61 | 62 | // The corresponding function is marked @internal here: 63 | // https://sourcegraph.com/github.com/microsoft/TypeScript@fbcdb8cf4fbbbea0111a9adeb9d0d2983c088b7c/-/blob/src/compiler/utilities.ts?L10586-10589 64 | export function getTextOfJsxAttributeName(node: ts.JsxAttributeName): string { 65 | return ts.isIdentifier(node) 66 | ? ts.idText(node) 67 | : `${ts.idText(node.namespace)}:${ts.idText(node.name)}` 68 | } 69 | 70 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3557 71 | type ObjectLiteralElementWithName = ts.ObjectLiteralElement & { 72 | name: ts.PropertyName 73 | parent: ts.ObjectLiteralExpression | ts.JsxAttributes 74 | } 75 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3534 76 | export function getContainingObjectLiteralElement( 77 | node: ts.Node 78 | ): ObjectLiteralElementWithName | undefined { 79 | const element = getContainingObjectLiteralElementWorker(node) 80 | return element && 81 | (ts.isObjectLiteralExpression(element.parent) || 82 | ts.isJsxAttributes(element.parent)) 83 | ? (element as ObjectLiteralElementWithName) 84 | : undefined 85 | } 86 | 87 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/services.ts?L3538 88 | function getContainingObjectLiteralElementWorker( 89 | node: ts.Node 90 | ): ts.ObjectLiteralElement | undefined { 91 | switch (node.kind) { 92 | case ts.SyntaxKind.StringLiteral: 93 | case ts.SyntaxKind.NoSubstitutionTemplateLiteral: 94 | case ts.SyntaxKind.NumericLiteral: { 95 | if (node.parent.kind === ts.SyntaxKind.ComputedPropertyName) { 96 | return ts.isObjectLiteralElement(node.parent.parent) 97 | ? node.parent.parent 98 | : undefined 99 | } 100 | // falls through 101 | } 102 | 103 | case ts.SyntaxKind.Identifier: { 104 | return ts.isObjectLiteralElement(node.parent) && 105 | (node.parent.parent.kind === ts.SyntaxKind.ObjectLiteralExpression || 106 | node.parent.parent.kind === ts.SyntaxKind.JsxAttributes) && 107 | node.parent.name === node 108 | ? node.parent 109 | : undefined 110 | } 111 | } 112 | return undefined 113 | } 114 | 115 | export function getPropertySymbolFromContextualType( 116 | node: ObjectLiteralElementWithName, 117 | contextualType: ts.Type 118 | ): ts.Symbol | undefined { 119 | const name = getNameFromPropertyName(node.name) 120 | if (!name) { 121 | return undefined 122 | } 123 | return contextualType.getProperty(name) 124 | } 125 | 126 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/services/utilities.ts?L2433 127 | export function getNameFromPropertyName( 128 | name: ts.PropertyName 129 | ): string | undefined { 130 | return name.kind === ts.SyntaxKind.ComputedPropertyName 131 | ? // treat computed property names where expression is string/numeric literal as just string/numeric literal 132 | isStringOrNumericLiteralLike(name.expression) 133 | ? name.expression.text 134 | : undefined 135 | : ts.isPrivateIdentifier(name) 136 | ? ts.idText(name) 137 | : getTextOfIdentifierOrLiteral(name) 138 | } 139 | 140 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L5269 141 | export function isStringOrNumericLiteralLike( 142 | node: ts.Node 143 | ): node is ts.StringLiteralLike | ts.NumericLiteral { 144 | return ts.isStringLiteralLike(node) || ts.isNumericLiteral(node) 145 | } 146 | 147 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L5346 148 | export function getTextOfIdentifierOrLiteral( 149 | node: ts.PropertyNameLiteral | ts.PrivateIdentifier 150 | ): string { 151 | return ts.isMemberName(node) 152 | ? ts.idText(node) 153 | : ts.isJsxNamespacedName(node) 154 | ? getTextOfJsxNamespacedName(node) 155 | : node.text 156 | } 157 | 158 | // https://sourcegraph.com/github.com/microsoft/TypeScript@2c23beae0297fe3e57868d02af8c9084b136f78c/-/blob/src/compiler/utilities.ts?L11012 159 | export function getTextOfJsxNamespacedName(node: ts.JsxNamespacedName): string { 160 | return `${ts.idText(node.namespace)}:${ts.idText(node.name)}` 161 | } 162 | -------------------------------------------------------------------------------- /src/inferTsconfig.test.ts: -------------------------------------------------------------------------------- 1 | import { join } from 'path' 2 | import * as process from 'process' 3 | 4 | import { test } from 'uvu' 5 | 6 | import { allowJsConfig, inferTsconfig, noJsConfig } from './inferTsconfig' 7 | 8 | const inputDirectory = join(process.cwd(), 'snapshots', 'inferTsConfig') 9 | 10 | function checkDirectory(name: string, expected: string): void { 11 | test(name, () => { 12 | const directory = join(inputDirectory, name) 13 | const obtained = inferTsconfig(directory) 14 | if (obtained !== expected) { 15 | throw new Error(`expected ('${expected}') != obtained ('${obtained}')`) 16 | } 17 | }) 18 | } 19 | 20 | checkDirectory('js-project', allowJsConfig) 21 | checkDirectory('ts-project', noJsConfig) 22 | 23 | test.run() 24 | -------------------------------------------------------------------------------- /src/inferTsconfig.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import * as path from 'path' 3 | 4 | /** 5 | * To limit the risk of making the `inferTsconfig` run for a very long time, we 6 | * stop the file traversal after visiting this number of files. 7 | */ 8 | const maximumFileTraversalCount = 1_000 9 | 10 | /** The TS config we use to index JavaScript files. */ 11 | export const allowJsConfig = '{"compilerOptions":{"allowJs":true}}' 12 | 13 | /** The TS config we use to index only TypeScript files. */ 14 | export const noJsConfig = '{}' 15 | 16 | /** 17 | * Returns the configuration that should be used for tsconfig.json in the provided path. 18 | * 19 | * If the directory contains at least one `*.{ts,tsx}` file then the config will be empty (`{}`). 20 | * If the directory doesn't contains one `*.{ts,tsx}` file then the config will 21 | */ 22 | export function inferTsconfig(projectPath: string): string { 23 | let hasTypeScriptFile = false 24 | let hasJavaScriptFile = false 25 | let visitedFileCount = 0 26 | const visitPath = (directory: string): { stop: boolean } => { 27 | if (directory.endsWith('.ts') || directory.endsWith('.tsx')) { 28 | hasTypeScriptFile = true 29 | return { stop: true } 30 | } 31 | if (directory.endsWith('.js') || directory.endsWith('.jsx')) { 32 | hasJavaScriptFile = true 33 | } 34 | if (!fs.statSync(directory).isDirectory()) { 35 | return { stop: false } 36 | } 37 | for (const child of fs.readdirSync(directory)) { 38 | visitedFileCount++ 39 | if (visitedFileCount > maximumFileTraversalCount) { 40 | return { stop: true } 41 | } 42 | const fullPath = path.resolve(directory, child) 43 | const recursiveWalk = visitPath(fullPath) 44 | if (recursiveWalk.stop) { 45 | return recursiveWalk 46 | } 47 | } 48 | return { stop: false } 49 | } 50 | visitPath(projectPath) 51 | if (hasTypeScriptFile || !hasJavaScriptFile) { 52 | return noJsConfig 53 | } 54 | return allowJsConfig 55 | } 56 | -------------------------------------------------------------------------------- /src/main.test.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import { join } from 'path' 3 | import * as path from 'path' 4 | import * as process from 'process' 5 | 6 | import * as Diff from 'diff' 7 | import { test } from 'uvu' 8 | 9 | import { Input } from './Input' 10 | import { indexCommand } from './main' 11 | import * as scip from './scip' 12 | import { formatSnapshot } from './SnapshotTesting' 13 | 14 | function isUpdateSnapshot(): boolean { 15 | return process.argv.includes('--update-snapshots') 16 | } 17 | 18 | const snapshotNodeModules = join(process.cwd(), 'snapshots', 'node_modules') 19 | if (!fs.existsSync(snapshotNodeModules)) { 20 | throw new Error( 21 | `no such file: ${snapshotNodeModules} (to fix this problem, run 'yarn install' in the snapshots/ directory)` 22 | ) 23 | } 24 | const inputDirectory = join(process.cwd(), 'snapshots', 'input') 25 | const outputDirectory = join(process.cwd(), 'snapshots', 'output') 26 | 27 | const snapshotDirectories = fs.readdirSync(inputDirectory) 28 | const isUpdate = isUpdateSnapshot() 29 | if (isUpdate && fs.existsSync(outputDirectory)) { 30 | fs.rmSync(outputDirectory, { recursive: true }) 31 | } 32 | interface PackageJson { 33 | workspaces: string[] 34 | packageManager?: string 35 | } 36 | for (const snapshotDirectory of snapshotDirectories) { 37 | // Uncomment below if you want to skip certain tests for local development. 38 | // if (!snapshotDirectory.includes('syntax')) { 39 | // continue 40 | // } 41 | const inputRoot = join(inputDirectory, snapshotDirectory) 42 | const outputRoot = join(outputDirectory, snapshotDirectory) 43 | if (!fs.statSync(inputRoot).isDirectory()) { 44 | continue 45 | } 46 | test(snapshotDirectory, () => { 47 | const packageJsonPath = path.join(inputRoot, 'package.json') 48 | const packageJson = JSON.parse( 49 | fs.readFileSync(packageJsonPath).toString() 50 | ) as PackageJson 51 | const tsconfigJsonPath = path.join(inputRoot, 'tsconfig.json') 52 | const inferTsconfig = !fs.existsSync(tsconfigJsonPath) 53 | const output = path.join(inputRoot, 'index.scip') 54 | indexCommand([], { 55 | cwd: inputRoot, 56 | inferTsconfig, 57 | output, 58 | yarnWorkspaces: Boolean(packageJson.workspaces), 59 | yarnBerryWorkspaces: false, 60 | pnpmWorkspaces: Boolean(packageJson.packageManager?.includes('pnpm')), 61 | progressBar: false, 62 | indexedProjects: new Set(), 63 | globalCaches: true, 64 | }) 65 | if (inferTsconfig) { 66 | fs.rmSync(tsconfigJsonPath) 67 | } 68 | const index = scip.scip.Index.deserializeBinary( 69 | fs.readFileSync(path.join(inputRoot, 'index.scip')) 70 | ) 71 | fs.mkdirSync(outputRoot, { recursive: true }) 72 | fs.renameSync(output, path.join(outputRoot, 'index.scip')) 73 | if (index.documents.length === 0) { 74 | throw new Error('empty LSIF index') 75 | } 76 | for (const document of index.documents) { 77 | const inputPath = path.join(inputRoot, document.relative_path) 78 | const relativeToInputDirectory = path.relative(inputDirectory, inputPath) 79 | const outputPath = path.resolve(outputDirectory, relativeToInputDirectory) 80 | const expected: string = fs.existsSync(outputPath) 81 | ? fs.readFileSync(outputPath).toString() 82 | : '' 83 | const input = Input.fromFile(inputPath) 84 | const obtained = formatSnapshot(input, document) 85 | if (obtained === expected) { 86 | // Test passed 87 | continue 88 | } 89 | if (isUpdate) { 90 | // Update the snapshot test to reflect the new behavior 91 | fs.mkdirSync(path.dirname(outputPath), { 92 | recursive: true, 93 | }) 94 | fs.writeFileSync(outputPath, obtained) 95 | console.log(`updated snapshot: ${outputPath}`) 96 | } else { 97 | // Fail the test with a diff error message 98 | const patch = Diff.createTwoFilesPatch( 99 | outputPath, 100 | outputPath, 101 | expected, 102 | obtained, 103 | '(what the snapshot tests expect)', 104 | "(what the current code produces). Run the command 'npm run update-snapshots' to accept the new behavior." 105 | ) 106 | throw new Error(patch) 107 | } 108 | } 109 | }) 110 | } 111 | 112 | test.run() 113 | -------------------------------------------------------------------------------- /src/parseHumanByteSizeIntoNumber.test.ts: -------------------------------------------------------------------------------- 1 | import { test } from 'uvu' 2 | import * as assert from 'uvu/assert' 3 | 4 | import { parseHumanByteSizeIntoNumber } from './parseHumanByteSizeIntoNumber' 5 | 6 | function checkHumanByteSize( 7 | humanInput: string, 8 | expectedByteNumber: number 9 | ): void { 10 | test(humanInput, () => { 11 | const obtained = parseHumanByteSizeIntoNumber(humanInput) 12 | assert.equal(obtained, expectedByteNumber) 13 | }) 14 | } 15 | 16 | // Invalid formats 17 | checkHumanByteSize('invalid', NaN) 18 | // TODO: These tests need to be fixed 19 | // checkHumanByteSize('15tb', NaN) 20 | // checkHumanByteSize('15b', NaN) 21 | 22 | // All numeral 23 | checkHumanByteSize('1001', 1001) 24 | 25 | // All lowercase 26 | checkHumanByteSize('1.2kb', 1_200) 27 | checkHumanByteSize('1.2mb', 1_200_000) 28 | checkHumanByteSize('1.2gb', 1_200_000_000) 29 | 30 | // All uppercase 31 | checkHumanByteSize('1.2KB', 1_200) 32 | checkHumanByteSize('1.2MB', 1_200_000) 33 | checkHumanByteSize('1.2GB', 1_200_000_000) 34 | 35 | // Mixed case 36 | checkHumanByteSize('1.2Kb', 1_200) 37 | checkHumanByteSize('1.2Mb', 1_200_000) 38 | checkHumanByteSize('1.2Gb', 1_200_000_000) 39 | 40 | test.run() 41 | -------------------------------------------------------------------------------- /src/parseHumanByteSizeIntoNumber.ts: -------------------------------------------------------------------------------- 1 | const kilo = 1_000 2 | const mega = 1_000_000 3 | const giga = 1_000_000_000 4 | 5 | export function parseHumanByteSizeIntoNumber(humanByteSize: string): number { 6 | let value = humanByteSize.toLowerCase() 7 | let multiplier = 1 8 | if (value.endsWith('kb')) { 9 | multiplier = kilo 10 | value = value.slice(0, -2) 11 | } else if (value.endsWith('mb')) { 12 | multiplier = mega 13 | value = value.slice(0, -2) 14 | } else if (value.endsWith('gb')) { 15 | multiplier = giga 16 | value = value.slice(0, -2) 17 | } 18 | return Number.parseFloat(value) * multiplier 19 | } 20 | 21 | export function formatByteSizeAsHumanReadable(byteSize: number): string { 22 | if (byteSize > giga) { 23 | return `${byteSize / giga}gb` 24 | } 25 | if (byteSize > mega) { 26 | return `${byteSize / mega}mb` 27 | } 28 | if (byteSize > kilo) { 29 | return `${byteSize / kilo}kb` 30 | } 31 | return byteSize.toString() 32 | } 33 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@sourcegraph/tsconfig", 3 | "compilerOptions": { 4 | "target": "es2019", 5 | "module": "commonjs", 6 | "allowJs": false, 7 | "moduleResolution": "node", 8 | "lib": ["esnext"], 9 | "rootDir": ".", 10 | "allowSyntheticDefaultImports": true, 11 | "outDir": "dist", 12 | "resolveJsonModule": true 13 | }, 14 | "include": ["./src/**/*"], 15 | "exclude": ["scip.ts", "snapshots"] 16 | } 17 | --------------------------------------------------------------------------------