提交 9670649b 编写于 作者: fxy060608's avatar fxy060608

wip(mp): mp-alipay

因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -230,6 +230,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
break
case 'move':
handleTouchMove(e)
e.stopPropagation()
break
case 'end':
case 'cancel':
......
......@@ -10937,6 +10937,7 @@ var PickerViewColumn = /* @__PURE__ */ defineBuiltInComponent({
break;
case "move":
handleTouchMove(e2);
e2.stopPropagation();
break;
case "end":
case "cancel":
......
......@@ -38,10 +38,10 @@ function assert(
describe('compiler', () => {
test('scope', () => {
assert(
`<custom :ref="custom"/>`,
`<custom class="v-r" data-ref="{{a}}" v-i="2a9ec0b0-0"/>`,
`<view :number="20" :str="'str'" :boolean="true" :null="null" :undefined="undefined"/>`,
`<view number="{{20}}" str="{{'str'}}" boolean="{{true}}" null="{{null}}" undefined="{{undefined}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.custom }
return {}
}`
)
})
......
......@@ -29,6 +29,15 @@ describe('compiler: transform v-bind', () => {
)
})
test('literal', () => {
assert(
`<view :number="20" :str="'str'" :boolean="true" :null="null" :undefined="undefined"/>`,
`<view number="{{20}}" str="{{'str'}}" boolean="{{true}}" null="{{null}}" undefined="{{undefined}}"/>`,
`(_ctx, _cache) => {
return {}
}`
)
})
test('dynamic arg', () => {
const onError = jest.fn()
parseWithVBind(`<view v-bind:[id]="id" />`, {
......
......@@ -18,7 +18,6 @@ import {
LogicalExpression,
logicalExpression,
StringLiteral,
isTemplateLiteral,
parenthesizedExpression,
binaryExpression,
} from '@babel/types'
......@@ -36,6 +35,7 @@ import { genBabelExpr } from '../codegen'
import { NORMALIZE_CLASS } from '../runtimeHelpers'
import { TransformContext } from '../transform'
import {
isStaticLiteral,
parseExprWithRewrite,
parseExprWithRewriteClass,
rewriteExpression,
......@@ -197,7 +197,7 @@ function rewriteClassObjectExpression(
key as Expression
) as Identifier
}
if (isLiteral(value) && !isTemplateLiteral(value)) {
if (isStaticLiteral(value)) {
return
} else {
const newExpr = parseExprWithRewriteClass(
......
......@@ -9,11 +9,9 @@ import {
isSpreadElement,
identifier,
ObjectExpression,
isLiteral,
isObjectProperty,
binaryExpression,
isIdentifier,
isTemplateLiteral,
} from '@babel/types'
import {
DirectiveNode,
......@@ -30,6 +28,7 @@ import { parseExpr, parseStringLiteral } from '../ast'
import { genBabelExpr } from '../codegen'
import { TransformContext } from '../transform'
import {
isStaticLiteral,
parseExprWithRewrite,
rewirteWithHelper,
rewriteExpression,
......@@ -160,7 +159,7 @@ function rewriteStyleObjectExpression(
prop.key.value = hyphenate(prop.key.value) + ':'
}
// {fontSize:`${fontSize}px`} => {'font-size':a}
if (isLiteral(value) && !isTemplateLiteral(value)) {
if (isStaticLiteral(value)) {
return
} else {
const newExpr = parseExprWithRewrite(
......
......@@ -4,7 +4,9 @@ import {
Identifier,
identifier,
isIdentifier,
isLiteral,
isReferenced,
isTemplateLiteral,
MemberExpression,
numericLiteral,
objectProperty,
......@@ -15,6 +17,7 @@ import {
createSimpleExpression,
ExpressionNode,
NodeTypes,
SimpleExpressionNode,
SourceLocation,
} from '@vue/compiler-core'
import { walk, BaseNode } from 'estree-walker'
......@@ -86,14 +89,17 @@ export function rewriteExpressionWithoutProperty(
babelNode?: Expression,
scope: CodegenScope = context.currentScope
) {
return rewriteExpression(node, context, babelNode, scope, false)
return rewriteExpression(node, context, babelNode, scope, {
property: false,
ignoreLiteral: false,
})
}
export function rewriteExpression(
node: ExpressionNode,
context: TransformContext,
babelNode?: Expression,
scope: CodegenScope = context.currentScope,
property: boolean = true
{ property, ignoreLiteral } = { property: true, ignoreLiteral: false }
) {
if (node.type === NodeTypes.SIMPLE_EXPRESSION && node.isStatic) {
return node
......@@ -105,6 +111,9 @@ export function rewriteExpression(
return createSimpleExpression(code)
}
}
if (!ignoreLiteral && isStaticLiteral(babelNode)) {
return node as SimpleExpressionNode
}
if (isUndefined(babelNode)) {
return createSimpleExpression('undefined', false, node.loc)
}
......@@ -169,3 +178,7 @@ function isReferencedByIds(node: Expression, knownIds: string[]) {
})
return referenced
}
export function isStaticLiteral(value: object | null | undefined) {
return isLiteral(value) && !isTemplateLiteral(value)
}
......@@ -104,13 +104,15 @@ export const transformFor = createStructuralDirectiveTransform(
const indexCode = genExpr(index)
const indexExpr = parseParam(indexCode, context, index)
const indexAlias = parseAlias(indexExpr, indexCode, 'i' + scopes.vFor)
// 先占位vFor,后续更新 cloneSourceExpr 为 CallExpression
// 先占位 vFor,后续更新 cloneSourceExpr 为 CallExpression
const cloneSourceExpr = cloneNode(sourceExpr!, false)
const sourceAlias = rewriteExpression(
source,
context,
cloneSourceExpr,
parentScope
parentScope,
// 强制 rewrite,因为即使是字符串,数字,也要走 vFor 函数
{ property: true, ignoreLiteral: true }
).content
const sourceCode = `{{${sourceAlias}}}`
const vForData: VForOptions = {
......
import {
ConditionalExpression,
isConditionalExpression,
isLiteral,
isTemplateLiteral,
isSpreadElement,
ObjectExpression,
} from '@babel/types'
......@@ -31,7 +29,7 @@ import {
traverseNode,
} from '../transform'
import { processExpression } from './transformExpression'
import { rewriteExpression } from './utils'
import { isStaticLiteral, rewriteExpression } from './utils'
interface IfOptions {
name: string
condition?: string
......@@ -59,7 +57,7 @@ export const transformIf = createStructuralDirectiveTransform(
condition,
})
if (condition) {
if (!isLiteral(condition) || isTemplateLiteral(condition)) {
if (!isStaticLiteral(condition)) {
ifOptions.condition = rewriteExpression(
dir.exp!,
context,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册