提交 28abd0a5 编写于 作者: fxy060608's avatar fxy060608

build uni runtime (props.type [String]=>String, mp-baidu:[String,Boolean]=>Boolean)

上级 5badfe66
......@@ -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']);
......
{
"name": "@dcloudio/uni-app-plus",
"version": "0.0.223",
"version": "0.0.224",
"description": "uni-app app-plus",
"main": "dist/index.js",
"scripts": {
......
......@@ -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']);
......
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.818",
"version": "0.0.820",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
......
......@@ -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']);
......
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "0.0.318",
"version": "0.0.319",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"scripts": {
......
......@@ -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']);
......
{
"name": "@dcloudio/uni-mp-weixin",
"version": "0.0.942",
"version": "0.0.943",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"scripts": {
......
......@@ -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'])
......
......@@ -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)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册