Skip to content

$http.delete shows warning "avoid using JavaScript unary operator as property name" (fix #11090) #11143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/error-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
Expand Down
9 changes: 9 additions & 0 deletions test/unit/features/options/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec name imo should be something like,
"should not warn dot prefixed keywords".

As the warning would appear even on general JS objects with a delete property and not just $http.

Vue.prototype.$http = { delete: () => {} };
new Vue({
template: `<div @click="$http.delete('/endpoint')"></div>`
}).$mount();
expect("Error compiling template").not.toHaveBeenWarned();
delete Vue.prototype.$http;
})
})