feat!: remove acorn dependency and require custom parser setup · unjs/unplugin@40e4a04 · GitHub
Skip to content

Commit 40e4a04

Browse files
committed
feat!: remove acorn dependency and require custom parser setup
Users must now call `setParseImpl` to provide custom parsing logic before invoking `this.parse`. Acorn has been removed as a dependency. closes #480
1 parent d153346 commit 40e4a04

13 files changed

Lines changed: 24 additions & 36 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ catalogs:
5151

5252
prod:
5353
'@jridgewell/remapping': ^2.3.5
54-
acorn: ^8.15.0
5554
picomatch: ^4.0.3
5655
webpack-virtual-modules: ^0.6.2
5756

src/bun/utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Loader, PluginBuilder } from 'bun'
22
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
33
import fs from 'node:fs'
44
import path from 'node:path'
5-
import * as acorn from 'acorn'
5+
import { parse } from '../utils/parse'
66

77
const ExtToLoader: Record<string, Loader> = {
88
'.js': 'js',
@@ -47,14 +47,7 @@ export function createBuildContext(build: PluginBuilder): UnpluginBuildContext {
4747
fs.writeFileSync(outPath, emittedFile.source)
4848
}
4949
},
50-
parse(code, opts = {}) {
51-
return acorn.parse(code, {
52-
sourceType: 'module',
53-
ecmaVersion: 'latest',
54-
locations: true,
55-
...opts,
56-
})
57-
},
50+
parse,
5851
getNativeBuildContext() {
5952
return { framework: 'bun', build }
6053
},

src/esbuild/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Buffer } from 'node:buffer'
66
import fs from 'node:fs'
77
import path from 'node:path'
88
import remapping from '@jridgewell/remapping'
9-
import { parse } from '../utils/context'
9+
import { parse } from '../utils/parse'
1010

1111
const ExtToLoader: Record<string, Loader> = {
1212
'.js': 'js',

src/farm/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { CompilationContext } from '@farmfe/core'
22
import type { UnpluginBuildContext, UnpluginContext } from '../types'
33
import { Buffer } from 'node:buffer'
44
import { extname } from 'node:path'
5-
import { parse } from '../utils/context'
5+
import { parse } from '../utils/parse'
66

77
export function createFarmContext(
88
context: CompilationContext,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './define'
22
export * from './types'
3+
export { setParseImpl } from './utils/parse'

src/rspack/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Compilation, Compiler, LoaderContext } from '@rspack/core'
22
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
33
import { Buffer } from 'node:buffer'
44
import { resolve } from 'node:path'
5-
import { parse } from '../utils/context'
5+
import { parse } from '../utils/parse'
66

77
export function createBuildContext(compiler: Compiler, compilation: Compilation, loaderContext?: LoaderContext): UnpluginBuildContext {
88
return {

src/types.ts

Lines changed: 2 additions & 3 deletions

src/utils/context.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)