Skip to content

Commit dd5111b

Browse files
authoredAug 2, 2021
chore: minor reafactoring for asc.js (#2010)
1 parent 935b865 commit dd5111b

File tree

1 file changed

+124
-87
lines changed

1 file changed

+124
-87
lines changed
 

‎cli/asc.js

+124-87
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ const dynrequire = typeof __webpack_require__ === "function"
4646

4747
const WIN = process.platform === "win32";
4848
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+
}
5054

5155
// Sets up an extension with its definition counterpart and relevant regexes.
5256
function setupExtension(ext) {
53-
if (!ext.startsWith(".")) ext = "." + ext;
57+
if (!ext.startsWith(".")) ext = `.${ext}`;
5458
return {
5559
ext,
56-
ext_d: ".d" + ext,
60+
ext_d: `.d${ext}`,
5761
re: new RegExp("\\" + ext + "$"),
5862
re_d: new RegExp("\\.d\\" + ext + "$"),
5963
re_except_d: new RegExp("^(?!.*\\.d\\" + ext + "$).*\\" + ext + "$"),
@@ -70,7 +74,9 @@ Object.defineProperty(exports, "ready", {
7074

7175
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
7276
// 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+
}
7480

7581
// Use distribution files if present, otherwise run the sources directly.
7682
function loadAssemblyScriptJS() {
@@ -95,7 +101,7 @@ function loadAssemblyScriptJS() {
95101
try { // `require("dist/asc.js")` in explicit browser tests
96102
exports = dynrequire("./assemblyscript");
97103
} catch (e) {
98-
throw Error(e_ts.stack + "\n---\n" + e.stack);
104+
throw Error(`${e_ts.stack}\n---\n${e.stack}`);
99105
}
100106
}
101107
}
@@ -107,14 +113,24 @@ function loadAssemblyScriptJS() {
107113
function loadAssemblyScriptWasm(binaryPath) {
108114
const loader = require("../lib/loader/umd/index");
109115
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+
},
112122
oncollect() {
113123
var gcProfile = rtrace.gcProfile;
114124
if (gcProfile && gcProfile.length && fs.writeFileSync) {
115125
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+
);
118134
}
119135
}
120136
});
@@ -149,8 +165,8 @@ function loadAssemblyScript() {
149165
__newString = str => str;
150166
__getString = ptr => ptr;
151167
__pin = ptr => ptr;
152-
__unpin = ptr => undefined;
153-
__collect = incremental => undefined;
168+
__unpin = _ => undefined;
169+
__collect = _ => undefined;
154170
}
155171
}
156172
loadAssemblyScript();
@@ -188,7 +204,7 @@ exports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if
188204
/** Bundled definition files. */
189205
exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // set up if not a bundle
190206
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}`),
192208
"utf8"
193209
);
194210
return {
@@ -199,7 +215,7 @@ exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // se
199215

200216
/** Convenience function that parses and compiles source strings directly. */
201217
exports.compileString = (sources, options) => {
202-
if (typeof sources === "string") sources = { ["input" + defaultExtension.ext]: sources };
218+
if (typeof sources === "string") sources = { [`input${defaultExtension.ext}`]: sources };
203219
const output = Object.create({
204220
stdout: createMemoryStream(),
205221
stderr: createMemoryStream()
@@ -212,12 +228,12 @@ exports.compileString = (sources, options) => {
212228
var val = options[key];
213229
var opt = exports.options[key];
214230
if (opt && opt.type === "b") {
215-
if (val) argv.push("--" + key);
231+
if (val) argv.push(`--${key}`);
216232
} else {
217233
if (Array.isArray(val)) {
218-
val.forEach(val => { argv.push("--" + key, String(val)); });
234+
val.forEach(val => { argv.push(`--${key}`, String(val)); });
219235
}
220-
else argv.push("--" + key, String(val));
236+
else argv.push(`--${key}`, String(val));
221237
}
222238
});
223239
exports.main(argv.concat(Object.keys(sources)), {
@@ -277,29 +293,33 @@ exports.main = function main(argv, options, callback) {
277293
const unknownOpts = optionsResult.unknown;
278294
if (unknownOpts.length) {
279295
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+
);
281299
});
282300
}
283301

284302
// Check for trailing arguments
285303
const trailingArgv = optionsResult.trailing;
286304
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+
);
288308
}
289309

290310
// Use default callback if none is provided
291311
if (!callback) callback = function defaultCallback(err) {
292312
var code = 0;
293313
if (err) {
294-
stderr.write(colorsUtil.stderr.red("FAILURE ") + err.stack.replace(/^ERROR: /i, "") + EOL);
314+
stderr.write(`${colorsUtil.stderr.red("FAILURE ")}${err.stack.replace(/^ERROR: /i, "")}${EOL}`);
295315
code = 1;
296316
}
297317
return code;
298318
};
299319

300320
// Just print the version if requested
301321
if (opts.version) {
302-
stdout.write("Version " + exports.version + EOL);
322+
stdout.write(`Version ${exports.version}${EOL}`);
303323
return callback(null);
304324
}
305325

@@ -308,7 +328,7 @@ exports.main = function main(argv, options, callback) {
308328
if (/^\.?[0-9a-zA-Z]{1,14}$/.test(opts.extension)) {
309329
extension = setupExtension(opts.extension);
310330
} else {
311-
return callback(Error("Invalid extension: " + opts.extension));
331+
return callback(Error(`Invalid extension: ${opts.extension}`));
312332
}
313333
}
314334

@@ -345,7 +365,7 @@ exports.main = function main(argv, options, callback) {
345365

346366
// I/O must be specified if not present in the environment
347367
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");
349369
if (writeFile === writeFileNode) throw Error("'options.writeFile' must be specified");
350370
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
351371
}
@@ -447,10 +467,12 @@ exports.main = function main(argv, options, callback) {
447467
for (let i = 0, k = aliases.length; i < k; ++i) {
448468
let part = aliases[i];
449469
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.`));
451471
let alias = part.substring(0, p).trim();
452472
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+
}
454476
{
455477
let aliasPtr = __pin(__newString(alias));
456478
let namePtr = __newString(name);
@@ -466,8 +488,8 @@ exports.main = function main(argv, options, callback) {
466488
if (typeof features === "string") features = features.split(",");
467489
for (let i = 0, k = features.length; i < k; ++i) {
468490
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.`));
471493
assemblyscript.disableFeature(compilerOptions, flag);
472494
}
473495
}
@@ -477,8 +499,8 @@ exports.main = function main(argv, options, callback) {
477499
if (typeof features === "string") features = features.split(",");
478500
for (let i = 0, k = features.length; i < k; ++i) {
479501
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.`));
482504
assemblyscript.enableFeature(compilerOptions, flag);
483505
}
484506
}
@@ -513,11 +535,17 @@ exports.main = function main(argv, options, callback) {
513535
for (let i = 0, k = transformArgs.length; i < k; ++i) {
514536
let filename = transformArgs[i].trim();
515537
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+
});
517543
tsNodeRegistered = true;
518544
}
519545
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+
})));
521549
} catch (e) {
522550
return callback(e);
523551
}
@@ -565,7 +593,7 @@ exports.main = function main(argv, options, callback) {
565593

566594
// Parse library files
567595
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
569597
stats.parseCount++;
570598
stats.parseTime += measure(() => {
571599
let textPtr = __pin(__newString(exports.libraryFiles[libPath]));
@@ -592,7 +620,9 @@ exports.main = function main(argv, options, callback) {
592620
for (let j = 0, l = libFiles.length; j < l; ++j) {
593621
let libPath = libFiles[j];
594622
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+
}
596626
stats.parseCount++;
597627
exports.libraryFiles[libPath.replace(extension.re, "")] = libText;
598628
stats.parseTime += measure(() => {
@@ -607,8 +637,8 @@ exports.main = function main(argv, options, callback) {
607637
opts.path = opts.path || [];
608638

609639
// 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();
612642

613643
// Gets the file matching the specified source path, imported at the given dependee path
614644
function getFile(internalPath, dependeePath) {
@@ -631,7 +661,7 @@ exports.main = function main(argv, options, callback) {
631661
// Search library in this order: stdlib, custom lib dirs, paths
632662
} else {
633663
const plainName = internalPath.substring(libraryPrefix.length);
634-
const indexName = plainName + "/index";
664+
const indexName = `${plainName}/index`;
635665
if (Object.prototype.hasOwnProperty.call(libraryFiles, plainName)) {
636666
sourceText = libraryFiles[plainName];
637667
sourcePath = libraryPrefix + plainName + extension.ext;
@@ -656,15 +686,24 @@ exports.main = function main(argv, options, callback) {
656686
const packageName = match[1];
657687
const isPackageRoot = match[2] === undefined;
658688
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+
}
661696
const paths = [];
662697
const parts = path.resolve(baseDir, basePath).split(SEP);
663698
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+
}
665702
}
666703
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+
}
668707
let mainPath = "assembly";
669708
if (packageMains.has(packageName)) { // use cached
670709
mainPath = packageMains.get(packageName);
@@ -684,16 +723,20 @@ exports.main = function main(argv, options, callback) {
684723
const mainDir = path.join(currentPath, packageName, mainPath);
685724
const plainName = filePath;
686725
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}`;
688727
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+
}
690731
break;
691732
} else if (!isPackageRoot) {
692-
const indexName = filePath + "/index";
733+
const indexName = `${filePath}/index`;
693734
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}`;
695736
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+
}
697740
break;
698741
}
699742
}
@@ -730,7 +773,7 @@ exports.main = function main(argv, options, callback) {
730773
}
731774
var numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic);
732775
if (numErrors) {
733-
const err = Error(numErrors + " parse error(s)");
776+
const err = Error(`${numErrors} parse error(s)`);
734777
err.stack = err.message; // omit stack
735778
return callback(err);
736779
}
@@ -739,14 +782,14 @@ exports.main = function main(argv, options, callback) {
739782
// Include runtime before entry files so its setup runs first
740783
{
741784
let runtimeName = String(opts.runtime);
742-
let runtimePath = "rt/index-" + runtimeName;
785+
let runtimePath = `rt/index-${runtimeName}`;
743786
let runtimeText = exports.libraryFiles[runtimePath];
744787
if (runtimeText == null) {
745788
runtimePath = runtimeName;
746789
runtimeText = readFile(runtimePath + extension.ext, baseDir);
747790
if (runtimeText == null) return callback(Error(`Runtime '${runtimeName}' not found.`));
748791
} else {
749-
runtimePath = "~lib/" + runtimePath;
792+
runtimePath = `~lib/${runtimePath}`;
750793
}
751794
stats.parseCount++;
752795
stats.parseTime += measure(() => {
@@ -760,17 +803,22 @@ exports.main = function main(argv, options, callback) {
760803
// Include entry files
761804
for (let i = 0, k = argv.length; i < k; ++i) {
762805
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(/[\\/]$/, "");
765810

766811
// 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;
768815

769816
// Try entryPath.ext, then entryPath/index.ext
770817
let sourceText = readFile(sourcePath + extension.ext, baseDir);
771818
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;
774822
else sourcePath += extension.ext;
775823
} else {
776824
sourcePath += extension.ext;
@@ -853,7 +901,7 @@ exports.main = function main(argv, options, callback) {
853901
var numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic);
854902
if (numErrors) {
855903
if (module) module.dispose();
856-
const err = Error(numErrors + " compile error(s)");
904+
const err = Error(`${numErrors} compile error(s)`);
857905
err.stack = err.message; // omit stack
858906
return callback(err);
859907
}
@@ -878,20 +926,11 @@ exports.main = function main(argv, options, callback) {
878926
}
879927

880928
// 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") {
891930
stats.optimizeCount++;
892931
stats.optimizeTime += measure(() => {
893932
try {
894-
module.runPasses(["trap-mode-js"]);
933+
module.runPasses([`trap-mode-${opts.trapMode}`]);
895934
} catch (e) {
896935
crash("runPasses", e);
897936
}
@@ -911,7 +950,7 @@ exports.main = function main(argv, options, callback) {
911950
}
912951
if (opts.runPasses.length) {
913952
opts.runPasses.forEach(pass => {
914-
if (runPasses.indexOf(pass = pass.trim()) < 0) {
953+
if (!runPasses.includes(pass = pass.trim())) {
915954
runPasses.push(pass);
916955
}
917956
});
@@ -957,7 +996,7 @@ exports.main = function main(argv, options, callback) {
957996
}
958997
if (next.length >= last.length) {
959998
if (next.length > last.length) {
960-
stderr.write("Last converge was suboptimial." + EOL);
999+
stderr.write(`Last converge was suboptimial.${EOL}`);
9611000
}
9621001
break;
9631002
}
@@ -969,9 +1008,9 @@ exports.main = function main(argv, options, callback) {
9691008
// Prepare output
9701009
if (!opts.noEmit) {
9711010
if (opts.outFile != null) {
972-
if (/\.was?t$/.test(opts.outFile) && opts.textFile == null) {
1011+
if (opts.textFile == null && /\.was?t$/.test(opts.outFile)) {
9731012
opts.textFile = opts.outFile;
974-
} else if (/\.js$/.test(opts.outFile) && opts.jsFile == null) {
1013+
} else if (opts.jsFile == null && /\.js$/.test(opts.outFile)) {
9751014
opts.jsFile = opts.outFile;
9761015
} else if (opts.binaryFile == null) {
9771016
opts.binaryFile = opts.outFile;
@@ -991,7 +1030,7 @@ exports.main = function main(argv, options, callback) {
9911030
let sourceMapURL = opts.sourceMap != null
9921031
? opts.sourceMap.length
9931032
? opts.sourceMap
994-
: "./" + basename + ".map"
1033+
: `./${basename}.map`
9951034
: null;
9961035

9971036
let wasm;
@@ -1015,11 +1054,11 @@ exports.main = function main(argv, options, callback) {
10151054
if (wasm.sourceMap != "") {
10161055
if (opts.binaryFile.length) {
10171056
let map = JSON.parse(wasm.sourceMap);
1018-
map.sourceRoot = "./" + basename;
1057+
map.sourceRoot = `./${basename}`;
10191058
let contents = [];
10201059
map.sources.forEach((name, index) => {
10211060
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.`));
10231062
contents[index] = text;
10241063
});
10251064
map.sourcesContent = contents;
@@ -1028,7 +1067,7 @@ exports.main = function main(argv, options, callback) {
10281067
path.basename(sourceMapURL)
10291068
).replace(/^\.\//, ""), JSON.stringify(map), baseDir);
10301069
} else {
1031-
stderr.write("Skipped source map (stdout already occupied)" + EOL);
1070+
stderr.write(`Skipped source map (stdout already occupied)${EOL}`);
10321071
}
10331072
}
10341073
}
@@ -1039,15 +1078,13 @@ exports.main = function main(argv, options, callback) {
10391078
if (opts.textFile != null && opts.textFile.length) {
10401079
// use superset text format when extension is `.wast`.
10411080
// Otherwise use official stack IR format (wat).
1042-
let wastFormat = opts.textFile.endsWith('.wast');
1081+
let wastFormat = opts.textFile.endsWith(".wast");
10431082
stats.emitCount++;
10441083
stats.emitTime += measure(() => {
10451084
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);
10511088
} catch (e) {
10521089
crash("emitText", e);
10531090
}
@@ -1225,33 +1262,33 @@ function getAsconfig(file, baseDir, readFile) {
12251262
try {
12261263
config = JSON.parse(contents);
12271264
} catch(ex) {
1228-
throw new Error("Asconfig is not valid json: " + location);
1265+
throw new Error(`Asconfig is not valid json: ${location}`);
12291266
}
12301267

12311268
// validate asconfig shape
12321269
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}`);
12341271
}
12351272

12361273
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}`);
12381275
}
12391276

12401277
if (config.targets) {
12411278
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}`);
12431280
}
12441281
const targets = Object.keys(config.targets);
12451282
for (let i = 0; i < targets.length; i++) {
12461283
const target = targets[i];
12471284
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}`);
12491286
}
12501287
}
12511288
}
12521289

12531290
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}`);
12551292
}
12561293

12571294
return config;
@@ -1344,20 +1381,20 @@ function measure(fn) {
13441381
exports.measure = measure;
13451382

13461383
function pad(str, len) {
1347-
while (str.length < len) str = " " + str;
1384+
while (str.length < len) str = ` ${str}`;
13481385
return str;
13491386
}
13501387

13511388
/** Formats a high resolution time to a human readable string. */
13521389
function formatTime(time) {
1353-
return time ? (time / 1e6).toFixed(3) + " ms" : "n/a";
1390+
return time ? `${(time / 1e6).toFixed(3)} ms` : "n/a";
13541391
}
13551392

13561393
exports.formatTime = formatTime;
13571394

13581395
/** Formats and prints out the contents of a set of stats. */
13591396
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}`;
13611398
(output || process.stdout).write([
13621399
"I/O Read : " + format(stats.readTime, stats.readCount),
13631400
"I/O Write : " + format(stats.writeTime, stats.writeCount),

0 commit comments

Comments
 (0)
Please sign in to comment.