Skip to content

Commit c0da43d

Browse files
committed
fix incorrect compiler warning for $delete usage in templates (fix vuejs#5464)
1 parent af43862 commit c0da43d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/compiler/error-detector.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ function checkNode (node: ASTNode, errors: Array<string>) {
5757
}
5858

5959
function checkEvent (exp: string, text: string, errors: Array<string>) {
60-
const keywordMatch = exp.replace(stripStringRE, '').match(unaryOperatorsRE)
61-
if (keywordMatch) {
60+
const stipped = exp.replace(stripStringRE, '')
61+
const keywordMatch: any = stipped.match(unaryOperatorsRE)
62+
if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
6263
errors.push(
6364
`avoid using JavaScript unary operator as property name: ` +
6465
`"${keywordMatch[0]}" in expression ${text.trim()}`

test/unit/features/options/template.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ describe('Options template', () => {
6161
expect('avoid using JavaScript keyword as property name: "do" in expression {{ do + 1 }}').toHaveBeenWarned()
6262
})
6363

64+
it('should not warn $ prefixed keywords', () => {
65+
new Vue({
66+
template: `<div @click="$delete(foo, 'bar')"></div>`
67+
}).$mount()
68+
expect('avoid using JavaScript keyword as property name').not.toHaveBeenWarned()
69+
})
70+
6471
it('warn error in generated function (v-for)', () => {
6572
new Vue({
6673
template: '<div><div v-for="(1, 2) in a----"></div></div>'

0 commit comments

Comments
 (0)