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

chore: .gitignore

上级 82b680d4
dist packages/uni-cli-shared/dist
packages/vite-plugin-uni/dist
.DS_Store .DS_Store
node_modules node_modules
coverage coverage
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -329,8 +329,6 @@ const mutableHandlers = { ...@@ -329,8 +329,6 @@ const mutableHandlers = {
} }
const readonlyHandlers = { const readonlyHandlers = {
get: readonlyGet, get: readonlyGet,
has,
ownKeys,
set(target, key) { set(target, key) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.warn( console.warn(
...@@ -1321,10 +1319,12 @@ function markAttrsAccessed() {} ...@@ -1321,10 +1319,12 @@ function markAttrsAccessed() {}
function emit(instance, event, ...args) { function emit(instance, event, ...args) {
const props = instance.vnode.props || EMPTY_OBJ const props = instance.vnode.props || EMPTY_OBJ
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const options = normalizeEmitsOptions(instance.type) const {
if (options) { emitsOptions,
if (!(event in options)) { propsOptions: [propsOptions]
const propsOptions = normalizePropsOptions(instance.type)[0] } = instance
if (emitsOptions) {
if (!(event in emitsOptions)) {
if (!propsOptions || !(`on` + capitalize(event) in propsOptions)) { if (!propsOptions || !(`on` + capitalize(event) in propsOptions)) {
warn( warn(
`Component emitted event "${event}" but it is neither declared in ` + `Component emitted event "${event}" but it is neither declared in ` +
...@@ -1332,7 +1332,7 @@ function emit(instance, event, ...args) { ...@@ -1332,7 +1332,7 @@ function emit(instance, event, ...args) {
) )
} }
} else { } else {
const validator = options[event] const validator = emitsOptions[event]
if (isFunction(validator)) { if (isFunction(validator)) {
const isValid = validator(...args) const isValid = validator(...args)
if (!isValid) { if (!isValid) {
...@@ -1370,46 +1370,53 @@ function emit(instance, event, ...args) { ...@@ -1370,46 +1370,53 @@ function emit(instance, event, ...args) {
) )
} }
} }
function normalizeEmitsOptions(comp) { function normalizeEmitsOptions(comp, appContext, asMixin = false) {
if (hasOwn(comp, '__emits')) { const appId = appContext.app ? appContext.app._uid : -1
return comp.__emits const cache = comp.__emits || (comp.__emits = {})
const cached = cache[appId]
if (cached !== undefined) {
return cached
} }
const raw = comp.emits const raw = comp.emits
let normalized = {} let normalized = {}
// apply mixin/extends props // apply mixin/extends props
let hasExtends = false let hasExtends = false
if (__VUE_OPTIONS_API__ && !isFunction(comp)) { if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
if (comp.extends) { const extendEmits = raw => {
hasExtends = true 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) { if (comp.mixins) {
hasExtends = true comp.mixins.forEach(extendEmits)
comp.mixins.forEach(m => extend(normalized, normalizeEmitsOptions(m)))
} }
} }
if (!raw && !hasExtends) { if (!raw && !hasExtends) {
return (comp.__emits = undefined) return (cache[appId] = null)
} }
if (isArray(raw)) { if (isArray(raw)) {
raw.forEach(key => (normalized[key] = null)) raw.forEach(key => (normalized[key] = null))
} else { } else {
extend(normalized, raw) extend(normalized, raw)
} }
return (comp.__emits = normalized) return (cache[appId] = normalized)
} }
// Check if an incoming prop key is a declared emit event listener. // Check if an incoming prop key is a declared emit event listener.
// e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
// both considered matched listeners. // both considered matched listeners.
function isEmitListener(comp, key) { function isEmitListener(options, key) {
let emits if (!options || !isOn(key)) {
if (!isOn(key) || !(emits = normalizeEmitsOptions(comp))) {
return false return false
} }
key = key.replace(/Once$/, '') key = key.replace(/Once$/, '')
return ( return (
hasOwn(emits, key[2].toLowerCase() + key.slice(3)) || hasOwn(options, key[2].toLowerCase() + key.slice(3)) ||
hasOwn(emits, key.slice(2)) hasOwn(options, key.slice(2))
) )
} }
...@@ -1421,12 +1428,12 @@ function initProps( ...@@ -1421,12 +1428,12 @@ function initProps(
) { ) {
const props = {} const props = {}
const attrs = {} const attrs = {}
// def(attrs, InternalObjectKey, 1) // fixed by xxxxx // def(attrs, InternalObjectKey, 1) // fixed by xxxxxx
def(attrs, '__vInternal', 1) def(attrs, '__vInternal', 1)
setFullProps(instance, rawProps, props, attrs) setFullProps(instance, rawProps, props, attrs)
// validation // validation
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
validateProps(props, instance.type) validateProps(props, instance)
} }
if (isStateful) { if (isStateful) {
// stateful // stateful
...@@ -1443,7 +1450,7 @@ function initProps( ...@@ -1443,7 +1450,7 @@ function initProps(
instance.attrs = attrs instance.attrs = attrs
} }
function setFullProps(instance, rawProps, props, attrs) { function setFullProps(instance, rawProps, props, attrs) {
const [options, needCastKeys] = normalizePropsOptions(instance.type) const [options, needCastKeys] = instance.propsOptions
if (rawProps) { if (rawProps) {
for (const key in rawProps) { for (const key in rawProps) {
const value = rawProps[key] const value = rawProps[key]
...@@ -1456,7 +1463,7 @@ function setFullProps(instance, rawProps, props, attrs) { ...@@ -1456,7 +1463,7 @@ function setFullProps(instance, rawProps, props, attrs) {
let camelKey let camelKey
if (options && hasOwn(options, (camelKey = camelize(key)))) { if (options && hasOwn(options, (camelKey = camelize(key)))) {
props[camelKey] = value 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 // 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 // into a separate `attrs` object for spreading. Make sure to preserve
// original key casing // original key casing
...@@ -1503,9 +1510,12 @@ function resolvePropValue(options, props, key, value) { ...@@ -1503,9 +1510,12 @@ function resolvePropValue(options, props, key, value) {
} }
return value return value
} }
function normalizePropsOptions(comp) { function normalizePropsOptions(comp, appContext, asMixin = false) {
if (comp.__props) { const appId = appContext.app ? appContext.app._uid : -1
return comp.__props const cache = comp.__props || (comp.__props = {})
const cached = cache[appId]
if (cached) {
return cached
} }
const raw = comp.props const raw = comp.props
const normalized = {} const normalized = {}
...@@ -1514,21 +1524,23 @@ function normalizePropsOptions(comp) { ...@@ -1514,21 +1524,23 @@ function normalizePropsOptions(comp) {
let hasExtends = false let hasExtends = false
if (__VUE_OPTIONS_API__ && !isFunction(comp)) { if (__VUE_OPTIONS_API__ && !isFunction(comp)) {
const extendProps = raw => { const extendProps = raw => {
const [props, keys] = normalizePropsOptions(raw) hasExtends = true
const [props, keys] = normalizePropsOptions(raw, appContext, true)
extend(normalized, props) extend(normalized, props)
if (keys) needCastKeys.push(...keys) if (keys) needCastKeys.push(...keys)
} }
if (!asMixin && appContext.mixins.length) {
appContext.mixins.forEach(extendProps)
}
if (comp.extends) { if (comp.extends) {
hasExtends = true
extendProps(comp.extends) extendProps(comp.extends)
} }
if (comp.mixins) { if (comp.mixins) {
hasExtends = true
comp.mixins.forEach(extendProps) comp.mixins.forEach(extendProps)
} }
} }
if (!raw && !hasExtends) { if (!raw && !hasExtends) {
return (comp.__props = EMPTY_ARR) return (cache[appId] = EMPTY_ARR)
} }
if (isArray(raw)) { if (isArray(raw)) {
for (let i = 0; i < raw.length; i++) { for (let i = 0; i < raw.length; i++) {
...@@ -1564,9 +1576,7 @@ function normalizePropsOptions(comp) { ...@@ -1564,9 +1576,7 @@ function normalizePropsOptions(comp) {
} }
} }
} }
const normalizedEntry = [normalized, needCastKeys] return (cache[appId] = [normalized, needCastKeys])
comp.__props = normalizedEntry
return normalizedEntry
} }
// use function string name to check type constructors // use function string name to check type constructors
// so that it works across vms / iframes. // so that it works across vms / iframes.
...@@ -1592,9 +1602,9 @@ function getTypeIndex(type, expectedTypes) { ...@@ -1592,9 +1602,9 @@ function getTypeIndex(type, expectedTypes) {
/** /**
* dev only * dev only
*/ */
function validateProps(props, comp) { function validateProps(props, instance) {
const rawValues = toRaw(props) const rawValues = toRaw(props)
const options = normalizePropsOptions(comp)[0] const options = instance.propsOptions[0]
for (const key in options) { for (const key in options) {
let opt = options[key] let opt = options[key]
if (opt == null) continue if (opt == null) continue
...@@ -1872,10 +1882,9 @@ function createAppContext() { ...@@ -1872,10 +1882,9 @@ function createAppContext() {
provides: Object.create(null) provides: Object.create(null)
} }
} }
let uid$1 = 0
// fixed by xxxxxx // fixed by xxxxxx
function createAppAPI() { function createAppAPI() {
// render: RootRenderFunction,
// hydrate?: RootHydrateFunction
return function createApp(rootComponent, rootProps = null) { return function createApp(rootComponent, rootProps = null) {
if (rootProps != null && !isObject(rootProps)) { if (rootProps != null && !isObject(rootProps)) {
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'production' &&
...@@ -1887,6 +1896,7 @@ function createAppAPI() { ...@@ -1887,6 +1896,7 @@ function createAppAPI() {
// fixed by xxxxxx // fixed by xxxxxx
// let isMounted = false // let isMounted = false
const app = (context.app = { const app = (context.app = {
_uid: uid$1++,
_component: rootComponent, _component: rootComponent,
_props: rootProps, _props: rootProps,
_container: null, _container: null,
...@@ -2300,7 +2310,7 @@ function applyOptions( ...@@ -2300,7 +2310,7 @@ function applyOptions(
const checkDuplicateProperties = const checkDuplicateProperties =
process.env.NODE_ENV !== 'production' ? createDuplicateChecker() : null process.env.NODE_ENV !== 'production' ? createDuplicateChecker() : null
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const propsOptions = normalizePropsOptions(options)[0] const [propsOptions] = instance.propsOptions
if (propsOptions) { if (propsOptions) {
for (const key in propsOptions) { for (const key in propsOptions) {
checkDuplicateProperties('Props' /* PROPS */, key) checkDuplicateProperties('Props' /* PROPS */, key)
...@@ -2601,17 +2611,18 @@ function resolveMergedOptions(instance) { ...@@ -2601,17 +2611,18 @@ function resolveMergedOptions(instance) {
if (!globalMixins.length && !mixins && !extendsOptions) return raw if (!globalMixins.length && !mixins && !extendsOptions) return raw
const options = {} const options = {}
globalMixins.forEach(m => mergeOptions(options, m, instance)) globalMixins.forEach(m => mergeOptions(options, m, instance))
extendsOptions && mergeOptions(options, extendsOptions, instance)
mixins && mixins.forEach(m => mergeOptions(options, m, instance))
mergeOptions(options, raw, instance) mergeOptions(options, raw, instance)
return (raw.__merged = options) return (raw.__merged = options)
} }
function mergeOptions(to, from, instance) { function mergeOptions(to, from, instance) {
const strats = instance.appContext.config.optionMergeStrategies 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) { for (const key in from) {
if (strats && hasOwn(strats, key)) { if (strats && hasOwn(strats, key)) {
to[key] = strats[key](to[key], from[key], instance.proxy, key) to[key] = strats[key](to[key], from[key], instance.proxy, key)
} else if (!hasOwn(to, key)) { } else {
to[key] = from[key] to[key] = from[key]
} }
} }
...@@ -2682,7 +2693,7 @@ const PublicInstanceProxyHandlers = { ...@@ -2682,7 +2693,7 @@ const PublicInstanceProxyHandlers = {
} else if ( } else if (
// only cache other properties when instance has declared (thus stable) // only cache other properties when instance has declared (thus stable)
// props // props
(normalizedProps = normalizePropsOptions(type)[0]) && (normalizedProps = instance.propsOptions[0]) &&
hasOwn(normalizedProps, key) hasOwn(normalizedProps, key)
) { ) {
accessCache[key] = 2 /* PROPS */ accessCache[key] = 2 /* PROPS */
...@@ -2727,12 +2738,16 @@ const PublicInstanceProxyHandlers = { ...@@ -2727,12 +2738,16 @@ const PublicInstanceProxyHandlers = {
// to infinite warning loop // to infinite warning loop
key.indexOf('__v') !== 0) 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( warn(
`Property ${JSON.stringify( `Property ${JSON.stringify(
key key
)} must be accessed via $data because it starts with a reserved ` + )} 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 { } else {
warn( warn(
...@@ -2782,7 +2797,7 @@ const PublicInstanceProxyHandlers = { ...@@ -2782,7 +2797,7 @@ const PublicInstanceProxyHandlers = {
}, },
has( has(
{ {
_: { data, setupState, accessCache, ctx, type, appContext } _: { data, setupState, accessCache, ctx, appContext, propsOptions }
}, },
key key
) { ) {
...@@ -2791,8 +2806,7 @@ const PublicInstanceProxyHandlers = { ...@@ -2791,8 +2806,7 @@ const PublicInstanceProxyHandlers = {
accessCache[key] !== undefined || accessCache[key] !== undefined ||
(data !== EMPTY_OBJ && hasOwn(data, key)) || (data !== EMPTY_OBJ && hasOwn(data, key)) ||
(setupState !== EMPTY_OBJ && hasOwn(setupState, key)) || (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
((normalizedProps = normalizePropsOptions(type)[0]) && ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
hasOwn(normalizedProps, key)) ||
hasOwn(ctx, key) || hasOwn(ctx, key) ||
hasOwn(publicPropertiesMap, key) || hasOwn(publicPropertiesMap, key) ||
hasOwn(appContext.config.globalProperties, key) hasOwn(appContext.config.globalProperties, key)
...@@ -2872,8 +2886,10 @@ function createRenderContext(instance) { ...@@ -2872,8 +2886,10 @@ function createRenderContext(instance) {
} }
// dev only // dev only
function exposePropsOnRenderContext(instance) { function exposePropsOnRenderContext(instance) {
const { ctx, type } = instance const {
const propsOptions = normalizePropsOptions(type)[0] ctx,
propsOptions: [propsOptions]
} = instance
if (propsOptions) { if (propsOptions) {
Object.keys(propsOptions).forEach(key => { Object.keys(propsOptions).forEach(key => {
Object.defineProperty(ctx, key, { Object.defineProperty(ctx, key, {
...@@ -2889,6 +2905,15 @@ function exposePropsOnRenderContext(instance) { ...@@ -2889,6 +2905,15 @@ function exposePropsOnRenderContext(instance) {
function exposeSetupStateOnRenderContext(instance) { function exposeSetupStateOnRenderContext(instance) {
const { ctx, setupState } = instance const { ctx, setupState } = instance
Object.keys(toRaw(setupState)).forEach(key => { 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, { Object.defineProperty(ctx, key, {
enumerable: true, enumerable: true,
configurable: true, configurable: true,
...@@ -2899,14 +2924,14 @@ function exposeSetupStateOnRenderContext(instance) { ...@@ -2899,14 +2924,14 @@ function exposeSetupStateOnRenderContext(instance) {
} }
const emptyAppContext = createAppContext() const emptyAppContext = createAppContext()
let uid$1 = 0 let uid$2 = 0
function createComponentInstance(vnode, parent, suspense) { function createComponentInstance(vnode, parent, suspense) {
const type = vnode.type const type = vnode.type
// inherit parent app context - or - if root, adopt from root vnode // inherit parent app context - or - if root, adopt from root vnode
const appContext = const appContext =
(parent ? parent.appContext : vnode.appContext) || emptyAppContext (parent ? parent.appContext : vnode.appContext) || emptyAppContext
const instance = { const instance = {
uid: uid$1++, uid: uid$2++,
vnode, vnode,
type, type,
parent, parent,
...@@ -2925,6 +2950,12 @@ function createComponentInstance(vnode, parent, suspense) { ...@@ -2925,6 +2950,12 @@ function createComponentInstance(vnode, parent, suspense) {
// local resovled assets // local resovled assets
components: null, components: null,
directives: null, directives: null,
// resolved props and emits options
propsOptions: normalizePropsOptions(type, appContext),
emitsOptions: normalizeEmitsOptions(type, appContext),
// emit
emit: null,
emitted: null,
// state // state
ctx: EMPTY_OBJ, ctx: EMPTY_OBJ,
data: EMPTY_OBJ, data: EMPTY_OBJ,
...@@ -2955,9 +2986,7 @@ function createComponentInstance(vnode, parent, suspense) { ...@@ -2955,9 +2986,7 @@ function createComponentInstance(vnode, parent, suspense) {
a: null, a: null,
rtg: null, rtg: null,
rtc: null, rtc: null,
ec: null, ec: null
emit: null,
emitted: null
} }
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
instance.ctx = createRenderContext(instance) instance.ctx = createRenderContext(instance)
...@@ -3214,7 +3243,7 @@ function computed$1(getterOrOptions) { ...@@ -3214,7 +3243,7 @@ function computed$1(getterOrOptions) {
} }
// Core API ------------------------------------------------------------------ // Core API ------------------------------------------------------------------
const version = '3.0.0-rc.9' const version = '3.0.0-rc.10'
// import deepCopy from './deepCopy' // 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.
先完成此消息的编辑!
想要评论请 注册