Skip to content

Commit 3b7e0c3

Browse files
authored
perf: do not bind plugin hook context functions (#15610)
1 parent 109fb80 commit 3b7e0c3

File tree

2 files changed

+0
-46
lines changed

2 files changed

+0
-46
lines changed

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,6 @@ let resolveId: (id: string) => any
1010
let moduleGraph: ModuleGraph
1111

1212
describe('plugin container', () => {
13-
it('has bound methods', async () => {
14-
expect.assertions(14)
15-
const entryUrl = '/x.js'
16-
17-
const plugin: Plugin = {
18-
name: 'p1',
19-
load(id) {
20-
// bound functions and bound arrow functions do not have prototype
21-
expect(this.parse.prototype).equals(undefined)
22-
expect(this.resolve.prototype).equals(undefined)
23-
expect(this.load.prototype).equals(undefined)
24-
expect(this.getModuleInfo.prototype).equals(undefined)
25-
expect(this.getModuleIds.prototype).equals(undefined)
26-
expect(this.addWatchFile.prototype).equals(undefined)
27-
expect(this.getWatchFiles.prototype).equals(undefined)
28-
expect(this.emitFile.prototype).equals(undefined)
29-
expect(this.setAssetSource.prototype).equals(undefined)
30-
expect(this.getFileName.prototype).equals(undefined)
31-
expect(this.warn.prototype).equals(undefined)
32-
expect(this.error.prototype).equals(undefined)
33-
expect(this.debug.prototype).equals(undefined)
34-
expect(this.info.prototype).equals(undefined)
35-
},
36-
}
37-
38-
const container = await getPluginContainer({
39-
plugins: [plugin],
40-
})
41-
42-
await container.load(entryUrl)
43-
})
44-
4513
describe('getModuleInfo', () => {
4614
beforeEach(() => {
4715
moduleGraph = new ModuleGraph((id) => resolveId(id))

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,6 @@ export async function createPluginContainer(
299299

300300
constructor(initialPlugin?: Plugin) {
301301
this._activePlugin = initialPlugin || null
302-
this.parse = this.parse.bind(this)
303-
this.resolve = this.resolve.bind(this)
304-
this.load = this.load.bind(this)
305-
this.getModuleInfo = this.getModuleInfo.bind(this)
306-
this.getModuleIds = this.getModuleIds.bind(this)
307-
this.addWatchFile = this.addWatchFile.bind(this)
308-
this.getWatchFiles = this.getWatchFiles.bind(this)
309-
this.emitFile = this.emitFile.bind(this)
310-
this.setAssetSource = this.setAssetSource.bind(this)
311-
this.getFileName = this.getFileName.bind(this)
312-
this.warn = this.warn.bind(this)
313-
this.error = this.error.bind(this)
314-
this.debug = this.debug.bind(this)
315-
this.info = this.info.bind(this)
316302
}
317303

318304
parse(code: string, opts: any) {

0 commit comments

Comments
 (0)