-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Svelte module resolution tweaks (#2481)
Svelte files are now resolved by intercepting checks for .d.svelte.ts instead of .svelte.ts. As a consequence, we can handle sibling foo.svelte / foo.svelte.ts files and importing both. When doing import Foo from './foo.svelte this now resolves to the Svelte file (prio to #2463 it would resovle to the .svelte.ts file), and doing import Foo from './foo.svelte.js will resolve to the TS file.
- Loading branch information
1 parent
8c080cf
commit a3a7a91
Showing
31 changed files
with
215 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist/ | ||
.vscode/ | ||
node_modules/ | ||
!test/plugins/typescript/features/diagnostics/fixtures/exports-map-svelte/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...t/plugins/typescript/features/diagnostics/fixtures/bindings-two-way-check/expectedv2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"code": -1, | ||
"message": "Unexpected token", | ||
"range": { | ||
"end": { | ||
"character": 47, | ||
"line": 12 | ||
}, | ||
"start": { | ||
"character": 47, | ||
"line": 12 | ||
} | ||
}, | ||
"severity": 1, | ||
"source": "ts" | ||
} | ||
] |
36 changes: 36 additions & 0 deletions
36
.../test/plugins/typescript/features/diagnostics/fixtures/exports-map-svelte/expectedv2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[ | ||
{ | ||
"code": 2307, | ||
"message": "Cannot find module 'package' or its corresponding type declarations.", | ||
"range": { | ||
"end": { | ||
"character": 45, | ||
"line": 1 | ||
}, | ||
"start": { | ||
"character": 36, | ||
"line": 1 | ||
} | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"tags": [] | ||
}, | ||
{ | ||
"code": 2307, | ||
"message": "Cannot find module 'package/y' or its corresponding type declarations.", | ||
"range": { | ||
"start": { | ||
"character": 38, | ||
"line": 3 | ||
}, | ||
"end": { | ||
"character": 49, | ||
"line": 3 | ||
} | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"tags": [] | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
...ver/test/plugins/typescript/features/diagnostics/fixtures/exports-map-svelte/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import DefaultSvelteWithTS from 'package'; // with https://github.com/sveltejs/language-tools/pull/2478 this would work; needs decision if we want that | ||
import SubWithDTS from 'package/x'; | ||
import SubWithoutDTSAndNotTS from 'package/y'; | ||
</script> | ||
|
||
<DefaultSvelteWithTS /> | ||
<SubWithDTS /> | ||
<SubWithoutDTSAndNotTS /> |
3 changes: 3 additions & 0 deletions
3
...pescript/features/diagnostics/fixtures/exports-map-svelte/node_modules/package/foo.svelte
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...script/features/diagnostics/fixtures/exports-map-svelte/node_modules/package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...script/features/diagnostics/fixtures/exports-map-svelte/node_modules/package/x-types.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...typescript/features/diagnostics/fixtures/exports-map-svelte/node_modules/package/x.svelte
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...typescript/features/diagnostics/fixtures/exports-map-svelte/node_modules/package/y.svelte
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...er/test/plugins/typescript/features/diagnostics/fixtures/exports-map-svelte/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"target": "esnext", | ||
"moduleResolution": "Bundler" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...e-server/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/a.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
export let foo = true; | ||
</script> |
1 change: 1 addition & 0 deletions
1
...ver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/a.svelte.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const a: boolean; |
3 changes: 3 additions & 0 deletions
3
...e-server/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/b.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
export let foo = true; | ||
</script> |
1 change: 1 addition & 0 deletions
1
...erver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/b.svelte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const b = true; |
1 change: 1 addition & 0 deletions
1
...ver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/c.d.svelte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const c: boolean; |
3 changes: 3 additions & 0 deletions
3
...e-server/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/c.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
export let foo = true; | ||
</script> |
3 changes: 3 additions & 0 deletions
3
...e-server/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/d.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
export let foo = true; | ||
</script> |
1 change: 1 addition & 0 deletions
1
...erver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/d.svelte.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const d = true; |
1 change: 1 addition & 0 deletions
1
...r/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/expectedv2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
15 changes: 15 additions & 0 deletions
15
...rver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts"> | ||
import { a } from './a.svelte'; | ||
import B from './b.svelte'; | ||
import { b } from './b.svelte.js'; | ||
import { c } from './c.svelte'; | ||
import D from './d.svelte'; | ||
import { d } from './d.svelte.js'; | ||
a; | ||
b; | ||
c; | ||
d; | ||
</script> | ||
|
||
<B /> | ||
<D /> |
13 changes: 13 additions & 0 deletions
13
...ver/test/plugins/typescript/features/diagnostics/fixtures/import-precedence/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"allowJs": true, | ||
"target": "ESNext", | ||
/** | ||
This is actually not needed, but makes the tests faster | ||
because TS does not look up other types. | ||
*/ | ||
"types": ["svelte"], | ||
"allowArbitraryExtensions": true // else .d.svelte.ts will be an error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.