-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Switch from Esprima to Espree for JavaScript linting in CodeMirror. #10806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Switch from Esprima to Espree for JavaScript linting in CodeMirror. #10806
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
5c7da3d to
cfd3baf
Compare
Replaces the `esprima`-based validation in the code editor with `espree` to provide support for modern JavaScript (ES6+).
Key Changes:
1. **New Linter Integration:**
* Introduces `src/js/_enqueues/vendor/codemirror/javascript-lint.js` which uses `espree` (v9.6.1) for parsing and error reporting.
* This replaces the previous dependency on the `jshint` and `esprima` scripts. The `espree` module is now loaded via a dynamic import on demand by the new javascript lint integration.
* This custom linter is bundled into the CodeMirror build via `tools/vendors/codemirror-entry.js`.
2. **Script Modules:**
* Registers `espree` as a script module in `src/wp-includes/script-modules.php`.
* Adds a workaround in the `wp-codemirror` registration to ensure `espree` is included in the importmap.
3. **Editor Settings:**
* Updates `wp_get_code_editor_settings()` in `src/wp-includes/general-template.php` to use ES11 defaults.
* Synchronizes JSHint settings from .jshintrc, even though these are not supported by Espree.
4. **Deprecations:**
* Marks `esprima` and `jshint` script handles as deprecated in `src/wp-includes/script-loader.php`.
5. **Build Tools:**
* Updates Webpack configuration (`tools/webpack/codemirror.config.js`) to bundle `espree` as a module.
* Updates `codemirror-entry.js` to use the new local `javascript-lint.js`.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cfd3baf to
bd2376c
Compare
…into replace-esprima-with-espree
… at 9acd7f0 Co-authored-by: Jon Surrell <jonsurrell@git.wordpress.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…resolution. By adding /* webpackIgnore: true */ to the dynamic import in javascript-lint.js, we prevent Webpack from bundling Espree into a separate chunk. This allows the browser to resolve Espree at runtime using the Import Map. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
The IIFE in javascript-lint.js is removed as it is redundant when bundled by Webpack. Both javascript-lint.js and codemirror-entry.js are updated to use 'const' instead of 'var' for the CodeMirror require, aligning with modern JavaScript practices in the project. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
942ce9e to
99a6994
Compare
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…vascript-lint.js. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| * @since 7.0.0 | ||
| */ | ||
|
|
||
| const CodeMirror = require( 'codemirror' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all requires webpack processing. Can we use a static import here which is more common in modern, compiled JavaScript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webpack processing is required anyway since it creates the bundle from codemirror-entry.js. Or is this for the future where we could possibly re-use this module as-is with v6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, I've switched to using ESM instead of CommonJS for everything in 9e3038d.
… at 9acd7f0...3a67800 Co-authored-by: Jon Surrell <jonsurrell@git.wordpress.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…into replace-esprima-with-espree
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Update src/js/_enqueues/vendor/codemirror/javascript-lint.js and tools/vendors/codemirror-entry.js to use ESM import statements instead of CommonJS require(). This aligns with modern JavaScript standards and ensures compatibility with the project's build process. Co-authored-by: Jon Surrell <jonsurrell@git.wordpress.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| @@ -0,0 +1 @@ | |||
| export * from 'espree'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, Epsree does not have an ES module included in its distribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces Esprima/JSHint with Espree for JavaScript linting in CodeMirror to address GPL compatibility issues. The change introduces a new custom JavaScript linter that uses the Espree parser (v9.6.1) for syntax validation, registers Espree as a script module, and deprecates the legacy esprima and jshint script handles.
Changes:
- Introduces a custom JavaScript linter using Espree for syntax-only validation (no linting rules)
- Registers Espree as a script module with import map integration via module dependencies
- Updates build tooling to generate separate espree.min.js module and integrate the new linter into codemirror.min.js
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/js/_enqueues/vendor/codemirror/javascript-lint.js | New custom JavaScript linter using Espree for syntax validation |
| tools/webpack/codemirror.config.js | Adds espree build configuration and restructures codemirror build |
| tools/vendors/espree-entry.js | Entry point for bundling espree as a module |
| tools/vendors/codemirror-entry.js | Updates to use new javascript-lint and ES module imports |
| src/wp-includes/script-modules.php | Registers espree as a script module |
| src/wp-includes/script-loader.php | Adds module dependency for wp-codemirror and deprecates jshint/esprima |
| src/wp-includes/general-template.php | Updates JSHint settings to ES11 and adds clarifying comments |
| tests/phpunit/tests/dependencies/scripts.php | Updates tests to reflect jshint key changes and adds espree to exclusions |
| tests/phpunit/tests/widgets/wpWidgetCustomHtml.php | Removes jshint enqueue test expectation |
| package.json | Adds espree 9.6.1 and @types/codemirror dependencies |
| package-lock.json | Lock file updates for new dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ); | ||
|
|
||
| $scripts->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.js', array(), '5.65.20' ); | ||
| did_action( 'init' ) && $scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) ); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition did_action( 'init' ) is used here as a guard, but this creates a timing-dependent behavior. If this code runs before the 'init' action, the module dependency won't be added. Consider either: (1) always adding this data unconditionally, or (2) hooking into the 'init' action to add this dependency at the appropriate time. The current pattern may lead to inconsistent behavior depending on when wp_default_scripts is called.
| did_action( 'init' ) && $scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) ); | |
| $scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) ); |
| // The following are copied from <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>. | ||
| // Nevertheless, they are not supported by Espree, which is used instead of JSHint for licensing reasons. |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states that the JSHint options are "not supported by Espree", but this is only partially accurate. While most of the JSHint options listed (boss, curly, eqeqeq, etc.) are indeed linting rules that Espree doesn't support, the options esversion, es5, es3, module, and strict ARE used by the Espree integration in javascript-lint.js. The comment should be clarified to distinguish between the parsing-related options that Espree does support and the linting-rule options that it doesn't support. This would help future developers understand which options are still relevant.
| // The following are copied from <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>. | |
| // Nevertheless, they are not supported by Espree, which is used instead of JSHint for licensing reasons. | |
| // The following JSHint *linting rule* options are copied from | |
| // <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>. | |
| // Parsing-related options such as `esversion` (and, in other contexts, `es5`, `es3`, `module`, `strict`) | |
| // are honored by the Espree-based integration, but these linting-rule options are not interpreted by Espree | |
| // and are kept only for compatibility/documentation with the original JSHint configuration. |
Previously developed in westonruter#4 as a sub-PR off of #10778
Depends on:
New Linter Integration:
src/js/_enqueues/vendor/codemirror/javascript-lint.jswhich usesespree(v9.6.1) for parsing and error reporting.jshintandesprimascripts. Theespreemodule is now loaded via a dynamic import on demand by the new javascript lint integration.tools/vendors/codemirror-entry.js.Script Modules:
espreeas a script module insrc/wp-includes/script-modules.php.wp-codemirrorregistration to ensureespreeis included in the importmap.Editor Settings:
wp_get_code_editor_settings()insrc/wp-includes/general-template.phpto use ES11 defaults.Deprecations:
esprimaandjshintscript handles as deprecated insrc/wp-includes/script-loader.php.Build Tools:
tools/webpack/codemirror.config.js) to bundleespreeas a module.codemirror-entry.jsto use the new localjavascript-lint.js.Trac ticket: https://core.trac.wordpress.org/ticket/64558
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.