Skip to content

Commit c6eb3cc

Browse files
authored
build: improve treeshakeability (#5682)
1 parent 053c65b commit c6eb3cc

File tree

7 files changed

+33
-31
lines changed

7 files changed

+33
-31
lines changed

packages/reactivity/src/baseHandlers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { warn } from './warning'
3535
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`)
3636

3737
const builtInSymbols = new Set(
38+
/*#__PURE__*/
3839
Object.getOwnPropertyNames(Symbol)
3940
.map(key => (Symbol as any)[key])
4041
.filter(isSymbol)

packages/reactivity/src/deferredComputed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ComputedGetter, ComputedRef } from './computed'
44
import { ReactiveFlags, toRaw } from './reactive'
55
import { trackRefValue, triggerRefValue } from './ref'
66

7-
const tick = Promise.resolve()
7+
const tick = /*#__PURE__*/ Promise.resolve()
88
const queue: any[] = []
99
let queued = false
1010

packages/runtime-core/src/componentPublicInstance.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ const getPublicInstance = (
223223
return getPublicInstance(i.parent)
224224
}
225225

226-
export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend(
227-
Object.create(null),
228-
{
226+
export const publicPropertiesMap: PublicPropertiesMap =
227+
// Move PURE marker to new line to workaround compiler discarding it
228+
// due to type annotation
229+
/*#__PURE__*/ extend(Object.create(null), {
229230
$: i => i,
230231
$el: i => i.vnode.el,
231232
$data: i => i.data,
@@ -240,8 +241,7 @@ export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend(
240241
$forceUpdate: i => () => queueJob(i.update),
241242
$nextTick: i => nextTick.bind(i.proxy!),
242243
$watch: i => (__FEATURE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
243-
} as PublicPropertiesMap
244-
)
244+
} as PublicPropertiesMap)
245245

246246
if (__COMPAT__) {
247247
installCompatInstanceProperties(publicPropertiesMap)
@@ -456,8 +456,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
456456
) {
457457
if (descriptor.get != null) {
458458
// invalidate key cache of a getter based property #5417
459-
target.$.accessCache[key] = 0;
460-
} else if (hasOwn(descriptor,'value')) {
459+
target.$.accessCache[key] = 0
460+
} else if (hasOwn(descriptor, 'value')) {
461461
this.set!(target, key, descriptor.value, null)
462462
}
463463
return Reflect.defineProperty(target, key, descriptor)

packages/runtime-core/src/scheduler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const pendingPostFlushCbs: SchedulerJob[] = []
4747
let activePostFlushCbs: SchedulerJob[] | null = null
4848
let postFlushIndex = 0
4949

50-
const resolvedPromise: Promise<any> = Promise.resolve()
50+
const resolvedPromise = /*#__PURE__*/ Promise.resolve() as Promise<any>
5151
let currentFlushPromise: Promise<void> | null = null
5252

5353
let currentPreFlushParentJob: SchedulerJob | null = null

packages/runtime-dom/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare module '@vue/reactivity' {
3131
}
3232
}
3333

34-
const rendererOptions = extend({ patchProp }, nodeOps)
34+
const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps)
3535

3636
// lazy create the renderer - this makes core renderer logic tree-shakable
3737
// in case the user only imports reactivity utilities from Vue.

packages/runtime-dom/src/modules/events.ts

+21-20
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,32 @@ interface Invoker extends EventListener {
1313
type EventValue = Function | Function[]
1414

1515
// Async edge case fix requires storing an event listener's attach timestamp.
16-
let _getNow: () => number = Date.now
17-
18-
let skipTimestampCheck = false
19-
20-
if (typeof window !== 'undefined') {
21-
// Determine what event timestamp the browser is using. Annoyingly, the
22-
// timestamp can either be hi-res (relative to page load) or low-res
23-
// (relative to UNIX epoch), so in order to compare time we have to use the
24-
// same timestamp type when saving the flush timestamp.
25-
if (_getNow() > document.createEvent('Event').timeStamp) {
26-
// if the low-res timestamp which is bigger than the event timestamp
27-
// (which is evaluated AFTER) it means the event is using a hi-res timestamp,
28-
// and we need to use the hi-res version for event listeners as well.
29-
_getNow = () => performance.now()
16+
const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
17+
let _getNow = Date.now
18+
let skipTimestampCheck = false
19+
if (typeof window !== 'undefined') {
20+
// Determine what event timestamp the browser is using. Annoyingly, the
21+
// timestamp can either be hi-res (relative to page load) or low-res
22+
// (relative to UNIX epoch), so in order to compare time we have to use the
23+
// same timestamp type when saving the flush timestamp.
24+
if (Date.now() > document.createEvent('Event').timeStamp) {
25+
// if the low-res timestamp which is bigger than the event timestamp
26+
// (which is evaluated AFTER) it means the event is using a hi-res timestamp,
27+
// and we need to use the hi-res version for event listeners as well.
28+
_getNow = () => performance.now()
29+
}
30+
// #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
31+
// and does not fire microtasks in between event propagation, so safe to exclude.
32+
const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i)
33+
skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53)
3034
}
31-
// #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
32-
// and does not fire microtasks in between event propagation, so safe to exclude.
33-
const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i)
34-
skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53)
35-
}
35+
return [_getNow, skipTimestampCheck]
36+
})()
3637

3738
// To avoid the overhead of repeatedly calling performance.now(), we cache
3839
// and use the same timestamp for all event listeners attached in the same tick.
3940
let cachedNow: number = 0
40-
const p = Promise.resolve()
41+
const p = /*#__PURE__*/ Promise.resolve()
4142
const reset = () => {
4243
cachedNow = 0
4344
}

packages/runtime-dom/src/nodeOps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const svgNS = 'http://www.w3.org/2000/svg'
44

55
const doc = (typeof document !== 'undefined' ? document : null) as Document
66

7-
const templateContainer = doc && doc.createElement('template')
7+
const templateContainer = doc && /*#__PURE__*/ doc.createElement('template')
88

99
export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
1010
insert: (child, parent, anchor) => {

0 commit comments

Comments
 (0)