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
5 changes: 4 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15379,7 +15379,10 @@ func (c *Checker) getExternalModuleFileFromDeclaration(declaration *ast.Node) *a
if ast.HasImportAttributes(declaration) {
importAttributesType = c.getTypeFromImportAttributes(ast.GetImportAttributes(declaration))
}
moduleSymbol := c.resolveExternalModuleNameWorker(specifier, specifier /*moduleNotFoundError*/, nil, false, false, importAttributesType) // TODO: GH#18217
// This is only used by emit and type printing, after checking has already reported any
// resolution errors for this specifier. Resolve with ignoreErrors so that these queries
// don't add new diagnostics (e.g. an implicit-any-module suggestion) as a side effect.
moduleSymbol := c.resolveExternalModuleNameWorker(specifier, specifier, nil /*moduleNotFoundError*/, true /*ignoreErrors*/, false /*isForAugmentation*/, importAttributesType)
if moduleSymbol == nil {
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions tsc/internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ type FourslashOptions struct {
Capabilities *lsproto.ClientCapabilities
ContentMapperSpawner contentmapper.Spawner
RunExternalCode bool
// Makes every textDocument/diagnostic request also emit the program and compare
// the diagnostics before and after emit, e.g. to catch ones added by the emit resolver.
TrackFlakyDiagnostics *lsproto.DiagnosticFlakeLogLevel
}

func NewFourslashWithOptions(t *testing.T, content string, options *FourslashOptions) (*FourslashTest, func()) {
Expand Down Expand Up @@ -260,7 +263,7 @@ func newFourslash(t *testing.T, content string, options *FourslashOptions, testP
// !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support
// !!! replace with a proper request *after initialize*
client.SetCompilerOptionsForInferredProjects(compilerOptions)
f.initialize(t, options.Capabilities, options.RunExternalCode)
f.initialize(t, options)

if testData.isStateBaseliningEnabled() {
// Single baseline, so initialize project state baseline too
Expand Down Expand Up @@ -365,11 +368,12 @@ func getBaseFileNameFromTest(t *testing.T) string {

const showCodeLensLocationsCommandName = "typescript.showCodeLensLocations"

func (f *FourslashTest) initialize(t *testing.T, capabilities *lsproto.ClientCapabilities, runExternalCode bool) {
func (f *FourslashTest) initialize(t *testing.T, options *FourslashOptions) {
initializationOptions := &lsproto.InitializationOptions{
CodeLensShowLocationsCommandName: new(showCodeLensLocationsCommandName),
TrackFlakyDiagnostics: options.TrackFlakyDiagnostics,
}
if runExternalCode {
if options.RunExternalCode {
initializationOptions.RunExternalCode = new(true)
}
params := &lsproto.InitializeParams{
Expand All @@ -378,7 +382,7 @@ func (f *FourslashTest) initialize(t *testing.T, capabilities *lsproto.ClientCap
InitializationOptions: initializationOptions,
},
}
params.Capabilities = getCapabilitiesWithDefaults(capabilities)
params.Capabilities = getCapabilitiesWithDefaults(options.Capabilities)
f.capabilities = params.Capabilities
resp, _, ok := f.client.SendRequest(t, lsproto.InitializeInfo, params)
if !ok {
Expand Down
6 changes: 3 additions & 3 deletions tsc/internal/testutil/harnessutil/harnessutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ func compileFilesWithHost(
preErrors = append(preErrors, preProgram.GetSyntacticDiagnostics(ctx, nil)...)
preErrors = append(preErrors, preProgram.GetSemanticDiagnostics(ctx, nil)...)
preErrors = append(preErrors, preProgram.GetGlobalDiagnostics(ctx)...)
if preProgram.Options().GetEmitDeclarations() {
preErrors = append(preErrors, preProgram.GetDeclarationDiagnostics(ctx, nil)...)
}
if harnessOptions.CaptureSuggestions {
preErrors = append(preErrors, preProgram.GetSuggestionDiagnostics(ctx, nil)...)
}
if preProgram.Options().GetEmitDeclarations() {
preErrors = append(preErrors, preProgram.GetDeclarationDiagnostics(ctx, nil)...)
}
preErrors = compiler.SortAndDeduplicateDiagnostics(preErrors)

postProgram := createProgram(host, config)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule1.ts] ////

//// [index.js]
exports.x = 1;
//// [index.js]
import { x } from "untyped";
x;


//// [index.js]
import { x } from "untyped";
x;


//// [index.d.ts]
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule1.ts] ////

=== /index.js ===
import { x } from "untyped";
>x : Symbol(x, Decl(index.js, 0, 8))

x;
>x : Symbol(x, Decl(index.js, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule1.ts] ////

=== /index.js ===
import { x } from "untyped";
>x : any

x;
>x : error

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule2.ts] ////

//// [untyped.js]
exports.x = 1;
//// [index.ts]
// @ts-expect-error
import { x } from "./untyped";
x;


//// [index.js]
// @ts-expect-error
import { x } from "./untyped";
x;


//// [index.d.ts]
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule2.ts] ////

=== /index.ts ===
// @ts-expect-error
import { x } from "./untyped";
>x : Symbol(x, Decl(index.ts, 1, 8))

x;
>x : Symbol(x, Decl(index.ts, 1, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule2.ts] ////

=== /index.ts ===
// @ts-expect-error
import { x } from "./untyped";
>x : any

x;
>x : error

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule3.ts] ////

//// [untyped.mjs]
export const x = 1;
//// [index.mts]
// @ts-expect-error
import { x } from "./untyped.mjs";
x;


//// [index.mjs]
// @ts-expect-error
import { x } from "./untyped.mjs";
x;


//// [index.d.mts]
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule3.ts] ////

=== /index.mts ===
// @ts-expect-error
import { x } from "./untyped.mjs";
>x : Symbol(x, Decl(index.mts, 1, 8))

x;
>x : Symbol(x, Decl(index.mts, 1, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/noFlakyDiagnosticsUntypedModule3.ts] ////

=== /index.mts ===
// @ts-expect-error
import { x } from "./untyped.mjs";
>x : any

x;
>x : error

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @allowJs: true
// @noImplicitAny: true
// @declaration: true
// @outDir: /out
// @noImplicitReferences: true
// @captureSuggestions: true
// @Filename: /node_modules/untyped/index.js
exports.x = 1;
// @Filename: /index.js
import { x } from "untyped";
x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @noImplicitAny: true
// @declaration: true
// @noImplicitReferences: true
// @captureSuggestions: true
// @Filename: /untyped.js
exports.x = 1;
// @Filename: /index.ts
// @ts-expect-error
import { x } from "./untyped";
x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @module: nodenext
// @noImplicitAny: true
// @declaration: true
// @noImplicitReferences: true
// @captureSuggestions: true
// @Filename: /untyped.mjs
export const x = 1;
// @Filename: /index.mts
// @ts-expect-error
import { x } from "./untyped.mjs";
x;
Loading