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

fix(mp): do not wrap wxs interpolation expr (#3527)

上级 7585600f
......@@ -3,8 +3,8 @@ import { assert } from './testUtils'
describe('compiler: transform wxs', () => {
test('basic', () => {
assert(
`<view :data-threshold="threshold" :change:prop="swipe.showWatch" :prop="is_show" @touchstart="swipe.touchstart"/>`,
`<view data-threshold="{{a}}" change:prop="{{swipe.showWatch}}" prop="{{b}}" bindtouchstart="{{swipe.touchstart}}"/>`,
`<view :data-threshold="threshold" :change:prop="swipe.showWatch" :prop="is_show" @touchstart="swipe.touchstart">{{swipe.message}}</view>`,
`<view data-threshold="{{a}}" change:prop="{{swipe.showWatch}}" prop="{{b}}" bindtouchstart="{{swipe.touchstart}}">{{swipe.message}}</view>`,
`(_ctx, _cache) => {
return { a: _ctx.threshold, b: _ctx.is_show }
}`,
......
......@@ -27,18 +27,31 @@ import {
rewritePropsBinding,
} from './transformComponent'
import { isUserComponent } from '@dcloudio/uni-cli-shared'
import { isString, isSymbol } from '@vue/shared'
export const transformIdentifier: NodeTransform = (node, context) => {
return function transformIdentifier() {
if (node.type === NodeTypes.INTERPOLATION) {
node.content = rewriteExpression(
createCompoundExpression([
`${context.helperString(TO_DISPLAY_STRING)}(`,
node.content,
`)`,
]),
context
)
const content = node.content
let isFilter = false
if (content.type === NodeTypes.COMPOUND_EXPRESSION) {
const firstChild = content.children[0]
isFilter =
!isString(firstChild) &&
!isSymbol(firstChild) &&
firstChild.type === NodeTypes.SIMPLE_EXPRESSION &&
context.filters.includes(firstChild.content)
}
if (!isFilter) {
node.content = rewriteExpression(
createCompoundExpression([
`${context.helperString(TO_DISPLAY_STRING)}(`,
content,
`)`,
]),
context
)
}
} else if (isSlotOutlet(node)) {
rewriteSlot(node, context)
} else if (node.type === NodeTypes.ELEMENT) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册