diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
index 2b41eef7b6198416bf4c4ab50111399d5cbd30aa..44eec7dbd7f5613e80ca8cb37b04d460bbeaa8ed 100644
--- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
@@ -97,6 +97,14 @@ describe('mp:compiler-mp-weixin', () => {
scopedSlotsCompiler: 'auto'
}
)
+ assertCodegen(
+ '{{item}}',
+ '',
+ 'with(this){}',
+ {
+ scopedSlotsCompiler: 'auto'
+ }
+ )
assertCodegen(
'{{getValue(item)}}',
'{{$root.m1}}',
diff --git a/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js b/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
index eb8af7b83e50c680f4512a7b34641c04359f3e0c..77284f67ebb234c3e0bb609279f8b2c2c6e66ab3 100644
--- a/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
+++ b/packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
@@ -2,17 +2,27 @@ const t = require('@babel/types')
const {
METHOD_BUILT_IN,
- METHOD_CREATE_EMPTY_VNODE
+ METHOD_CREATE_EMPTY_VNODE,
+ METHOD_CREATE_ELEMENT
} = require('../../constants')
function needSlotMode (path, ids) {
let need
path.traverse({
noScope: false,
+ Property (path) {
+ // 跳过事件
+ if (path.node.key.name === 'on') {
+ const parentPath = path.parentPath.parentPath
+ if (t.isCallExpression(parentPath) && parentPath.node.callee.name === METHOD_CREATE_ELEMENT) {
+ path.skip()
+ }
+ }
+ },
Identifier (path) {
const name = path.node.name
if (path.key !== 'key' && (path.key !== 'property' || path.parent.computed)) {
- // 使用方法或作用域外数据
+ // 使用作用域内方法或作用域外数据
if (name in ids) {
need = path.key === 'callee' ? true : need
} else if (!path.scope.hasBinding(name) && !METHOD_BUILT_IN.includes(name)) {