From 28abd0a5b3867c80f9f6a65b1ff2a41aedc687e7 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 20 Apr 2019 15:26:19 +0800 Subject: [PATCH] build uni runtime (props.type [String]=>String, mp-baidu:[String,Boolean]=>Boolean) --- packages/uni-app-plus/dist/index.js | 18 +++++++-- packages/uni-app-plus/package.json | 2 +- packages/uni-mp-baidu/dist/index.js | 41 ++++++++++++++++++-- packages/uni-mp-baidu/package.json | 2 +- packages/uni-mp-toutiao/dist/index.js | 18 +++++++-- packages/uni-mp-toutiao/package.json | 2 +- packages/uni-mp-weixin/dist/index.js | 18 +++++++-- packages/uni-mp-weixin/package.json | 2 +- src/core/runtime/wrapper/create-component.js | 2 +- src/core/runtime/wrapper/util.js | 39 ++++++++++++++++++- 10 files changed, 125 insertions(+), 19 deletions(-) diff --git a/packages/uni-app-plus/dist/index.js b/packages/uni-app-plus/dist/index.js index 27ecea610..9b1a0b12e 100644 --- a/packages/uni-app-plus/dist/index.js +++ b/packages/uni-app-plus/dist/index.js @@ -393,7 +393,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -425,14 +433,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -875,7 +887,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-app-plus/package.json b/packages/uni-app-plus/package.json index 4466e963d..edcb3831a 100644 --- a/packages/uni-app-plus/package.json +++ b/packages/uni-app-plus/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-app-plus", - "version": "0.0.223", + "version": "0.0.224", "description": "uni-app app-plus", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index 356b036ae..6d9cf553a 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -528,7 +528,38 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + { + if ( + Array.isArray(type) && + type.length === 2 && + type.indexOf(String) !== -1 + ) { // [String,Boolean]=>Boolean + if (type.indexOf(Boolean) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use Boolean instead of [String,Boolean] . at ${file}` + ); + } + return Boolean + } else if (type.indexOf(Number) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use String or Number instead of [String,Number]. at ${file}` + ); + } + return String + } + } + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -560,14 +591,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -1042,7 +1077,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 506159b0e..83b86e5d0 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": "0.0.818", + "version": "0.0.820", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index 655b83ddb..4f4f9b1c0 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -573,7 +573,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -605,14 +613,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -1066,7 +1078,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index a01bb1a01..3178fd0be 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": "0.0.318", + "version": "0.0.319", "description": "uni-app mp-toutiao", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index e688db429..ffb45f28f 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -420,7 +420,15 @@ function getBehaviors (vueExtends, vueMixins) { return behaviors } -function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + return type +} + +function getProperties (props, isBehavior = false, file = '') { const properties = {}; if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -452,14 +460,18 @@ function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value(); } + + opts.type = parsePropType(key, opts.type, file); + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) }; } else { // content:String + const type = parsePropType(key, opts, file); properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) }; } @@ -895,7 +907,7 @@ function initVm$2 (VueComponent) { function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions; - const properties = getProperties(vueOptions.props); + const properties = getProperties(vueOptions.props, false, vueOptions.__file); const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']); diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 8f96c5ab6..e1a5b1d7f 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": "0.0.942", + "version": "0.0.943", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/wrapper/create-component.js b/src/core/runtime/wrapper/create-component.js index fb65f668d..d492e0169 100644 --- a/src/core/runtime/wrapper/create-component.js +++ b/src/core/runtime/wrapper/create-component.js @@ -43,7 +43,7 @@ function initVm (VueComponent) { export function createComponent (vueOptions) { vueOptions = vueOptions.default || vueOptions - const properties = getProperties(vueOptions.props) + const properties = getProperties(vueOptions.props, false, vueOptions.__file) const behaviors = getBehaviors(vueOptions['extends'], vueOptions['mixins']) diff --git a/src/core/runtime/wrapper/util.js b/src/core/runtime/wrapper/util.js index 937f86a6a..6d3f25c4d 100644 --- a/src/core/runtime/wrapper/util.js +++ b/src/core/runtime/wrapper/util.js @@ -89,7 +89,38 @@ export function getBehaviors (vueExtends, vueMixins) { return behaviors } -export function getProperties (props, isBehavior = false) { +function parsePropType (key, type, file) { + // [String]=>String + if (Array.isArray(type) && type.length === 1) { + return type[0] + } + if (__PLATFORM__ === 'mp-baidu') { + if ( + Array.isArray(type) && + type.length === 2 && + type.indexOf(String) !== -1 + ) { // [String,Boolean]=>Boolean + if (type.indexOf(Boolean) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use Boolean instead of [String,Boolean] . at ${file}` + ) + } + return Boolean + } else if (type.indexOf(Number) !== -1) { + if (file) { + console.warn( + `props.${key}.type should use String or Number instead of [String,Number]. at ${file}` + ) + } + return String + } + } + } + return type +} + +export function getProperties (props, isBehavior = false, file = '') { const properties = {} if (!isBehavior) { properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -121,14 +152,18 @@ export function getProperties (props, isBehavior = false) { if (isFn(value)) { value = value() } + + opts.type = parsePropType(key, opts.type, file) + properties[key] = { type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null, value, observer: createObserver(key) } } else { // content:String + const type = parsePropType(key, opts, file) properties[key] = { - type: PROP_TYPES.indexOf(opts) !== -1 ? opts : null, + type: PROP_TYPES.indexOf(type) !== -1 ? type : null, observer: createObserver(key) } } -- GitLab