From d08ce2f6287ba12051f54bc597b7c226e25d78e9 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Thu, 16 May 2019 12:08:44 +0200 Subject: [PATCH] refactor: small readability improvements (#5748) --- packages/babel-preset-app/src/index.js | 2 +- packages/builder/src/context/template.js | 2 +- packages/cli/src/commands/build.js | 2 +- packages/server/test/server.test.js | 2 +- packages/vue-app/template/client.js | 6 ++--- packages/vue-app/template/index.js | 2 +- packages/vue-app/template/utils.js | 27 +++++++++++----------- packages/webpack/src/config/base.js | 2 +- packages/webpack/src/plugins/vue/client.js | 2 +- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/babel-preset-app/src/index.js b/packages/babel-preset-app/src/index.js index fd0104819d..afcef0da68 100644 --- a/packages/babel-preset-app/src/index.js +++ b/packages/babel-preset-app/src/index.js @@ -47,7 +47,7 @@ module.exports = (context, options = {}) => { const presets = [] const plugins = [] - const modern = !!options.modern + const modern = Boolean(options.modern) const { polyfills: userPolyfills, diff --git a/packages/builder/src/context/template.js b/packages/builder/src/context/template.js index e5abefad2c..f9856e96cc 100644 --- a/packages/builder/src/context/template.js +++ b/packages/builder/src/context/template.js @@ -10,7 +10,7 @@ export default class TemplateContext { constructor(builder, options) { this.templateFiles = Array.from(builder.template.files) this.templateVars = { - options: options, + options, extensions: options.extensions .map(ext => ext.replace(/^\./, '')) .join('|'), diff --git a/packages/cli/src/commands/build.js b/packages/cli/src/commands/build.js index 6f745cb95b..3259a467b9 100644 --- a/packages/cli/src/commands/build.js +++ b/packages/cli/src/commands/build.js @@ -45,7 +45,7 @@ export default { // Silence output when using --quiet options.build = options.build || {} if (argv.quiet) { - options.build.quiet = !!argv.quiet + options.build.quiet = Boolean(argv.quiet) } } }, diff --git a/packages/server/test/server.test.js b/packages/server/test/server.test.js index d5037297a4..60336b7645 100644 --- a/packages/server/test/server.test.js +++ b/packages/server/test/server.test.js @@ -447,7 +447,7 @@ describe('server: server', () => { expect(renderAndGetWindow).toBeCalledWith('/render/window', {}, { loadedCallback: globals.loadedCallback, ssr: nuxt.options.render.ssr, - globals: globals + globals }) }) diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index c4750655e1..b7107f2305 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -128,7 +128,7 @@ function mapTransitions(Components, to, from) { async function loadAsyncComponents(to, from, next) { // Check if route path changed (this._pathChanged), only if the page is not an error (for validate()) - this._pathChanged = !!app.nuxt.err || from.path !== to.path + this._pathChanged = Boolean(app.nuxt.err) || from.path !== to.path this._queryChanged = JSON.stringify(to.query) !== JSON.stringify(from.query) this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, from.query) : []) @@ -267,7 +267,7 @@ async function render(to, from, next) { next: _next.bind(this) }) this._dateLastError = app.nuxt.dateErr - this._hadError = !!app.nuxt.err + this._hadError = Boolean(app.nuxt.err) // Get route's matched components const matches = [] @@ -376,7 +376,7 @@ async function render(to, from, next) { Component.options.asyncData && typeof Component.options.asyncData === 'function' ) - const hasFetch = !!Component.options.fetch + const hasFetch = Boolean(Component.options.fetch) <% if (loading) { %> const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45 <% } %> diff --git a/packages/vue-app/template/index.js b/packages/vue-app/template/index.js index c9004d538a..6ee47a9704 100644 --- a/packages/vue-app/template/index.js +++ b/packages/vue-app/template/index.js @@ -88,7 +88,7 @@ async function createApp(ssrContext) { dateErr: null, error(err) { err = err || null - app.context._errored = !!err + app.context._errored = Boolean(err) err = err ? normalizeError(err) : null const nuxt = this.nuxt || this.$options.nuxt nuxt.dateErr = Date.now() diff --git a/packages/vue-app/template/utils.js b/packages/vue-app/template/utils.js index 4647f830d7..536d863f26 100644 --- a/packages/vue-app/template/utils.js +++ b/packages/vue-app/template/utils.js @@ -169,16 +169,16 @@ export async function setContext(app, context) { // "/absolute/route", "./relative/route" or "../relative/route" if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) { app.context.next({ - path: path, - query: query, - status: status + path, + query, + status }) } else { path = formatUrl(path, query) if (process.server) { app.context.next({ - path: path, - status: status + path, + status }) } if (process.client) { @@ -215,7 +215,7 @@ export async function setContext(app, context) { app.context.next = context.next app.context._redirected = false app.context._errored = false - app.context.isHMR = !!context.isHMR + app.context.isHMR = Boolean(context.isHMR) app.context.params = app.context.route.params || {} app.context.query = app.context.route.query || {} } @@ -310,7 +310,7 @@ export function normalizeError(err) { } return { ...err, - message: message, + message, statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500) } } @@ -384,11 +384,11 @@ function parse(str, options) { tokens.push({ name: name || key++, prefix: prefix || '', - delimiter: delimiter, - optional: optional, - repeat: repeat, - partial: partial, - asterisk: !!asterisk, + delimiter, + optional, + repeat, + partial, + asterisk: Boolean(asterisk), pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') }) } @@ -558,8 +558,7 @@ function formatUrl(url, query) { let hash parts = path.split('#') if (parts.length === 2) { - path = parts[0] - hash = parts[1] + [path, hash] = parts } result += path ? '/' + path : '' diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js index ff489e2f03..c2514841a4 100644 --- a/packages/webpack/src/config/base.js +++ b/packages/webpack/src/config/base.js @@ -38,7 +38,7 @@ export default class WebpackBaseConfig { isDev: this.dev, isServer: this.isServer, isClient: !this.isServer, - isModern: !!this.isModern + isModern: Boolean(this.isModern) } } diff --git a/packages/webpack/src/plugins/vue/client.js b/packages/webpack/src/plugins/vue/client.js index 4cca62f523..35cb125d17 100644 --- a/packages/webpack/src/plugins/vue/client.js +++ b/packages/webpack/src/plugins/vue/client.js @@ -52,7 +52,7 @@ export default class VueSSRClientPlugin { stats.modules.forEach((m) => { // Ignore modules duplicated in multiple chunks if (m.chunks.length === 1) { - const cid = m.chunks[0] + const [cid] = m.chunks const chunk = stats.chunks.find(c => c.id === cid) if (!chunk || !chunk.files) { return