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.
这里修复以下几个问题:
但是这里的处理有问题:
一是在解析v-for指令的时候,没有保存iterator1和iterator2,所以这里用到的iterator1和iterator2是没有意义的。看了vue的源码之后,其实源码在解析v-for时是有解析iterator1和iterator2的,作者应该是想降低复杂度,从简处理了。所以相应的,这里的iterator1和iterator2其实可以删除。
二是作者的processFor处理漏掉了一种情况,即alias是带括号的情况。举例:v-for="(val, key, idx) in data"时,作者的alias匹配得到的是(val, key, idx),代入genFor中,得到的代码块就成了function((val, key, idx)),这就出错了。所以可以在作者的基础之上用正则去掉alias中的括号即可。
genChildren的返回值应该是一个数组的字符串,而不是join(',')之后的字符串。原来的处理会更改了_c的传参,影响到children后面的参数。
genElement最后生成的code中,第一个逗号位置错了,后面的class最好用引号括起来,在es6中是关键字,导致编译出错。