Skip to content

esm: improve check for ESM syntax#50127

Merged
aduh95 merged 5 commits intonodejs:mainfrom
GeoffreyBooth:better-esm-check
Oct 18, 2023
Merged

esm: improve check for ESM syntax#50127
aduh95 merged 5 commits intonodejs:mainfrom
GeoffreyBooth:better-esm-check

Conversation

@GeoffreyBooth
Copy link
Member

@GeoffreyBooth GeoffreyBooth commented Oct 10, 2023

This PR speeds up and simplifies the error path for when users require ES modules. In particular, the previous hasEsmSyntax helper used Acorn to parse the required module’s source code to find ESM syntax. In this refactor, the check moves into C++ and relies on V8 throwing a SyntaxError with one of the error messages that we know are caused by ESM syntax in a module compiled as CommonJS. This allows us to eliminate one use of Acorn from the codebase.

This also creates the helper function that #50096 needs.

@nodejs/loaders @nodejs/cpp-reviewers

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. lib / src Issues and PRs related to general changes in the lib or src directory. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants