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
|
// number of middleware
|
||||||
|
|
||||||
const n = parseInt(process.env.MW || '1', 10);
|
const n = parseInt(process.env.MW || '1', 10);
|
||||||
console.log(' %s async middleware', n);
|
console.log(` ${n} async middleware`);
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
app.use(async function (next){
|
app.use(async function (next){
|
||||||
|
|
|
@ -8,7 +8,7 @@ const app = koa();
|
||||||
// number of middleware
|
// number of middleware
|
||||||
|
|
||||||
const n = parseInt(process.env.MW || '1', 10);
|
const n = parseInt(process.env.MW || '1', 10);
|
||||||
console.log(' %s middleware', n);
|
console.log(` ${n} middleware`);
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
app.use(function *(next){
|
app.use(function *(next){
|
||||||
|
|
|
@ -165,7 +165,7 @@ app.createContext = function(req, res){
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.onerror = function(err){
|
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 (404 == err.status || err.expose) return;
|
||||||
if (this.silent) return;
|
if (this.silent) return;
|
||||||
|
|
|
@ -104,7 +104,7 @@ const proto = module.exports = {
|
||||||
// to node-style callbacks.
|
// to node-style callbacks.
|
||||||
if (null == err) return;
|
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
|
// delegate
|
||||||
this.app.emit('error', err, this);
|
this.app.emit('error', err, this);
|
||||||
|
|
|
@ -69,7 +69,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
get origin() {
|
get origin() {
|
||||||
return this.protocol + '://' + this.host;
|
return `${this.protocol}://${this.host}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +196,7 @@ module.exports = {
|
||||||
|
|
||||||
get search() {
|
get search() {
|
||||||
if (!this.querystring) return '';
|
if (!this.querystring) return '';
|
||||||
return '?' + this.querystring;
|
return `?${this.querystring}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,7 +80,7 @@ module.exports = {
|
||||||
|
|
||||||
set status(code) {
|
set status(code) {
|
||||||
assert('number' == typeof code, 'status code must be a number');
|
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._explicitStatus = true;
|
||||||
this.res.statusCode = code;
|
this.res.statusCode = code;
|
||||||
this.res.statusMessage = statuses[code];
|
this.res.statusMessage = statuses[code];
|
||||||
|
@ -263,13 +263,13 @@ module.exports = {
|
||||||
if (this.ctx.accepts('html')) {
|
if (this.ctx.accepts('html')) {
|
||||||
url = escape(url);
|
url = escape(url);
|
||||||
this.type = 'text/html; charset=utf-8';
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// text
|
// text
|
||||||
this.type = 'text/plain; charset=utf-8';
|
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) {
|
set etag(val) {
|
||||||
if (!/^(W\/)?"/.test(val)) val = '"' + val + '"';
|
if (!/^(W\/)?"/.test(val)) val = `"${val}"`;
|
||||||
this.set('ETag', val);
|
this.set('ETag', val);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ describe('ctx.redirect(url)', function(){
|
||||||
ctx.header.accept = 'text/html';
|
ctx.header.accept = 'text/html';
|
||||||
ctx.redirect(url);
|
ctx.redirect(url);
|
||||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
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(){
|
it('should escape the url', function(){
|
||||||
|
@ -56,7 +56,7 @@ describe('ctx.redirect(url)', function(){
|
||||||
ctx.redirect(url);
|
ctx.redirect(url);
|
||||||
url = escape(url);
|
url = escape(url);
|
||||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
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';
|
const url = 'http://google.com';
|
||||||
ctx.header.accept = 'text/plain';
|
ctx.header.accept = 'text/plain';
|
||||||
ctx.redirect(url);
|
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.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(301);
|
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.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(302);
|
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.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(302);
|
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');
|
ctx.type.should.equal('text/plain');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue