wip(compiler): tweak codegen, avoid duplicated asset resolution, improve formatting

This commit is contained in:
Evan You
2019-09-27 22:49:20 -04:00
parent 32666c7708
commit 262be6733c
3 changed files with 18 additions and 8 deletions

View File

@@ -296,7 +296,13 @@ function genNodeListAsArray(
nodes: (string | CodegenNode | ChildNode[])[],
context: CodegenContext
) {
const multilines = nodes.length > 1
const multilines =
nodes.length > 1 ||
((!__BROWSER__ || __DEV__) &&
nodes.some(
n =>
isArray(n) || (!isString(n) && n.type !== NodeTypes.SIMPLE_EXPRESSION)
))
context.push(`[`)
multilines && context.indent()
genNodeList(nodes, context, multilines)
@@ -552,7 +558,10 @@ function genCallExpression(
function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
const { push, indent, deindent, newline, resetMapping } = context
const { properties } = node
const multilines = properties.length > 1
const multilines =
properties.length > 1 ||
((!__BROWSER__ || __DEV__) &&
properties.some(p => p.value.type !== NodeTypes.SIMPLE_EXPRESSION))
push(multilines ? `{` : `{ `)
multilines && indent()
for (let i = 0; i < properties.length; i++) {
@@ -570,7 +579,8 @@ function genObjectExpression(node: ObjectExpression, context: CodegenContext) {
}
}
multilines && deindent()
push(multilines ? `}` : ` }`)
const lastChar = context.code[context.code.length - 1]
push(multilines || /[\])}]/.test(lastChar) ? `}` : ` }`)
}
function genArrayExpression(node: ArrayExpression, context: CodegenContext) {