Skip to content

Commit 3366712

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 3366712

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-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":
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
co := core.CompilerOptions{}
14+
for _, field := range reflect.VisibleFields(reflect.TypeOf(co)) {
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+
testValue := core.TSTrue
22+
ParseCompilerOptions(keyName, testValue, &co)
23+
newSetValue := reflect.ValueOf(co).FieldByName(field.Name)
24+
if !newSetValue.Equal(reflect.ValueOf(testValue)) {
25+
missingKeys = append(missingKeys, keyName)
26+
}
27+
}
28+
}
29+
if len(missingKeys) > 0 {
30+
t.Errorf("The following Tristate keys are missing entries in the ParseCompilerOptions switch statement:\n%v", missingKeys)
31+
}
32+
}

0 commit comments

Comments
 (0)