mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 14:41:25 +00:00
refactor: small readability improvements (#5748)
This commit is contained in:
parent
119bbfc3e8
commit
d08ce2f628
@ -47,7 +47,7 @@ module.exports = (context, options = {}) => {
|
|||||||
const presets = []
|
const presets = []
|
||||||
const plugins = []
|
const plugins = []
|
||||||
|
|
||||||
const modern = !!options.modern
|
const modern = Boolean(options.modern)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
polyfills: userPolyfills,
|
polyfills: userPolyfills,
|
||||||
|
@ -10,7 +10,7 @@ export default class TemplateContext {
|
|||||||
constructor(builder, options) {
|
constructor(builder, options) {
|
||||||
this.templateFiles = Array.from(builder.template.files)
|
this.templateFiles = Array.from(builder.template.files)
|
||||||
this.templateVars = {
|
this.templateVars = {
|
||||||
options: options,
|
options,
|
||||||
extensions: options.extensions
|
extensions: options.extensions
|
||||||
.map(ext => ext.replace(/^\./, ''))
|
.map(ext => ext.replace(/^\./, ''))
|
||||||
.join('|'),
|
.join('|'),
|
||||||
|
@ -45,7 +45,7 @@ export default {
|
|||||||
// Silence output when using --quiet
|
// Silence output when using --quiet
|
||||||
options.build = options.build || {}
|
options.build = options.build || {}
|
||||||
if (argv.quiet) {
|
if (argv.quiet) {
|
||||||
options.build.quiet = !!argv.quiet
|
options.build.quiet = Boolean(argv.quiet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -447,7 +447,7 @@ describe('server: server', () => {
|
|||||||
expect(renderAndGetWindow).toBeCalledWith('/render/window', {}, {
|
expect(renderAndGetWindow).toBeCalledWith('/render/window', {}, {
|
||||||
loadedCallback: globals.loadedCallback,
|
loadedCallback: globals.loadedCallback,
|
||||||
ssr: nuxt.options.render.ssr,
|
ssr: nuxt.options.render.ssr,
|
||||||
globals: globals
|
globals
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ function mapTransitions(Components, to, from) {
|
|||||||
|
|
||||||
async function loadAsyncComponents(to, from, next) {
|
async function loadAsyncComponents(to, from, next) {
|
||||||
// Check if route path changed (this._pathChanged), only if the page is not an error (for validate())
|
// 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._queryChanged = JSON.stringify(to.query) !== JSON.stringify(from.query)
|
||||||
this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, 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)
|
next: _next.bind(this)
|
||||||
})
|
})
|
||||||
this._dateLastError = app.nuxt.dateErr
|
this._dateLastError = app.nuxt.dateErr
|
||||||
this._hadError = !!app.nuxt.err
|
this._hadError = Boolean(app.nuxt.err)
|
||||||
|
|
||||||
// Get route's matched components
|
// Get route's matched components
|
||||||
const matches = []
|
const matches = []
|
||||||
@ -376,7 +376,7 @@ async function render(to, from, next) {
|
|||||||
Component.options.asyncData &&
|
Component.options.asyncData &&
|
||||||
typeof Component.options.asyncData === 'function'
|
typeof Component.options.asyncData === 'function'
|
||||||
)
|
)
|
||||||
const hasFetch = !!Component.options.fetch
|
const hasFetch = Boolean(Component.options.fetch)
|
||||||
<% if (loading) { %>
|
<% if (loading) { %>
|
||||||
const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45
|
const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45
|
||||||
<% } %>
|
<% } %>
|
||||||
|
@ -88,7 +88,7 @@ async function createApp(ssrContext) {
|
|||||||
dateErr: null,
|
dateErr: null,
|
||||||
error(err) {
|
error(err) {
|
||||||
err = err || null
|
err = err || null
|
||||||
app.context._errored = !!err
|
app.context._errored = Boolean(err)
|
||||||
err = err ? normalizeError(err) : null
|
err = err ? normalizeError(err) : null
|
||||||
const nuxt = this.nuxt || this.$options.nuxt
|
const nuxt = this.nuxt || this.$options.nuxt
|
||||||
nuxt.dateErr = Date.now()
|
nuxt.dateErr = Date.now()
|
||||||
|
@ -169,16 +169,16 @@ export async function setContext(app, context) {
|
|||||||
// "/absolute/route", "./relative/route" or "../relative/route"
|
// "/absolute/route", "./relative/route" or "../relative/route"
|
||||||
if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) {
|
if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) {
|
||||||
app.context.next({
|
app.context.next({
|
||||||
path: path,
|
path,
|
||||||
query: query,
|
query,
|
||||||
status: status
|
status
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
path = formatUrl(path, query)
|
path = formatUrl(path, query)
|
||||||
if (process.server) {
|
if (process.server) {
|
||||||
app.context.next({
|
app.context.next({
|
||||||
path: path,
|
path,
|
||||||
status: status
|
status
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
@ -215,7 +215,7 @@ export async function setContext(app, context) {
|
|||||||
app.context.next = context.next
|
app.context.next = context.next
|
||||||
app.context._redirected = false
|
app.context._redirected = false
|
||||||
app.context._errored = 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.params = app.context.route.params || {}
|
||||||
app.context.query = app.context.route.query || {}
|
app.context.query = app.context.route.query || {}
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ export function normalizeError(err) {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...err,
|
...err,
|
||||||
message: message,
|
message,
|
||||||
statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500)
|
statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,11 +384,11 @@ function parse(str, options) {
|
|||||||
tokens.push({
|
tokens.push({
|
||||||
name: name || key++,
|
name: name || key++,
|
||||||
prefix: prefix || '',
|
prefix: prefix || '',
|
||||||
delimiter: delimiter,
|
delimiter,
|
||||||
optional: optional,
|
optional,
|
||||||
repeat: repeat,
|
repeat,
|
||||||
partial: partial,
|
partial,
|
||||||
asterisk: !!asterisk,
|
asterisk: Boolean(asterisk),
|
||||||
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
|
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -558,8 +558,7 @@ function formatUrl(url, query) {
|
|||||||
let hash
|
let hash
|
||||||
parts = path.split('#')
|
parts = path.split('#')
|
||||||
if (parts.length === 2) {
|
if (parts.length === 2) {
|
||||||
path = parts[0]
|
[path, hash] = parts
|
||||||
hash = parts[1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result += path ? '/' + path : ''
|
result += path ? '/' + path : ''
|
||||||
|
@ -38,7 +38,7 @@ export default class WebpackBaseConfig {
|
|||||||
isDev: this.dev,
|
isDev: this.dev,
|
||||||
isServer: this.isServer,
|
isServer: this.isServer,
|
||||||
isClient: !this.isServer,
|
isClient: !this.isServer,
|
||||||
isModern: !!this.isModern
|
isModern: Boolean(this.isModern)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ export default class VueSSRClientPlugin {
|
|||||||
stats.modules.forEach((m) => {
|
stats.modules.forEach((m) => {
|
||||||
// Ignore modules duplicated in multiple chunks
|
// Ignore modules duplicated in multiple chunks
|
||||||
if (m.chunks.length === 1) {
|
if (m.chunks.length === 1) {
|
||||||
const cid = m.chunks[0]
|
const [cid] = m.chunks
|
||||||
const chunk = stats.chunks.find(c => c.id === cid)
|
const chunk = stats.chunks.find(c => c.id === cid)
|
||||||
if (!chunk || !chunk.files) {
|
if (!chunk || !chunk.files) {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user