Skip to content
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

Enable type stripping by default #4292

Merged
merged 2 commits into from
Jan 29, 2025
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
3 changes: 1 addition & 2 deletions internal/cmd/runtime_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/test_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/js/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/js/compiler/enhanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -41,15 +40,13 @@ 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 ")"`)
})
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";
Expand All @@ -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)
Expand Down
Loading