Skip to content

feat: allow top level using declaration in "commonjs"#734

Merged
DMartens merged 1 commit intoeslint:mainfrom
ota-meshi:commonjs
Mar 3, 2026
Merged

feat: allow top level using declaration in "commonjs"#734
DMartens merged 1 commit intoeslint:mainfrom
ota-meshi:commonjs

Conversation

@ota-meshi
Copy link
Member

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

This PR changes Espree to allow top-level using declarations when parsed with sourceType: commonjs.

What changes did you make? (Give an overview)

Since the sourceType: commonjs option was added in acorn, I changed it to use it directly.

CHANGELOG: https://github.com/acornjs/acorn/blob/master/acorn/CHANGELOG.md#8160-2026-02-19
PR: acornjs/acorn#1377

Related Issues

close #662

Is there anything you'd like reviewers to focus on?

@eslint-github-bot
Copy link

Hi @ota-meshi!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@ota-meshi ota-meshi changed the title feat(espree): allow top level using declaration in "commonjs" feat: allow top level using declaration in "commonjs" Feb 28, 2026
Comment on lines +57 to +69
it("should parse top-level using", () => {
espree.parse("using x = resource;", {
sourceType: "commonjs",
ecmaVersion: "latest",
});
});

it("should parse top-level new.target", () => {
espree.parse("new.target;", {
sourceType: "commonjs",
ecmaVersion: "latest",
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Are these all the differences between passing sourceType: "commonjs" and passing allowReturnOutsideFunction: true to Acorn?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe these are the only two top-level additional syntaxes allowed.

@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Mar 2, 2026
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open for @DMartens to verify.

Copy link

@DMartens DMartens left a comment

Choose a reason for hiding this comment

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

Changes LGTM, thanks.

@DMartens DMartens merged commit 3f7fb58 into eslint:main Mar 3, 2026
19 checks passed
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Mar 3, 2026
@eslintbot eslintbot mentioned this pull request Mar 3, 2026
@ota-meshi ota-meshi deleted the commonjs branch March 3, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Change Request: CommonJS always allows top-level using declarations

4 participants