Skip to content

Commit 698898f

Browse files
committed
automatically generate the separate files
1 parent 5382d3f commit 698898f

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

pkg/api/api_js_table.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file was automatically generated by "compat-table.js"
2+
13
package api
24

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

pkg/cli/cli_js_table.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file was automatically generated by "compat-table.js"
2+
13
package cli
24

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

scripts/compat-table.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ const features = {
8383

8484
const versions = {}
8585
const engines = [
86+
// The JavaScript standard
87+
'es',
88+
89+
// Common JavaScript runtimes
8690
'chrome',
8791
'edge',
88-
'es',
8992
'firefox',
9093
'ie',
9194
'ios',
@@ -362,6 +365,15 @@ function jsTableMap(obj) {
362365
}).join('\n')}\n\t}`
363366
}
364367

368+
function jsTableValidEnginesMap(engines) {
369+
const keys = engines.slice().sort()
370+
const maxLength = keys.reduce((a, b) => Math.max(a, b.length + 4), 0)
371+
if (keys.length === 0) return '{}'
372+
return keys.map(x => {
373+
return `\t${`"${x}": `.padEnd(maxLength)}api.Engine${upper(x)},`
374+
}).join('\n')
375+
}
376+
365377
fs.writeFileSync(__dirname + '/../internal/compat/js_table.go',
366378
`// This file was automatically generated by "${path.basename(__filename)}"
367379
@@ -370,12 +382,12 @@ package compat
370382
type Engine uint8
371383
372384
const (
373-
${engines.map((x, i) => `\t${upper(x)}${i ? '' : ' Engine = iota'}`).join('\n')}
385+
${engines.slice().sort().map((x, i) => `\t${upper(x)}${i ? '' : ' Engine = iota'}`).join('\n')}
374386
)
375387
376388
func (e Engine) String() string {
377389
\tswitch e {
378-
${engines.map((x, i) => `\tcase ${upper(x)}:\n\t\treturn "${x}"`).join('\n')}
390+
${engines.slice().sort().map(x => `\tcase ${upper(x)}:\n\t\treturn "${x}"`).join('\n')}
379391
\t}
380392
\treturn ""
381393
}
@@ -418,3 +430,37 @@ func UnsupportedJSFeatures(constraints map[Engine][]int) (unsupported JSFeature)
418430
\treturn
419431
}
420432
`)
433+
434+
fs.writeFileSync(__dirname + '/../pkg/api/api_js_table.go',
435+
`// This file was automatically generated by "${path.basename(__filename)}"
436+
437+
package api
438+
439+
import "github.com/evanw/esbuild/internal/compat"
440+
441+
type EngineName uint8
442+
443+
const (
444+
${engines.filter(x => x !== 'es').map((x, i) => `\tEngine${upper(x)}${i ? '' : ' EngineName = iota'}`).join('\n')}
445+
)
446+
447+
func convertEngineName(engine EngineName) compat.Engine {
448+
\tswitch engine {
449+
${engines.filter(x => x !== 'es').map(x => `\tcase Engine${upper(x)}:\n\t\treturn compat.${upper(x)}`).join('\n')}
450+
\tdefault:
451+
\t\tpanic("Invalid engine name")
452+
\t}
453+
}
454+
`)
455+
456+
fs.writeFileSync(__dirname + '/../pkg/cli/cli_js_table.go',
457+
`// This file was automatically generated by "${path.basename(__filename)}"
458+
459+
package cli
460+
461+
import "github.com/evanw/esbuild/pkg/api"
462+
463+
var validEngines = map[string]api.EngineName{
464+
${jsTableValidEnginesMap(engines.filter(x => x !== 'es'))}
465+
}
466+
`)

0 commit comments

Comments
 (0)