Skip to content

Commit

Permalink
Switch acorn to rollup's internal swc-based parser
Browse files Browse the repository at this point in the history
  • Loading branch information
calebeby committed Jul 29, 2024
1 parent 2cefafc commit 20152d0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .renovaterc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"groupName": "compatibility testing-only dependencies"
},
{
"matchPackagePatterns": ["rollup", "acorn"],
"matchPackagePatterns": ["rollup"],
"automerge": true,
"groupName": "rollup/plugins"
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
},
"dependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"acorn": "^8.12.1",
"cjs-module-lexer": "^1.3.1",
"es-module-lexer": "^1.5.4",
"esbuild": "^0.19.2",
Expand Down
13 changes: 5 additions & 8 deletions src/module-server/rollup-plugin-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@
- Error handling (with code frame, using source maps) added to transform hook
- Stubbed out options hook was added
- Added object-hooks support and plugin ordering (from Vite version)
- Updated to use import { parseAst } from 'rollup/parseAst' instead of acorn (rollup v4 change)
*/

import { dirname, resolve } from 'node:path';

import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping';
import { Parser } from 'acorn';
import type {
LoadResult,
ResolveIdResult,
TransformPluginContext as RollupPluginContext,
} from 'rollup';
// eslint-disable-next-line @cloudfour/n/file-extension-in-import
import { parseAst } from 'rollup/parseAst';

import { combineSourceMaps } from './combine-source-maps.js';
import { ErrorWithLocation } from './error-with-location.js';
Expand Down Expand Up @@ -112,19 +114,14 @@ export const createPluginContainer = (plugins: Plugin[]) => {
const MODULES = new Map();

let plugin: Plugin | undefined;
const parser = Parser;

const ctx: PluginContext = {
meta: {
rollupVersion: '2.8.0',
watchMode: true,
},
parse(code, opts) {
return parser.parse(code, {
sourceType: 'module',
ecmaVersion: 2020,
locations: true,
onComment: [],
return parseAst(code, {
...opts,
});
},
Expand Down Expand Up @@ -225,7 +222,7 @@ export const createPluginContainer = (plugins: Plugin[]) => {
'handler' in p.resolveId ? p.resolveId.handler : p.resolveId;
result = await resolveId.call(ctx as any, id, importer, {
isEntry: false,
assertions: {},
attributes: {},
});
} finally {
if (_skip) resolveSkips.delete(p, key);
Expand Down

0 comments on commit 20152d0

Please sign in to comment.