Plan and start ES6 migration#4
Conversation
This commit implements ES6/ECMAScript 2015+ support for YUICompressor: - Upgrade language version from VERSION_1_8 to VERSION_ES6 - Add ES6 reserved words (let, const, await, yield, of, async, etc.) - Arrow functions with proper => syntax preservation - Template literals with backticks and interpolation - All comparison, logical, and bitwise operators - Control flow statements (if/else, for, while, switch, try/catch) - For-in/for-of loops with proper variable scoping - Destructuring pattern variable extraction - Generator functions with function* syntax - Add ES6SupportTest.java with 40+ test cases - Add comprehensive ES6_MIGRATION_PLAN.md
There was a problem hiding this comment.
Pull request overview
This PR implements ES6/ECMAScript 2015+ support for YUICompressor by upgrading the language version from ES5.1 to ES6, adding comprehensive support for modern JavaScript syntax including arrow functions, template literals, and enhanced control flow handling.
Key changes:
- Upgraded Rhino parser from VERSION_1_8 to VERSION_ES6 for ES6+ syntax parsing
- Added ES6 reserved words (let, const, await, yield, of, async, etc.) to prevent munging
- Implemented explicit code generation for 40+ ES6 features including arrow functions, template literals, all operators, and control structures
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ES6SupportTest.java | Comprehensive test suite with 40+ test cases covering ES6 features including arrow functions, template literals, operators, control flow, and AST parsing |
| ScopeBuilder.java | Enhanced scope tracking for ES6 features including destructuring patterns, for-in/of loops, try-catch blocks, and object property handling |
| MungedCodeGenerator.java | Extended code generation with explicit handlers for ES6 syntax including arrow functions, template literals, all operators, control statements, and proper precedence handling |
| JavaScriptCompressor.java | Updated parser configuration to VERSION_ES6 and added ES6 reserved words to prevent munging |
| ES6_MIGRATION_PLAN.md | Detailed migration plan documenting ES6 support implementation phases, priorities, and completion status |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| break; | ||
|
|
||
| // For-in and For-of loops | ||
| case 162: // Token.FOR_IN (may vary by Rhino version) |
There was a problem hiding this comment.
Using a magic number (162) for Token.FOR_IN is fragile and error-prone. This should use the proper token constant like Token.FOR_IN or a documented constant. If the token value truly varies by Rhino version, this needs version detection logic or a configuration option.
| case 162: // Token.FOR_IN (may vary by Rhino version) | |
| case Token.FOR_IN: |
| if (element != null && !(element instanceof EmptyExpression)) { | ||
| declareVariableIdentifiers(element, scope); | ||
| } |
There was a problem hiding this comment.
The EmptyExpression check is present in declareVariableIdentifiers for arrays but not in declareParameterIdentifiers (line 182). Consider adding the same check to declareParameterIdentifiers for consistency, or document why array parameters don't need this check.
…estructuring - Handle ForInLoop correctly by checking instanceof before ForLoop - Add Scope block handling alongside Block for let/const scopes - Fix getter/setter detection using isGetterMethod/isSetterMethod - Skip empty elements in array destructuring parameters ([a, , b]) - Add comprehensive ES6 tests and @ignore unsupported features - Add .serena/ to .gitignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit implements ES6/ECMAScript 2015+ support for YUICompressor: