@@ -83,9 +83,12 @@ const features = {
83
83
84
84
const versions = { }
85
85
const engines = [
86
+ // The JavaScript standard
87
+ 'es' ,
88
+
89
+ // Common JavaScript runtimes
86
90
'chrome' ,
87
91
'edge' ,
88
- 'es' ,
89
92
'firefox' ,
90
93
'ie' ,
91
94
'ios' ,
@@ -362,6 +365,15 @@ function jsTableMap(obj) {
362
365
} ) . join ( '\n' ) } \n\t}`
363
366
}
364
367
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
+
365
377
fs . writeFileSync ( __dirname + '/../internal/compat/js_table.go' ,
366
378
`// This file was automatically generated by "${ path . basename ( __filename ) } "
367
379
@@ -370,12 +382,12 @@ package compat
370
382
type Engine uint8
371
383
372
384
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' ) }
374
386
)
375
387
376
388
func (e Engine) String() string {
377
389
\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' ) }
379
391
\t}
380
392
\treturn ""
381
393
}
@@ -418,3 +430,37 @@ func UnsupportedJSFeatures(constraints map[Engine][]int) (unsupported JSFeature)
418
430
\treturn
419
431
}
420
432
` )
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