build: generate more treeshaking friendly code

This commit is contained in:
Evan You
2021-09-16 10:56:34 -04:00
parent a6e5f82d8e
commit a31303f835
2 changed files with 131 additions and 124 deletions

View File

@@ -1,5 +1,5 @@
import { ErrorCodes, callWithErrorHandling } from './errorHandling'
import { isArray } from '@vue/shared'
import { isArray, NOOP } from '@vue/shared'
import { ComponentInternalInstance, getComponentName } from './component'
import { warn } from './warning'
@@ -128,10 +128,7 @@ function queueCb(
if (!isArray(cb)) {
if (
!activeQueue ||
!activeQueue.includes(
cb,
cb.allowRecurse ? index + 1 : index
)
!activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)
) {
pendingQueue.push(cb)
}
@@ -241,11 +238,20 @@ function flushJobs(seen?: CountMap) {
// its update can be skipped.
queue.sort((a, b) => getId(a) - getId(b))
// conditional usage of checkRecursiveUpdate must be determined out of
// try ... catch block since Rollup by default de-optimizes treeshaking
// inside try-catch. This can leave all warning code unshaked. Although
// they would get eventually shaken by a minifier like terser, some minifiers
// would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
const check = __DEV__
? (job: SchedulerJob) => checkRecursiveUpdates(seen!, job)
: NOOP
try {
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
const job = queue[flushIndex]
if (job && job.active !== false) {
if (__DEV__ && checkRecursiveUpdates(seen!, job)) {
if (__DEV__ && check(job)) {
continue
}
// console.log(`running:`, job.id)