-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compile): supports compiling v-if to the weex native directive
- Loading branch information
1 parent
8b893c1
commit 7ad368e
Showing
4 changed files
with
42 additions
and
16 deletions.
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
19 changes: 7 additions & 12 deletions
19
src/platforms/weex/compiler/modules/recycle-list/v-bind.js
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,31 +1,26 @@ | ||
/* @flow */ | ||
|
||
import { camelize } from 'shared/util' | ||
import { getAndRemoveAttr, addAttr } from 'compiler/helpers' | ||
|
||
function isBindingAttr (name) { | ||
function isBindingAttr (name: string): boolean { | ||
return /^(v\-bind)?\:/.test(name) | ||
} | ||
|
||
function parseRealName (name: string): string { | ||
return name.replace(/^(v\-bind)?\:/, '') | ||
function parseAttrName (name: string): string { | ||
return camelize(name.replace(/^(v\-bind)?\:/, '')) | ||
} | ||
|
||
export function transformVBind (el: ASTElement) { | ||
if (!el.attrsList.length) { | ||
if (!el.attrsList || !el.attrsList.length) { | ||
return | ||
} | ||
el.attrsList.forEach(attr => { | ||
// console.log('is binding attr:', attr.name, isBindingAttr(attr.name)) | ||
if (isBindingAttr(attr.name)) { | ||
const realName: string = parseRealName(attr.name) | ||
const name: string = parseAttrName(attr.name) | ||
const binding = getAndRemoveAttr(el, attr.name) | ||
if (el.attrs) { | ||
el.attrs = el.attrs.filter(at => at.name !== realName) // omit duplicated | ||
} | ||
getAndRemoveAttr(el, realName) | ||
addAttr(el, realName, { '@binding': binding }) | ||
addAttr(el, name, { '@binding': binding }) | ||
} | ||
}) | ||
el.hasBindings = false | ||
// el.plain = true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* @flow */ | ||
|
||
import { getAndRemoveAttr, addAttr } from 'compiler/helpers' | ||
|
||
function isConditionAttr (name: string): boolean { | ||
return /^v\-if|v\-else|v\-else\-if/.test(name) | ||
} | ||
|
||
export function transformVIf (el: ASTElement) { | ||
for (const attr in el.attrsMap) { | ||
if (!isConditionAttr(attr)) { | ||
continue | ||
} | ||
const binding = getAndRemoveAttr(el, attr) | ||
switch (attr) { | ||
case 'v-if': { | ||
addAttr(el, '[[match]]', binding) | ||
el.attrsMap['[[match]]'] = binding | ||
el.attrsList.push({ name: '[[match]]', value: binding }) | ||
delete el.attrsMap[attr] | ||
delete el.if | ||
delete el.ifConditions | ||
break | ||
} | ||
|
||
// TODO: support v-else and v-else-if | ||
} | ||
} | ||
} |