-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
feat(compiler): output source range for compiler errors (#6338) #7127
Conversation
This is great! Thanks a lot for the work. Since this is a big PR, it will take some time to properly review. But I hope we can include this in 2.6. |
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.
Thanks for your contribution!
I have seen that most warning code is enclosed in conditional env
block. But it would be better if you can report the new bundle size in the PR.
Great work!
src/compiler/directives/on.js
Outdated
|
||
export default function on (el: ASTElement, dir: ASTDirective) { | ||
if (process.env.NODE_ENV !== 'production' && dir.modifiers) { | ||
warn(`v-on without argument does not support modifiers.`) | ||
warn(`v-on without argument does not support modifiers.`, getRawAttr(el, 'v-on')) |
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.
I might be wrong, but warn
's second parameter seems to accept Vue vm
instance, but getRawAttr
returns AstAttr
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.
You're right, I didn't notice that warn
is different from the one in other files.
} | ||
} | ||
|
||
export function getRawBindingAttr ( |
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.
Can you add a test for getRawBindingAttr
, I mean, <div v-bind:key="wrong-key">
should return an error with :key
's range, even if we call getRawBindingAttr(el, 'key')
.
src/compiler/helpers.js
Outdated
@@ -149,3 +181,18 @@ export function getAndRemoveAttr ( | |||
} | |||
return val | |||
} | |||
|
|||
function setRange ( |
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.
A bit nit-picky, but setRange
implies side-effect, rangeSetItem
might be a better naming.
@@ -22,6 +22,13 @@ function transformNode (el: ASTElement, options: CompilerOptions) { | |||
el.attrsMap[realName] = el.attrsMap[attr.name] | |||
delete el.attrsMap[attr.name] | |||
} | |||
const rawAttrsList = el.rawAttrsList || [] | |||
for (let i = rawAttrsList.length - 1; i >= 0; i--) { |
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.
This is a quadratic time complexity. I wonder if it will impact compile time.
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.
Switched to using an object to track raw attribute info in 5991522
@HerringtonDarkholme I've just enclosed And here are the new bundle size from
|
@gzzhanghao Thanks! Size overhead seems to be acceptable! Thanks again! |
So nice to see this land! Do you know of any effort implementing support for this in |
@lbogdan it already does! (not released yet). But thanks for offering to help! |
@yyx990803 I need to tranfsorm
I'm searching for "something" in ast. When I find "something" I'd like to create output like f.e.:
where For example |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Just like #6764, but will output the range data instead of writing it into the error message. Here's an example of how it works:
https://gist.github.com/gzzhanghao/363fac4a201306f5fccf903e35bc652a