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

Merged
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
10 changes: 10 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,10 @@ 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 "extendedDiagnostics":
allOptions.ExtendedDiagnostics = parseTristate(value)
case "emitDecoratorMetadata":
Expand Down Expand Up @@ -261,6 +267,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 +319,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
41 changes: 41 additions & 0 deletions internal/tsoptions/parsinghelpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tsoptions

import (
"reflect"
"strings"
"testing"

"github.com/microsoft/typescript-go/internal/core"
)

func TestParseCompilerOptionNoMissingTristates(t *testing.T) {
t.Parallel()

var missingKeys []string
for _, field := range reflect.VisibleFields(reflect.TypeFor[core.CompilerOptions]()) {
keyName := field.Name
// use the JSON key from the tag, if present
// e.g. `json:"dog[,anythingelse]"` --> dog
if jsonTag, ok := field.Tag.Lookup("json"); ok {
keyName = strings.SplitN(jsonTag, ",", 2)[0]
}

isTristate := field.Type == reflect.TypeFor[core.Tristate]()
if isTristate {
// Set the field on a CompilerOptions to something other than the
// default (i.e. not 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)
}
}
1 change: 1 addition & 0 deletions internal/tsoptions/tsconfigparsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ func TestParseSrcCompiler(t *testing.T) {
ConfigFilePath: tsconfigFileName,
Declaration: core.TSTrue,
DeclarationMap: core.TSTrue,
EmitDeclarationOnly: core.TSTrue,
AlwaysStrict: core.TSTrue,
Composite: core.TSTrue,
IsolatedDeclarations: core.TSTrue,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
--- old.classReferencedInContextualParameterWithinItsOwnBaseExpression.js
+++ new.classReferencedInContextualParameterWithinItsOwnBaseExpression.js
@@= skipped -39, +39 lines =@@
) {}


@@= skipped -0, +-1 lines =@@
-//// [tests/cases/compiler/classReferencedInContextualParameterWithinItsOwnBaseExpression.ts] ////
-
-//// [classReferencedInContextualParameterWithinItsOwnBaseExpression.ts]
-interface Pretty<To> {
- (a: To): string;
-}
-
-interface Schema<A> {
- readonly pretty?: Pretty<A>;
-}
-
-interface Class<A> {
- new (): A;
-}
-
-declare const Class: <Self>(
- identifier: string,
-) => <Fields>(
- fields: Fields,
- annotations?: Schema<Self>,
-) => Class<OutputFrom<Fields>>;
-
-type Type<TOutput> = {
- _TOutput: TOutput;
-};
-
-type OutputFrom<TFields> = {
- [K in keyof TFields]: "_TOutput" extends keyof TFields[K]
- ? TFields[K]["_TOutput"]
- : never;
-};
-
-declare function string(): Type<string>;
-
-export class A extends Class<A>("A")(
- { a: string },
- {
- pretty: (a) => JSON.stringify(a),
- },
-) {}
-
-
-
-
-//// [classReferencedInContextualParameterWithinItsOwnBaseExpression.d.ts]
-interface Pretty<To> {
- (a: To): string;
+//// [classReferencedInContextualParameterWithinItsOwnBaseExpression.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.A = void 0;
+class A extends Class("A")({ a: string }, {
+ pretty: (a) => JSON.stringify(a),
+}) {
}
-}
-interface Schema<A> {
- readonly pretty?: Pretty<A>;
-}
Expand All @@ -37,4 +69,5 @@
-export declare class A extends A_base {
-}
-export {};
+exports.A = A;
@@= skipped --1, +1 lines =@@
+<no content>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
--- old.declFileEmitDeclarationOnly.js
+++ new.declFileEmitDeclarationOnly.js
@@= skipped -14, +14 lines =@@
}


@@= skipped -0, +-1 lines =@@
-//// [tests/cases/compiler/declFileEmitDeclarationOnly.ts] ////
-
-//// [helloworld.ts]
-const Log = {
- info(msg: string) {}
-}
-
-class HelloWorld {
- constructor(private name: string) {
- }
-
- public hello() {
- Log.info(`Hello ${this.name}`);
- }
-}
-
-
-
-
-//// [helloworld.d.ts]
-declare const Log: {
- info(msg: string): void;
+//// [helloworld.js]
+const Log = {
+ info(msg) { }
};
-};
-declare class HelloWorld {
- private name;
- constructor(name: string);
- hello(): void;
+class HelloWorld {
+ name;
+ constructor(name) {
+ this.name = name;
+ }
+ hello() {
+ Log.info(`Hello ${this.name}`);
+ }
}
-}
@@= skipped --1, +1 lines =@@
+<no content>

This file was deleted.

This file was deleted.

This file was deleted.

Loading