From 4787a4d6eacfbf8f5d7d8bb9f8c70e94e487c429 Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 15 Jan 2024 20:12:36 +0100 Subject: [PATCH] perf: do not bind plugin hook context functions --- .../server/__tests__/pluginContainer.spec.ts | 32 ------------------- .../vite/src/node/server/pluginContainer.ts | 14 -------- 2 files changed, 46 deletions(-) diff --git a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts index 33243331f35da2..070dedd2acb463 100644 --- a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts +++ b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts @@ -10,38 +10,6 @@ let resolveId: (id: string) => any let moduleGraph: ModuleGraph describe('plugin container', () => { - it('has bound methods', async () => { - expect.assertions(14) - const entryUrl = '/x.js' - - const plugin: Plugin = { - name: 'p1', - load(id) { - // bound functions and bound arrow functions do not have prototype - expect(this.parse.prototype).equals(undefined) - expect(this.resolve.prototype).equals(undefined) - expect(this.load.prototype).equals(undefined) - expect(this.getModuleInfo.prototype).equals(undefined) - expect(this.getModuleIds.prototype).equals(undefined) - expect(this.addWatchFile.prototype).equals(undefined) - expect(this.getWatchFiles.prototype).equals(undefined) - expect(this.emitFile.prototype).equals(undefined) - expect(this.setAssetSource.prototype).equals(undefined) - expect(this.getFileName.prototype).equals(undefined) - expect(this.warn.prototype).equals(undefined) - expect(this.error.prototype).equals(undefined) - expect(this.debug.prototype).equals(undefined) - expect(this.info.prototype).equals(undefined) - }, - } - - const container = await getPluginContainer({ - plugins: [plugin], - }) - - await container.load(entryUrl) - }) - describe('getModuleInfo', () => { beforeEach(() => { moduleGraph = new ModuleGraph((id) => resolveId(id)) diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 3d412ccae0c502..fa2dd4167fce5d 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -299,20 +299,6 @@ export async function createPluginContainer( constructor(initialPlugin?: Plugin) { this._activePlugin = initialPlugin || null - this.parse = this.parse.bind(this) - this.resolve = this.resolve.bind(this) - this.load = this.load.bind(this) - this.getModuleInfo = this.getModuleInfo.bind(this) - this.getModuleIds = this.getModuleIds.bind(this) - this.addWatchFile = this.addWatchFile.bind(this) - this.getWatchFiles = this.getWatchFiles.bind(this) - this.emitFile = this.emitFile.bind(this) - this.setAssetSource = this.setAssetSource.bind(this) - this.getFileName = this.getFileName.bind(this) - this.warn = this.warn.bind(this) - this.error = this.error.bind(this) - this.debug = this.debug.bind(this) - this.info = this.info.bind(this) } parse(code: string, opts: any) {