Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Oct 25, 2021
1 parent 218d8f4 commit efade35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewBundle(
// Compile sources, both ES5 and ES6 are supported.
code := string(src.Data)
c := compiler.New(logger)
c.COpts = compiler.CompilerOptions{
c.COpts = compiler.Options{
CompatibilityMode: compatMode,
Strict: true,
SourceMapEnabled: true,
Expand Down Expand Up @@ -137,7 +137,7 @@ func NewBundleFromArchive(
}

c := compiler.New(logger)
c.COpts = compiler.CompilerOptions{
c.COpts = compiler.Options{
Strict: true,
CompatibilityMode: compatMode,
SourceMapEnabled: true,
Expand Down
11 changes: 6 additions & 5 deletions js/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const sourceMapURLFromBabel = "k6://internal-should-not-leak/file.map"
type Compiler struct {
logger logrus.FieldLogger
babel *babel
COpts CompilerOptions // TODO change this, this is just way faster
COpts Options // TODO change this, this is just way faster
}

// New returns a new Compiler
Expand Down Expand Up @@ -128,8 +128,8 @@ func (c *Compiler) Transform(src, filename string, inputSrcMap []byte) (code str
return
}

// CompilerOptions are options to the compiler ;)
type CompilerOptions struct { // TODO maybe have the fields an exported and use the functional options pattern
// Options are options to the compiler
type Options struct { // TODO maybe have the fields an exported and use the functional options pattern
CompatibilityMode lib.CompatibilityMode
SourceMapEnabled bool
// TODO maybe move only this in the compiler itself and leave ht rest as parameters to the Compile
Expand All @@ -138,12 +138,13 @@ type CompilerOptions struct { // TODO maybe have the fields an exported and use
}

// Compile the program in the given CompatibilityMode, wrapping it between pre and post code
func (c *Compiler) Compile(src, filename string, main bool, cOpts CompilerOptions) (*goja.Program, string, error) {
func (c *Compiler) Compile(src, filename string, main bool, cOpts Options) (*goja.Program, string, error) {
return c.compileImpl(src, filename, main, cOpts, nil)
}

//nolint:cyclop
func (c *Compiler) compileImpl(
src, filename string, main bool, cOpts CompilerOptions, srcmap []byte,
src, filename string, main bool, cOpts Options, srcmap []byte,
) (*goja.Program, string, error) {
code := src
if !main {
Expand Down
1 change: 1 addition & 0 deletions js/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.k6.io/k6/lib/testutils"
)

//nolint:paralleltest
func TestTransform(t *testing.T) {
c := New(testutils.NewLogger(t))
t.Run("blank", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions js/tc39/tc39_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (ctx *tc39TestCtx) compile(base, name string) (*goja.Program, error) {
str := string(b)
comp := ctx.compilerPool.Get()
defer ctx.compilerPool.Put(comp)
prg, _, err = comp.Compile(str, name, true, compiler.CompilerOptions{Strict: false, CompatibilityMode: lib.CompatibilityModeExtended})
prg, _, err = comp.Compile(str, name, true, compiler.Options{Strict: false, CompatibilityMode: lib.CompatibilityModeExtended})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -481,11 +481,11 @@ func (ctx *tc39TestCtx) runTC39Script(name, src string, includes []string, vm *g
var p *goja.Program
comp := ctx.compilerPool.Get()
defer ctx.compilerPool.Put(comp)
p, _, origErr = comp.Compile(src, name, true, compiler.CompilerOptions{Strict: false, CompatibilityMode: lib.CompatibilityModeBase})
p, _, origErr = comp.Compile(src, name, true, compiler.Options{Strict: false, CompatibilityMode: lib.CompatibilityModeBase})
if origErr != nil {
src, _, err = comp.Transform(src, name, nil)
if err == nil {
p, _, err = comp.Compile(src, name, true, compiler.CompilerOptions{Strict: false, CompatibilityMode: lib.CompatibilityModeBase})
p, _, err = comp.Compile(src, name, true, compiler.Options{Strict: false, CompatibilityMode: lib.CompatibilityModeBase})
}
} else {
err = origErr
Expand Down

0 comments on commit efade35

Please sign in to comment.