0&&(n.currentTime=t)});var a=["canplay","play","pause","ended","timeUpdate","error","waiting","seeking","seeked"],u=["pause","seeking","seeked","timeUpdate"];a.forEach(function(t){n.addEventListener(t.toLowerCase(),function(){e._stoping&&u.indexOf(t)>=0||e._events["on".concat(t.substr(0,1).toUpperCase()).concat(t.substr(1))].forEach(function(t){t()})},!1)})}return a(t,[{key:"play",value:function(){this._stoping=!1,this._audio.play()}},{key:"pause",value:function(){this._audio.pause()}},{key:"stop",value:function(){this._stoping=!0,this._audio.pause(),this._audio.currentTime=0,this._events.onStop.forEach(function(t){t()})}},{key:"seek",value:function(t){this._stoping=!1,t=Number(t),"number"!==typeof t||isNaN(t)||(this._audio.currentTime=t)}},{key:"destroy",value:function(){this.stop()}}]),t}();function h(){return new l}c.forEach(function(t){l.prototype[t]=function(e){"function"===typeof e&&this._events[t].push(e)}}),u.forEach(function(t){l.prototype[t]=function(e){var n=this._events[t.replace("off","on")],i=n.indexOf(e);i>=0&&n.splice(i,1)}})},fa1e:function(t,e,n){"use strict";function i(){var t=document.activeElement;!t||"TEXTAREA"!==t.tagName&&"INPUT"!==t.tagName||t.blur()}n.r(e),n.d(e,"hideKeyboard",function(){return i})},fa89:function(t,e,n){},fae3:function(t,e,n){"use strict";var i;(n.r(e),"undefined"!==typeof window)&&(n("f6fd"),(i=window.document.currentScript)&&(i=i.src.match(/(.+\/)[^\/]+\.js(\?.*)?$/))&&(n.p=i[1]));n("2ef3")},fb61:function(t,e,n){"use strict";var i=n("90c9"),r=n.n(i);r.a},fcd1:function(t,e,n){"use strict";n.r(e),n.d(e,"setTabBarItem",function(){return c}),n.d(e,"setTabBarStyle",function(){return u}),n.d(e,"hideTabBar",function(){return l}),n.d(e,"showTabBar",function(){return h}),n.d(e,"hideTabBarRedDot",function(){return f}),n.d(e,"showTabBarRedDot",function(){return d}),n.d(e,"removeTabBarBadge",function(){return p}),n.d(e,"setTabBarBadge",function(){return g});var i=n("f2b3"),r=["text","iconPath","selectedIconPath"],o=["color","selectedColor","backgroundColor","borderStyle"],a=["badge","redDot"];function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=getApp();if(n){var s=!1,c=getCurrentPages();if(c.length?c[c.length-1].$page.meta.isTabBar&&(s=!0):n.$children[0].hasTabBar&&(s=!0),!s)return{errMsg:"".concat(t,":fail not TabBar page")};var u=e.index,l=n.$children[0].tabBar;if(u>=__uniConfig.tabBar.list.length)return{errMsg:"".concat(t,":fail tabbar item not found")};switch(t){case"showTabBar":n.$children[0].hideTabBar=!1;break;case"hideTabBar":n.$children[0].hideTabBar=!0;break;case"setTabBarItem":Object(i["g"])(l.list[u],r,e);break;case"setTabBarStyle":Object(i["g"])(l,o,e);break;case"showTabBarRedDot":Object(i["g"])(l.list[u],a,{badge:"",redDot:!0});break;case"setTabBarBadge":Object(i["g"])(l.list[u],a,{badge:e.text,redDot:!0});break;case"hideTabBarRedDot":case"removeTabBarBadge":Object(i["g"])(l.list[u],a,{badge:"",redDot:!1});break}}return{}}function c(t){return s("setTabBarItem",t)}function u(t){return s("setTabBarStyle",t)}function l(t){return s("hideTabBar",t)}function h(t){return s("showTabBar",t)}function f(t){return s("hideTabBarRedDot",t)}function d(t){return s("showTabBarRedDot",t)}function p(t){return s("removeTabBarBadge",t)}function g(t){return s("setTabBarBadge",t)}},fcd8:function(t,e,n){},ff28:function(t,e,n){"use strict";var i=n("23af"),r=n.n(i);r.a},ffdb:function(t,e,n){},ffdc:function(t,e,n){"use strict";function i(t,e,n,i){var r,o=document.createElement("script"),a=e.callback||"callback",s="__callback"+Date.now(),c=e.timeout||3e4;function u(){clearTimeout(r),delete window[s],o.remove()}window[s]=function(t){"function"===typeof n&&n(t),u()},o.onerror=function(){"function"===typeof i&&i(),u()},r=setTimeout(function(){"function"===typeof i&&i(),u()},c),o.src=t+(t.indexOf("?")>=0?"&":"?")+a+"="+s,document.body.appendChild(o)}n.d(e,"a",function(){return i})}})});
\ No newline at end of file
diff --git a/packages/uni-h5/package.json b/packages/uni-h5/package.json
index 5ab919a67598183bfff70bc7da296ac85174d04d..30eceaef4509c30bc6c7e30b4da89d1b7638644d 100644
--- a/packages/uni-h5/package.json
+++ b/packages/uni-h5/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-h5",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"repository": {
@@ -18,5 +18,5 @@
"intersection-observer": "^0.7.0",
"safe-area-insets": "^1.4.1"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json
index d1068e9b5de27d1dc875378324db02e8c5200e8f..f64a505f9cb2a57d75b0f6440360bab9b66e280a 100644
--- a/packages/uni-mp-alipay/package.json
+++ b/packages/uni-mp-alipay/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-alipay",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json
index 90c9166504a0e980940eed1b6e8d472086443188..b90b4b7768328e1481c4a71924ca6593c27b77a4 100644
--- a/packages/uni-mp-baidu/package.json
+++ b/packages/uni-mp-baidu/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-baidu",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-mp-qq/package.json b/packages/uni-mp-qq/package.json
index 88a8e63ace04d42a20eebd6dbab86fdd3d3d512c..c90fdc0e719d9b159753ec2e7fa28e4f4020ed17 100644
--- a/packages/uni-mp-qq/package.json
+++ b/packages/uni-mp-qq/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-qq",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app mp-qq",
"main": "dist/index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json
index 5e5aeeecf8413cf371cff9c7f423a3943d6548ae..ded8d250130d40ac043755b258c701b51601f190 100644
--- a/packages/uni-mp-toutiao/package.json
+++ b/packages/uni-mp-toutiao/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-toutiao",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json
index 843b950f15ccef508f4348f82130ff24b0aedfa9..3267d4e04ac5979e60423c147c69e67583b099a5 100644
--- a/packages/uni-mp-weixin/package.json
+++ b/packages/uni-mp-weixin/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-weixin",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-stat/package.json b/packages/uni-stat/package.json
index 15de354876095e6070bce25f0c619da1d73fc6fa..dfacf93696e5dd824a703e4d55e3aa4e445b070c 100644
--- a/packages/uni-stat/package.json
+++ b/packages/uni-stat/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-stat",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "",
"main": "dist/index.js",
"repository": {
@@ -34,5 +34,5 @@
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.2"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
index 311e15e9d84dcccf632eae8837daafba02b3f9e0..bffd4b20cd8bb328d02e12771291763735c3b7a1 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
@@ -70,6 +70,17 @@ describe('codegen', () => {
'{{ user.firstName }}',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
)
+ })
+
+ it('generate keep-alive', () => {
+ assertCodegen(
+ ``,
+ `with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
+ )
+ assertCodegen(
+ ``,
+ `with(this){return _c('keep-alive',{attrs:{"exclude":_$s(0,'a-exclude',componentWithStatus1),"_i":0}},[_c(_$s(1,'is','componentWithStatus'+index),{tag:"component",attrs:{"_i":1}})],1)}`
+ )
})
})
/* eslint-enable quotes */
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
index f4ed62645b09dabecbd4bce839ea4f3c2a109c9e..7be0c7a11d429c5578fd995c855899e87c02190a 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
@@ -15,7 +15,7 @@ describe('codegen', () => {
it('generate directive', () => {
assertCodegen(
'',
- `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
+ `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
it('generate v-for directive', () => {
@@ -45,6 +45,16 @@ describe('codegen', () => {
'{{ user.firstName }}',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$g(0,'t0')))]}}])})}`
)
+ })
+ it('generate keep-alive', () => {
+ assertCodegen(
+ ``,
+ `with(this){return _c('keep-alive',{attrs:{"exclude":"componentWithStatus1","_i":0}},[_c("componentWithStatus",{tag:"component",attrs:{"_i":1}})],1)}`
+ )
+ assertCodegen(
+ ``,
+ `with(this){return _c('keep-alive',{attrs:{"exclude":_$g(0,'a-exclude'),"_i":0}},[_c(_$g(1,'is'),{tag:"component",attrs:{"_i":1}})],1)}`
+ )
})
})
/* eslint-enable quotes */
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
index dbbdabc73e2bba2fc5ed61f0e9404ca3335b69a8..2128a7bb616ed67c003834466189d523139820e0 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
@@ -576,7 +576,7 @@ describe('codegen', () => {
)
assertCodegen(
'',
- `with(this){return _c(component1,{tag:"div"})}`
+ `with(this){return _c(_$s(0,'is',component1),{tag:"div"})}`
)
// maybe a component and normalize type should be 1
assertCodegen(
@@ -589,7 +589,7 @@ describe('codegen', () => {
// have "inline-template'"
assertCodegen(
'hello world
',
- `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _c('p',[_c('span')])}}]}})}`
+ `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('p',[_c('span')])}},staticRenderFns:[]}})}`
)
// "have inline-template attrs, but not having exactly one child element
assertCodegen(
@@ -616,7 +616,7 @@ describe('codegen', () => {
it('generate static trees inside v-for', () => {
assertCodegen(
``,
- `with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_m(0,true)])}),0)}`
+ `with(this){return _c('div',_l((10),function(i,$10,$20,$30){return _c('div',[_c('p',[_c('span')])])}),0)}`
// [`with(this){return _c('p',[_c('span')])}`]
)
})
@@ -660,7 +660,7 @@ describe('codegen', () => {
it('does not squash templates inside v-pre', () => {
assertCodegen(
'',
- `with(this){return _m(0)}`
+ `with(this){return _c('div',[[_c('p')]],2)}`
)
// const template = ''
// const generatedCode = `with(this){return _m(0)}`
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
index 2aef257befeaedfe3a050a84e659472b169182af..0045b252ba9ddc1837b0f7e0877a722a3c14511f 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
@@ -15,12 +15,12 @@ describe('codegen', () => {
it('generate directive', () => {
assertCodegen(
'',
- `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
+ `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
// extra
assertCodegen(
'',
- `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:(_$g(0,'v-custom1')),expression:"_$g(0,'v-custom1')",arg:_$g(0,'v-custom1-arg'),modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}`
+ `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}`
)
})
@@ -576,7 +576,7 @@ describe('codegen', () => {
)
assertCodegen(
'',
- `with(this){return _c(component1,{tag:"v-uni-view",attrs:{"_i":0}})}`
+ `with(this){return _c(_$g(0,'is'),{tag:"v-uni-view",attrs:{"_i":0}})}`
)
// maybe a component and normalize type should be 1
assertCodegen(
diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js
index 5f9a46fa8cb6ebb3b5d5619715b99be865cfec87..ea55e3f53c35c400040d04bead188e25833f4fd9 100644
--- a/packages/uni-template-compiler/__tests__/demo.js
+++ b/packages/uni-template-compiler/__tests__/demo.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
const res = compiler.compile(
`
-A{{ d | e | f }}B{{text}}C
+
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
@@ -13,7 +13,7 @@ const res = compiler.compile(
mp: {
platform: 'app-plus'
},
- service: true,
+ // service: true,
view: true
})
console.log(require('util').inspect(res, {
diff --git a/packages/uni-template-compiler/lib/app/optimizer.js b/packages/uni-template-compiler/lib/app/optimizer.js
index 2ced1db00c9ed07d909eb47bda5c5d1649a0728a..50d5d7d0f7b29db394d1f52e4dbc311ea77fa3fd 100644
--- a/packages/uni-template-compiler/lib/app/optimizer.js
+++ b/packages/uni-template-compiler/lib/app/optimizer.js
@@ -14,7 +14,11 @@ function no (a, b, c) {
}
function isBuiltInTag (tag) {
- if (tag === 'slot' || tag === 'component') {
+ if (
+ tag === 'slot' ||
+ tag === 'component' ||
+ tag === 'keep-alive'
+ ) {
return true
}
}
@@ -48,11 +52,11 @@ function markStatic (node) {
}
delete node.attrs
}
- if (node.type === 1) {
+ if (node.type === 1) {
delete node.staticClass
delete node.staticStyle
- if (node.attrs && !isComponent(node.tag)) { // 移除静态属性
+ if (node.attrs && !isComponent(node.tag) && node.tag !== 'keep-alive') { // 移除静态属性
node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value))
}
diff --git a/packages/uni-template-compiler/lib/app/parser/base-parser.js b/packages/uni-template-compiler/lib/app/parser/base-parser.js
index 426ac5313e16ac50e0ed8267761b28bc7a9b3228..40c79406a0b4143feaf3a3d04d11198ba3b7a414 100644
--- a/packages/uni-template-compiler/lib/app/parser/base-parser.js
+++ b/packages/uni-template-compiler/lib/app/parser/base-parser.js
@@ -1,5 +1,6 @@
const {
ID,
+ C_IS,
V_IF,
V_FOR,
V_ELSE_IF,
@@ -8,6 +9,15 @@ const {
const parseTextExpr = require('./text-parser')
+function parseIs (el, genVar) {
+ if (!el.component) {
+ return
+ }
+ if (isVar(el.component)) {
+ el.component = genVar(C_IS, el.component)
+ }
+}
+
function parseIf (el, createGenVar) {
if (!el.if) {
return
@@ -60,6 +70,7 @@ function parseText (el, parent, state) {
}
module.exports = {
+ parseIs,
parseIf,
parseFor,
parseText,
diff --git a/packages/uni-template-compiler/lib/app/parser/component-parser.js b/packages/uni-template-compiler/lib/app/parser/component-parser.js
index c558bd6bf5856220ffd4ce6b3ac1f210efd977d1..446569ee5cff350d95ec69b90d2ff78d7958e201 100644
--- a/packages/uni-template-compiler/lib/app/parser/component-parser.js
+++ b/packages/uni-template-compiler/lib/app/parser/component-parser.js
@@ -1,14 +1,15 @@
const {
- ID,
- hasOwn
+ ID
} = require('../util')
-const tags = require('../../../../uni-cli-shared/lib/tags')
+const {
+ isComponent
+} = require('../../util')
// 仅限 view 层
module.exports = function parseComponent (el) {
// 需要把自定义组件的 attrs, props 全干掉
- if (el.tag && !hasOwn(tags, el.tag.replace('v-uni-', ''))) {
+ if (el.tag && isComponent(el.tag)) {
// 仅保留 ID
el.attrs && (el.attrs = el.attrs.filter(attr => attr.name === ID))
}
diff --git a/packages/uni-template-compiler/lib/app/service.js b/packages/uni-template-compiler/lib/app/service.js
index 28adee2ece35a0d762cf1eb1e978f764780e16ff..2883d648bbf5f8d9168272d618375c8f7a6bd980 100644
--- a/packages/uni-template-compiler/lib/app/service.js
+++ b/packages/uni-template-compiler/lib/app/service.js
@@ -14,6 +14,7 @@ const {
} = require('../util')
const {
+ parseIs,
parseIf,
parseFor,
parseText,
@@ -82,6 +83,7 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID])
+ parseIs(el, genVar)
parseFor(el, createGenVar)
parseKey(el)
diff --git a/packages/uni-template-compiler/lib/app/util.js b/packages/uni-template-compiler/lib/app/util.js
index 51bf36b668bca8781502dad31fed65f9e5013afe..2924c9b6102951a183822800c124e29cebce71f9 100644
--- a/packages/uni-template-compiler/lib/app/util.js
+++ b/packages/uni-template-compiler/lib/app/util.js
@@ -9,6 +9,8 @@ const ITERATOR2 = '$2'
const ITERATOR3 = '$3'
const SET_DATA = '_$s'
const GET_DATA = '_$g'
+
+const C_IS = 'is'
const V_FOR = 'f'
const V_IF = 'i'
@@ -190,7 +192,8 @@ function addHandler (el, name, value, important) {
el.plain = false
}
-module.exports = {
+module.exports = {
+ C_IS,
V_FOR,
V_IF,
V_ELSE_IF,
diff --git a/packages/uni-template-compiler/lib/app/view.js b/packages/uni-template-compiler/lib/app/view.js
index e22130f37e0a7e0f7053e1f0f5e6f65f7a1a9737..a98cf49d2a7c1cc0cd67a0663ae4813f7db722d7 100644
--- a/packages/uni-template-compiler/lib/app/view.js
+++ b/packages/uni-template-compiler/lib/app/view.js
@@ -9,10 +9,10 @@ const {
} = require('./util')
const {
+ parseIs,
parseIf,
parseFor,
parseText,
- parseDirs,
parseAttrs,
parseProps,
parseBinding
@@ -53,6 +53,41 @@ function parseKey (el) {
}
}
+function parseDirs (el, genVar, ignoreDirs, includeDirs = []) {
+ if (!el.directives) {
+ return
+ }
+ el.directives = el.directives.filter(dir => {
+ if (includeDirs.indexOf(dir.name) !== -1) {
+ if (ignoreDirs.indexOf(dir.name) === -1) {
+ dir.value && (dir.value = genVar('v-' + dir.name, dir.value))
+ dir.isDynamicArg && (dir.arg = genVar('v-' + dir.name + '-arg', dir.arg))
+ }
+ return true
+ }
+ })
+}
+
+const includeDirs = [
+ 'text',
+ 'html',
+ 'bind',
+ 'model',
+ 'show',
+ 'if',
+ 'else',
+ 'else-if',
+ 'for',
+ 'on',
+ 'bind',
+ 'slot',
+ 'pre',
+ 'cloak',
+ 'once'
+]
+
+const ignoreDirs = ['model']
+
function transformNode (el, parent, state) {
if (el.type === 3) {
return
@@ -74,6 +109,8 @@ function transformNode (el, parent, state) {
const genVar = createGenVar(el.attrsMap[ID])
+ parseIs(el, genVar)
+
if (parseFor(el, createGenVar)) {
if (el.alias[0] === '{') { //
el.alias = '$item'
@@ -83,7 +120,7 @@ function transformNode (el, parent, state) {
parseIf(el, createGenVar)
parseBinding(el, genVar)
- parseDirs(el, genVar, ['model'])
+ parseDirs(el, genVar, ignoreDirs, includeDirs)
parseAttrs(el, genVar)
parseProps(el, genVar)
}
diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js
index 4286c2baa4a7e6ba11e96d1795ba878df6bee808..ddb4c9b0579f9b4df0926b69947d0a7dfc42debd 100644
--- a/packages/uni-template-compiler/lib/index.js
+++ b/packages/uni-template-compiler/lib/index.js
@@ -30,7 +30,7 @@ module.exports = {
compile (source, options = {}) {
if (options.service) {
(options.modules || (options.modules = [])).push(require('./app/service'))
- options.optimize = true // 启用 staticRenderFns
+ options.optimize = false // 启用 staticRenderFns
// domProps => attrs
options.mustUseProp = () => false
options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置
@@ -38,12 +38,11 @@ module.exports = {
// clear staticRenderFns
const compiled = compile(source, options)
- compiled.staticRenderFns.length = 0
return compiled
} else if (options.view) {
(options.modules || (options.modules = [])).push(require('./app/view'))
- options.optimize = false // 暂不启用 staticRenderFns
+ options.optimize = false // 暂不启用 staticRenderFns
options.isReservedTag = (tagName) => false // 均为组件
return compile(source, options)
}
diff --git a/packages/uni-template-compiler/lib/util.js b/packages/uni-template-compiler/lib/util.js
index 5a4fd8d77d1eeeb9f27dfcfe62725e67ae1d4c26..bf119e07ee1ef92b62e11529ac089737c60b316f 100644
--- a/packages/uni-template-compiler/lib/util.js
+++ b/packages/uni-template-compiler/lib/util.js
@@ -183,9 +183,13 @@ const {
} = require('./h5')
function isComponent (tagName) {
- if (tagName === 'block' || tagName === 'template') {
+ if (
+ tagName === 'block' ||
+ tagName === 'template' ||
+ tagName === 'keep-alive'
+ ) {
return false
- }
+ }
return !hasOwn(tags, getTagName(tagName.replace('v-uni-', '')))
}
diff --git a/packages/uni-template-compiler/package.json b/packages/uni-template-compiler/package.json
index 14f234bbe8fe427e9f3145380674d4196f026054..5e4ce5a00464b091abf610e642ad9160970a46f1 100644
--- a/packages/uni-template-compiler/package.json
+++ b/packages/uni-template-compiler/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-template-compiler",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-template-compiler",
"main": "lib/index.js",
"repository": {
@@ -22,5 +22,5 @@
"@babel/types": "^7.3.3",
"vue-template-compiler": "^2.6.10"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/vue-cli-plugin-hbuilderx/package.json b/packages/vue-cli-plugin-hbuilderx/package.json
index 10282a0026cf0ab7d4018c41f971481a6242b310..583d5df70352c93d3a46da23753c176a5f356139 100644
--- a/packages/vue-cli-plugin-hbuilderx/package.json
+++ b/packages/vue-cli-plugin-hbuilderx/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/vue-cli-plugin-hbuilderx",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "HBuilderX plugin for vue-cli 3",
"main": "index.js",
"repository": {
@@ -18,5 +18,5 @@
"css": "~2.2.1",
"escodegen": "^1.8.1"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/vue-cli-plugin-uni-optimize/package.json b/packages/vue-cli-plugin-uni-optimize/package.json
index f7de1a2ee1e32f5fa2c4a328661910afdd88939b..21e9b9fe26e52692f8fb51fe4a6cee0687d34e14 100644
--- a/packages/vue-cli-plugin-uni-optimize/package.json
+++ b/packages/vue-cli-plugin-uni-optimize/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/vue-cli-plugin-uni-optimize",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js",
"repository": {
@@ -13,5 +13,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/vue-cli-plugin-uni/package.json b/packages/vue-cli-plugin-uni/package.json
index 4d84df8c63793e199259cca8feca79b35d619866..ec21f39823b140f04a4e7bee486609c6c42e0a01 100644
--- a/packages/vue-cli-plugin-uni/package.json
+++ b/packages/vue-cli-plugin-uni/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/vue-cli-plugin-uni",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app plugin for vue-cli 3",
"main": "index.js",
"repository": {
@@ -17,7 +17,7 @@
"author": "fxy060608",
"license": "Apache-2.0",
"dependencies": {
- "@dcloudio/uni-stat": "^3.0.0-alpha-24020191018012",
+ "@dcloudio/uni-stat": "^3.0.0-alpha-24020191018017",
"copy-webpack-plugin": "^4.6.0",
"cross-env": "^5.2.0",
"envinfo": "^6.0.1",
@@ -34,5 +34,5 @@
"wrap-loader": "^0.2.0",
"xregexp": "4.0.0"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
index 0d42f19479d431a8365168278d9fadfbae7da30d..d5d3875bed80e3def91c55ec6ac3f4a84b44a5b3 100644
--- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
+++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
@@ -17,7 +17,9 @@ const {
parseComponents
} = require('./util')
-function getDefineComponents(components) {
+function getDefineComponents({
+ components
+}) {
return components.map(({
name,
source
@@ -93,7 +95,7 @@ module.exports = function(source, map) {
return `
import 'uni-pages'
function initView(){
- ${getStylesCode(this)}
+ ${getStylesCode(this)}
injectStyles()
${getDefineComponents(parseComponents(source, traverse)).join('\n')}
UniViewJSBridge.publishHandler('webviewReady')
diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js
index 9036d20edd840e05c71fc92ba16f15e6884e6cfb..77f1395a647e7f8e67370fb70aa61c916485120e 100644
--- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js
+++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/script.js
@@ -10,7 +10,7 @@ const {
parseComponents
} = require('./util')
-function genComponentCode (components) {
+function genComponentCode(components) {
const importCode = []
const componentsCode = []
components.forEach(({
@@ -24,12 +24,20 @@ function genComponentCode (components) {
return [importCode.join('\n'), componentsCode.join(',\n')]
}
-function genCode (components, css = []) {
+function genCode({
+ components,
+ options
+}, css = []) {
+ const optionsCode = []
+ Object.keys(options).forEach(name => {
+ options[name] !== null && optionsCode.push(`${name}:${options[name]}`)
+ })
const [importComponentCode, componentsCode] = genComponentCode(components)
// TODO js 内引用 css
return `
${importComponentCode}
export default {
+ ${optionsCode.length?(optionsCode.join(',')+','):''}
data(){
return {}
},
@@ -40,7 +48,7 @@ export default {
`
}
-module.exports = function (content, map) {
+module.exports = function(content, map) {
this.cacheable && this.cacheable()
content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js
index 1e4edac659a1ab0f00fe6d9027678d6886ea29c8..26f293577c63484dfbff3ef86e266ba043a5a1f4 100644
--- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js
+++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js
@@ -1,8 +1,9 @@
const parser = require('@babel/parser')
-function parseComponents (content, traverse) {
+function parseComponents(content, traverse) {
const {
state: {
+ options,
components
}
} = traverse(parser.parse(content, {
@@ -15,9 +16,16 @@ function parseComponents (content, traverse) {
'classProperties'
]
}), {
- components: []
+ components: [],
+ options: {
+ name: null,
+ inheritAttrs: null
+ }
})
- return components
+ return {
+ components,
+ options
+ }
}
module.exports = {
diff --git a/packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js b/packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
index f29dabe45e5bdeb1fc3992e1719b6a461f7d420d..f17ff36bc9e481fc27a2c69289824199158268c1 100644
--- a/packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
+++ b/packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
@@ -6,10 +6,27 @@ const {
} = require('./util')
function handleObjectExpression (declaration, path, state) {
+ if (state.options) { // name,inheritAttrs
+ Object.keys(state.options).forEach(name => {
+ const optionProperty = declaration.properties.filter(prop => {
+ return t.isObjectProperty(prop) &&
+ t.isIdentifier(prop.key) &&
+ prop.key.name === name
+ })[0]
+ if (optionProperty) {
+ if (t.isStringLiteral(optionProperty.value)) {
+ state.options[name] = JSON.stringify(optionProperty.value.value)
+ } else {
+ state.options[name] = optionProperty.value.value
+ }
+ }
+ })
+ }
+
const componentsProperty = declaration.properties.filter(prop => {
return t.isObjectProperty(prop) &&
- t.isIdentifier(prop.key) &&
- prop.key.name === 'components'
+ t.isIdentifier(prop.key) &&
+ prop.key.name === 'components'
})[0]
if (componentsProperty && t.isObjectExpression(componentsProperty.value)) {
@@ -27,7 +44,8 @@ function handleObjectExpression (declaration, path, state) {
module.exports = function (ast, state = {
type: 'Component',
- components: []
+ components: [],
+ options: {}
}) {
babelTraverse(ast, {
ExportDefaultDeclaration (path) {
@@ -35,15 +53,15 @@ module.exports = function (ast, state = {
if (t.isObjectExpression(declaration)) { // export default {components:{}}
handleObjectExpression(declaration, path, state)
} else if (t.isCallExpression(declaration) &&
- t.isMemberExpression(declaration.callee) &&
- declaration.arguments.length === 1) { // export default Vue.extend({components:{}})
+ t.isMemberExpression(declaration.callee) &&
+ declaration.arguments.length === 1) { // export default Vue.extend({components:{}})
if (declaration.callee.object.name === 'Vue' && declaration.callee.property.name ===
- 'extend') {
+ 'extend') {
handleObjectExpression(declaration.arguments[0], path, state)
}
} else if (t.isClassDeclaration(declaration) &&
- declaration.decorators &&
- declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
+ declaration.decorators &&
+ declaration.decorators.length) { // export default @Component({components:{}}) class MyComponent extend Vue
const componentDecorator = declaration.decorators[0]
if (t.isCallExpression(componentDecorator.expression)) {
const args = componentDecorator.expression.arguments
diff --git a/packages/webpack-uni-mp-loader/package.json b/packages/webpack-uni-mp-loader/package.json
index b7c3cd36b964e6bdeba77a3a553c0a38791b308c..904d66adf8f5c972c59ae786fda34e465aaee2a0 100644
--- a/packages/webpack-uni-mp-loader/package.json
+++ b/packages/webpack-uni-mp-loader/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/webpack-uni-mp-loader",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "webpack-uni-mp-loader",
"main": "index.js",
"repository": {
@@ -16,5 +16,5 @@
},
"author": "fxy060608",
"license": "Apache-2.0",
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}
diff --git a/packages/webpack-uni-pages-loader/package.json b/packages/webpack-uni-pages-loader/package.json
index 02c1eb7e162be35c85a8f98cae9a052b9736d089..299fe59f1125304d1dbcfc70aa623cf08b743d9b 100644
--- a/packages/webpack-uni-pages-loader/package.json
+++ b/packages/webpack-uni-pages-loader/package.json
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/webpack-uni-pages-loader",
- "version": "3.0.0-alpha-24020191018012",
+ "version": "3.0.0-alpha-24020191018017",
"description": "uni-app pages.json loader",
"main": "lib/index.js",
"repository": {
@@ -23,5 +23,5 @@
"uni-app": {
"compilerVersion": "2.3.4"
},
- "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
+ "gitHead": "e5da9bbe2de350cb7302245c0e968a5610c65a23"
}