Skip to content

Commit

Permalink
perf: do not bind plugin hook context functions (#15610)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jan 16, 2024
1 parent 109fb80 commit 3b7e0c3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
32 changes: 0 additions & 32 deletions packages/vite/src/node/server/__tests__/pluginContainer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 0 additions & 14 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3b7e0c3

Please sign in to comment.