mirror of https://github.com/vuejs/core.git
wip: save
This commit is contained in:
parent
229acec4c7
commit
0aa49b069c
|
@ -100,7 +100,7 @@ export function genEffects(
|
||||||
push(`)`)
|
push(`)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// declare variables: let _foo, _bar
|
// declare variables: let _foo, __foo
|
||||||
if (declareNames.size) {
|
if (declareNames.size) {
|
||||||
frag.splice(1, 0, `let ${[...declareNames].join(', ')}`, NEWLINE)
|
frag.splice(1, 0, `let ${[...declareNames].join(', ')}`, NEWLINE)
|
||||||
}
|
}
|
||||||
|
@ -125,43 +125,28 @@ export function genEffect(
|
||||||
allDeclareNames.add([...preAccessNames].join(', '))
|
allDeclareNames.add([...preAccessNames].join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pre access: __foo = _ctx.foo
|
||||||
const accessExps: CodeFragment[] =
|
const accessExps: CodeFragment[] =
|
||||||
preAccessExps.size > 0 ? [[...preAccessExps].join(';'), NEWLINE] : []
|
preAccessExps.size > 0 ? [[...preAccessExps].join(';'), NEWLINE] : []
|
||||||
// const newlineCount = operationsExps.filter(frag => frag === NEWLINE).length
|
// check start: if (_foo !== __foo) {
|
||||||
// if (newlineCount > 1) {
|
const checkStartExps: CodeFragment[] =
|
||||||
// multiline check expression: if (_foo !== _ctx.foo || _bar !== _ctx.bar) {
|
|
||||||
const checkExpsStart: CodeFragment[] =
|
|
||||||
earlyCheckExps.length > 0
|
earlyCheckExps.length > 0
|
||||||
? [`if(`, ...earlyCheckExps.join(' || '), `) {`, INDENT_START]
|
? [`if(`, ...earlyCheckExps.join(' || '), `) {`, INDENT_START]
|
||||||
: []
|
: []
|
||||||
const checkExpsEnd: CodeFragment[] =
|
// check end: }
|
||||||
|
const checkEndExps: CodeFragment[] =
|
||||||
earlyCheckExps.length > 0 ? [INDENT_END, NEWLINE, '}'] : []
|
earlyCheckExps.length > 0 ? [INDENT_END, NEWLINE, '}'] : []
|
||||||
// assignment: _foo = _ctx.foo; _bar = _ctx.bar
|
// assignment: _foo = __foo
|
||||||
const assignmentExps: CodeFragment[] =
|
const assignmentExps: CodeFragment[] =
|
||||||
earlyCheckExps.length > 0
|
earlyCheckExps.length > 0
|
||||||
? [NEWLINE, ...earlyCheckExps.map(c => c.replace('!==', '=')).join(';')]
|
? [NEWLINE, ...earlyCheckExps.map(c => c.replace('!==', '=')).join(';')]
|
||||||
: []
|
: []
|
||||||
push(
|
push(
|
||||||
...accessExps,
|
...accessExps,
|
||||||
...checkExpsStart,
|
...checkStartExps,
|
||||||
...operationsExps,
|
...operationsExps,
|
||||||
...assignmentExps,
|
...assignmentExps,
|
||||||
...checkExpsEnd,
|
...checkEndExps,
|
||||||
)
|
)
|
||||||
// } else {
|
|
||||||
// single line check expression: (_foo !== _ctx.foo || _bar !== _ctx.bar) &&
|
|
||||||
// const multiple = earlyCheckExps.length > 1
|
|
||||||
// const checkExps: CodeFragment[] =
|
|
||||||
// earlyCheckExps.length > 0
|
|
||||||
// ? [
|
|
||||||
// multiple ? `(` : undefined,
|
|
||||||
// ...earlyCheckExps.join(' || '),
|
|
||||||
// multiple ? `)` : undefined,
|
|
||||||
// ' && ',
|
|
||||||
// ]
|
|
||||||
// : []
|
|
||||||
// push(...checkExps, ...operationsExps.filter(frag => frag !== NEWLINE))
|
|
||||||
// }
|
|
||||||
|
|
||||||
return frag
|
return frag
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,16 +46,10 @@ export function genSetProp(
|
||||||
} = oper
|
} = oper
|
||||||
const { helperName, omitKey } = getRuntimeHelper(tag, key.content, modifier)
|
const { helperName, omitKey } = getRuntimeHelper(tag, key.content, modifier)
|
||||||
const propValue = genPropValue(values, context)
|
const propValue = genPropValue(values, context)
|
||||||
const { prevValueName, shouldWrapInParentheses } = processPropValues(
|
const { prevValueName } = processPropValues(context, helperName, [propValue])
|
||||||
context,
|
|
||||||
helperName,
|
|
||||||
[propValue],
|
|
||||||
)
|
|
||||||
return [
|
return [
|
||||||
NEWLINE,
|
NEWLINE,
|
||||||
...(prevValueName
|
...(prevValueName ? [`${prevValueName} = `] : []),
|
||||||
? [shouldWrapInParentheses ? `(` : undefined, `${prevValueName} = `]
|
|
||||||
: []),
|
|
||||||
...genCall(
|
...genCall(
|
||||||
[helper(helperName), null],
|
[helper(helperName), null],
|
||||||
`n${oper.element}`,
|
`n${oper.element}`,
|
||||||
|
@ -67,7 +61,6 @@ export function genSetProp(
|
||||||
? 'true'
|
? 'true'
|
||||||
: undefined,
|
: undefined,
|
||||||
),
|
),
|
||||||
...(prevValueName && shouldWrapInParentheses ? [`)`] : []),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,16 +77,14 @@ export function genDynamicProps(
|
||||||
? genLiteralObjectProps([props], context) // dynamic arg props
|
? genLiteralObjectProps([props], context) // dynamic arg props
|
||||||
: genExpression(props.value, context),
|
: genExpression(props.value, context),
|
||||||
) // v-bind=""
|
) // v-bind=""
|
||||||
const { prevValueName, shouldWrapInParentheses } = processPropValues(
|
const { prevValueName } = processPropValues(
|
||||||
context,
|
context,
|
||||||
'setDynamicProps',
|
'setDynamicProps',
|
||||||
values,
|
values,
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
NEWLINE,
|
NEWLINE,
|
||||||
...(prevValueName
|
...(prevValueName ? [`${prevValueName} = `] : []),
|
||||||
? [shouldWrapInParentheses ? `(` : undefined, `${prevValueName} = `]
|
|
||||||
: []),
|
|
||||||
...genCall(
|
...genCall(
|
||||||
helper('setDynamicProps'),
|
helper('setDynamicProps'),
|
||||||
`n${oper.element}`,
|
`n${oper.element}`,
|
||||||
|
@ -101,7 +92,6 @@ export function genDynamicProps(
|
||||||
genMulti(DELIMITERS_ARRAY, ...values),
|
genMulti(DELIMITERS_ARRAY, ...values),
|
||||||
oper.root && 'true',
|
oper.root && 'true',
|
||||||
),
|
),
|
||||||
...(prevValueName && shouldWrapInParentheses ? [`)`] : []),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,12 +231,8 @@ function processPropValues(
|
||||||
context: CodegenContext,
|
context: CodegenContext,
|
||||||
helperName: string,
|
helperName: string,
|
||||||
values: CodeFragment[][],
|
values: CodeFragment[][],
|
||||||
): { prevValueName: string | undefined; shouldWrapInParentheses: boolean } {
|
): { prevValueName: string | undefined } {
|
||||||
const { shouldCacheRenderEffectDeps, processingRenderEffect } = context
|
const { shouldCacheRenderEffectDeps, processingRenderEffect } = context
|
||||||
// single-line render effect and the operation needs cache return a value,
|
|
||||||
// the expression needs to be wrapped in parentheses.
|
|
||||||
// e.g. _foo === _ctx.foo && (_prev_foo = _setStyle(...))
|
|
||||||
let shouldWrapInParentheses: boolean = false
|
|
||||||
let prevValueName
|
let prevValueName
|
||||||
if (shouldCacheRenderEffectDeps()) {
|
if (shouldCacheRenderEffectDeps()) {
|
||||||
const { declareNames, preAccessNames, preAccessExps } =
|
const { declareNames, preAccessNames, preAccessExps } =
|
||||||
|
@ -268,10 +254,9 @@ function processPropValues(
|
||||||
}
|
}
|
||||||
declareNames.add(prevValueName)
|
declareNames.add(prevValueName)
|
||||||
}
|
}
|
||||||
shouldWrapInParentheses = false //operations.length === 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { prevValueName, shouldWrapInParentheses }
|
return { prevValueName }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function processValues(
|
export function processValues(
|
||||||
|
@ -301,15 +286,12 @@ function processValue(
|
||||||
const { declareNames, earlyCheckExps, preAccessNames, preAccessExps } =
|
const { declareNames, earlyCheckExps, preAccessNames, preAccessExps } =
|
||||||
processingRenderEffect!
|
processingRenderEffect!
|
||||||
|
|
||||||
// const isSingleLine = operations.length === 1
|
|
||||||
for (const frag of values) {
|
for (const frag of values) {
|
||||||
if (!isArray(frag)) continue
|
if (!isArray(frag)) continue
|
||||||
// [code, newlineIndex, loc, name] -> [(_name = code), newlineIndex, loc, name]
|
// [code, newlineIndex, loc, name] -> [(__name), newlineIndex, loc, name]
|
||||||
const [newName, , , rawName] = frag
|
const [newName, , , rawName] = frag
|
||||||
if (rawName) {
|
if (rawName) {
|
||||||
let name = rawName.replace(/[^\w]/g, '_')
|
let name = rawName.replace(/[^\w]/g, '_')
|
||||||
// if (rewrittenNames.has(name)) continue
|
|
||||||
// rewrittenNames.add(name)
|
|
||||||
|
|
||||||
name = `_${name}`
|
name = `_${name}`
|
||||||
if (!declareNames.has(name)) {
|
if (!declareNames.has(name)) {
|
||||||
|
@ -324,6 +306,7 @@ function processValue(
|
||||||
preAccessExps.add(`${preAccessName} = ${newName}`)
|
preAccessExps.add(`${preAccessName} = ${newName}`)
|
||||||
earlyCheckExps.push(`${name} !== ${preAccessName}`)
|
earlyCheckExps.push(`${name} !== ${preAccessName}`)
|
||||||
if (needRewrite) {
|
if (needRewrite) {
|
||||||
|
// replace the original name with the preAccessName
|
||||||
frag[0] = `${preAccessName}`
|
frag[0] = `${preAccessName}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue