refactor to use ES6 template strings
replace string interp w/ templates in core use string templating es6 in benchmarks template strings in tests dir
This commit is contained in:
parent
9f27c1c414
commit
ed19e67055
7 changed files with 16 additions and 16 deletions
|
@ -10,7 +10,7 @@ app.experimental = true;
|
|||
// number of middleware
|
||||
|
||||
const n = parseInt(process.env.MW || '1', 10);
|
||||
console.log(' %s async middleware', n);
|
||||
console.log(` ${n} async middleware`);
|
||||
|
||||
while (n--) {
|
||||
app.use(async function (next){
|
||||
|
|
|
@ -8,7 +8,7 @@ const app = koa();
|
|||
// number of middleware
|
||||
|
||||
const n = parseInt(process.env.MW || '1', 10);
|
||||
console.log(' %s middleware', n);
|
||||
console.log(` ${n} middleware`);
|
||||
|
||||
while (n--) {
|
||||
app.use(function *(next){
|
||||
|
|
|
@ -165,7 +165,7 @@ app.createContext = function(req, res){
|
|||
*/
|
||||
|
||||
app.onerror = function(err){
|
||||
assert(err instanceof Error, 'non-error thrown: ' + err);
|
||||
assert(err instanceof Error, `non-error thrown: ${err}`);
|
||||
|
||||
if (404 == err.status || err.expose) return;
|
||||
if (this.silent) return;
|
||||
|
|
|
@ -104,7 +104,7 @@ const proto = module.exports = {
|
|||
// to node-style callbacks.
|
||||
if (null == err) return;
|
||||
|
||||
if (!(err instanceof Error)) err = new Error('non-error thrown: ' + err);
|
||||
if (!(err instanceof Error)) err = new Error(`non-error thrown: ${err}`);
|
||||
|
||||
// delegate
|
||||
this.app.emit('error', err, this);
|
||||
|
|
|
@ -69,7 +69,7 @@ module.exports = {
|
|||
*/
|
||||
|
||||
get origin() {
|
||||
return this.protocol + '://' + this.host;
|
||||
return `${this.protocol}://${this.host}`;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -196,7 +196,7 @@ module.exports = {
|
|||
|
||||
get search() {
|
||||
if (!this.querystring) return '';
|
||||
return '?' + this.querystring;
|
||||
return `?${this.querystring}`;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,7 +80,7 @@ module.exports = {
|
|||
|
||||
set status(code) {
|
||||
assert('number' == typeof code, 'status code must be a number');
|
||||
assert(statuses[code], 'invalid status code: ' + code);
|
||||
assert(statuses[code], `invalid status code: ${code}`);
|
||||
this._explicitStatus = true;
|
||||
this.res.statusCode = code;
|
||||
this.res.statusMessage = statuses[code];
|
||||
|
@ -263,13 +263,13 @@ module.exports = {
|
|||
if (this.ctx.accepts('html')) {
|
||||
url = escape(url);
|
||||
this.type = 'text/html; charset=utf-8';
|
||||
this.body = 'Redirecting to <a href="' + url + '">' + url + '</a>.';
|
||||
this.body = `Redirecting to <a href="${url}">${url}</a>.`;
|
||||
return;
|
||||
}
|
||||
|
||||
// text
|
||||
this.type = 'text/plain; charset=utf-8';
|
||||
this.body = 'Redirecting to ' + url + '.';
|
||||
this.body = `Redirecting to ${url}.`;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -344,7 +344,7 @@ module.exports = {
|
|||
*/
|
||||
|
||||
set etag(val) {
|
||||
if (!/^(W\/)?"/.test(val)) val = '"' + val + '"';
|
||||
if (!/^(W\/)?"/.test(val)) val = `"${val}"`;
|
||||
this.set('ETag', val);
|
||||
},
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ describe('ctx.redirect(url)', function(){
|
|||
ctx.header.accept = 'text/html';
|
||||
ctx.redirect(url);
|
||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
||||
ctx.body.should.equal('Redirecting to <a href="' + url + '">' + url + '</a>.');
|
||||
ctx.body.should.equal(`Redirecting to <a href="${url}">${url}</a>.`);
|
||||
})
|
||||
|
||||
it('should escape the url', function(){
|
||||
|
@ -56,7 +56,7 @@ describe('ctx.redirect(url)', function(){
|
|||
ctx.redirect(url);
|
||||
url = escape(url);
|
||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
||||
ctx.body.should.equal('Redirecting to <a href="' + url + '">' + url + '</a>.');
|
||||
ctx.body.should.equal(`Redirecting to <a href="${url}">${url}</a>.`);
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -66,7 +66,7 @@ describe('ctx.redirect(url)', function(){
|
|||
const url = 'http://google.com';
|
||||
ctx.header.accept = 'text/plain';
|
||||
ctx.redirect(url);
|
||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
||||
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -78,7 +78,7 @@ describe('ctx.redirect(url)', function(){
|
|||
ctx.header.accept = 'text/plain';
|
||||
ctx.redirect('http://google.com');
|
||||
ctx.status.should.equal(301);
|
||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
||||
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -90,7 +90,7 @@ describe('ctx.redirect(url)', function(){
|
|||
ctx.header.accept = 'text/plain';
|
||||
ctx.redirect('http://google.com');
|
||||
ctx.status.should.equal(302);
|
||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
||||
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -102,7 +102,7 @@ describe('ctx.redirect(url)', function(){
|
|||
ctx.header.accept = 'text/plain';
|
||||
ctx.redirect('http://google.com');
|
||||
ctx.status.should.equal(302);
|
||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
||||
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||
ctx.type.should.equal('text/plain');
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue