-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Type checking for template expressions #681
Merged
Merged
Changes from 23 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
e98740d
Move script mode integration test
ktsn e4b1549
Provide diagnostics for template by using type info
ktsn dc9d8c1
[wip] template diagnostics
ktsn 912b134
Use vue-eslint-parser
ktsn a68726e
transform vue-eslint-parser ast to ts ast
ktsn a66b78c
format codes
ktsn a10d492
template diagnostics provide correct error positions
ktsn 6865c30
Inject this expression for template identifiers
ktsn 34a58dc
check v-for expression
ktsn 3b852e4
remove global scope test of injectThis
ktsn de2e859
fix the position of v-for expression
ktsn c6a38a0
rewrite template render function
ktsn b90f96a
Avoid parsing error of script block
ktsn 1f02005
Handle object literal expression properly
ktsn deaa8a7
Move template type checking fixtures
ktsn 68b8200
Process template code as JS to avoid unnecessary errors
ktsn 6fc1e52
Handle v-on statement properly
ktsn 60562ef
Extract common logic of template checking test
ktsn 3138243
Refactoring transformTemplate
ktsn 7696040
Remove unused @types/estree
ktsn b7a805b
Use component constructor directly in generated template ts code
ktsn a8ef51e
Bump Vue typings for testing
ktsn 0c97e75
Remove unused packages
ktsn 1642733
Rename internal template helpers
ktsn ce43c75
Simplify v-on transformation
ktsn 55191cb
Merge branch 'master' into template-type-checking
ktsn bd98089
Merge remote-tracking branch 'upstream/master' into template-type-che…
ktsn 9f5304d
Merge remote-tracking branch 'upstream/master' into template-type-che…
ktsn f2f3236
support literal iteration of v-for
ktsn bca4ad4
add a flag to control template type check
ktsn 5d6d62f
inject 'this' to expressions in template expression
ktsn 0fd53f0
check array literal expression
ktsn 0542c1a
bump vue-eslint-parser
ktsn 653bf3d
enable noImplicitAny on template region
ktsn aabba0f
avoid duplicated identifier error when no script block
ktsn 31d88bf
allow to put normal class/style and v-bind ones on the same element
ktsn bec63eb
check directive expression
ktsn 71fd337
add test case of directive check
ktsn 4e73004
Merge remote-tracking branch 'upstream/master' into template-type-che…
ktsn b8be711
inject this value to ElementAccessExpression
ktsn 889d1ce
inject this to computed property name of object literal
ktsn 39c807b
Various improvements for template type checking
octref 30ddc84
Merge remote-tracking branch 'origin/ktsn-types' into HEAD
octref e26d5d9
Small cleanup
octref 79dc034
:lipstick:
octref ef7978a
Fix some failing tests
octref c143dfa
handle VExpressionContainer of dynamic directive argument
ktsn d0713d1
Support dynamic argument of directive
ktsn eff560a
Fix broken v-on template diagnostic test
ktsn f428765
Simplify special attribute check
ktsn 2923e08
Skip v-slot check to avoid false-positive error
ktsn 96797c0
Fix typo
ktsn de998c6
Merge remote-tracking branch 'origin/master' into template-type-checking
octref 532074a
Update comment
ktsn ab4a5cc
Fix createLiteral argument to correct value
ktsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import { renderHelperName, componentHelperName, iterationHelperName } from './transformTemplate'; | ||
|
||
// this bridge file will be injected into TypeScript service | ||
// it enable type checking and completion, yet still preserve precise option type | ||
|
||
export const moduleName = 'vue-editor-bridge'; | ||
|
||
export const fileName = 'vue-temp/vue-editor-bridge.ts'; | ||
|
||
const renderHelpers = ` | ||
export declare const ${renderHelperName}: { | ||
<T>(Component: (new (...args: any[]) => T), fn: (this: T) => any): any; | ||
}; | ||
export declare const ${componentHelperName}: { | ||
(tag: string, data: any, children: any[]): any; | ||
}; | ||
export declare const ${iterationHelperName}: { | ||
<T>(list: T[], fn: (value: T, index: number) => any): any; | ||
<T>(obj: { [key: string]: T }, fn: (value: T, key: string, index: number) => any): any; | ||
<T>(obj: object, fn: (value: any, key: string, index: number) => any): any; | ||
}; | ||
`; | ||
|
||
export const oldContent = ` | ||
import Vue from 'vue'; | ||
export interface GeneralOption extends Vue.ComponentOptions<Vue> { | ||
[key: string]: any; | ||
} | ||
export default function bridge<T>(t: T & GeneralOption): T { | ||
return t; | ||
}`; | ||
} | ||
` + renderHelpers; | ||
|
||
export const content = ` | ||
import Vue from 'vue'; | ||
const func = Vue.extend; | ||
export default func; | ||
`; | ||
` + renderHelpers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can implement parsing in VLS at all, so no additional dependency/script is needed. Actually template completion needs it too.
But I don't have time to implement Vue specific elements 😞 . For now eslint-parser is the only option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I actually tried to extend the parser in VLS on the first time but I ended up using vue-eslint-parser because I would like to focus finishing essential implementation of template type checking at first.
In that case, I can work on the VSL template parser after this PR is finished 🙂