@@ -46,14 +46,18 @@ const dynrequire = typeof __webpack_require__ === "function"
46
46
47
47
const WIN = process . platform === "win32" ;
48
48
const EOL = WIN ? "\r\n" : "\n" ;
49
- const SEP = WIN ? "\\" : "/" ;
49
+ const SEP = WIN ? "\\" : "/" ;
50
+
51
+ function toUpperSnakeCase ( str ) {
52
+ return str . replace ( / - / g, "_" ) . toUpperCase ( ) ;
53
+ }
50
54
51
55
// Sets up an extension with its definition counterpart and relevant regexes.
52
56
function setupExtension ( ext ) {
53
- if ( ! ext . startsWith ( "." ) ) ext = "." + ext ;
57
+ if ( ! ext . startsWith ( "." ) ) ext = `. ${ ext } ` ;
54
58
return {
55
59
ext,
56
- ext_d : ".d" + ext ,
60
+ ext_d : `.d ${ ext } ` ,
57
61
re : new RegExp ( "\\" + ext + "$" ) ,
58
62
re_d : new RegExp ( "\\.d\\" + ext + "$" ) ,
59
63
re_except_d : new RegExp ( "^(?!.*\\.d\\" + ext + "$).*\\" + ext + "$" ) ,
@@ -70,7 +74,9 @@ Object.defineProperty(exports, "ready", {
70
74
71
75
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
72
76
// useless code fragment on top of an actual error. suppress this:
73
- if ( process . removeAllListeners ) process . removeAllListeners ( "uncaughtException" ) ;
77
+ if ( process . removeAllListeners ) {
78
+ process . removeAllListeners ( "uncaughtException" ) ;
79
+ }
74
80
75
81
// Use distribution files if present, otherwise run the sources directly.
76
82
function loadAssemblyScriptJS ( ) {
@@ -95,7 +101,7 @@ function loadAssemblyScriptJS() {
95
101
try { // `require("dist/asc.js")` in explicit browser tests
96
102
exports = dynrequire ( "./assemblyscript" ) ;
97
103
} catch ( e ) {
98
- throw Error ( e_ts . stack + " \n---\n" + e . stack ) ;
104
+ throw Error ( ` ${ e_ts . stack } \n---\n${ e . stack } ` ) ;
99
105
}
100
106
}
101
107
}
@@ -107,14 +113,24 @@ function loadAssemblyScriptJS() {
107
113
function loadAssemblyScriptWasm ( binaryPath ) {
108
114
const loader = require ( "../lib/loader/umd/index" ) ;
109
115
const rtrace = new ( require ( "../lib/rtrace/umd/index" ) . Rtrace ) ( {
110
- onerror ( err , info ) { console . log ( err , info ) ; } ,
111
- getMemory ( ) { return exports . memory ; } ,
116
+ onerror ( err , info ) {
117
+ console . log ( err , info ) ;
118
+ } ,
119
+ getMemory ( ) {
120
+ return exports . memory ;
121
+ } ,
112
122
oncollect ( ) {
113
123
var gcProfile = rtrace . gcProfile ;
114
124
if ( gcProfile && gcProfile . length && fs . writeFileSync ) {
115
125
let timestamp = Date . now ( ) ;
116
- fs . writeFileSync ( `rtrace-gc-profile-${ timestamp } .json` , JSON . stringify ( gcProfile ) ) ;
117
- fs . writeFileSync ( `rtrace-gc-profile-${ timestamp } .csv` , `time,memory,pause\n${ gcProfile . join ( "\n" ) } ` ) ;
126
+ fs . writeFileSync (
127
+ `rtrace-gc-profile-${ timestamp } .json` ,
128
+ JSON . stringify ( gcProfile )
129
+ ) ;
130
+ fs . writeFileSync (
131
+ `rtrace-gc-profile-${ timestamp } .csv` ,
132
+ `time,memory,pause\n${ gcProfile . join ( "\n" ) } `
133
+ ) ;
118
134
}
119
135
}
120
136
} ) ;
@@ -149,8 +165,8 @@ function loadAssemblyScript() {
149
165
__newString = str => str ;
150
166
__getString = ptr => ptr ;
151
167
__pin = ptr => ptr ;
152
- __unpin = ptr => undefined ;
153
- __collect = incremental => undefined ;
168
+ __unpin = _ => undefined ;
169
+ __collect = _ => undefined ;
154
170
}
155
171
}
156
172
loadAssemblyScript ( ) ;
@@ -188,7 +204,7 @@ exports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if
188
204
/** Bundled definition files. */
189
205
exports . definitionFiles = exports . isBundle ? BUNDLE_DEFINITIONS : ( ( ) => { // set up if not a bundle
190
206
const readDefinition = name => fs . readFileSync (
191
- path . join ( __dirname , ".." , "std" , name , " index" + defaultExtension . ext_d ) ,
207
+ path . join ( __dirname , ".." , "std" , name , ` index${ defaultExtension . ext_d } ` ) ,
192
208
"utf8"
193
209
) ;
194
210
return {
@@ -199,7 +215,7 @@ exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // se
199
215
200
216
/** Convenience function that parses and compiles source strings directly. */
201
217
exports . compileString = ( sources , options ) => {
202
- if ( typeof sources === "string" ) sources = { [ " input" + defaultExtension . ext ] : sources } ;
218
+ if ( typeof sources === "string" ) sources = { [ ` input${ defaultExtension . ext } ` ] : sources } ;
203
219
const output = Object . create ( {
204
220
stdout : createMemoryStream ( ) ,
205
221
stderr : createMemoryStream ( )
@@ -212,12 +228,12 @@ exports.compileString = (sources, options) => {
212
228
var val = options [ key ] ;
213
229
var opt = exports . options [ key ] ;
214
230
if ( opt && opt . type === "b" ) {
215
- if ( val ) argv . push ( "--" + key ) ;
231
+ if ( val ) argv . push ( `-- ${ key } ` ) ;
216
232
} else {
217
233
if ( Array . isArray ( val ) ) {
218
- val . forEach ( val => { argv . push ( "--" + key , String ( val ) ) ; } ) ;
234
+ val . forEach ( val => { argv . push ( `-- ${ key } ` , String ( val ) ) ; } ) ;
219
235
}
220
- else argv . push ( "--" + key , String ( val ) ) ;
236
+ else argv . push ( `-- ${ key } ` , String ( val ) ) ;
221
237
}
222
238
} ) ;
223
239
exports . main ( argv . concat ( Object . keys ( sources ) ) , {
@@ -277,29 +293,33 @@ exports.main = function main(argv, options, callback) {
277
293
const unknownOpts = optionsResult . unknown ;
278
294
if ( unknownOpts . length ) {
279
295
unknownOpts . forEach ( arg => {
280
- stderr . write ( colorsUtil . stderr . yellow ( "WARNING " ) + "Unknown option '" + arg + "'" + EOL ) ;
296
+ stderr . write (
297
+ `${ colorsUtil . stderr . yellow ( "WARNING " ) } Unknown option '${ arg } '%{EOL}`
298
+ ) ;
281
299
} ) ;
282
300
}
283
301
284
302
// Check for trailing arguments
285
303
const trailingArgv = optionsResult . trailing ;
286
304
if ( trailingArgv . length ) {
287
- stderr . write ( colorsUtil . stderr . yellow ( "WARNING " ) + "Unsupported trailing arguments: " + trailingArgv . join ( " " ) + EOL ) ;
305
+ stderr . write (
306
+ `${ colorsUtil . stderr . yellow ( "WARNING " ) } Unsupported trailing arguments: ${ trailingArgv . join ( " " ) } ${ EOL } `
307
+ ) ;
288
308
}
289
309
290
310
// Use default callback if none is provided
291
311
if ( ! callback ) callback = function defaultCallback ( err ) {
292
312
var code = 0 ;
293
313
if ( err ) {
294
- stderr . write ( colorsUtil . stderr . red ( "FAILURE " ) + err . stack . replace ( / ^ E R R O R : / i, "" ) + EOL ) ;
314
+ stderr . write ( ` ${ colorsUtil . stderr . red ( "FAILURE " ) } ${ err . stack . replace ( / ^ E R R O R : / i, "" ) } ${ EOL } ` ) ;
295
315
code = 1 ;
296
316
}
297
317
return code ;
298
318
} ;
299
319
300
320
// Just print the version if requested
301
321
if ( opts . version ) {
302
- stdout . write ( " Version " + exports . version + EOL ) ;
322
+ stdout . write ( ` Version ${ exports . version } ${ EOL } ` ) ;
303
323
return callback ( null ) ;
304
324
}
305
325
@@ -308,7 +328,7 @@ exports.main = function main(argv, options, callback) {
308
328
if ( / ^ \. ? [ 0 - 9 a - z A - Z ] { 1 , 14 } $ / . test ( opts . extension ) ) {
309
329
extension = setupExtension ( opts . extension ) ;
310
330
} else {
311
- return callback ( Error ( " Invalid extension: " + opts . extension ) ) ;
331
+ return callback ( Error ( ` Invalid extension: ${ opts . extension } ` ) ) ;
312
332
}
313
333
}
314
334
@@ -345,7 +365,7 @@ exports.main = function main(argv, options, callback) {
345
365
346
366
// I/O must be specified if not present in the environment
347
367
if ( ! fs . readFileSync ) {
348
- if ( readFile === readFileNode ) throw Error ( "'options.readFile' must be specified" ) ;
368
+ if ( readFile === readFileNode ) throw Error ( "'options.readFile' must be specified" ) ;
349
369
if ( writeFile === writeFileNode ) throw Error ( "'options.writeFile' must be specified" ) ;
350
370
if ( listFiles === listFilesNode ) throw Error ( "'options.listFiles' must be specified" ) ;
351
371
}
@@ -447,10 +467,12 @@ exports.main = function main(argv, options, callback) {
447
467
for ( let i = 0 , k = aliases . length ; i < k ; ++ i ) {
448
468
let part = aliases [ i ] ;
449
469
let p = part . indexOf ( "=" ) ;
450
- if ( p < 0 ) return callback ( Error ( " Global alias '" + part + " ' is invalid." ) ) ;
470
+ if ( p < 0 ) return callback ( Error ( ` Global alias '${ part } ' is invalid.` ) ) ;
451
471
let alias = part . substring ( 0 , p ) . trim ( ) ;
452
472
let name = part . substring ( p + 1 ) . trim ( ) ;
453
- if ( ! alias . length ) return callback ( Error ( "Global alias '" + part + "' is invalid." ) ) ;
473
+ if ( ! alias . length ) {
474
+ return callback ( Error ( `Global alias '${ part } ' is invalid.` ) ) ;
475
+ }
454
476
{
455
477
let aliasPtr = __pin ( __newString ( alias ) ) ;
456
478
let namePtr = __newString ( name ) ;
@@ -466,8 +488,8 @@ exports.main = function main(argv, options, callback) {
466
488
if ( typeof features === "string" ) features = features . split ( "," ) ;
467
489
for ( let i = 0 , k = features . length ; i < k ; ++ i ) {
468
490
let name = features [ i ] . trim ( ) ;
469
- let flag = assemblyscript [ " FEATURE_" + name . replace ( / - / g , "_" ) . toUpperCase ( ) ] ;
470
- if ( ! flag ) return callback ( Error ( " Feature '" + name + " ' is unknown." ) ) ;
491
+ let flag = assemblyscript [ ` FEATURE_${ toUpperSnakeCase ( name ) } ` ] ;
492
+ if ( ! flag ) return callback ( Error ( ` Feature '${ name } ' is unknown.` ) ) ;
471
493
assemblyscript . disableFeature ( compilerOptions , flag ) ;
472
494
}
473
495
}
@@ -477,8 +499,8 @@ exports.main = function main(argv, options, callback) {
477
499
if ( typeof features === "string" ) features = features . split ( "," ) ;
478
500
for ( let i = 0 , k = features . length ; i < k ; ++ i ) {
479
501
let name = features [ i ] . trim ( ) ;
480
- let flag = assemblyscript [ " FEATURE_" + name . replace ( / - / g , "_" ) . toUpperCase ( ) ] ;
481
- if ( ! flag ) return callback ( Error ( " Feature '" + name + " ' is unknown." ) ) ;
502
+ let flag = assemblyscript [ ` FEATURE_${ toUpperSnakeCase ( name ) } ` ] ;
503
+ if ( ! flag ) return callback ( Error ( ` Feature '${ name } ' is unknown.` ) ) ;
482
504
assemblyscript . enableFeature ( compilerOptions , flag ) ;
483
505
}
484
506
}
@@ -513,11 +535,17 @@ exports.main = function main(argv, options, callback) {
513
535
for ( let i = 0 , k = transformArgs . length ; i < k ; ++ i ) {
514
536
let filename = transformArgs [ i ] . trim ( ) ;
515
537
if ( ! tsNodeRegistered && filename . endsWith ( ".ts" ) ) { // ts-node requires .ts specifically
516
- dynrequire ( "ts-node" ) . register ( { transpileOnly : true , skipProject : true , compilerOptions : { target : "ES2016" } } ) ;
538
+ dynrequire ( "ts-node" ) . register ( {
539
+ transpileOnly : true ,
540
+ skipProject : true ,
541
+ compilerOptions : { target : "ES2016" }
542
+ } ) ;
517
543
tsNodeRegistered = true ;
518
544
}
519
545
try {
520
- transforms . push ( dynrequire ( dynrequire . resolve ( filename , { paths : [ baseDir , process . cwd ( ) ] } ) ) ) ;
546
+ transforms . push ( dynrequire ( dynrequire . resolve ( filename , {
547
+ paths : [ baseDir , process . cwd ( ) ]
548
+ } ) ) ) ;
521
549
} catch ( e ) {
522
550
return callback ( e ) ;
523
551
}
@@ -565,7 +593,7 @@ exports.main = function main(argv, options, callback) {
565
593
566
594
// Parse library files
567
595
Object . keys ( exports . libraryFiles ) . forEach ( libPath => {
568
- if ( libPath . indexOf ( "/" ) >= 0 ) return ; // in sub-directory: imported on demand
596
+ if ( libPath . includes ( "/" ) ) return ; // in sub-directory: imported on demand
569
597
stats . parseCount ++ ;
570
598
stats . parseTime += measure ( ( ) => {
571
599
let textPtr = __pin ( __newString ( exports . libraryFiles [ libPath ] ) ) ;
@@ -592,7 +620,9 @@ exports.main = function main(argv, options, callback) {
592
620
for ( let j = 0 , l = libFiles . length ; j < l ; ++ j ) {
593
621
let libPath = libFiles [ j ] ;
594
622
let libText = readFile ( libPath , libDir ) ;
595
- if ( libText === null ) return callback ( Error ( "Library file '" + libPath + "' not found." ) ) ;
623
+ if ( libText == null ) {
624
+ return callback ( Error ( `Library file '${ libPath } ' not found.` ) ) ;
625
+ }
596
626
stats . parseCount ++ ;
597
627
exports . libraryFiles [ libPath . replace ( extension . re , "" ) ] = libText ;
598
628
stats . parseTime += measure ( ( ) => {
@@ -607,8 +637,8 @@ exports.main = function main(argv, options, callback) {
607
637
opts . path = opts . path || [ ] ;
608
638
609
639
// Maps package names to parent directory
610
- var packageMains = new Map ( ) ;
611
- var packageBases = new Map ( ) ;
640
+ const packageMains = new Map ( ) ;
641
+ const packageBases = new Map ( ) ;
612
642
613
643
// Gets the file matching the specified source path, imported at the given dependee path
614
644
function getFile ( internalPath , dependeePath ) {
@@ -631,7 +661,7 @@ exports.main = function main(argv, options, callback) {
631
661
// Search library in this order: stdlib, custom lib dirs, paths
632
662
} else {
633
663
const plainName = internalPath . substring ( libraryPrefix . length ) ;
634
- const indexName = plainName + " /index" ;
664
+ const indexName = ` ${ plainName } /index` ;
635
665
if ( Object . prototype . hasOwnProperty . call ( libraryFiles , plainName ) ) {
636
666
sourceText = libraryFiles [ plainName ] ;
637
667
sourcePath = libraryPrefix + plainName + extension . ext ;
@@ -656,15 +686,24 @@ exports.main = function main(argv, options, callback) {
656
686
const packageName = match [ 1 ] ;
657
687
const isPackageRoot = match [ 2 ] === undefined ;
658
688
const filePath = isPackageRoot ? "index" : match [ 2 ] ;
659
- const basePath = packageBases . has ( dependeePath ) ? packageBases . get ( dependeePath ) : "." ;
660
- if ( opts . traceResolution ) stderr . write ( "Looking for package '" + packageName + "' file '" + filePath + "' relative to '" + basePath + "'" + EOL ) ;
689
+ const basePath = packageBases . has ( dependeePath )
690
+ ? packageBases . get ( dependeePath )
691
+ : "." ;
692
+
693
+ if ( opts . traceResolution ) {
694
+ stderr . write ( `Looking for package '${ packageName } ' file '${ filePath } ' relative to '${ basePath } '${ EOL } ` ) ;
695
+ }
661
696
const paths = [ ] ;
662
697
const parts = path . resolve ( baseDir , basePath ) . split ( SEP ) ;
663
698
for ( let i = parts . length , k = WIN ? 1 : 0 ; i >= k ; -- i ) {
664
- if ( parts [ i - 1 ] !== "node_modules" ) paths . push ( parts . slice ( 0 , i ) . join ( SEP ) + SEP + "node_modules" ) ;
699
+ if ( parts [ i - 1 ] !== "node_modules" ) {
700
+ paths . push ( `${ parts . slice ( 0 , i ) . join ( SEP ) } ${ SEP } node_modules` ) ;
701
+ }
665
702
}
666
703
for ( const currentPath of paths . concat ( ...opts . path ) . map ( p => path . relative ( baseDir , p ) ) ) {
667
- if ( opts . traceResolution ) stderr . write ( " in " + path . join ( currentPath , packageName ) + EOL ) ;
704
+ if ( opts . traceResolution ) {
705
+ stderr . write ( ` in ${ path . join ( currentPath , packageName ) } ${ EOL } ` ) ;
706
+ }
668
707
let mainPath = "assembly" ;
669
708
if ( packageMains . has ( packageName ) ) { // use cached
670
709
mainPath = packageMains . get ( packageName ) ;
@@ -684,16 +723,20 @@ exports.main = function main(argv, options, callback) {
684
723
const mainDir = path . join ( currentPath , packageName , mainPath ) ;
685
724
const plainName = filePath ;
686
725
if ( ( sourceText = readFile ( path . join ( mainDir , plainName + extension . ext ) , baseDir ) ) != null ) {
687
- sourcePath = libraryPrefix + packageName + "/" + plainName + extension . ext ;
726
+ sourcePath = ` ${ libraryPrefix } ${ packageName } / ${ plainName } ${ extension . ext } ` ;
688
727
packageBases . set ( sourcePath . replace ( extension . re , "" ) , path . join ( currentPath , packageName ) ) ;
689
- if ( opts . traceResolution ) stderr . write ( " -> " + path . join ( mainDir , plainName + extension . ext ) + EOL ) ;
728
+ if ( opts . traceResolution ) {
729
+ stderr . write ( ` -> ${ path . join ( mainDir , plainName + extension . ext ) } ${ EOL } ` ) ;
730
+ }
690
731
break ;
691
732
} else if ( ! isPackageRoot ) {
692
- const indexName = filePath + " /index" ;
733
+ const indexName = ` ${ filePath } /index` ;
693
734
if ( ( sourceText = readFile ( path . join ( mainDir , indexName + extension . ext ) , baseDir ) ) !== null ) {
694
- sourcePath = libraryPrefix + packageName + "/" + indexName + extension . ext ;
735
+ sourcePath = ` ${ libraryPrefix } ${ packageName } / ${ indexName } ${ extension . ext } ` ;
695
736
packageBases . set ( sourcePath . replace ( extension . re , "" ) , path . join ( currentPath , packageName ) ) ;
696
- if ( opts . traceResolution ) stderr . write ( " -> " + path . join ( mainDir , indexName + extension . ext ) + EOL ) ;
737
+ if ( opts . traceResolution ) {
738
+ stderr . write ( ` -> ${ path . join ( mainDir , indexName + extension . ext ) } ${ EOL } ` ) ;
739
+ }
697
740
break ;
698
741
}
699
742
}
@@ -730,7 +773,7 @@ exports.main = function main(argv, options, callback) {
730
773
}
731
774
var numErrors = checkDiagnostics ( program , stderr , options . reportDiagnostic ) ;
732
775
if ( numErrors ) {
733
- const err = Error ( numErrors + " parse error(s)" ) ;
776
+ const err = Error ( ` ${ numErrors } parse error(s)` ) ;
734
777
err . stack = err . message ; // omit stack
735
778
return callback ( err ) ;
736
779
}
@@ -739,14 +782,14 @@ exports.main = function main(argv, options, callback) {
739
782
// Include runtime before entry files so its setup runs first
740
783
{
741
784
let runtimeName = String ( opts . runtime ) ;
742
- let runtimePath = " rt/index-" + runtimeName ;
785
+ let runtimePath = ` rt/index-${ runtimeName } ` ;
743
786
let runtimeText = exports . libraryFiles [ runtimePath ] ;
744
787
if ( runtimeText == null ) {
745
788
runtimePath = runtimeName ;
746
789
runtimeText = readFile ( runtimePath + extension . ext , baseDir ) ;
747
790
if ( runtimeText == null ) return callback ( Error ( `Runtime '${ runtimeName } ' not found.` ) ) ;
748
791
} else {
749
- runtimePath = " ~lib/" + runtimePath ;
792
+ runtimePath = ` ~lib/${ runtimePath } ` ;
750
793
}
751
794
stats . parseCount ++ ;
752
795
stats . parseTime += measure ( ( ) => {
@@ -760,17 +803,22 @@ exports.main = function main(argv, options, callback) {
760
803
// Include entry files
761
804
for ( let i = 0 , k = argv . length ; i < k ; ++ i ) {
762
805
const filename = argv [ i ] ;
763
-
764
- let sourcePath = String ( filename ) . replace ( / \\ / g, "/" ) . replace ( extension . re , "" ) . replace ( / [ \\ / ] $ / , "" ) ;
806
+ let sourcePath = String ( filename )
807
+ . replace ( / \\ / g, "/" )
808
+ . replace ( extension . re , "" )
809
+ . replace ( / [ \\ / ] $ / , "" ) ;
765
810
766
811
// Setting the path to relative path
767
- sourcePath = path . isAbsolute ( sourcePath ) ? path . relative ( baseDir , sourcePath ) . replace ( / \\ / g, "/" ) : sourcePath ;
812
+ sourcePath = path . isAbsolute ( sourcePath )
813
+ ? path . relative ( baseDir , sourcePath ) . replace ( / \\ / g, "/" )
814
+ : sourcePath ;
768
815
769
816
// Try entryPath.ext, then entryPath/index.ext
770
817
let sourceText = readFile ( sourcePath + extension . ext , baseDir ) ;
771
818
if ( sourceText == null ) {
772
- sourceText = readFile ( sourcePath + "/index" + extension . ext , baseDir ) ;
773
- if ( sourceText != null ) sourcePath += "/index" + extension . ext ;
819
+ const path = `${ sourcePath } /index${ extension . ext } ` ;
820
+ sourceText = readFile ( path , baseDir ) ;
821
+ if ( sourceText != null ) sourcePath = path ;
774
822
else sourcePath += extension . ext ;
775
823
} else {
776
824
sourcePath += extension . ext ;
@@ -853,7 +901,7 @@ exports.main = function main(argv, options, callback) {
853
901
var numErrors = checkDiagnostics ( program , stderr , options . reportDiagnostic ) ;
854
902
if ( numErrors ) {
855
903
if ( module ) module . dispose ( ) ;
856
- const err = Error ( numErrors + " compile error(s)" ) ;
904
+ const err = Error ( ` ${ numErrors } compile error(s)` ) ;
857
905
err . stack = err . message ; // omit stack
858
906
return callback ( err ) ;
859
907
}
@@ -878,20 +926,11 @@ exports.main = function main(argv, options, callback) {
878
926
}
879
927
880
928
// Set Binaryen-specific options
881
- if ( opts . trapMode === "clamp" ) {
882
- stats . optimizeCount ++ ;
883
- stats . optimizeTime += measure ( ( ) => {
884
- try {
885
- module . runPasses ( [ "trap-mode-clamp" ] ) ;
886
- } catch ( e ) {
887
- crash ( "runPasses" , e ) ;
888
- }
889
- } ) ;
890
- } else if ( opts . trapMode === "js" ) {
929
+ if ( opts . trapMode === "clamp" || opts . trapMode === "js" ) {
891
930
stats . optimizeCount ++ ;
892
931
stats . optimizeTime += measure ( ( ) => {
893
932
try {
894
- module . runPasses ( [ " trap-mode-js" ] ) ;
933
+ module . runPasses ( [ ` trap-mode-${ opts . trapMode } ` ] ) ;
895
934
} catch ( e ) {
896
935
crash ( "runPasses" , e ) ;
897
936
}
@@ -911,7 +950,7 @@ exports.main = function main(argv, options, callback) {
911
950
}
912
951
if ( opts . runPasses . length ) {
913
952
opts . runPasses . forEach ( pass => {
914
- if ( runPasses . indexOf ( pass = pass . trim ( ) ) < 0 ) {
953
+ if ( ! runPasses . includes ( pass = pass . trim ( ) ) ) {
915
954
runPasses . push ( pass ) ;
916
955
}
917
956
} ) ;
@@ -957,7 +996,7 @@ exports.main = function main(argv, options, callback) {
957
996
}
958
997
if ( next . length >= last . length ) {
959
998
if ( next . length > last . length ) {
960
- stderr . write ( " Last converge was suboptimial." + EOL ) ;
999
+ stderr . write ( ` Last converge was suboptimial.${ EOL } ` ) ;
961
1000
}
962
1001
break ;
963
1002
}
@@ -969,9 +1008,9 @@ exports.main = function main(argv, options, callback) {
969
1008
// Prepare output
970
1009
if ( ! opts . noEmit ) {
971
1010
if ( opts . outFile != null ) {
972
- if ( / \. w a s ? t $ / . test ( opts . outFile ) && opts . textFile == null ) {
1011
+ if ( opts . textFile == null && / \. w a s ? t $ / . test ( opts . outFile ) ) {
973
1012
opts . textFile = opts . outFile ;
974
- } else if ( / \. j s $ / . test ( opts . outFile ) && opts . jsFile == null ) {
1013
+ } else if ( opts . jsFile == null && / \. j s $ / . test ( opts . outFile ) ) {
975
1014
opts . jsFile = opts . outFile ;
976
1015
} else if ( opts . binaryFile == null ) {
977
1016
opts . binaryFile = opts . outFile ;
@@ -991,7 +1030,7 @@ exports.main = function main(argv, options, callback) {
991
1030
let sourceMapURL = opts . sourceMap != null
992
1031
? opts . sourceMap . length
993
1032
? opts . sourceMap
994
- : "./" + basename + " .map"
1033
+ : `./ ${ basename } .map`
995
1034
: null ;
996
1035
997
1036
let wasm ;
@@ -1015,11 +1054,11 @@ exports.main = function main(argv, options, callback) {
1015
1054
if ( wasm . sourceMap != "" ) {
1016
1055
if ( opts . binaryFile . length ) {
1017
1056
let map = JSON . parse ( wasm . sourceMap ) ;
1018
- map . sourceRoot = "./" + basename ;
1057
+ map . sourceRoot = `./ ${ basename } ` ;
1019
1058
let contents = [ ] ;
1020
1059
map . sources . forEach ( ( name , index ) => {
1021
1060
let text = assemblyscript . getSource ( program , __newString ( name . replace ( extension . re , "" ) ) ) ;
1022
- if ( text == null ) return callback ( Error ( " Source of file '" + name + " ' not found." ) ) ;
1061
+ if ( text == null ) return callback ( Error ( ` Source of file '${ name } ' not found.` ) ) ;
1023
1062
contents [ index ] = text ;
1024
1063
} ) ;
1025
1064
map . sourcesContent = contents ;
@@ -1028,7 +1067,7 @@ exports.main = function main(argv, options, callback) {
1028
1067
path . basename ( sourceMapURL )
1029
1068
) . replace ( / ^ \. \/ / , "" ) , JSON . stringify ( map ) , baseDir ) ;
1030
1069
} else {
1031
- stderr . write ( " Skipped source map (stdout already occupied)" + EOL ) ;
1070
+ stderr . write ( ` Skipped source map (stdout already occupied)${ EOL } ` ) ;
1032
1071
}
1033
1072
}
1034
1073
}
@@ -1039,15 +1078,13 @@ exports.main = function main(argv, options, callback) {
1039
1078
if ( opts . textFile != null && opts . textFile . length ) {
1040
1079
// use superset text format when extension is `.wast`.
1041
1080
// Otherwise use official stack IR format (wat).
1042
- let wastFormat = opts . textFile . endsWith ( ' .wast' ) ;
1081
+ let wastFormat = opts . textFile . endsWith ( " .wast" ) ;
1043
1082
stats . emitCount ++ ;
1044
1083
stats . emitTime += measure ( ( ) => {
1045
1084
try {
1046
- if ( wastFormat ) {
1047
- out = module . emitText ( ) ;
1048
- } else {
1049
- out = module . emitStackIR ( true ) ;
1050
- }
1085
+ out = wastFormat
1086
+ ? module . emitText ( )
1087
+ : module . emitStackIR ( true ) ;
1051
1088
} catch ( e ) {
1052
1089
crash ( "emitText" , e ) ;
1053
1090
}
@@ -1225,33 +1262,33 @@ function getAsconfig(file, baseDir, readFile) {
1225
1262
try {
1226
1263
config = JSON . parse ( contents ) ;
1227
1264
} catch ( ex ) {
1228
- throw new Error ( " Asconfig is not valid json: " + location ) ;
1265
+ throw new Error ( ` Asconfig is not valid json: ${ location } ` ) ;
1229
1266
}
1230
1267
1231
1268
// validate asconfig shape
1232
1269
if ( config . options && ! isObject ( config . options ) ) {
1233
- throw new Error ( " Asconfig.options is not an object: " + location ) ;
1270
+ throw new Error ( ` Asconfig.options is not an object: ${ location } ` ) ;
1234
1271
}
1235
1272
1236
1273
if ( config . include && ! Array . isArray ( config . include ) ) {
1237
- throw new Error ( " Asconfig.include is not an array: " + location ) ;
1274
+ throw new Error ( ` Asconfig.include is not an array: ${ location } ` ) ;
1238
1275
}
1239
1276
1240
1277
if ( config . targets ) {
1241
1278
if ( ! isObject ( config . targets ) ) {
1242
- throw new Error ( " Asconfig.targets is not an object: " + location ) ;
1279
+ throw new Error ( ` Asconfig.targets is not an object: ${ location } ` ) ;
1243
1280
}
1244
1281
const targets = Object . keys ( config . targets ) ;
1245
1282
for ( let i = 0 ; i < targets . length ; i ++ ) {
1246
1283
const target = targets [ i ] ;
1247
1284
if ( ! isObject ( config . targets [ target ] ) ) {
1248
- throw new Error ( " Asconfig.targets." + target + " is not an object: " + location ) ;
1285
+ throw new Error ( ` Asconfig.targets.${ target } is not an object: ${ location } ` ) ;
1249
1286
}
1250
1287
}
1251
1288
}
1252
1289
1253
1290
if ( config . extends && typeof config . extends !== "string" ) {
1254
- throw new Error ( " Asconfig.extends is not a string: " + location ) ;
1291
+ throw new Error ( ` Asconfig.extends is not a string: ${ location } ` ) ;
1255
1292
}
1256
1293
1257
1294
return config ;
@@ -1344,20 +1381,20 @@ function measure(fn) {
1344
1381
exports . measure = measure ;
1345
1382
1346
1383
function pad ( str , len ) {
1347
- while ( str . length < len ) str = " " + str ;
1384
+ while ( str . length < len ) str = ` ${ str } ` ;
1348
1385
return str ;
1349
1386
}
1350
1387
1351
1388
/** Formats a high resolution time to a human readable string. */
1352
1389
function formatTime ( time ) {
1353
- return time ? ( time / 1e6 ) . toFixed ( 3 ) + " ms" : "n/a" ;
1390
+ return time ? ` ${ ( time / 1e6 ) . toFixed ( 3 ) } ms` : "n/a" ;
1354
1391
}
1355
1392
1356
1393
exports . formatTime = formatTime ;
1357
1394
1358
1395
/** Formats and prints out the contents of a set of stats. */
1359
1396
function printStats ( stats , output ) {
1360
- const format = ( time , count ) => pad ( formatTime ( time ) , 12 ) + " n=" + count ;
1397
+ const format = ( time , count ) => ` ${ pad ( formatTime ( time ) , 12 ) } n= ${ count } ` ;
1361
1398
( output || process . stdout ) . write ( [
1362
1399
"I/O Read : " + format ( stats . readTime , stats . readCount ) ,
1363
1400
"I/O Write : " + format ( stats . writeTime , stats . writeCount ) ,
0 commit comments