Skip to content

Commit 15c7b3a

Browse files
TrottFishrock123
authored andcommitted
src,tools: use template literals
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: #5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Conflicts: src/.eslintrc src/node.js
1 parent 1ccf9b4 commit 15c7b3a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/.eslintrc

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

src/node.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,19 @@
535535
module.paths = Module._nodeModulePaths(cwd);
536536
var script = process._eval;
537537
var body = script;
538-
script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
538+
script = `global.__filename = ${JSON.stringify(name)};\n` +
539539
'global.exports = exports;\n' +
540540
'global.module = module;\n' +
541541
'global.__dirname = __dirname;\n' +
542542
'global.require = require;\n' +
543543
'return require("vm").runInThisContext(' +
544-
JSON.stringify(body) + ', { filename: ' +
545-
JSON.stringify(name) + ' });\n';
544+
`${JSON.stringify(body)}, { filename: ` +
545+
`${JSON.stringify(name)} });\n`;
546546
// Defer evaluation for a tick. This is a workaround for deferred
547547
// events not firing when evaluating scripts from the command line,
548548
// see https://github.com/nodejs/node/issues/1600.
549549
process.nextTick(function() {
550-
var result = module._compile(script, name + '-wrapper');
550+
var result = module._compile(script, `${name}-wrapper`);
551551
if (process._print_eval) console.log(result);
552552
});
553553
}
@@ -739,7 +739,7 @@
739739
sig.slice(0, 3) === 'SIG') {
740740
err = process._kill(pid, startup.lazyConstants()[sig]);
741741
} else {
742-
throw new Error('Unknown signal: ' + sig);
742+
throw new Error(`Unknown signal: ${sig}`);
743743
}
744744
}
745745

@@ -844,7 +844,7 @@
844844
}
845845

846846
function NativeModule(id) {
847-
this.filename = id + '.js';
847+
this.filename = `${id}.js`;
848848
this.id = id;
849849
this.exports = {};
850850
this.loaded = false;
@@ -864,10 +864,10 @@
864864
}
865865

866866
if (!NativeModule.exists(id)) {
867-
throw new Error('No such native module ' + id);
867+
throw new Error(`No such native module ${id}`);
868868
}
869869

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

872872
var nativeModule = new NativeModule(id);
873873

0 commit comments

Comments
 (0)