提交 b8f8859a 编写于 作者: Q qiang

fix(mp): template with global Identifier

上级 757f34b5
......@@ -860,6 +860,11 @@ describe('mp:compiler-extra', () => {
'<button type="primary" data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" bindtap="__e">click me</button>',
'with(this){if(!_isMounted){e0=function($event){click1();obj.click2()}}}'
)
assertCodegen(
'<button type="primary" @click="()=>test(encodeURIComponent(JSON.stringify(arr)))">click me</button>',
'<button type="primary" data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" bindtap="__e">click me</button>',
'with(this){if(!_isMounted){e0=()=>test(encodeURIComponent(JSON.stringify(arr)))}}'
)
})
it('generate bool attr', () => {
assertCodegen(
......
......@@ -43,7 +43,20 @@ const ALLOWED_GLOBAL_OBJECT = [
'Set',
'JSON',
'Intl',
'console'
'console',
'Infinity',
'undefined',
'NaN',
'isFinite',
'isNaN',
'parseFloat',
'parseInt',
'decodeURI',
'decodeURIComponent',
'encodeURI',
'encodeURIComponent',
'require',
'arguments'
]
module.exports = {
......
......@@ -8,7 +8,8 @@ const {
ATTR_DATA_EVENT_OPTS,
ATTR_DATA_EVENT_PARAMS,
INTERNAL_SET_SYNC,
INTERNAL_SET_MODEL
INTERNAL_SET_MODEL,
ALLOWED_GLOBAL_OBJECT
} = require('../../../constants')
const {
......@@ -402,7 +403,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
const scope = path.scope
const node = path.node
const name = node.name
if (isValuePath(path) && scope && !scope.hasOwnBinding(name) && scope.hasBinding(name) && !params.includes(name) && name !== 'undefined') {
if (!ALLOWED_GLOBAL_OBJECT.includes(name) && isValuePath(path) && scope && !scope.hasOwnBinding(name) && scope.hasBinding(name) && !params.includes(name) && name !== 'undefined') {
params.push(name)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册