Skip to content

Commit

Permalink
move engine-related code to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 29, 2022
1 parent 3f97a32 commit 5382d3f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 44 deletions.
13 changes: 0 additions & 13 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,6 @@ const (
FormatESModule
)

type EngineName uint8

const (
EngineChrome EngineName = iota
EngineEdge
EngineFirefox
EngineIE
EngineIOS
EngineNode
EngineOpera
EngineSafari
)

type Engine struct {
Name EngineName
Version string
Expand Down
21 changes: 1 addition & 20 deletions pkg/api/api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,7 @@ func validateFeatures(log logger.Log, target Target, engines []Engine) (config.T
if patch, err := strconv.Atoi(match[3]); err == nil {
version = append(version, patch)
}
switch engine.Name {
case EngineChrome:
constraints[compat.Chrome] = version
case EngineEdge:
constraints[compat.Edge] = version
case EngineFirefox:
constraints[compat.Firefox] = version
case EngineIE:
constraints[compat.IE] = version
case EngineIOS:
constraints[compat.IOS] = version
case EngineNode:
constraints[compat.Node] = version
case EngineOpera:
constraints[compat.Opera] = version
case EngineSafari:
constraints[compat.Safari] = version
default:
panic("Invalid engine name")
}
constraints[convertEngineName(engine.Name)] = version
continue
}
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/api/api_js_table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package api

import "github.com/evanw/esbuild/internal/compat"

type EngineName uint8

const (
EngineChrome EngineName = iota
EngineEdge
EngineFirefox
EngineIE
EngineIOS
EngineNode
EngineOpera
EngineSafari
)

func convertEngineName(engine EngineName) compat.Engine {
switch engine {
case EngineChrome:
return compat.Chrome
case EngineEdge:
return compat.Edge
case EngineFirefox:
return compat.Firefox
case EngineIE:
return compat.IE
case EngineIOS:
return compat.IOS
case EngineNode:
return compat.Node
case EngineOpera:
return compat.Opera
case EngineSafari:
return compat.Safari
default:
panic("Invalid engine name")
}
}
11 changes: 0 additions & 11 deletions pkg/cli/cli_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,17 +886,6 @@ func parseTargets(targets []string, arg string) (target api.Target, engines []ap
"es2022": api.ES2022,
}

validEngines := map[string]api.EngineName{
"chrome": api.EngineChrome,
"edge": api.EngineEdge,
"firefox": api.EngineFirefox,
"ie": api.EngineIE,
"ios": api.EngineIOS,
"node": api.EngineNode,
"opera": api.EngineOpera,
"safari": api.EngineSafari,
}

outer:
for _, value := range targets {
if valid, ok := validTargets[strings.ToLower(value)]; ok {
Expand Down
14 changes: 14 additions & 0 deletions pkg/cli/cli_js_table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cli

import "github.com/evanw/esbuild/pkg/api"

var validEngines = map[string]api.EngineName{
"chrome": api.EngineChrome,
"edge": api.EngineEdge,
"firefox": api.EngineFirefox,
"ie": api.EngineIE,
"ios": api.EngineIOS,
"node": api.EngineNode,
"opera": api.EngineOpera,
"safari": api.EngineSafari,
}

0 comments on commit 5382d3f

Please sign in to comment.