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

chore: .gitignore

上级 82b680d4
dist
packages/uni-cli-shared/dist
packages/vite-plugin-uni/dist
.DS_Store
node_modules
coverage
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -329,8 +329,6 @@ const mutableHandlers = {
}
const readonlyHandlers = {
get: readonlyGet,
has,
ownKeys,
set(target, key) {
if (process.env.NODE_ENV !== 'production') {
console.warn(
......@@ -1321,10 +1319,12 @@ function markAttrsAccessed() {}
function emit(instance, event, ...args) {
const props = instance.vnode.props || EMPTY_OBJ
if (process.env.NODE_ENV !== 'production') {
const options = normalizeEmitsOptions(instance.type)
if (options) {
if (!(event in options)) {
const propsOptions = normalizePropsOptions(instance.type)[0]
const {
emitsOptions,
propsOptions: [propsOptions]
} = instance
if (emitsOptions) {
if (!(event in emitsOptions)) {
if (!propsOptions || !(`on` + capitalize(event) in propsOptions)) {
warn(
`Component emitted event "${event}" but it is neither declared in ` +
......@@ -1332,7 +1332,7 @@ function emit(instance, event, ...args) {
)
}
} else {
const validator = options[event]
const validator = emitsOptions[event]
if (isFunction(validator)) {
const isValid = validator(...args)
if (!isValid) {
......@@ -1370,46 +1370,53 @@ function emit(instance, event, ...args) {
)
}
}
function normalizeEmitsOptions(comp) {
if (hasOwn(comp, '__emits')) {
return comp.__emits
function normalizeEmitsOptions(comp, appContext, asMixin = false) {
const appId = appContext.app ? appContext.app._uid : -1
const cache = comp.__emits || (comp.__emits = {})
const cached = cache[appId]
if (cached !== undefined) {
return cached
}
const raw = comp.emits
let normalized = {}
// apply mixin/extends props
let hasExtends = false
if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
if (comp.extends) {
const extendEmits = raw => {
hasExtends = true
extend(normalized, normalizeEmitsOptions(comp.extends))
extend(normalized, normalizeEmitsOptions(raw, appContext, true))
}
if (!asMixin && appContext.mixins.length) {
appContext.mixins.forEach(extendEmits)
}
if (comp.extends) {
extendEmits(comp.extends)
}
if (comp.mixins) {
hasExtends = true
comp.mixins.forEach(m => extend(normalized, normalizeEmitsOptions(m)))
comp.mixins.forEach(extendEmits)
}
}
if (!raw && !hasExtends) {
return (comp.__emits = undefined)
return (cache[appId] = null)
}
if (isArray(raw)) {
raw.forEach(key => (normalized[key] = null))
} else {
extend(normalized, raw)
}
return (comp.__emits = normalized)
return (cache[appId] = normalized)
}
// Check if an incoming prop key is a declared emit event listener.
// e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
// both considered matched listeners.
function isEmitListener(comp, key) {
let emits
if (!isOn(key) || !(emits = normalizeEmitsOptions(comp))) {
function isEmitListener(options, key) {
if (!options || !isOn(key)) {
return false
}
key = key.replace(/Once$/, '')
return (
hasOwn(emits, key[2].toLowerCase() + key.slice(3)) ||
hasOwn(emits, key.slice(2))
hasOwn(options, key[2].toLowerCase() + key.slice(3)) ||
hasOwn(options, key.slice(2))
)
}
......@@ -1421,12 +1428,12 @@ function initProps(
) {
const props = {}
const attrs = {}
// def(attrs, InternalObjectKey, 1) // fixed by xxxxx
// def(attrs, InternalObjectKey, 1) // fixed by xxxxxx
def(attrs, '__vInternal', 1)
setFullProps(instance, rawProps, props, attrs)
// validation
if (process.env.NODE_ENV !== 'production') {
validateProps(props, instance.type)
validateProps(props, instance)
}
if (isStateful) {
// stateful
......@@ -1443,7 +1450,7 @@ function initProps(
instance.attrs = attrs
}
function setFullProps(instance, rawProps, props, attrs) {
const [options, needCastKeys] = normalizePropsOptions(instance.type)
const [options, needCastKeys] = instance.propsOptions
if (rawProps) {
for (const key in rawProps) {
const value = rawProps[key]
......@@ -1456,7 +1463,7 @@ function setFullProps(instance, rawProps, props, attrs) {
let camelKey
if (options && hasOwn(options, (camelKey = camelize(key)))) {
props[camelKey] = value
} else if (!isEmitListener(instance.type, key)) {
} else if (!isEmitListener(instance.emitsOptions, key)) {
// Any non-declared (either as a prop or an emitted event) props are put
// into a separate `attrs` object for spreading. Make sure to preserve
// original key casing
......@@ -1503,9 +1510,12 @@ function resolvePropValue(options, props, key, value) {
}
return value
}
function normalizePropsOptions(comp) {
if (comp.__props) {
return comp.__props
function normalizePropsOptions(comp, appContext, asMixin = false) {
const appId = appContext.app ? appContext.app._uid : -1
const cache = comp.__props || (comp.__props = {})
const cached = cache[appId]
if (cached) {
return cached
}
const raw = comp.props
const normalized = {}
......@@ -1514,21 +1524,23 @@ function normalizePropsOptions(comp) {
let hasExtends = false
if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
const extendProps = raw => {
const [props, keys] = normalizePropsOptions(raw)
hasExtends = true
const [props, keys] = normalizePropsOptions(raw, appContext, true)
extend(normalized, props)
if (keys) needCastKeys.push(...keys)
}
if (!asMixin && appContext.mixins.length) {
appContext.mixins.forEach(extendProps)
}
if (comp.extends) {
hasExtends = true
extendProps(comp.extends)
}
if (comp.mixins) {
hasExtends = true
comp.mixins.forEach(extendProps)
}
}
if (!raw && !hasExtends) {
return (comp.__props = EMPTY_ARR)
return (cache[appId] = EMPTY_ARR)
}
if (isArray(raw)) {
for (let i = 0; i < raw.length; i++) {
......@@ -1564,9 +1576,7 @@ function normalizePropsOptions(comp) {
}
}
}
const normalizedEntry = [normalized, needCastKeys]
comp.__props = normalizedEntry
return normalizedEntry
return (cache[appId] = [normalized, needCastKeys])
}
// use function string name to check type constructors
// so that it works across vms / iframes.
......@@ -1592,9 +1602,9 @@ function getTypeIndex(type, expectedTypes) {
/**
* dev only
*/
function validateProps(props, comp) {
function validateProps(props, instance) {
const rawValues = toRaw(props)
const options = normalizePropsOptions(comp)[0]
const options = instance.propsOptions[0]
for (const key in options) {
let opt = options[key]
if (opt == null) continue
......@@ -1872,10 +1882,9 @@ function createAppContext() {
provides: Object.create(null)
}
}
let uid$1 = 0
// fixed by xxxxxx
function createAppAPI() {
// render: RootRenderFunction,
// hydrate?: RootHydrateFunction
return function createApp(rootComponent, rootProps = null) {
if (rootProps != null && !isObject(rootProps)) {
process.env.NODE_ENV !== 'production' &&
......@@ -1887,6 +1896,7 @@ function createAppAPI() {
// fixed by xxxxxx
// let isMounted = false
const app = (context.app = {
_uid: uid$1++,
_component: rootComponent,
_props: rootProps,
_container: null,
......@@ -2300,7 +2310,7 @@ function applyOptions(
const checkDuplicateProperties =
process.env.NODE_ENV !== 'production' ? createDuplicateChecker() : null
if (process.env.NODE_ENV !== 'production') {
const propsOptions = normalizePropsOptions(options)[0]
const [propsOptions] = instance.propsOptions
if (propsOptions) {
for (const key in propsOptions) {
checkDuplicateProperties('Props' /* PROPS */, key)
......@@ -2601,17 +2611,18 @@ function resolveMergedOptions(instance) {
if (!globalMixins.length && !mixins && !extendsOptions) return raw
const options = {}
globalMixins.forEach(m => mergeOptions(options, m, instance))
extendsOptions && mergeOptions(options, extendsOptions, instance)
mixins && mixins.forEach(m => mergeOptions(options, m, instance))
mergeOptions(options, raw, instance)
return (raw.__merged = options)
}
function mergeOptions(to, from, instance) {
const strats = instance.appContext.config.optionMergeStrategies
const { mixins, extends: extendsOptions } = from
extendsOptions && mergeOptions(to, extendsOptions, instance)
mixins && mixins.forEach(m => mergeOptions(to, m, instance))
for (const key in from) {
if (strats && hasOwn(strats, key)) {
to[key] = strats[key](to[key], from[key], instance.proxy, key)
} else if (!hasOwn(to, key)) {
} else {
to[key] = from[key]
}
}
......@@ -2682,7 +2693,7 @@ const PublicInstanceProxyHandlers = {
} else if (
// only cache other properties when instance has declared (thus stable)
// props
(normalizedProps = normalizePropsOptions(type)[0]) &&
(normalizedProps = instance.propsOptions[0]) &&
hasOwn(normalizedProps, key)
) {
accessCache[key] = 2 /* PROPS */
......@@ -2727,12 +2738,16 @@ const PublicInstanceProxyHandlers = {
// to infinite warning loop
key.indexOf('__v') !== 0)
) {
if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
if (
data !== EMPTY_OBJ &&
(key[0] === '$' || key[0] === '_') &&
hasOwn(data, key)
) {
warn(
`Property ${JSON.stringify(
key
)} must be accessed via $data because it starts with a reserved ` +
`character and is not proxied on the render context.`
`character ("$" or "_") and is not proxied on the render context.`
)
} else {
warn(
......@@ -2782,7 +2797,7 @@ const PublicInstanceProxyHandlers = {
},
has(
{
_: { data, setupState, accessCache, ctx, type, appContext }
_: { data, setupState, accessCache, ctx, appContext, propsOptions }
},
key
) {
......@@ -2791,8 +2806,7 @@ const PublicInstanceProxyHandlers = {
accessCache[key] !== undefined ||
(data !== EMPTY_OBJ && hasOwn(data, key)) ||
(setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
((normalizedProps = normalizePropsOptions(type)[0]) &&
hasOwn(normalizedProps, key)) ||
((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
hasOwn(ctx, key) ||
hasOwn(publicPropertiesMap, key) ||
hasOwn(appContext.config.globalProperties, key)
......@@ -2872,8 +2886,10 @@ function createRenderContext(instance) {
}
// dev only
function exposePropsOnRenderContext(instance) {
const { ctx, type } = instance
const propsOptions = normalizePropsOptions(type)[0]
const {
ctx,
propsOptions: [propsOptions]
} = instance
if (propsOptions) {
Object.keys(propsOptions).forEach(key => {
Object.defineProperty(ctx, key, {
......@@ -2889,6 +2905,15 @@ function exposePropsOnRenderContext(instance) {
function exposeSetupStateOnRenderContext(instance) {
const { ctx, setupState } = instance
Object.keys(toRaw(setupState)).forEach(key => {
if (key[0] === '$' || key[0] === '_') {
warn(
`setup() return property ${JSON.stringify(
key
)} should not start with "$" or "_" ` +
`which are reserved prefixes for Vue internals.`
)
return
}
Object.defineProperty(ctx, key, {
enumerable: true,
configurable: true,
......@@ -2899,14 +2924,14 @@ function exposeSetupStateOnRenderContext(instance) {
}
const emptyAppContext = createAppContext()
let uid$1 = 0
let uid$2 = 0
function createComponentInstance(vnode, parent, suspense) {
const type = vnode.type
// inherit parent app context - or - if root, adopt from root vnode
const appContext =
(parent ? parent.appContext : vnode.appContext) || emptyAppContext
const instance = {
uid: uid$1++,
uid: uid$2++,
vnode,
type,
parent,
......@@ -2925,6 +2950,12 @@ function createComponentInstance(vnode, parent, suspense) {
// local resovled assets
components: null,
directives: null,
// resolved props and emits options
propsOptions: normalizePropsOptions(type, appContext),
emitsOptions: normalizeEmitsOptions(type, appContext),
// emit
emit: null,
emitted: null,
// state
ctx: EMPTY_OBJ,
data: EMPTY_OBJ,
......@@ -2955,9 +2986,7 @@ function createComponentInstance(vnode, parent, suspense) {
a: null,
rtg: null,
rtc: null,
ec: null,
emit: null,
emitted: null
ec: null
}
if (process.env.NODE_ENV !== 'production') {
instance.ctx = createRenderContext(instance)
......@@ -3214,7 +3243,7 @@ function computed$1(getterOrOptions) {
}
// Core API ------------------------------------------------------------------
const version = '3.0.0-rc.9'
const version = '3.0.0-rc.10'
// import deepCopy from './deepCopy'
/**
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
import { isPlainObject } from '@vue/shared'
const NAVBAR_HEIGHT = 44
const TABBAR_HEIGHT = 50
const COMPONENT_NAME_PREFIX = 'VUni'
function debounce(fn, delay) {
let timeout
const newFn = function() {
clearTimeout(timeout)
const timerFn = () => fn.apply(this, arguments)
timeout = setTimeout(timerFn, delay)
}
newFn.cancel = function() {
clearTimeout(timeout)
}
return newFn
}
function plusReady(callback) {
if (typeof callback !== 'function') {
return
}
if (window.plus) {
return callback()
}
document.addEventListener('plusready', callback)
}
const encode = encodeURIComponent
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
? Object.keys(obj)
.map(key => {
let val = obj[key]
if (typeof val === undefined || val === null) {
val = ''
} else if (isPlainObject(val)) {
val = JSON.stringify(val)
}
return encodeStr(key) + '=' + encodeStr(val)
})
.filter(x => x.length > 0)
.join('&')
: null
return res ? `?${res}` : ''
}
const TAGS = [
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
'uni-page-wrapper',
'uni-page-body',
'uni-page-refresh',
'uni-actionsheet',
'uni-modal',
'uni-toast',
'uni-resize-sensor',
'uni-shadow-root',
'uni-ad',
'uni-audio',
'uni-button',
'uni-camera',
'uni-canvas',
'uni-checkbox',
'uni-checkbox-group',
'uni-cover-image',
'uni-cover-view',
'uni-editor',
'uni-form',
'uni-functional-page-navigator',
'uni-icon',
'uni-image',
'uni-input',
'uni-label',
'uni-live-player',
'uni-live-pusher',
'uni-map',
'uni-movable-area',
'uni-movable-view',
'uni-navigator',
'uni-official-account',
'uni-open-data',
'uni-picker',
'uni-picker-view',
'uni-picker-view-column',
'uni-progress',
'uni-radio',
'uni-radio-group',
'uni-rich-text',
'uni-scroll-view',
'uni-slider',
'uni-swiper',
'uni-swiper-item',
'uni-switch',
'uni-text',
'uni-textarea',
'uni-video',
'uni-view',
'uni-web-view'
]
function isCustomElement(tag) {
return TAGS.indexOf(tag) !== -1
}
export {
COMPONENT_NAME_PREFIX,
NAVBAR_HEIGHT,
TABBAR_HEIGHT,
TAGS,
debounce,
isCustomElement,
plusReady,
stringifyQuery
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册