Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: replace acorn with @babel/parser (#663)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
eduardoboucas and kodiakhq[bot] committed Sep 20, 2021
1 parent b843aae commit c28eaaf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"url": "https://github.com/netlify/zip-it-and-ship-it/issues"
},
"dependencies": {
"@babel/parser": "^7.15.7",
"@netlify/esbuild": "^0.13.6",
"acorn": "^8.4.0",
"archiver": "^5.3.0",
"array-flat-polyfill": "^1.0.1",
"common-path-prefix": "^3.0.0",
Expand Down
11 changes: 6 additions & 5 deletions src/runtimes/node/dynamic_imports/parser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { join, relative, resolve } = require('path')

const acorn = require('acorn')
const babel = require('@babel/parser')

const ECMA_VERSION = 2021
const GLOB_WILDCARD = '**'

// Transforms an array of glob nodes into a glob string including an absolute
Expand Down Expand Up @@ -56,8 +55,10 @@ const getWildcardFromASTNode = (node) => {
// - `includedPathsGlob`: A glob with the files to be included in the bundle
// - `type`: The expression type (e.g. "require", "import")
const parseExpression = ({ basePath, expression: rawExpression, resolveDir }) => {
const { body } = acorn.parse(rawExpression, { ecmaVersion: ECMA_VERSION })
const [topLevelExpression] = body
const { program } = babel.parse(rawExpression, {
sourceType: 'module',
})
const [topLevelExpression] = program.body
const { expression } = topLevelExpression

if (expression.type === 'CallExpression' && expression.callee.name === 'require') {
Expand Down Expand Up @@ -113,7 +114,7 @@ const parseBinaryExpression = (expression) => {
case 'BinaryExpression':
return parseBinaryExpression(operand)

case 'Literal':
case 'StringLiteral':
return operand.value

default:
Expand Down

1 comment on commit c28eaaf

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 11.6s

largeDepsZisi: 1m 1.9s

Please sign in to comment.