diff --git a/cmd/runtime_options.go b/cmd/runtime_options.go index 60c2d038935..5ad14981d8c 100644 --- a/cmd/runtime_options.go +++ b/cmd/runtime_options.go @@ -22,11 +22,11 @@ func runtimeOptionFlagSet(includeSysEnv bool) *pflag.FlagSet { flags := pflag.NewFlagSet("", 0) 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" + flags.String("compatibility-mode", "enhanced", + `JavaScript compiler compatibility mode, "extended" or "base" or "enhanced" 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 +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/cmd/runtime_options_test.go b/cmd/runtime_options_test.go index de484839de7..578be85609e 100644 --- a/cmd/runtime_options_test.go +++ b/cmd/runtime_options_test.go @@ -109,10 +109,10 @@ func testRuntimeOptionsCase(t *testing.T, tc runtimeOptionsTestCase) { func TestRuntimeOptions(t *testing.T) { t.Parallel() var ( - defaultCompatMode = null.NewString("extended", false) + defaultCompatMode = null.NewString("enhanced", false) baseCompatMode = null.NewString("base", true) extendedCompatMode = null.NewString("extended", true) - enhancedCompatMode = null.NewString("experimental_enhanced", true) + enhancedCompatMode = null.NewString("enhanced", true) defaultTracesOutput = null.NewString("none", false) ) @@ -147,9 +147,9 @@ func TestRuntimeOptions(t *testing.T) { TracesOutput: defaultTracesOutput, }, }, - "disabled sys env by default with experimental_enhanced compat mode": { + "disabled sys env by default with enhanced compat mode": { useSysEnv: false, - systemEnv: map[string]string{"test1": "val1", "K6_COMPATIBILITY_MODE": "experimental_enhanced"}, + systemEnv: map[string]string{"test1": "val1", "K6_COMPATIBILITY_MODE": "enhanced"}, expRTOpts: lib.RuntimeOptions{ IncludeSystemEnvVars: null.NewBool(false, false), CompatibilityMode: enhancedCompatMode, diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 0ad0304372a..df8729c92f8 100644 --- a/cmd/tests/cmd_run_test.go +++ b/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", "--compatibility-mode", "enhanced", "--quiet", "test.ts"} cmd.ExecuteWithGlobalState(ts.GlobalState) diff --git a/js/bundle_test.go b/js/bundle_test.go index 0264ca31002..87ee0dfd472 100644 --- a/js/bundle_test.go +++ b/js/bundle_test.go @@ -189,7 +189,7 @@ func TestNewBundle(t *testing.T) { }{ { "InvalidCompat", "es1", `export default function() {};`, - `invalid compatibility mode "es1". Use: "extended", "base", "experimental_enhanced"`, + `invalid compatibility mode "es1". Use: "extended", "base", "enhanced"`, }, } diff --git a/js/compiler/compiler.go b/js/compiler/compiler.go index 35140c36fae..312ecd53407 100644 --- a/js/compiler/compiler.go +++ b/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 ps.compatibilityMode == lib.CompatibilityModeEnhanced && 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/js/compiler/enhanced_test.go b/js/compiler/enhanced_test.go index a249fb8cdde..ad58514b7f6 100644 --- a/js/compiler/enhanced_test.go +++ b/js/compiler/enhanced_test.go @@ -34,22 +34,22 @@ func Test_esbuildTransform_ts(t *testing.T) { require.NotEmpty(t, code) } -func TestCompile_experimental_enhanced(t *testing.T) { +func TestCompile_enhanced(t *testing.T) { t.Parallel() - t.Run("experimental_enhanced Invalid", func(t *testing.T) { + t.Run("enhanced Invalid", func(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) src := `1+(function() { return 2; )()` - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced + c.Options.CompatibilityMode = lib.CompatibilityModeEnhanced _, _, 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 ")"`) }) - t.Run("experimental_enhanced", func(t *testing.T) { + t.Run("enhanced", func(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced + c.Options.CompatibilityMode = lib.CompatibilityModeEnhanced 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"; @@ -67,10 +67,10 @@ require(t); require.NoError(t, err) require.True(t, requireCalled) }) - t.Run("experimental_enhanced sourcemap", func(t *testing.T) { + t.Run("enhanced sourcemap", func(t *testing.T) { t.Parallel() c := New(testutils.NewLogger(t)) - c.Options.CompatibilityMode = lib.CompatibilityModeExperimentalEnhanced + c.Options.CompatibilityMode = lib.CompatibilityModeEnhanced 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) diff --git a/js/tc39/breaking_test_errors-experimental_enhanced.json b/js/tc39/breaking_test_errors-enhanced.json similarity index 100% rename from js/tc39/breaking_test_errors-experimental_enhanced.json rename to js/tc39/breaking_test_errors-enhanced.json diff --git a/js/tc39/tc39_test.go b/js/tc39/tc39_test.go index 9098de9d3cc..c494e230aaf 100644 --- a/js/tc39/tc39_test.go +++ b/js/tc39/tc39_test.go @@ -644,7 +644,7 @@ func (ctx *tc39TestCtx) runFile(base, name string, vm *sobek.Runtime) error { func (ctx *tc39TestCtx) compileOnly(src, name string, compatibilityMode lib.CompatibilityMode) (*sobek.Program, error) { comp := ctx.compiler() - if compatibilityMode == lib.CompatibilityModeExperimentalEnhanced { + if compatibilityMode == lib.CompatibilityModeEnhanced { code, _, err := compiler.StripTypes(src, name) if err != nil { return nil, err @@ -722,7 +722,7 @@ func (ctx *tc39TestCtx) runTC39Module(name, src string, includes []string, vm *s func(specifier *url.URL, _ string) ([]byte, error) { b, err := fs.ReadFile(os.DirFS("."), specifier.Path[1:]) - if ctx.compatibilityMode == lib.CompatibilityModeExperimentalEnhanced { + if ctx.compatibilityMode == lib.CompatibilityModeEnhanced { code, _, err := compiler.StripTypes(string(b), name) if err != nil { return nil, err @@ -797,7 +797,7 @@ func TestTC39(t *testing.T) { } runTestTC39(t, lib.CompatibilityModeExtended) - runTestTC39(t, lib.CompatibilityModeExperimentalEnhanced) + runTestTC39(t, lib.CompatibilityModeEnhanced) } func runTestTC39(t *testing.T, compatibilityMode lib.CompatibilityMode) { diff --git a/lib/compatibility_mode_gen.go b/lib/compatibility_mode_gen.go index d9f527c40fe..7abcf389054 100644 --- a/lib/compatibility_mode_gen.go +++ b/lib/compatibility_mode_gen.go @@ -6,9 +6,9 @@ import ( "fmt" ) -const _CompatibilityModeName = "extendedbaseexperimental_enhanced" +const _CompatibilityModeName = "extendedbaseenhanced" -var _CompatibilityModeIndex = [...]uint8{0, 8, 12, 33} +var _CompatibilityModeIndex = [...]uint8{0, 8, 12, 20} func (i CompatibilityMode) String() string { i -= 1 @@ -23,7 +23,7 @@ var _CompatibilityModeValues = []CompatibilityMode{1, 2, 3} var _CompatibilityModeNameToValueMap = map[string]CompatibilityMode{ _CompatibilityModeName[0:8]: 1, _CompatibilityModeName[8:12]: 2, - _CompatibilityModeName[12:33]: 3, + _CompatibilityModeName[12:20]: 3, } // CompatibilityModeString retrieves an enum value from the enum constants string name. diff --git a/lib/runtime_options.go b/lib/runtime_options.go index b82acc38db5..3641dfca3da 100644 --- a/lib/runtime_options.go +++ b/lib/runtime_options.go @@ -9,6 +9,12 @@ import ( // CompatibilityMode specifies the JS compatibility mode // +// There are several CLIs called enumer, and several versions of them. +// The generated code can be produced exactly as follows: +// +// go run github.com/alvaroloes/enumer@v1.0.0 -type=CompatibilityMode -transform=snake \ +// -trimprefix CompatibilityMode -output compatibility_mode_gen.go +// //go:generate enumer -type=CompatibilityMode -transform=snake -trimprefix CompatibilityMode -output compatibility_mode_gen.go type CompatibilityMode uint8 @@ -17,8 +23,8 @@ const ( CompatibilityModeExtended CompatibilityMode = iota + 1 // CompatibilityModeBase is standard Sobek, which means pure vanilla JS following ECMAScript standards. CompatibilityModeBase - // CompatibilityModeExperimentalEnhanced achieves TypeScript and ES6+ compatibility with esbuild - CompatibilityModeExperimentalEnhanced + // CompatibilityModeEnhanced achieves TypeScript and ES6+ compatibility with esbuild + CompatibilityModeEnhanced ) // RuntimeOptions are settings passed onto the Sobek JS runtime