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

Commit2d09ee3

Browse files
Hanks10100yyx990803
authored andcommitted
feat($compiler): compile weex native directives in preTransformNode
1 parent9bd1483 commit2d09ee3

File tree

5 files changed

+49
-67
lines changed

5 files changed

+49
-67
lines changed

‎src/compiler/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
2626
conststripParensRE=/^\(|\)$/g
2727

2828
constargRE=/:(.*)$/
29-
constbindRE=/^:|^v-bind:/
29+
exportconstbindRE=/^:|^v-bind:/
3030
constmodifierRE=/\.[^.]+/g
3131

3232
constliteralValueRE=/^(\{.*\}|\[.*\])$/

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ function preTransformNode (el: ASTElement) {
1111
if(el.tag==='recycle-list'){
1212
currentRecycleList=el
1313
}
14+
if(currentRecycleList){
15+
// TODO
16+
transformVBind(el)
17+
transformVIf(el)
18+
transformVFor(el)
19+
}
1420
}
1521

1622
functiontransformNode(el:ASTElement){
1723
if(currentRecycleList){
1824
// TODO
19-
transformVIf(el)
20-
transformVFor(el)
21-
transformVBind(el)
2225
}
2326
}
2427

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
/*@flow */
22

33
import{camelize}from'shared/util'
4-
import{getAndRemoveAttr,addAttr}from'compiler/helpers'
5-
6-
functionisBindingAttr(name:string):boolean{
7-
return/^(v\-bind)?\:/.test(name)
8-
}
4+
import{bindRE}from'compiler/parser/index'
5+
import{getAndRemoveAttr}from'compiler/helpers'
96

107
functionparseAttrName(name:string):string{
11-
returncamelize(name.replace(/^(v\-bind)?\:/,''))
8+
returncamelize(name.replace(bindRE,''))
129
}
1310

1411
exportfunctiontransformVBind(el:ASTElement){
15-
if(!el.attrsList||!el.attrsList.length){
16-
return
17-
}
18-
el.attrsList.forEach(attr=>{
19-
if(isBindingAttr(attr.name)){
20-
constname:string=parseAttrName(attr.name)
21-
constbinding=getAndRemoveAttr(el,attr.name)
22-
addAttr(el,name,{'@binding':binding})
12+
for(constattrinel.attrsMap){
13+
if(bindRE.test(attr)){
14+
constname:string=parseAttrName(attr)
15+
constvalue={
16+
'@binding':getAndRemoveAttr(el,attr)
17+
}
18+
deleteel.attrsMap[attr]
19+
el.attrsMap[name]=value
20+
el.attrsList.push({ name, value})
21+
// addAttr(el, name, value)
22+
// el.hasBindings = false
2323
}
24-
})
25-
el.hasBindings=false
24+
}
2625
}
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
/*@flow */
22

3-
import{addAttr}from'compiler/helpers'
4-
5-
functionisVForAttr(name:string):boolean{
6-
return/^v\-for/.test(name)
7-
}
3+
import{forAliasRE,forIteratorRE}from'compiler/parser/index'
4+
import{getAndRemoveAttr}from'compiler/helpers'
85

96
exportfunctiontransformVFor(el:ASTElement){
10-
for(constattrinel.attrsMap){
11-
if(!isVForAttr(attr)){
12-
continue
13-
}
7+
constexp=getAndRemoveAttr(el,'v-for')
8+
if(!exp){
9+
return
10+
}
11+
constinMatch=exp.match(forAliasRE)
12+
if(inMatch){
13+
constalias=inMatch[1].trim()
1414
constdesc:Object={
15-
'@expression':el.for,
16-
'@alias':el.alias
17-
}
18-
if(el.iterator1){
19-
desc['@index']=el.iterator1
15+
'@expression':inMatch[2].trim(),
16+
'@alias':alias
2017
}
21-
if(el.iterator2){
22-
desc['@key']=el.iterator1
23-
desc['@index']=el.iterator2
18+
constiteratorMatch=alias.match(forIteratorRE)
19+
if(iteratorMatch){
20+
desc['@alias']=iteratorMatch[1].trim()
21+
desc['@index']=iteratorMatch[2].trim()
22+
if(iteratorMatch[3]){
23+
desc['@key']=iteratorMatch[2].trim()
24+
desc['@index']=iteratorMatch[3].trim()
25+
}
2426
}
25-
addAttr(el,'[[repeat]]',desc)
27+
deleteel.attrsMap['v-for']
2628
el.attrsMap['[[repeat]]']=desc
2729
el.attrsList.push({name:'[[repeat]]',value:desc})
28-
deleteel.attrsMap[attr]
29-
deleteel.for
30-
deleteel.alias
31-
deleteel.key
32-
deleteel.iterator1
33-
deleteel.iterator2
3430
}
3531
}
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
/*@flow */
22

3-
import{getAndRemoveAttr,addAttr}from'compiler/helpers'
4-
5-
functionisConditionAttr(name:string):boolean{
6-
return/^v\-if|v\-else|v\-else\-if/.test(name)
7-
}
3+
import{getAndRemoveAttr}from'compiler/helpers'
84

95
exportfunctiontransformVIf(el:ASTElement){
10-
for(constattrinel.attrsMap){
11-
if(!isConditionAttr(attr)){
12-
continue
13-
}
14-
constbinding=getAndRemoveAttr(el,attr)
15-
switch(attr){
16-
case'v-if':{
17-
addAttr(el,'[[match]]',binding)
18-
el.attrsMap['[[match]]']=binding
19-
el.attrsList.push({name:'[[match]]',value:binding})
20-
deleteel.attrsMap[attr]
21-
deleteel.if
22-
deleteel.ifConditions
23-
break
24-
}
25-
26-
// TODO: support v-else and v-else-if
27-
}
6+
constexp=getAndRemoveAttr(el,'v-if')
7+
if(exp){
8+
el.attrsMap['[[match]]']=exp
9+
el.attrsList.push({name:'[[match]]',value:exp})
10+
deleteel.attrsMap['v-if']
2811
}
12+
// TODO: support v-else and v-else-if
2913
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp