Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Jan 27, 2026

Previously developed in westonruter#4 as a sub-PR off of #10778

Depends on:

  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.

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.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

westonruter and others added 2 commits January 28, 2026 10:11
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>
@westonruter westonruter force-pushed the replace-esprima-with-espree branch from cfd3baf to bd2376c Compare January 28, 2026 18:39
westonruter and others added 6 commits January 30, 2026 19:53
… 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>
westonruter and others added 2 commits January 30, 2026 20:54
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant