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
2 changes: 1 addition & 1 deletion internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
compilerOptions := &core.CompilerOptions{
SkipDefaultLibCheck: core.TSTrue,
}
harnessutil.SetCompilerOptionsFromTestConfig(t, testData.GlobalOptions, compilerOptions)
harnessutil.SetCompilerOptionsFromTestConfig(t, testData.GlobalOptions, compilerOptions, rootDir)

inputReader, inputWriter := newLSPPipe()
outputReader, outputWriter := newLSPPipe()
Expand Down
15 changes: 8 additions & 7 deletions internal/incremental/snapshottobuildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ func (t *toBuildInfo) toFileIdListId(set *collections.Set[tspath.Path]) BuildInf
}

func (t *toBuildInfo) toRelativeToBuildInfoCompilerOptionValue(option *tsoptions.CommandLineOption, v any) any {
if !option.IsFilePath {
return v
}
if option.Kind == "list" {
if arr, ok := v.([]string); ok {
return core.Map(arr, t.relativeToBuildInfo)
if option.Elements().IsFilePath {
if arr, ok := v.([]string); ok {
return core.Map(arr, t.relativeToBuildInfo)
}
}
} else if option.IsFilePath {
if str, ok := v.(string); ok && str != "" {
return t.relativeToBuildInfo(v.(string))
}
} else if str, ok := v.(string); ok && str != "" {
return t.relativeToBuildInfo(v.(string))
}
return v
}
Expand Down
31 changes: 21 additions & 10 deletions internal/testutil/harnessutil/harnessutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func CompileFiles(

// Parse harness and compiler options from the test configuration
if testConfig != nil {
setOptionsFromTestConfig(t, testConfig, compilerOptions, &harnessOptions)
setOptionsFromTestConfig(t, testConfig, compilerOptions, &harnessOptions, currentDirectory)
}

return CompileFilesEx(t, inputFiles, otherFiles, &harnessOptions, compilerOptions, currentDirectory, symlinks, tsconfig)
Expand Down Expand Up @@ -224,7 +224,7 @@ func CompileFilesEx(
result.Repeat = func(testConfig TestConfiguration) *CompilationResult {
newHarnessOptions := *harnessOptions
newCompilerOptions := compilerOptions.Clone()
setOptionsFromTestConfig(t, testConfig, newCompilerOptions, &newHarnessOptions)
setOptionsFromTestConfig(t, testConfig, newCompilerOptions, &newHarnessOptions, currentDirectory)
return CompileFilesEx(t, inputFiles, otherFiles, &newHarnessOptions, newCompilerOptions, currentDirectory, symlinks, tsconfig)
}
return result
Expand Down Expand Up @@ -255,15 +255,15 @@ var testLibFolderMap = sync.OnceValue(func() map[string]any {
return testfs
})

func SetCompilerOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration, compilerOptions *core.CompilerOptions) {
func SetCompilerOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration, compilerOptions *core.CompilerOptions, currentDirectory string) {
for name, value := range testConfig {
if name == "typescriptversion" {
continue
}

commandLineOption := getCommandLineOption(name)
if commandLineOption != nil {
parsedValue := getOptionValue(t, commandLineOption, value)
parsedValue := getOptionValue(t, commandLineOption, value, currentDirectory)
errors := tsoptions.ParseCompilerOptions(commandLineOption.Name, parsedValue, compilerOptions)
if len(errors) > 0 {
t.Fatalf("Error parsing value '%s' for compiler option '%s'.", value, commandLineOption.Name)
Expand All @@ -272,15 +272,15 @@ func SetCompilerOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration
}
}

func setOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration, compilerOptions *core.CompilerOptions, harnessOptions *HarnessOptions) {
func setOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration, compilerOptions *core.CompilerOptions, harnessOptions *HarnessOptions, currentDirectory string) {
for name, value := range testConfig {
if name == "typescriptversion" {
continue
}

commandLineOption := getCommandLineOption(name)
if commandLineOption != nil {
parsedValue := getOptionValue(t, commandLineOption, value)
parsedValue := getOptionValue(t, commandLineOption, value, currentDirectory)
errors := tsoptions.ParseCompilerOptions(commandLineOption.Name, parsedValue, compilerOptions)
if len(errors) > 0 {
t.Fatalf("Error parsing value '%s' for compiler option '%s'.", value, commandLineOption.Name)
Expand All @@ -289,7 +289,7 @@ func setOptionsFromTestConfig(t *testing.T, testConfig TestConfiguration, compil
}
harnessOption := getHarnessOption(name)
if harnessOption != nil {
parsedValue := getOptionValue(t, harnessOption, value)
parsedValue := getOptionValue(t, harnessOption, value, currentDirectory)
parseHarnessOption(t, harnessOption.Name, parsedValue, harnessOptions)
continue
}
Expand Down Expand Up @@ -395,7 +395,10 @@ func parseHarnessOption(t *testing.T, key string, value any, harnessOptions *Har
case "fileName":
harnessOptions.FileName = value.(string)
case "libFiles":
harnessOptions.LibFiles = value.([]string)
harnessOptions.LibFiles = make([]string, 0, len(value.([]any)))
for _, v := range value.([]any) {
harnessOptions.LibFiles = append(harnessOptions.LibFiles, v.(string))
}
case "noImplicitReferences":
harnessOptions.NoImplicitReferences = value.(bool)
case "currentDirectory":
Expand All @@ -421,9 +424,12 @@ func parseHarnessOption(t *testing.T, key string, value any, harnessOptions *Har

var deprecatedModuleResolution []string = []string{"node", "classic", "node10"}

func getOptionValue(t *testing.T, option *tsoptions.CommandLineOption, value string) tsoptions.CompilerOptionsValue {
func getOptionValue(t *testing.T, option *tsoptions.CommandLineOption, value string, cwd string) tsoptions.CompilerOptionsValue {
switch option.Kind {
case tsoptions.CommandLineOptionTypeString:
if option.IsFilePath {
return tspath.GetNormalizedAbsolutePath(value, cwd)
}
return value
case tsoptions.CommandLineOptionTypeNumber:
numVal, err := strconv.Atoi(value)
Expand All @@ -448,6 +454,11 @@ func getOptionValue(t *testing.T, option *tsoptions.CommandLineOption, value str
return enumVal
case tsoptions.CommandLineOptionTypeList, tsoptions.CommandLineOptionTypeListOrElement:
listVal, errors := tsoptions.ParseListTypeOption(option, value)
if option.Elements().IsFilePath {
return core.Map(listVal, func(item any) any {
return tspath.GetNormalizedAbsolutePath(item.(string), cwd)
})
}
if len(errors) > 0 {
t.Fatalf("Unknown value '%s' for compiler option '%s'", value, option.Name)
}
Expand Down Expand Up @@ -987,7 +998,7 @@ func getValueOfOptionString(t *testing.T, option string, value string) tsoptions
if optionDecl.Name == "moduleResolution" && slices.Contains(deprecatedModuleResolution, strings.ToLower(value)) {
return value
}
return getOptionValue(t, optionDecl, value)
return getOptionValue(t, optionDecl, value, "/")
}

func getCommandLineOption(option string) *tsoptions.CommandLineOption {
Expand Down
32 changes: 14 additions & 18 deletions internal/tsoptions/commandlineparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,59 +282,55 @@ func (p *commandLineParser) parseOptionValue(
return i
}

func (p *commandLineParser) parseListTypeOption(opt *CommandLineOption, value string) ([]string, []*ast.Diagnostic) {
func (p *commandLineParser) parseListTypeOption(opt *CommandLineOption, value string) ([]any, []*ast.Diagnostic) {
return ParseListTypeOption(opt, value)
}

func ParseListTypeOption(opt *CommandLineOption, value string) ([]string, []*ast.Diagnostic) {
func ParseListTypeOption(opt *CommandLineOption, value string) ([]any, []*ast.Diagnostic) {
value = strings.TrimSpace(value)
var errors []*ast.Diagnostic
if strings.HasPrefix(value, "-") {
return []string{}, errors
return []any{}, errors
}
if opt.Kind == "listOrElement" && !strings.ContainsRune(value, ',') {
val, err := validateJsonOptionValue(opt, value, nil, nil)
if err != nil {
return []string{}, err
return []any{}, err
}
return []string{val.(string)}, errors
return []any{val.(string)}, errors
}
if value == "" {
return []string{}, errors
return []any{}, errors
}
values := strings.Split(value, ",")
switch opt.Elements().Kind {
case "string":
elements := core.Filter(core.Map(values, func(v string) string {
elements := core.MapFiltered(values, func(v string) (any, bool) {
val, err := validateJsonOptionValue(opt.Elements(), v, nil, nil)
if s, ok := val.(string); ok && len(err) == 0 && s != "" {
return s
return s, true
}
errors = append(errors, err...)
return ""
}), isDefined)
return "", false
})
return elements, errors
case "boolean", "object", "number":
// do nothing: only string and enum/object types currently allowed as list entries
// !!! we don't actually have number list options, so I didn't implement number list parsing
panic("List of " + opt.Elements().Kind + " is not yet supported.")
default:
result := core.Filter(core.Map(values, func(v string) string {
result := core.MapFiltered(values, func(v string) (any, bool) {
val, err := convertJsonOptionOfEnumType(opt.Elements(), strings.TrimFunc(v, stringutil.IsWhiteSpaceLike), nil, nil)
if s, ok := val.(string); ok && len(err) == 0 && s != "" {
return s
return s, true
}
errors = append(errors, err...)
return ""
}), isDefined)
return "", false
})
return result, errors
}
}

func isDefined(s string) bool {
return s != ""
}

func convertJsonOptionOfEnumType(
opt *CommandLineOption,
value string,
Expand Down
14 changes: 8 additions & 6 deletions internal/tsoptions/parsinghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,18 @@ func convertToOptionsWithAbsolutePaths(optionsBase *collections.OrderedMap[strin

func ConvertOptionToAbsolutePath(o string, v any, optionMap CommandLineOptionNameMap, cwd string) (any, bool) {
option := optionMap.Get(o)
if option == nil || !option.IsFilePath {
if option == nil {
return nil, false
}
if option.Kind == "list" {
if arr, ok := v.([]string); ok {
return core.Map(arr, func(item string) string {
return tspath.GetNormalizedAbsolutePath(item, cwd)
}), true
if option.Elements().IsFilePath {
if arr, ok := v.([]string); ok {
return core.Map(arr, func(item string) string {
return tspath.GetNormalizedAbsolutePath(item, cwd)
}), true
}
}
} else {
} else if option.IsFilePath {
return tspath.GetNormalizedAbsolutePath(v.(string), cwd), true
}
return nil, false
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@
=== /src/index.ts ===
class Src implements NS.Dep { }
>Src : Symbol(Src, Decl(index.ts, 0, 0))
>NS.Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))
>NS : Symbol(NS, Decl(dep.d.ts, 0, 0))
>Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))

=== /deps/dep/dep.d.ts ===
declare namespace NS {
>NS : Symbol(NS, Decl(dep.d.ts, 0, 0))

interface Dep {
>Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
class Src implements NS.Dep { }
>Src : Symbol(Src, Decl(index.ts, 0, 0))
->NS.Dep : Symbol(NS.Dep, Decl(dep.d.ts, 0, 22))
->NS : Symbol(NS, Decl(dep.d.ts, 0, 0))
+>NS.Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))
>NS : Symbol(NS, Decl(dep.d.ts, 0, 0))
->Dep : Symbol(NS.Dep, Decl(dep.d.ts, 0, 22))
-
-=== /deps/dep/dep.d.ts ===
-declare namespace NS {
->NS : Symbol(NS, Decl(dep.d.ts, 0, 0))
-
- interface Dep {
->Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))
- }
-}
+
+>Dep : Symbol(Dep, Decl(dep.d.ts, 0, 22))

=== /deps/dep/dep.d.ts ===
declare namespace NS {
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ class Src implements NS.Dep { }
>Src : Src
>NS : any

=== /deps/dep/dep.d.ts ===

declare namespace NS {
interface Dep {
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
import { a2 } from "phaser";
>a2 : Symbol(a2, Decl(a.ts, 0, 8))

=== /typings/phaser/types/phaser.d.ts ===
export const a2: number;
>a2 : Symbol(a2, Decl(phaser.d.ts, 0, 12))

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
import { a2 } from "phaser";
>a2 : any

=== /typings/phaser/types/phaser.d.ts ===
export const a2: number;
>a2 : number

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
=== /a.ts ===
import { a2 } from "phaser";
->a2 : number
-
-=== /typings/phaser/types/phaser.d.ts ===
-export const a2: number;
->a2 : number
+>a2 : any

=== /typings/phaser/types/phaser.d.ts ===
export const a2: number;
Loading
Loading