Skip to content

Commit ff3642a

Browse files
committed
add missing compiler options, add a test to help prevent this in future
This is a more comprehensive fix than microsoft#838. Future work would involve doing the same sort of tests for non-Tristate types.
1 parent 54aed8f commit ff3642a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

internal/tsoptions/parsinghelpers.go

+12
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
143143
switch key {
144144
case "allowJs":
145145
allOptions.AllowJs = parseTristate(value)
146+
case "allowImportingTsExtensions":
147+
allOptions.AllowImportingTsExtensions = parseTristate(value)
146148
case "allowSyntheticDefaultImports":
147149
allOptions.AllowSyntheticDefaultImports = parseTristate(value)
148150
case "allowNonTsExtensions":
@@ -185,6 +187,12 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
185187
allOptions.DeclarationMap = parseTristate(value)
186188
case "declaration":
187189
allOptions.Declaration = parseTristate(value)
190+
case "downlevelIteration":
191+
allOptions.DownlevelIteration = parseTristate(value)
192+
case "emitDeclarationOnly":
193+
allOptions.EmitDeclarationOnly = parseTristate(value)
194+
case "eSModuleInterop":
195+
allOptions.ESModuleInterop = parseTristate(value)
188196
case "extendedDiagnostics":
189197
allOptions.ExtendedDiagnostics = parseTristate(value)
190198
case "emitDecoratorMetadata":
@@ -261,6 +269,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
261269
allOptions.NoFallthroughCasesInSwitch = parseTristate(value)
262270
case "noEmitForJsFiles":
263271
allOptions.NoEmitForJsFiles = parseTristate(value)
272+
case "noErrorTruncation":
273+
allOptions.NoErrorTruncation = parseTristate(value)
264274
case "noImplicitAny":
265275
allOptions.NoImplicitAny = parseTristate(value)
266276
case "noImplicitThis":
@@ -311,6 +321,8 @@ func ParseCompilerOptions(key string, value any, allOptions *core.CompilerOption
311321
allOptions.ResolvePackageJsonImports = parseTristate(value)
312322
case "reactNamespace":
313323
allOptions.ReactNamespace = parseString(value)
324+
case "rewriteRelativeImportExtensions":
325+
allOptions.RewriteRelativeImportExtensions = parseTristate(value)
314326
case "rootDir":
315327
allOptions.RootDir = parseString(value)
316328
case "rootDirs":
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tsoptions
2+
3+
import (
4+
"github.com/microsoft/typescript-go/internal/core"
5+
"reflect"
6+
"testing"
7+
"unicode"
8+
)
9+
10+
func TestParseCompilerOptions_noMissingTristates(t *testing.T) {
11+
var missingKeys []string
12+
13+
for _, field := range reflect.VisibleFields(reflect.TypeFor[core.CompilerOptions]()) {
14+
// The key name in ParseCompilerOptions has the first rune in lowercase
15+
r := []rune(field.Name)
16+
r[0] = unicode.ToLower(r[0])
17+
keyName := string(r)
18+
19+
isTristate := field.Type == reflect.TypeFor[core.Tristate]()
20+
if isTristate {
21+
// Set the field on a CompilerOptions to something other than the
22+
// default (i.e. TSTrue != TSUnknown), then check whether
23+
// ParseCompilerOptions does actually update the value for that key.
24+
testValue := core.TSTrue
25+
co := core.CompilerOptions{}
26+
ParseCompilerOptions(keyName, testValue, &co)
27+
newSetValue := reflect.ValueOf(co).FieldByName(field.Name)
28+
if !newSetValue.Equal(reflect.ValueOf(testValue)) {
29+
missingKeys = append(missingKeys, keyName)
30+
}
31+
}
32+
}
33+
if len(missingKeys) > 0 {
34+
t.Errorf("The following Tristate keys are missing entries in the ParseCompilerOptions switch statement:\n%v", missingKeys)
35+
}
36+
}

0 commit comments

Comments
 (0)