refactor: small readability improvements (#5748)

This commit is contained in:
Alexander Lichter 2019-05-16 12:08:44 +02:00 committed by Pooya Parsa
parent 119bbfc3e8
commit d08ce2f628
9 changed files with 23 additions and 24 deletions

View File

@ -47,7 +47,7 @@ module.exports = (context, options = {}) => {
const presets = []
const plugins = []
const modern = !!options.modern
const modern = Boolean(options.modern)
const {
polyfills: userPolyfills,

View File

@ -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('|'),

View File

@ -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)
}
}
},

View File

@ -447,7 +447,7 @@ describe('server: server', () => {
expect(renderAndGetWindow).toBeCalledWith('/render/window', {}, {
loadedCallback: globals.loadedCallback,
ssr: nuxt.options.render.ssr,
globals: globals
globals
})
})

View File

@ -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
<% } %>

View File

@ -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()

View File

@ -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 : ''

View File

@ -38,7 +38,7 @@ export default class WebpackBaseConfig {
isDev: this.dev,
isServer: this.isServer,
isClient: !this.isServer,
isModern: !!this.isModern
isModern: Boolean(this.isModern)
}
}

View File

@ -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