Skip to content

add missing compiler options, add a test to help prevent this in future #839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions internal/tsoptions/parsinghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
switch key {
case "allowJs":
allOptions.AllowJs = parseTristate(value)
case "allowImportingTsExtensions":
allOptions.AllowImportingTsExtensions = parseTristate(value)
case "allowSyntheticDefaultImports":
allOptions.AllowSyntheticDefaultImports = parseTristate(value)
case "allowNonTsExtensions":
Expand Down Expand Up @@ -185,6 +187,12 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
allOptions.DeclarationMap = parseTristate(value)
case "declaration":
allOptions.Declaration = parseTristate(value)
case "downlevelIteration":
allOptions.DownlevelIteration = parseTristate(value)
case "emitDeclarationOnly":
allOptions.EmitDeclarationOnly = parseTristate(value)
case "eSModuleInterop":
allOptions.ESModuleInterop = parseTristate(value)
case "extendedDiagnostics":
allOptions.ExtendedDiagnostics = parseTristate(value)
case "emitDecoratorMetadata":
Expand Down Expand Up @@ -261,6 +269,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
allOptions.NoFallthroughCasesInSwitch = parseTristate(value)
case "noEmitForJsFiles":
allOptions.NoEmitForJsFiles = parseTristate(value)
case "noErrorTruncation":
allOptions.NoErrorTruncation = parseTristate(value)
case "noImplicitAny":
allOptions.NoImplicitAny = parseTristate(value)
case "noImplicitThis":
Expand Down Expand Up @@ -311,6 +321,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
allOptions.ResolvePackageJsonImports = parseTristate(value)
case "reactNamespace":
allOptions.ReactNamespace = parseString(value)
case "rewriteRelativeImportExtensions":
allOptions.RewriteRelativeImportExtensions = parseTristate(value)
case "rootDir":
allOptions.RootDir = parseString(value)
case "rootDirs":
Expand Down
36 changes: 36 additions & 0 deletions internal/tsoptions/parsinghelpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package tsoptions

import (
"github.com/microsoft/typescript-go/internal/core"
"reflect"
"testing"
"unicode"
)

func TestParseCompilerOptions_noMissingTristates(t *testing.T) {
var missingKeys []string

for _, field := range reflect.VisibleFields(reflect.TypeFor[core.CompilerOptions]()) {
// The key name in ParseCompilerOptions has the first rune in lowercase
r := []rune(field.Name)
r[0] = unicode.ToLower(r[0])
keyName := string(r)

isTristate := field.Type == reflect.TypeFor[core.Tristate]()
if isTristate {
// Set the field on a CompilerOptions to something other than the
// default (i.e. TSTrue != TSUnknown), then check whether
// ParseCompilerOptions does actually update the value for that key.
testValue := core.TSTrue
co := core.CompilerOptions{}
ParseCompilerOptions(keyName, testValue, &co)
newSetValue := reflect.ValueOf(co).FieldByName(field.Name)
if !newSetValue.Equal(reflect.ValueOf(testValue)) {
missingKeys = append(missingKeys, keyName)
}
}
}
if len(missingKeys) > 0 {
t.Errorf("The following Tristate keys are missing entries in the ParseCompilerOptions switch statement:\n%v", missingKeys)
}
}