Skip to content

Commit 4f683ab

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
src,tools: use template literals
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: nodejs#5778 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
1 parent 200f763 commit 4f683ab

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ECMAScript-6
2+
# http://eslint.org/docs/rules/#ecmascript-6
3+
prefer-template: 2

src/node.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,19 @@
564564
module.paths = Module._nodeModulePaths(cwd);
565565
var script = process._eval;
566566
var body = script;
567-
script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
567+
script = `global.__filename = ${JSON.stringify(name)};\n` +
568568
'global.exports = exports;\n' +
569569
'global.module = module;\n' +
570570
'global.__dirname = __dirname;\n' +
571571
'global.require = require;\n' +
572572
'return require("vm").runInThisContext(' +
573-
JSON.stringify(body) + ', { filename: ' +
574-
JSON.stringify(name) + ' });\n';
573+
`${JSON.stringify(body)}, { filename: ` +
574+
`${JSON.stringify(name)} });\n`;
575575
// Defer evaluation for a tick. This is a workaround for deferred
576576
// events not firing when evaluating scripts from the command line,
577577
// see https://github.com/nodejs/node/issues/1600.
578578
process.nextTick(function() {
579-
var result = module._compile(script, name + '-wrapper');
579+
var result = module._compile(script, `${name}-wrapper`);
580580
if (process._print_eval) console.log(result);
581581
});
582582
}
@@ -768,7 +768,7 @@
768768
sig.slice(0, 3) === 'SIG') {
769769
err = process._kill(pid, startup.lazyConstants()[sig]);
770770
} else {
771-
throw new Error('Unknown signal: ' + sig);
771+
throw new Error(`Unknown signal: ${sig}`);
772772
}
773773
}
774774

@@ -873,7 +873,7 @@
873873
}
874874

875875
function NativeModule(id) {
876-
this.filename = id + '.js';
876+
this.filename = `${id}.js`;
877877
this.id = id;
878878
this.exports = {};
879879
this.loaded = false;
@@ -893,10 +893,10 @@
893893
}
894894

895895
if (!NativeModule.exists(id)) {
896-
throw new Error('No such native module ' + id);
896+
throw new Error(`No such native module ${id}`);
897897
}
898898

899-
process.moduleLoadList.push('NativeModule ' + id);
899+
process.moduleLoadList.push(`NativeModule ${id}`);
900900

901901
var nativeModule = new NativeModule(id);
902902

0 commit comments

Comments
 (0)