test(linter/plugins): remove directives when parsing as ES3#18636
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR enables parsing ES3-compliant test cases by converting directives to plain string literals when ecmaVersion: 3 is specified in conformance tests. In ES3, directives like "use strict" didn't exist, so they should be treated as regular string literals rather than directives.
Changes:
- Added ES3 AST transformation logic that traverses the AST and sets
directiveproperty tonullfor allExpressionStatementnodes when parsing as ES3 - Exported
ecmaVersionvariable fromcontext.tsto enable ES3 detection in the AST transformation - Removed workarounds that were skipping 8 ESLint test cases for
no-eval,no-invalid-this, andno-unused-expressionsrules
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/oxlint/src-js/plugins/source_code.ts | Added fixES3Ast(), fixES3NodesArray(), and fixES3Node() functions to traverse AST and convert directives to string literals when ecmaVersion === 3; integrated transformation into initAst() |
| apps/oxlint/src-js/plugins/context.ts | Exported ecmaVersion variable to allow ES3 detection in source_code.ts |
| apps/oxlint/conformance/src/groups/eslint.ts | Removed workaround that was skipping ES3 test cases for no-eval, no-invalid-this, and no-unused-expressions rules |
| apps/oxlint/conformance/snapshots/eslint.md | Updated test statistics showing 8 additional tests now passing (from 32873 to 32881) and 8 fewer skipped (from 286 to 278) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
In ES3, directives didn't exist yet, and therefore `"use strict"` is treated as a standard string literal, rather than a directive. In conformance tests, when test case specifies ES3, walk the AST and set `directive` property of all `ExpressionStatement`s to `null`. This transforms any directives in AST into plain string literals. Combined with #18632 which fixed `"use strict"` processing in TS-ESLint, this means there are 8 ESLint test cases we no longer have to skip. More importantly, we're less likely to run into erroneous test failures when testing other plugins, which are laborious to diagnose.
c2f4cc5 to
4e08b91
Compare
602e15b to
1363943
Compare

In ES3, directives didn't exist yet, and therefore
"use strict"is treated as a standard string literal, rather than a directive.In conformance tests, when test case specifies ES3, walk the AST and set
directiveproperty of allExpressionStatements tonull. This transforms any directives in AST into plain string literals.Combined with #18632 which fixed
"use strict"processing in TS-ESLint, this means there are 8 ESLint test cases we no longer have to skip. More importantly, we're less likely to run into erroneous test failures when testing other plugins, which are laborious to diagnose.