Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions internal/project/untitled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,26 @@ x++;`
// We expect to find 4 references
assert.Assert(t, len(refs) == 4, "Expected 4 references, got %d", len(refs))
}

func TestImportsInUntitled(t *testing.T) {
t.Parallel()
if !bundled.Embedded {
t.Skip("bundled files are not embedded")
}

files := map[string]any{
// Make sure typings directory exists so it would actually try to fetch typings from this location
projecttestutil.TestTypingsLocation + "/node_modules/@types/somelib/index.d.ts": `export const x: number;`,
}
session, _ := projecttestutil.Setup(files)
content := `import "https://deno.land/std@0.208.0/path/mod.ts"
import "./relative"
`
uri1 := lsproto.DocumentUri("untitled:Untitled-1")
session.DidOpenFile(context.Background(), uri1, 1, content, lsproto.LanguageKindTypeScript)

// 2) Wait for ATA/background tasks to finish, then get a language service for the first file
session.WaitForBackgroundTasks()
_, err := session.GetLanguageService(context.Background(), uri1)
assert.NilError(t, err)
}
4 changes: 3 additions & 1 deletion internal/vfs/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ type Common struct {

func RootLength(p string) int {
l := tspath.GetEncodedRootLength(p)
if l <= 0 {
if l == 0 {
panic(fmt.Sprintf("vfs: path %q is not absolute", p))
} else if l < 0 {
return ^l
}
return l
}
Expand Down
3 changes: 3 additions & 0 deletions internal/vfs/iovfs/iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func From(fsys fs.FS, useCaseSensitiveFileNames bool) FsWithSys {
p := tspath.RemoveTrailingDirectorySeparator(root)
sub, err := fs.Sub(fsys, p)
if err != nil {
if tspath.IsUrl(root) {
return nil
Comment thread
jakebailey marked this conversation as resolved.
}
panic(fmt.Sprintf("vfs: failed to create sub file system for %q: %v", p, err))
}
return sub
Expand Down
10 changes: 10 additions & 0 deletions testdata/baselines/reference/compiler/importUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/importUrl.ts] ////

//// [index.ts]
import "https://deno.land/std@0.208.0/path/mod.ts"


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("https://deno.land/std@0.208.0/path/mod.ts");
6 changes: 6 additions & 0 deletions testdata/baselines/reference/compiler/importUrl.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/importUrl.ts] ////

=== /src/index.ts ===

import "https://deno.land/std@0.208.0/path/mod.ts"

7 changes: 7 additions & 0 deletions testdata/baselines/reference/compiler/importUrl.trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
======== Resolving module 'https://deno.land/std@0.208.0/path/mod.ts' from '/src/index.ts'. ========
Module resolution kind is not specified, using 'Bundler'.
Resolving in CJS mode with conditions 'require', 'types'.
File '/src/package.json' does not exist.
File '/package.json' does not exist.
Skipping module 'https://deno.land/std@0.208.0/path/mod.ts' that looks like an absolute URI, target file types: TypeScript, JavaScript, Declaration, JSON.
======== Module name 'https://deno.land/std@0.208.0/path/mod.ts' was not resolved. ========
6 changes: 6 additions & 0 deletions testdata/baselines/reference/compiler/importUrl.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/importUrl.ts] ////

=== /src/index.ts ===

import "https://deno.land/std@0.208.0/path/mod.ts"

17 changes: 17 additions & 0 deletions testdata/baselines/reference/compiler/importUrlNodeModulesExist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/importUrlNodeModulesExist.ts] ////

//// [package.json]
{ "name": "foo", "version": "1.0.0" }

//// [index.d.ts]
export declare function useFoo(): string;

//// [index.ts]
import "https://deno.land/std@0.208.0/path/mod.ts"



//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("https://deno.land/std@0.208.0/path/mod.ts");
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/importUrlNodeModulesExist.ts] ////

=== /node_modules/foo/index.d.ts ===
export declare function useFoo(): string;
>useFoo : Symbol(useFoo, Decl(index.d.ts, 0, 0))

=== /src/index.ts ===

import "https://deno.land/std@0.208.0/path/mod.ts"


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
======== Resolving module 'https://deno.land/std@0.208.0/path/mod.ts' from '/src/index.ts'. ========
Module resolution kind is not specified, using 'Bundler'.
Resolving in CJS mode with conditions 'require', 'types'.
File '/src/package.json' does not exist.
File '/package.json' does not exist.
Skipping module 'https://deno.land/std@0.208.0/path/mod.ts' that looks like an absolute URI, target file types: TypeScript, JavaScript, Declaration, JSON.
======== Module name 'https://deno.land/std@0.208.0/path/mod.ts' was not resolved. ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/importUrlNodeModulesExist.ts] ////

=== /node_modules/foo/index.d.ts ===
export declare function useFoo(): string;
>useFoo : () => string

=== /src/index.ts ===

import "https://deno.land/std@0.208.0/path/mod.ts"


4 changes: 4 additions & 0 deletions testdata/tests/cases/compiler/importUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @traceResolution: true

// @filename: /src/index.ts
import "https://deno.land/std@0.208.0/path/mod.ts"
11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/importUrlNodeModulesExist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @traceResolution: true

// @filename: /node_modules/foo/package.json
{ "name": "foo", "version": "1.0.0" }

// @filename: /node_modules/foo/index.d.ts
export declare function useFoo(): string;

// @filename: /src/index.ts
import "https://deno.land/std@0.208.0/path/mod.ts"

Loading