Skip to content

Commit a34ddd6

Browse files
committed
Add Svelte indexing support
Transform Svelte components with svelte2tsx while mapping symbols and ranges back to the original source. Cover runes, legacy and JavaScript components, imported stores, malformed files, modern module resolution, and cross-project prop identity. Amp-Thread-ID: https://ampcode.com/threads/T-01a029e2-5095-710a-9cce-0c6d8645c173
1 parent 1cc21a7 commit a34ddd6

34 files changed

Lines changed: 1371 additions & 55 deletions

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# scip-typescript
22

3-
[SCIP](https://github.com/sourcegraph/scip) indexer for TypeScript and JavaScript.
3+
[SCIP](https://github.com/sourcegraph/scip) indexer for TypeScript, JavaScript,
4+
and Svelte.
45

56
## Quick start
67

@@ -33,6 +34,18 @@ scip-typescript index --infer-tsconfig
3334
To improve the quality of indexing results for JavaScript,
3435
consider adding `@types/*` packages as `devDependencies` in `package.json`.
3536

37+
### Indexing a Svelte project
38+
39+
Install the project dependencies and run the indexer from the directory that
40+
contains the project's `tsconfig.json` or `jsconfig.json`. SvelteKit projects
41+
should run `svelte-kit sync` first so their generated configuration is current.
42+
43+
```sh
44+
npm install # or yarn/pnpm install
45+
npx svelte-kit sync # SvelteKit projects only
46+
scip-typescript index
47+
```
48+
3649
### Index a TypeScript project using Yarn workspaces
3750

3851
Navigate to the project root, containing `package.json`.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sourcegraph/scip-typescript",
33
"version": "0.4.0",
4-
"description": "SCIP indexer for TypeScript and JavaScript",
4+
"description": "SCIP indexer for TypeScript, JavaScript, and Svelte",
55
"publisher": "sourcegraph",
66
"bin": "dist/src/main.js",
77
"main": "./dist/src/main.js",
@@ -36,9 +36,12 @@
3636
},
3737
"homepage": "https://github.com/sourcegraph/scip-typescript#readme",
3838
"dependencies": {
39+
"@jridgewell/trace-mapping": "^0.3.31",
3940
"commander": "^14.0.3",
4041
"google-protobuf": "^4.0.2",
4142
"progress": "^2.0.3",
43+
"svelte": "^5.56.10",
44+
"svelte2tsx": "^0.7.61",
4245
"typescript": "^6.0.3"
4346
},
4447
"devDependencies": {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
type Props = { label: string }
3+
let { label }: Props = $props()
4+
</script>
5+
6+
<p>{label}</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import Component from '../../a/src/Component.svelte'
3+
</script>
4+
5+
<Component label="cross-project" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
let { label, count = 0 }: { label: string; count?: number } = $props()
3+
const doubled = $derived(count * 2)
4+
</script>
5+
6+
<button>{label}: {doubled}</button>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts" generics="Value">
2+
let { value }: { value: Value } = $props()
3+
</script>
4+
5+
<span>{value}</span>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
export let value: string
3+
</script>
4+
5+
<span>{value}</span>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { writable } from 'svelte/store'
3+
import Child from './Child.svelte'
4+
import Generic from './Generic.svelte'
5+
import Legacy from './Legacy.svelte'
6+
import Plain from './Plain.svelte'
7+
import { format, type User } from './helper'
8+
import { importedCount } from './stores'
9+
10+
const user: User = { name: 'Ada' }
11+
let clicks = $state(1)
12+
const count = writable(2)
13+
let generic: Generic<User> | undefined = $state()
14+
15+
function increment(): void {
16+
clicks += 1
17+
}
18+
</script>
19+
20+
{#snippet greeting(name: string)}
21+
<strong>Hello {name}</strong>
22+
{/snippet}
23+
24+
<button onclick={increment}>Increment</button>
25+
<Child label={format(user.name)} count={clicks} />
26+
<Generic bind:this={generic} value={user} />
27+
<Legacy value="legacy" />
28+
<Plain enabled={true} />
29+
<p>{$count}</p>
30+
<p>{$importedCount}</p>
31+
{@render greeting(user.name)}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let enabled = false
3+
</script>
4+
5+
{#if enabled}
6+
<p>enabled</p>
7+
{/if}

snapshots/input/svelte/helper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface User {
2+
name: string
3+
}
4+
5+
export function format(name: string): string {
6+
return name.toUpperCase()
7+
}

0 commit comments

Comments
 (0)