diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index 6b3a15870b4eac101c573fe4e5efee7e6a0398b2..c60718a174accde57f3c7ffdde4e5115fd5cd662 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, hasOwn, isArray, toNumber, capitalize, isFunction, EMPTY_OBJ, camelize } from '@vue/shared'; +import { isPlainObject, hasOwn, capitalize, isFunction, extend, isArray, EMPTY_OBJ, camelize } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -143,154 +123,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -358,15 +190,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -559,19 +382,30 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-alipay" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -596,6 +430,12 @@ function createProperty(key, prop) { return prop; } } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -614,18 +454,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index bf0a49d13e74e8997426a8b2513a8281a0bf3761..d3ad646e1f4b96b36bafa12253fb5a4fca7f9a5d 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -141,154 +121,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -347,15 +179,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -588,29 +411,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - { - if ( - // [String,Boolean]=>Boolean - defaultValue === false && - isArray(type) && - type.length === 2 && - type.indexOf(String) !== -1 && - type.indexOf(Boolean) !== -1) { - return Boolean; - } - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-baidu" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -634,6 +458,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -652,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type, value); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts, null); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-mp-core/src/runtime/componentInstance/index.ts b/packages/uni-mp-core/src/runtime/componentInstance/index.ts index 084f543865a6048a3466826bfc818cf0e17e7f79..69403bcf2c393a2f8b917d5d840f76478e2ca0a9 100644 --- a/packages/uni-mp-core/src/runtime/componentInstance/index.ts +++ b/packages/uni-mp-core/src/runtime/componentInstance/index.ts @@ -1,76 +1,8 @@ import { EventChannel, invokeArrayFns } from '@dcloudio/uni-shared' -import { - capitalize, - hasOwn, - isArray, - toNumber, - isObject, - isPlainObject, -} from '@vue/shared' +import { capitalize, hasOwn, isArray } from '@vue/shared' import { ComponentPublicInstance, ComponentInternalInstance } from 'vue' import { getEventChannel } from '../../api/protocols/navigateTo' import { MPComponentInstance } from '../component' -import { getClass, getStyle, getValue } from './utils' - -function setModel( - this: ComponentPublicInstance, - target: ComponentPublicInstance, - key: string, - value: any, - modifiers: string[] -) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = (value as string).trim() - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value) - } - } - if (!target) { - target = this - } - ;(target as any)[key] = value -} - -function setSync( - this: ComponentPublicInstance, - target: ComponentPublicInstance, - key: string, - value: any -) { - if (!target) { - target = this - } - ;(target as any)[key] = value -} - -function getOrig(data: unknown) { - if (isPlainObject(data)) { - return (data as any).$orig || data - } - return data -} - -function map(val: unknown, iteratee: Function) { - let ret, i, l, keys, key - if (isArray(val)) { - ret = new Array(val.length) - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i) - } - return ret - } else if (isObject(val)) { - keys = Object.keys(val) - ret = Object.create(null) - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i] - ret[key] = iteratee(val[key], key, i) - } - return ret - } - return [] -} const MP_METHODS = [ 'createSelectorQuery', @@ -179,16 +111,6 @@ export function initComponentInstance( } } }) - - // TODO other - ctx.__set_model = setModel - ctx.__set_sync = setSync - ctx.__get_orig = getOrig - // TODO - ctx.__get_value = getValue - ctx.__get_class = getClass - ctx.__get_style = getStyle - ctx.__map = map } export function initMocks( diff --git a/packages/uni-mp-core/src/runtime/componentInstance/utils.ts b/packages/uni-mp-core/src/runtime/componentInstance/utils.ts deleted file mode 100644 index 5c4b0d2431bde0b61780d2fb0502a888d2f42614..0000000000000000000000000000000000000000 --- a/packages/uni-mp-core/src/runtime/componentInstance/utils.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { ComponentPublicInstance } from 'vue' -import { extend, isObject, hyphenate } from '@vue/shared' -import { cache, getDataByPath } from '@dcloudio/uni-shared' - -export function getValue( - this: ComponentPublicInstance, - dataPath: string, - target: Record -) { - return getDataByPath(target || this, dataPath) -} - -export function getClass(dynamicClass: unknown, staticClass: string) { - return renderClass(staticClass, dynamicClass) -} - -export function getStyle(dynamicStyle: unknown, staticStyle: string) { - if (!dynamicStyle && !staticStyle) { - return '' - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle) - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj - return Object.keys(styleObj as any) - .map(function (name) { - return hyphenate(name) + ':' + (styleObj as any)[name] - }) - .join(';') -} -function toObject(arr: unknown[]) { - var res = {} - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]) - } - } - return res -} - -function normalizeStyleBinding(bindingStyle: unknown) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle) - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle) - } - return bindingStyle -} - -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {} - var listDelimiter = /;(?![^(]*\))/g - var propertyDelimiter = /:(.+)/ - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter) - tmp.length > 1 && ((res as any)[tmp[0].trim()] = tmp[1].trim()) - } - }) - return res -}) - -function isDef(v: unknown) { - return v !== undefined && v !== null -} - -function renderClass(staticClass: string, dynamicClass: unknown) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)) - } - /* istanbul ignore next */ - return '' -} - -function concat(a?: string, b?: string) { - return a ? (b ? a + ' ' + b : a) : b || '' -} - -function stringifyClass(value: unknown) { - if (Array.isArray(value)) { - return stringifyArray(value) - } - if (isObject(value)) { - return stringifyObject(value) - } - if (typeof value === 'string') { - return value - } - /* istanbul ignore next */ - return '' -} - -function stringifyArray(value: unknown[]) { - var res = '' - var stringified - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' ' - } - res += stringified - } - } - return res -} - -function stringifyObject(value: Record) { - var res = '' - for (var key in value) { - if (value[key]) { - if (res) { - res += ' ' - } - res += key - } - } - return res -} diff --git a/packages/uni-mp-core/src/runtime/componentProps.ts b/packages/uni-mp-core/src/runtime/componentProps.ts index f603b34a7d4520b94930cd06867b4dc66b05a68d..81e85528bee65689daa5893e3357d2b0b269a8e6 100644 --- a/packages/uni-mp-core/src/runtime/componentProps.ts +++ b/packages/uni-mp-core/src/runtime/componentProps.ts @@ -4,7 +4,7 @@ import { MPComponentOptions, MPComponentInstance } from './component' import Component = WechatMiniprogram.Component -const PROP_TYPES = [String, Number, Boolean, Object, Array, null] +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name: string) { return function observer(this: MPComponentInstance, newVal: unknown) { @@ -14,31 +14,31 @@ function createObserver(name: string) { } } -function parsePropType(key: string, type: unknown, defaultValue: unknown) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0] - } - if (__PLATFORM__ === 'mp-baidu') { - if ( - // [String,Boolean]=>Boolean - defaultValue === false && - isArray(type) && - type.length === 2 && - type.indexOf(String) !== -1 && - type.indexOf(Boolean) !== -1 - ) { - return Boolean - } - } - return type -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if (__PLATFORM__ === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior: boolean = false) { const properties: Component.PropertyOption = {} if (!isBehavior) { properties.vI = { - type: String, + type: null, // 均不指定类型,避免 property received type-uncompatible value 警告 value: '', } if (__PLATFORM__ === 'mp-toutiao') { @@ -73,6 +73,12 @@ function createProperty(key: string, prop: any) { return prop } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ export function initProps( mpComponentOptions: MPComponentOptions, rawProps: ComponentPropsOptions | null, @@ -95,17 +101,17 @@ export function initProps( if (isFunction(value)) { value = value() } - const type = (opts as any).type as any - ;(opts as any).type = parsePropType(key, type, value) + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, value, }) } else { // content:String - const type = parsePropType(key, opts, null) + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }) } }) diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index 6a04a30cf2de53babb23f1ec73735dd6ba234f67..a499e3fc7c2a93a5d99fce61acef4793975f6f6c 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -141,154 +121,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -347,15 +179,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -588,18 +411,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-kuaishou" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -623,6 +458,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -641,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index 4dd9590ceee08b7a104ede99b494853e2da5fc3d..aea9a44fd1ac1e7087e0964abea17b307bcb46e9 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -141,154 +121,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -347,15 +179,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -580,7 +403,7 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -588,18 +411,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-qq" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -623,6 +458,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -641,18 +482,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index 8edfc48566adfff541af5de0a801114953c606fd..10a618659a86e0a1df7834dae74b8a3553d32d43 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -141,154 +121,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -347,15 +179,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -583,7 +406,7 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -591,18 +414,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-toutiao" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; { @@ -632,6 +467,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -650,18 +491,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index c583ecb8146ea554e736579e778f13ea80425dcd..1a4e8b5863b59b8f8f7a89517c459c2ec513341c 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -5012,14 +5012,10 @@ function renderSlot(name, props = {}) { return; } const invoker = findScopedSlotInvoker(vueIds.split(',')[0], instance); + // 可能不存在,因为插槽不是必需的 if (invoker) { invoker(name, props); } - else { - if (process.env.NODE_ENV !== 'production') { - console.error('scoped slot invoker not found', vueIds, name, props); - } - } } function findScopedSlotInvoker(vueId, instance) { let parent = instance.parent; diff --git a/packages/uni-mp-vue/src/helpers/renderSlot.ts b/packages/uni-mp-vue/src/helpers/renderSlot.ts index c6158ae4b7ed9feaa498a9f4434738316a03ebf0..ed05aa4aebf8898c741efe2031688668459b4dc3 100644 --- a/packages/uni-mp-vue/src/helpers/renderSlot.ts +++ b/packages/uni-mp-vue/src/helpers/renderSlot.ts @@ -9,12 +9,9 @@ export function renderSlot(name: string, props: Data = {}) { return } const invoker = findScopedSlotInvoker(vueIds.split(',')[0], instance) + // 可能不存在,因为插槽不是必需的 if (invoker) { invoker(name, props) - } else { - if (process.env.NODE_ENV !== 'production') { - console.error('scoped slot invoker not found', vueIds, name, props) - } } } diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index 736285856d399f537a2e507a896b4fa82d560dc7..2dc69d46885183c5b2457671a0847e8dd6351a56 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -78,154 +58,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -284,15 +116,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -526,7 +349,7 @@ function findVmByVueId(instance, vuePid) { } } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -534,18 +357,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("mp-weixin" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -569,6 +404,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -587,18 +428,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } }); diff --git a/packages/uni-quickapp-webview/dist/uni.mp.esm.js b/packages/uni-quickapp-webview/dist/uni.mp.esm.js index 405e5ccf2ab1b98e5d86c5dd732ddc0257bfce4f..d3b6c9dff8d5573af6dcf93304cc52d1c64bafba 100644 --- a/packages/uni-quickapp-webview/dist/uni.mp.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { isPlainObject, extend, hyphenate, isObject, isArray, hasOwn, toNumber, isFunction, camelize } from '@vue/shared'; +import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared'; import { injectHook, ref } from 'vue'; const encode = encodeURIComponent; @@ -20,26 +20,6 @@ function stringifyQuery(obj, encodeStr = encode) { : null; return res ? `?${res}` : ''; } - -function getDataByPath(obj, path) { - const parts = path.split('.'); - const key = parts[0]; - if (!obj) { - obj = {}; - } - if (parts.length === 1) { - return obj[key]; - } - return getDataByPath(obj[key], parts.slice(1).join('.')); -} - -function cache(fn) { - const cache = Object.create(null); - return (str) => { - const hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; -} const invokeArrayFns = (fns, arg) => { let ret; for (let i = 0; i < fns.length; i++) { @@ -141,154 +121,6 @@ function getEventChannel(id) { return eventChannelStack.shift(); } -function getValue(dataPath, target) { - return getDataByPath(target || this, dataPath); -} -function getClass(dynamicClass, staticClass) { - return renderClass(staticClass, dynamicClass); -} -function getStyle(dynamicStyle, staticStyle) { - if (!dynamicStyle && !staticStyle) { - return ''; - } - var dynamicStyleObj = normalizeStyleBinding(dynamicStyle); - var styleObj = staticStyle - ? extend(staticStyle, dynamicStyleObj) - : dynamicStyleObj; - return Object.keys(styleObj) - .map(function (name) { - return hyphenate(name) + ':' + styleObj[name]; - }) - .join(';'); -} -function toObject(arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res; -} -function normalizeStyleBinding(bindingStyle) { - if (Array.isArray(bindingStyle)) { - return toObject(bindingStyle); - } - if (typeof bindingStyle === 'string') { - return parseStyleText(bindingStyle); - } - return bindingStyle; -} -var parseStyleText = cache(function parseStyleText(cssText) { - var res = {}; - var listDelimiter = /;(?![^(]*\))/g; - var propertyDelimiter = /:(.+)/; - cssText.split(listDelimiter).forEach(function (item) { - if (item) { - var tmp = item.split(propertyDelimiter); - tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim()); - } - }); - return res; -}); -function isDef(v) { - return v !== undefined && v !== null; -} -function renderClass(staticClass, dynamicClass) { - if (isDef(staticClass) || isDef(dynamicClass)) { - return concat(staticClass, stringifyClass(dynamicClass)); - } - /* istanbul ignore next */ - return ''; -} -function concat(a, b) { - return a ? (b ? a + ' ' + b : a) : b || ''; -} -function stringifyClass(value) { - if (Array.isArray(value)) { - return stringifyArray(value); - } - if (isObject(value)) { - return stringifyObject(value); - } - if (typeof value === 'string') { - return value; - } - /* istanbul ignore next */ - return ''; -} -function stringifyArray(value) { - var res = ''; - var stringified; - for (var i = 0, l = value.length; i < l; i++) { - if (isDef((stringified = stringifyClass(value[i]))) && stringified !== '') { - if (res) { - res += ' '; - } - res += stringified; - } - } - return res; -} -function stringifyObject(value) { - var res = ''; - for (var key in value) { - if (value[key]) { - if (res) { - res += ' '; - } - res += key; - } - } - return res; -} - -function setModel(target, key, value, modifiers) { - if (isArray(modifiers)) { - if (modifiers.indexOf('trim') !== -1) { - value = value.trim(); - } - if (modifiers.indexOf('number') !== -1) { - value = toNumber(value); - } - } - if (!target) { - target = this; - } - target[key] = value; -} -function setSync(target, key, value) { - if (!target) { - target = this; - } - target[key] = value; -} -function getOrig(data) { - if (isPlainObject(data)) { - return data.$orig || data; - } - return data; -} -function map(val, iteratee) { - let ret, i, l, keys, key; - if (isArray(val)) { - ret = new Array(val.length); - for (i = 0, l = val.length; i < l; i++) { - ret[i] = iteratee(val[i], i); - } - return ret; - } - else if (isObject(val)) { - keys = Object.keys(val); - ret = Object.create(null); - for (i = 0, l = keys.length; i < l; i++) { - key = keys[i]; - ret[key] = iteratee(val[key], key, i); - } - return ret; - } - return []; -} const MP_METHODS = [ 'createSelectorQuery', 'createIntersectionObserver', @@ -347,15 +179,6 @@ function initComponentInstance(instance, options) { } }; }); - // TODO other - ctx.__set_model = setModel; - ctx.__set_sync = setSync; - ctx.__get_orig = getOrig; - // TODO - ctx.__get_value = getValue; - ctx.__get_class = getClass; - ctx.__get_style = getStyle; - ctx.__map = map; } function initMocks(instance, mpInstance, mocks) { const ctx = instance.ctx; @@ -561,7 +384,7 @@ function initRefs(instance, mpInstance) { }); } -const PROP_TYPES = [String, Number, Boolean, Object, Array, null]; +// const PROP_TYPES = [String, Number, Boolean, Object, Array, null] function createObserver(name) { return function observer(newVal) { if (this.$vm) { @@ -569,18 +392,30 @@ function createObserver(name) { } }; } -function parsePropType(key, type, defaultValue) { - // [String]=>String - if (isArray(type) && type.length === 1) { - return type[0]; - } - return type; -} +// function parsePropType(key: string, type: unknown, defaultValue: unknown) { +// // [String]=>String +// if (isArray(type) && type.length === 1) { +// return type[0] +// } +// if ("quickapp-webview" === 'mp-baidu') { +// if ( +// // [String,Boolean]=>Boolean +// defaultValue === false && +// isArray(type) && +// type.length === 2 && +// type.indexOf(String) !== -1 && +// type.indexOf(Boolean) !== -1 +// ) { +// return Boolean +// } +// } +// return type +// } function initDefaultProps(isBehavior = false) { const properties = {}; if (!isBehavior) { properties.vI = { - type: String, + type: null, value: '', }; // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots @@ -604,6 +439,12 @@ function createProperty(key, prop) { prop.observer = createObserver(key); return prop; } +/** + * 不再生成具体的 type 类型,因为微信首次初始化,值为 undefined 时,会告警:property received type-uncompatible value + * @param mpComponentOptions + * @param rawProps + * @param isBehavior + */ function initProps(mpComponentOptions, rawProps, isBehavior = false) { const properties = initDefaultProps(isBehavior); if (isArray(rawProps)) { @@ -622,18 +463,18 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) { if (isFunction(value)) { value = value(); } - const type = opts.type; - opts.type = parsePropType(key, type); + // const type = (opts as any).type as any + // ;(opts as any).type = parsePropType(key, type, value) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, value, }); } else { // content:String - const type = parsePropType(key, opts); + // const type = parsePropType(key, opts, null) properties[key] = createProperty(key, { - type: PROP_TYPES.indexOf(type) !== -1 ? type : null, + type: null, //PROP_TYPES.indexOf(type) !== -1 ? type : null, }); } });