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

feat: replace acorn with @babel/parser #663

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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