Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit2a1ce0d

Browse files
Hanks10100yyx990803
authored andcommitted
feat($compiler): supports compiling v-else-if and v-else to the weex native directive
1 parent2d09ee3 commit2a1ce0d

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

‎src/platforms/weex/compiler/modules/recycle-list/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { transformVFor } from './v-for'
77

88
letcurrentRecycleList=null
99

10-
functionpreTransformNode(el:ASTElement){
10+
functionpreTransformNode(el:ASTElement,options:CompilerOptions){
1111
if(el.tag==='recycle-list'){
1212
currentRecycleList=el
1313
}
1414
if(currentRecycleList){
1515
// TODO
1616
transformVBind(el)
17-
transformVIf(el)
18-
transformVFor(el)
17+
transformVIf(el,options)// and v-else-if and v-else
18+
transformVFor(el,options)
1919
}
2020
}
2121

‎src/platforms/weex/compiler/modules/recycle-list/v-for.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import{forAliasRE,forIteratorRE}from'compiler/parser/index'
44
import{getAndRemoveAttr}from'compiler/helpers'
55

6-
exportfunctiontransformVFor(el:ASTElement){
6+
exportfunctiontransformVFor(el:ASTElement,options:CompilerOptions){
77
constexp=getAndRemoveAttr(el,'v-for')
88
if(!exp){
99
return
@@ -27,5 +27,7 @@ export function transformVFor (el: ASTElement) {
2727
deleteel.attrsMap['v-for']
2828
el.attrsMap['[[repeat]]']=desc
2929
el.attrsList.push({name:'[[repeat]]',value:desc})
30+
}elseif(process.env.NODE_ENV!=='production'&&options.warn){
31+
options.warn(`Invalid v-for expression:${exp}`)
3032
}
3133
}

‎src/platforms/weex/compiler/modules/recycle-list/v-if.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,47 @@
22

33
import{getAndRemoveAttr}from'compiler/helpers'
44

5-
exportfunctiontransformVIf(el:ASTElement){
6-
constexp=getAndRemoveAttr(el,'v-if')
7-
if(exp){
5+
functionhasConditionDirective(el:ASTElement):boolean{
6+
for(constattrinel.attrsMap){
7+
if(/^v\-if|v\-else|v\-else\-if$/.test(attr)){
8+
returntrue
9+
}
10+
}
11+
returnfalse
12+
}
13+
14+
functiongetPrevMatch(el:ASTElement):any{
15+
if(el.parent&&el.parent.children){
16+
constprev:Object=el.parent.children[el.parent.children.length-1]
17+
returnprev.attrsMap['[[match]]']
18+
}
19+
}
20+
21+
exportfunctiontransformVIf(el:ASTElement,options:CompilerOptions){
22+
if(hasConditionDirective(el)){
23+
letexp
24+
constifExp=getAndRemoveAttr(el,'v-if')
25+
constelseifExp=getAndRemoveAttr(el,'v-else-if')
26+
if(ifExp){
27+
exp=ifExp
28+
}else{
29+
constprevMatch=getPrevMatch(el)
30+
if(prevMatch){
31+
exp=elseifExp
32+
?`!(${prevMatch}) && (${elseifExp})`// v-else-if
33+
:`!(${prevMatch})`// v-else
34+
}elseif(process.env.NODE_ENV!=='production'&&options.warn){
35+
options.warn(
36+
`v-${elseifExp ?('else-if="'+elseifExp+'"') :'else'} `+
37+
`used on element <${el.tag}> without corresponding v-if.`
38+
)
39+
return
40+
}
41+
}
842
el.attrsMap['[[match]]']=exp
943
el.attrsList.push({name:'[[match]]',value:exp})
1044
deleteel.attrsMap['v-if']
45+
deleteel.attrsMap['v-else-if']
46+
deleteel.attrsMap['v-else']
1147
}
12-
// TODO: support v-else and v-else-if
1348
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp