From 025ab2d9601f76e82b7e58c3a28878bf75d2e052 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 28 Jan 2025 16:44:32 +0200 Subject: [PATCH 1/2] Enable type stripping by default --- internal/cmd/runtime_options.go | 3 +-- internal/cmd/tests/cmd_run_test.go | 2 +- internal/js/compiler/compiler.go | 2 +- internal/js/compiler/enhanced_test.go | 4 ---- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/cmd/runtime_options.go b/internal/cmd/runtime_options.go index 60c2d038935..dd6cef91dc4 100644 --- a/internal/cmd/runtime_options.go +++ b/internal/cmd/runtime_options.go @@ -23,10 +23,9 @@ func runtimeOptionFlagSet(includeSysEnv bool) *pflag.FlagSet { flags.SortFlags = false flags.Bool("include-system-env-vars", includeSysEnv, "pass the real system environment variables to the runtime") flags.String("compatibility-mode", "extended", - `JavaScript compiler compatibility mode, "extended" or "base" or "experimental_enhanced" + `JavaScript compiler compatibility mode, "extended" or "base" base: pure Sobek - Golang JS VM supporting ES6+ extended: base + sets "global" as alias for "globalThis" -experimental_enhanced: esbuild-based transpiling for TypeScript and ES6+ support `) flags.StringP("type", "t", "", "override test type, \"js\" or \"archive\"") flags.StringArrayP("env", "e", nil, "add/override environment variable with `VAR=value`") diff --git a/internal/cmd/tests/cmd_run_test.go b/internal/cmd/tests/cmd_run_test.go index b306a98e594..a6abfb8563c 100644 --- a/internal/cmd/tests/cmd_run_test.go +++ b/internal/cmd/tests/cmd_run_test.go @@ -2394,7 +2394,7 @@ func TestTypeScriptSupport(t *testing.T) { require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "test.ts"), []byte(mainScript), 0o644)) require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "bar.ts"), []byte(depScript), 0o644)) - ts.CmdArgs = []string{"k6", "run", "--compatibility-mode", "experimental_enhanced", "--quiet", "test.ts"} + ts.CmdArgs = []string{"k6", "run", "--quiet", "test.ts"} cmd.ExecuteWithGlobalState(ts.GlobalState) diff --git a/internal/js/compiler/compiler.go b/internal/js/compiler/compiler.go index 265872df2f8..022d8c0d79e 100644 --- a/internal/js/compiler/compiler.go +++ b/internal/js/compiler/compiler.go @@ -119,7 +119,7 @@ func (ps *parsingState) parseImpl(src, filename string, commonJSWrap bool) (*ast return prg, code, nil } - if ps.compatibilityMode == lib.CompatibilityModeExperimentalEnhanced && strings.HasSuffix(filename, ".ts") { + if strings.HasSuffix(filename, ".ts") { if err := ps.compiler.usage.Uint64(usageParsedTSFilesKey, 1); err != nil { ps.compiler.logger.WithError(err).Warn("couldn't report usage for " + usageParsedTSFilesKey) } diff --git a/internal/js/compiler/enhanced_test.go b/internal/js/compiler/enhanced_test.go index 9fd53e3fa03..31b1f338404 100644 --- a/internal/js/compiler/enhanced_test.go +++ b/internal/js/compiler/enhanced_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "go.k6.io/k6/internal/lib/testutils" - "go.k6.io/k6/lib" ) func Test_esbuildTransform_js(t *testing.T) { @@ -41,7 +40,6 @@ func TestCompile_experimental_enhanced(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) src := `1+(function() { return 2; )()` - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced _, _, err := c.Parse(src, "script.ts", false, false) assert.IsType(t, &parser.Error{}, err) assert.Contains(t, err.Error(), `script.ts: Line 1:26 Unexpected ")"`) @@ -49,7 +47,6 @@ func TestCompile_experimental_enhanced(t *testing.T) { t.Run("experimental_enhanced", func(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced prg, code, err := c.Parse(`let t :string = "something"; require(t);`, "script.ts", false, false) require.NoError(t, err) assert.Equal(t, `let t = "something"; @@ -70,7 +67,6 @@ require(t); t.Run("experimental_enhanced sourcemap", func(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced c.Options.SourceMapLoader = func(_ string) ([]byte, error) { return nil, nil } _, code, err := c.Parse(`let t :string = "something"; require(t);`, "script.ts", false, false) require.NoError(t, err) From d04e5878d990065a6adb42ac71de7e5b3ee7ef5a Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 28 Jan 2025 17:05:28 +0200 Subject: [PATCH 2/2] Warn on using 'experimental_enhanced' --- internal/cmd/test_load.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/cmd/test_load.go b/internal/cmd/test_load.go index 1b85817c33c..9910e872972 100644 --- a/internal/cmd/test_load.go +++ b/internal/cmd/test_load.go @@ -67,6 +67,12 @@ func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*l return nil, err } + if runtimeOptions.CompatibilityMode.String == lib.CompatibilityModeExperimentalEnhanced.String() { + gs.Logger.Warnf("ComaptibilityMode %[1]q is deprecated. Types are stripped by default for `.ts` files. "+ + "Please move to using %[2]q instead as %[1]q will be removed in the future", + lib.CompatibilityModeExperimentalEnhanced.String(), lib.CompatibilityModeBase.String()) + } + registry := metrics.NewRegistry() state := &lib.TestPreInitState{ Logger: gs.Logger,