From 5f4ebbb965766ad6c90784bc50be01e1c34ca55e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 2 Dec 2020 17:27:42 +0800 Subject: [PATCH] feat(mp): add defineComponent... --- packages/uni-mp-vue/dist/vue.runtime.esm.js | 88 ++++++++++++++++++++- packages/uni-mp-vue/lib/vue.runtime.esm.js | 86 +++++++++++++++++++- 2 files changed, 171 insertions(+), 3 deletions(-) diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index e2391ac98..d32b90c7e 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -1,4 +1,4 @@ -import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, capitalize, NO, invokeArrayFns, isSet, makeMap, toNumber, hyphenate, camelize, isReservedProp, EMPTY_ARR, toTypeString, isOn } from '@vue/shared'; +import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, capitalize, toHandlerKey, remove, EMPTY_OBJ, NOOP, isGloballyWhitelisted, isIntegerKey, hasOwn, hasChanged, camelize, NO, invokeArrayFns, isSet, makeMap, toNumber, hyphenate, isReservedProp, EMPTY_ARR, toTypeString, isOn } from '@vue/shared'; export { camelize } from '@vue/shared'; const targetMap = new WeakMap(); @@ -1366,6 +1366,57 @@ let currentRenderingInstance = null; function markAttrsAccessed() { } +const COMPONENTS = 'components'; +const DIRECTIVES = 'directives'; +/** + * @private + */ +function resolveDirective(name) { + return resolveAsset(DIRECTIVES, name); +} +// implementation +function resolveAsset(type, name, warnMissing = true) { + const instance = currentInstance; + if (instance) { + const Component = instance.type; + // self name has highest priority + if (type === COMPONENTS) { + // special self referencing call generated by compiler + // inferred from SFC filename + if (name === `_self`) { + return Component; + } + const selfName = Component.displayName || Component.name; + if (selfName && + (selfName === name || + selfName === camelize(name) || + selfName === capitalize(camelize(name)))) { + return Component; + } + } + const res = + // local registration + // check instance[type] first for components with mixin or extends. + resolve(instance[type] || Component[type], name) || + // global registration + resolve(instance.appContext[type], name); + if ((process.env.NODE_ENV !== 'production') && warnMissing && !res) { + warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`); + } + return res; + } + else if ((process.env.NODE_ENV !== 'production')) { + warn(`resolve${capitalize(type.slice(0, -1))} ` + + `can only be used in render() or setup().`); + } +} +function resolve(registry, name) { + return (registry && + (registry[name] || + registry[camelize(name)] || + registry[capitalize(camelize(name))])); +} + function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison isSSR = false) { const props = {}; @@ -1798,6 +1849,15 @@ function validateDirectiveName(name) { if (isBuiltInDirective(name)) { warn('Do not use built-in directive ids as custom directive id: ' + name); } +} +/** + * Adds directives to a VNode. + */ +function withDirectives(vnode, directives) { + { + (process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`); + return vnode; + } } function createAppContext() { @@ -1928,6 +1988,11 @@ function createAppAPI() { }; } +// implementation, close to no-op +function defineComponent(options) { + return isFunction(options) ? { setup: options, name: options.name } : options; +} + const queuePostRenderEffect = queuePostFlushCb; // Simple effect. @@ -3158,6 +3223,25 @@ function computed$1(getterOrOptions) { return c; } +// implementation +function defineProps() { + if ((process.env.NODE_ENV !== 'production')) { + warn(`defineProps() is a compiler-hint helper that is only usable inside ` + + `