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

wip(mp): mp-alipay

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