提交 92118e1e 编写于 作者: Q qiang

Merge branch 'dev' of github.com:dcloudio/uni-app into dev

...@@ -201,6 +201,10 @@ const third = [ ...@@ -201,6 +201,10 @@ const third = [
'setPageMeta' 'setPageMeta'
] ]
const ad = [
'createRewardedVideoAd'
]
const apis = [ const apis = [
...base, ...base,
...network, ...network,
...@@ -214,7 +218,8 @@ const apis = [ ...@@ -214,7 +218,8 @@ const apis = [
...event, ...event,
...file, ...file,
...canvas, ...canvas,
...third ...third,
...ad
] ]
module.exports = apis module.exports = apis
...@@ -206,4 +206,10 @@ ...@@ -206,4 +206,10 @@
"uni.base64ToArrayBuffer": true, "uni.base64ToArrayBuffer": true,
"uni.arrayBufferToBase64": true "uni.arrayBufferToBase64": true
} }
}, {
"name": "ad",
"title": "广告",
"apiList": {
"uni.createRewardedVideoAd": true
}
}] }]
...@@ -18,10 +18,10 @@ const defaultAsync = { ...@@ -18,10 +18,10 @@ const defaultAsync = {
} }
const networkTimeout = { const networkTimeout = {
request: 6000, request: 60000,
connectSocket: 6000, connectSocket: 60000,
uploadFile: 6000, uploadFile: 60000,
downloadFile: 6000 downloadFile: 60000
} }
function getManifestJson () { function getManifestJson () {
......
...@@ -136,6 +136,12 @@ describe('codegen', () => { ...@@ -136,6 +136,12 @@ describe('codegen', () => {
'<view data-a="1" :data-b="b"></view>', '<view data-a="1" :data-b="b"></view>',
`with(this){return _c('view',{attrs:{"data-b":_$s(0,'a-data-b',b),"_i":0}})}` `with(this){return _c('view',{attrs:{"data-b":_$s(0,'a-data-b',b),"_i":0}})}`
) )
})
it('generate v-if directive', () => {
assertCodegen(
'<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>',
`with(this){return (_$s(0,'i',a))?_c('text'):(_$s(1,'e',b))?_c('text'):(_$s(2,'e',c))?_c('text'):_c('text')}`
)
}) })
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -75,6 +75,12 @@ describe('codegen', () => { ...@@ -75,6 +75,12 @@ describe('codegen', () => {
'<view data-a="1" :data-b="b"></view>', '<view data-a="1" :data-b="b"></view>',
`with(this){return _c('v-uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}` `with(this){return _c('v-uni-view',{attrs:{"data-a":"1","data-b":_$g(0,'a-data-b'),"_i":0}})}`
) )
})
it('generate v-if directive', () => {
assertCodegen(
'<text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>',
`with(this){return (_$g(0,'i'))?_c('v-uni-text',{attrs:{"_i":0}},[_v("1")]):(_$g(1,'e'))?_c('v-uni-text',{attrs:{"_i":1}},[_v("2")]):(_$g(2,'e'))?_c('v-uni-text',{attrs:{"_i":2}},[_v("3")]):_c('v-uni-text',{attrs:{"_i":3}},[_v("d")])}`
)
}) })
}) })
/* eslint-enable quotes */ /* eslint-enable quotes */
...@@ -141,14 +141,14 @@ describe('codegen', () => { ...@@ -141,14 +141,14 @@ describe('codegen', () => {
it('generate v-model directive', () => { it('generate v-model directive', () => {
assertCodegen( assertCodegen(
'<input v-model="test">', '<input v-model="test">',
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:_$g(0,'v-model'),callback:function(){},expression:"test"}})}` `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:_$g(0,'v-model'),callback:function($$v){$handleVModelEvent(0,$$v)},expression:"test"}})}`
) )
}) })
it('generate multiline v-model directive', () => { it('generate multiline v-model directive', () => {
assertCodegen( assertCodegen(
'<input v-model="\n test \n">', '<input v-model="\n test \n">',
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:_$g(0,'v-model'),callback:function(){},expression:"\\n test \\n"}})}` `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:_$g(0,'v-model'),callback:function($$v){$handleVModelEvent(0,$$v)},expression:"\\n test \\n"}})}`
) )
}) })
......
...@@ -18,13 +18,8 @@ const scopedPath = path.resolve(__dirname, '../../') ...@@ -18,13 +18,8 @@ const scopedPath = path.resolve(__dirname, '../../')
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<view class="h-page"> <text v-if="a">1</text><text v-else-if="b">2</text><text v-else-if="c">3</text><text v-else>d</text>
<slot></slot>
<h-dialog></h-dialog>
<h-navbar></h-navbar>
<h-toast></h-toast>
</view>
`, { `, {
miniprogram: true, miniprogram: true,
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
...@@ -37,9 +32,9 @@ const res = compiler.compile( ...@@ -37,9 +32,9 @@ const res = compiler.compile(
mp: { mp: {
platform: 'mp-weixin' platform: 'mp-weixin'
}, },
filterModules: ['swipe'] filterModules: ['swipe'],
// service: true, // service: true,
// view: true view: true
}) })
console.log(require('util').inspect(res, { console.log(require('util').inspect(res, {
......
...@@ -18,6 +18,10 @@ function parseIs (el, genVar) { ...@@ -18,6 +18,10 @@ function parseIs (el, genVar) {
} }
} }
function isProcessed (exp) {
return String(exp).indexOf('_$') === 0
}
// 当根节点是由if,elseif,else组成,会调用多次parseIf来解析root
function parseIf (el, createGenVar, isScopedSlot) { function parseIf (el, createGenVar, isScopedSlot) {
if (!el.if) { if (!el.if) {
return return
...@@ -26,11 +30,13 @@ function parseIf (el, createGenVar, isScopedSlot) { ...@@ -26,11 +30,13 @@ function parseIf (el, createGenVar, isScopedSlot) {
isScopedSlot = false isScopedSlot = false
} }
el.ifConditions.forEach(con => { el.ifConditions.forEach(con => {
if (isVar(con.exp)) { if (!isProcessed(con.exp) && isVar(con.exp)) {
con.exp = createGenVar(con.block.attrsMap[ID], isScopedSlot)(con.block.elseif ? V_ELSE_IF : V_IF, con.exp) con.exp = createGenVar(con.block.attrsMap[ID], isScopedSlot)(con.block.elseif ? V_ELSE_IF : V_IF, con.exp)
} }
}) })
el.if = createGenVar(el.attrsMap[ID], isScopedSlot)(V_IF, el.if) if (!isProcessed(el.if)) {
el.if = createGenVar(el.attrsMap[ID], isScopedSlot)(V_IF, el.if)
}
} }
function parseFor (el, createGenVar, isScopedSlot, fill = false) { function parseFor (el, createGenVar, isScopedSlot, fill = false) {
......
...@@ -156,6 +156,11 @@ function transformNode (el, parent, state, isScopedSlot) { ...@@ -156,6 +156,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function postTransformNode (el, options) { function postTransformNode (el, options) {
if (!el.parent) { // 从根节点开始递归处理 if (!el.parent) { // 从根节点开始递归处理
if (options.root) { // 当根节点是由if,elseif,else组成
parseIf(options.root, createGenVar)
} else {
options.root = el
}
traverseNode(el, false, { traverseNode(el, false, {
forIteratorId: 0, forIteratorId: 0,
transformNode, transformNode,
......
...@@ -155,6 +155,11 @@ function transformNode (el, parent, state, isScopedSlot) { ...@@ -155,6 +155,11 @@ function transformNode (el, parent, state, isScopedSlot) {
function postTransformNode (el, options) { function postTransformNode (el, options) {
if (!el.parent) { // 从根节点开始递归处理 if (!el.parent) { // 从根节点开始递归处理
if (options.root) { // 当根节点是由if,elseif,else组成
parseIf(options.root, createGenVar)
} else {
options.root = el
}
traverseNode(el, false, { traverseNode(el, false, {
forIteratorId: 0, forIteratorId: 0,
transformNode, transformNode,
...@@ -235,4 +240,4 @@ module.exports = { ...@@ -235,4 +240,4 @@ module.exports = {
}, },
postTransformNode, postTransformNode,
genData genData
} }
此差异已折叠。
此差异已折叠。
...@@ -69,3 +69,5 @@ export { ...@@ -69,3 +69,5 @@ export {
export * from './ui/tab-bar' export * from './ui/tab-bar'
export * from './ui/request-component-info' export * from './ui/request-component-info'
export * from './ad/rewarded-video-ad'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册