Skip to content
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

Template Interpolation Issue - First letter not recognized in event variable assignment #1319

Closed
xon52 opened this issue Jun 6, 2019 · 26 comments

Comments

@xon52
Copy link

xon52 commented Jun 6, 2019

Info

  • Platform: Win
  • Vetur version: 0.21.0
  • VS Code version: 1.35.0

Problem

When entering a data property into an event, it ignores the first letter and so persistently reports that the property does not exist. This error can be removed by surrounding the statement in curly brackets, but that creates a bigger Vue error.
vetur issue

Reproducible Case

Turn Template Interpolation Service on and write the following code:

<template>
	<span @click="eg = true">Test</span>
</template>

<script>
export default {
	data() {
		return {
			eg: false
		}
	}
}
</script>
@ktsn
Copy link
Member

ktsn commented Jun 15, 2019

I just copied & pasted your reproducible case but cannot reproduce on my local. Could you provide full contained repro by cloning and modifying Veturpack?

@xon52
Copy link
Author

xon52 commented Jun 15, 2019

So using a Veturpack repo I could not reproduce the issue above. Then I tried my example above again and I didn't have the issue anymore. Then I tried everything I could do to get that error in a new project and couldn't... So probably another interaction issue. Not really sure how else to test.

However, incase this does come up later, I have made a couple more observations.

The issue above can be removed in a couple ways:

  1. If the @click property is modified using Event Modifiers
  2. If there are multiple properties for the element, and you include one or more on the same line as the @click:
    Screenshot_1

Both are really strange, so I hope you can see a link between those observations and the vetur code I don't!

@ktsn
Copy link
Member

ktsn commented Jun 15, 2019

That's weird... Even there is multi-lined attribute element, its v-on handler works fine for me.

By the way, what can you see when you execute a command Vetur: show corresponding virtual file and source map? (please copy and paste the result)

@xon52
Copy link
Author

xon52 commented Jun 16, 2019

OK I found the command vetur.showCorrespondingVirtualFile... But just for fun let's pretend I don't know how to run that command - how would I do that?

@ktsn
Copy link
Member

ktsn commented Jun 16, 2019

Open command palette (by Ctrl + Shif + P), and type search word (e.g. vetur virtual). Then the command will be suggested on Editor, then click it or press enter.
Screenshot 2019-06-16 at 9 06 12 AM

@xon52
Copy link
Author

xon52 commented Jun 16, 2019

Thanks. Unfortunately, doesn't say much:
Screenshot_1

@ekulabuhov
Copy link

Hey! I've a similar issue. Both SourceMap and compiled version shows broken variable name:
image

Is there anything else I could do to help diagnose the problem?

@imdbere
Copy link

imdbere commented Jul 23, 2019

I have the exact same problem. Would be happy to help if there is any additional information i could provide

@ktsn
Copy link
Member

ktsn commented Jul 30, 2019

This may be solved by this PR #1335

@rille111
Copy link

Still same problem. Using vuetify. Doesnt seem to be the same problems in other projects, weirdly enough.

@chartinger
Copy link

chartinger commented Jan 13, 2020

I have the same problem. Running test:int (Windows 10, node 12.13.1, yarn 1.21.1, VSCode used by testrunner 1.41.1) on commit 26ab1b0 correctly results in a failed test in 1) Shows template diagnostics for v-on.vue:

1 failing                                                                                                  
1) Should find template-diagnostics in <template> region                                                   
     Shows template diagnostics for v-on.vue:                                                              
                                                                                                           
    AssertionError [ERR_ASSERTION]: Expected diagnostics length is not same as actual diagnostics one      
    + expected - actual                                                                                    
                                                                                                           
    -4                                                                                                     
    +7 

The 3 extra errors seem to be the "off-by-first character" errors. (They are shown when opening the file with the my "normal" VSCode)

Edit: expected and actual are in the wrong order (https://github.com/vuejs/vetur/blob/master/test/interpolation/diagnostics/helper.ts#L17)

@chartinger
Copy link

chartinger commented Jan 14, 2020

The problem is related to the configured line endings. Switching VS Code to LF and it works as expected, CRLF results in the error.

@octref
Copy link
Member

octref commented Feb 14, 2020

@octref
Copy link
Member

octref commented Feb 14, 2020

vuejs/vue-eslint-parser#59 is the upstream issue. expression is off by 1 when using CRLF.

I can only suggest using LF now, I don't have a whole afternoon to dive into the eslint parser...

@sethidden
Copy link
Contributor

I tried to force LF in a project I was setting up at work and it's problematic. Mainly because Git will by default change line endings to CRLF on Windows even if they were saved as LF during cloning the repo.

I haven't been able to override these Git settings using a config file commited to the repo (eg. .gitattributes). It's supposedly possible to do git config --global core.eol lf but telling every developer after cloning the project "yeah just do git config --global core.eol lf or else prettier will be complaining to you" is a pain

@octref octref added the upstream label Jun 7, 2020
@octref
Copy link
Member

octref commented Jun 7, 2020

Waiting for the upstream PR: vuejs/vue-eslint-parser#74

@lanyizi
Copy link

lanyizi commented Aug 23, 2020

Before upstream fixes this, another workaround could be wrapping the assignment in a function.
This is useful when you do want to keep each event on its own line to keep readability (or if your auto formatter does this)
The insertion of code (which causes this issue) only happens when the attribute value is a statement, and vue-eslint-parser will try to insert void function($event){ and then recalculate (a presumably wrong) offset, which will then cause the issue.

If you don't want to write a dedicated vue method for your statement, you can wrap your statement inside a lambda, for example

<span
  @click="() => eg = false"
/>

@stevenarm
Copy link

stevenarm commented Oct 4, 2020

I have this issue as well. Would be happy to help or post code if needed. I am Vetur v0.28.0 and VS Code 1.49.3

@octref
Copy link
Member

octref commented Oct 6, 2020

I'll merge vuejs/vue-eslint-parser#74 to my branch and publish it, so I can depend on it.

@ota-meshi Thanks for your work! Do you think we can keep a fork active together until @mysticatea is less busy and can get back to vue-eslint-parser?

@octref
Copy link
Member

octref commented Oct 7, 2020

Does this still repro for you? I cannot repro in latest version. CI cannot detect this error as well:

https://github.com/vuejs/vetur/runs/1218328035

This file with CRLF: https://github.com/vuejs/vetur/blob/1319/test/interpolation/fixture/diagnostics/crlf/crlf.vue

Triggers this error:

[
  {
    "severity": "Error",
    "message": "Property 'egg' does not exist on type 'CombinedVueInstance<Record<never, any> & Vue, object, object, object, Record<never, any>>'.",
    "range": [
      {
        "line": 1,
        "character": 16
      },
      {
        "line": 1,
        "character": 19
      }
    ],
    "source": "Vetur",
    "code": 2339
  }
]

@ota-meshi
Copy link
Member

ota-meshi commented Oct 7, 2020

Do you think we can keep a fork active together

@octref Sure.
And I'm actually contacting him via Discord now and waiting for his reply.

@ota-meshi
Copy link
Member

I was able to contact him.
Then, I merged and released a fix for the CRLF issue.

https://www.npmjs.com/package/vue-eslint-parser/v/7.1.1
https://github.com/mysticatea/vue-eslint-parser/releases/tag/v7.1.1

This is my first release so please let me know if you have any issues.

@octref octref closed this as completed in 062d747 Oct 12, 2020
@octref
Copy link
Member

octref commented Oct 12, 2020

@ota-meshi Thanks a ton! I pulled it in and it works great during my test. Thanks for reviving vue-eslint-parser.

@bestickley
Copy link

bestickley commented Oct 14, 2020

I'm still having an issue with this.

  • Vetur 0.28.0
    Related node modules:
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "^4.4.1",
    "@vue/cli-plugin-babel": "^4.5.7",
    "@vue/cli-plugin-eslint": "^4.5.7",
    "@vue/cli-plugin-typescript": "^4.5.7",
    "@vue/cli-plugin-unit-jest": "^4.5.7",
    "@vue/cli-service": "^4.5.7",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^7.0.0",
    "@vue/test-utils": "^1.1.0",
    "eslint": "^7.11.0",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-vue": "^7.0.1",

image

@yoyo930021
Copy link
Member

yoyo930021 commented Oct 15, 2020

I'm still having an issue with this.

  • Vetur 0.28.0
    Related node modules:
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "^4.4.1",
    "@vue/cli-plugin-babel": "^4.5.7",
    "@vue/cli-plugin-eslint": "^4.5.7",
    "@vue/cli-plugin-typescript": "^4.5.7",
    "@vue/cli-plugin-unit-jest": "^4.5.7",
    "@vue/cli-service": "^4.5.7",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^7.0.0",
    "@vue/test-utils": "^1.1.0",
    "eslint": "^7.11.0",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-vue": "^7.0.1",

image

This fix is not release now.

@stvoidmain
Copy link

Before upstream fixes this, another workaround could be wrapping the assignment in a function.
This is useful when you do want to keep each event on its own line to keep readability (or if your auto formatter does this)
The insertion of code (which causes this issue) only happens when the attribute value is a statement, and vue-eslint-parser will try to insert void function($event){ and then recalculate (a presumably wrong) offset, which will then cause the issue.

If you don't want to write a dedicated vue method for your statement, you can wrap your statement inside a lambda, for example

<span
  @click="() => eg = false"
/>

Using a lambda work nicely to avoid the error and keep readability, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests