Skip to content

Rename and add options to this-in-template. #163

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

Merged
merged 6 commits into from
Sep 1, 2017

Conversation

armano2
Copy link
Contributor

@armano2 armano2 commented Aug 16, 2017

fixes #148

@armano2 armano2 changed the title Add options to no-this-in-template. Rename and add options to this-in-template. Aug 17, 2017
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

Thank you very much!

Almost looks good to me, but I have some concerns.
Could you take a look?

function validateNever () {
return {
'VExpressionContainer ThisExpression' (node) {
if (options === 'never') {
Copy link
Member

Choose a reason for hiding this comment

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

I think that it should check whether variables which have the same name as the property name.

<template>
    <div v-for="x of xs">
        {{this.x}} <!-- we cannot remove this `this.`. -->
    </div>
</template>

Also, I think that it should check whether the this is MemberExpression#object.

<template>
    <child :parent="this" /> <!-- we cannot remove this `this`. -->
</template>

@mysticatea
Copy link
Member

mysticatea commented Aug 17, 2017

Incidentally, I have improved vue-eslint-parser as having the relationship between variables and references: vuejs/vue-eslint-parser@02579df.

  • Variable#references is an array of references which use the variable. If this is empty, it's an unused variable.
  • Reference#variable is the variable that the reference uses. If this is null, it's global variable or the member of the instance or undefined.

Though, I'm not sure that it helps this rule.

@armano2
Copy link
Contributor Author

armano2 commented Aug 18, 2017

@mysticatea i i like changes with references it can simplify this rule and no-template-shadow

but for now there is infinite loop there: vuejs/vue-eslint-parser#16
https://gist.github.com/armano2/c34068d62fdb190a37e1a43ad0f88faf


suggestions applied

@mysticatea
Copy link
Member

Thank you!

I'm sorry, I have realized one more thing. If property name is a reserved word (e.g. this.class), we cannot remove the this. since it causes syntax errors. Could you add the check into "never"?

@armano2
Copy link
Contributor Author

armano2 commented Aug 19, 2017

@mysticatea check for js reserved names added

@armano2
Copy link
Contributor Author

armano2 commented Aug 19, 2017

additionality i added support for this['0aaaa'] and this['foo-bar bas'] which should not be warned

@armano2
Copy link
Contributor Author

armano2 commented Aug 19, 2017

@mysticatea with latest change to parser, reference variables are no longer there

Sent from my Xiaomi Redmi 4A using FastHub

@mysticatea
Copy link
Member

I'm sorry for late.

additionality i added support for this['0aaaa'] and this['foo-bar bas'] which should not be warned

Good catch!

with latest change to parser, reference variables are no longer there

I think, in fact, console.log() no longer shows Variable#references and Reference#variable since those are non-enumerable properties. But those are still there. Tests exist at vue-eslint-parser/test/variables-references.js#L152-L248.

@mysticatea mysticatea requested a review from michalsnik August 24, 2017 10:21
@mysticatea mysticatea merged commit a73f5e2 into vuejs:master Sep 1, 2017
@michalsnik
Copy link
Member

GJ! I'll release it at the end of this weekend @mysticatea @armano2 . I'm moving to new place, so have quite a lot on my plate lately..

@armano2 armano2 deleted the 148-no-this-in-template-fix branch September 1, 2017 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow this in template
3 participants