diff --git a/src/compiler/error-detector.js b/src/compiler/error-detector.js index 05df8b27d54..778becad8b8 100644 --- a/src/compiler/error-detector.js +++ b/src/compiler/error-detector.js @@ -59,7 +59,7 @@ function checkNode (node: ASTNode, warn: Function) { function checkEvent (exp: string, text: string, warn: Function, range?: Range) { const stripped = exp.replace(stripStringRE, '') const keywordMatch: any = stripped.match(unaryOperatorsRE) - if (keywordMatch && stripped.charAt(keywordMatch.index - 1) !== '$') { + if (keywordMatch && !['$', '.'].includes(stripped.charAt(keywordMatch.index - 1))) { warn( `avoid using JavaScript unary operator as property name: ` + `"${keywordMatch[0]}" in expression ${text.trim()}`, diff --git a/test/unit/features/options/template.spec.js b/test/unit/features/options/template.spec.js index 09aafd3efaa..99019f9b7db 100644 --- a/test/unit/features/options/template.spec.js +++ b/test/unit/features/options/template.spec.js @@ -88,4 +88,13 @@ describe('Options template', () => { `avoid using JavaScript unary operator as property name: "delete()" in expression @click="delete('Delete')"` ).toHaveBeenWarned() }) + + it('warn error in generated function (v-on)', () => { + Vue.prototype.$http = { delete: () => {} }; + new Vue({ + template: `
` + }).$mount(); + expect("Error compiling template").not.toHaveBeenWarned(); + delete Vue.prototype.$http; + }) })