Add decorator tests#5048
Open
bennypowers wants to merge 13 commits into
Open
Conversation
Add behavioral tests for the TC39 decorators proposal, covering: - Decorator context object (kind, name, access, static, private) - Return value handling for class, method, getter, setter, field, and accessor decorators - Decorator ordering (application order, initialization phases) - Class decorator rebinding and proxy/subclass returns - Field and accessor initializer `this` binding - Invalid return value error cases - Computed member expression syntax errors Tests use test262's template/case generation system to cover all combinations of class declarations/expressions, public/private, instance/static, and standard/with-init variants. Based on tc39#4103. Co-Authored-By: Kristen Maevyn <kris@bitski.com> Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- accessor-deco-returns-set: "getter" -> "setter" - context-access-set: "`get`" -> "`set`" - context-kind-accessor: "a method" -> "an accessor" - context-kind-class: "a method" -> "a class" - context-kind-getter: '"method"' -> '"getter"', "a method" -> "a getter" - context-kind-setter: "a method" -> "a setter" - context-static-true: "false for instance" -> "true for static" - context-private-true/false: swap file contents to match filenames (true.case now tests private elements, false.case tests public) Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The template was applying the decorator to a private method inside the class expression instead of to the class expression itself. This caused class decorator error cases (e.g. class-deco-invalid-return-arrow) to test method decorator behavior when expanded through this template. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
prod-FieldExpression -> prod-ClassExpression Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy-paste artifact from class-deco-returns-subclass.case. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All 8 generator method templates had identical path: values to standard method templates (e.g. method/public/instance/). Generated tests from generator templates would silently overwrite standard method tests. Add generator/ subdirectory to all paths so generated tests land in method/generator/public/instance/ etc., matching the convention used by async method templates (method/async/). Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These are standard (non-error) getter templates but their path: values included an error/ segment, causing generated tests to land in the wrong directory (getter/error/ instead of getter/). Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generator and async method templates had the same name: values as standard method templates, making generated test descriptions ambiguous. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add 8 templates for async generator methods (async * element()) covering all public/private, instance/static, declaration/expression combinations. Add async-generator-specific cases for return value replacement and undefined return behavior, testing that the decorated value produces an async iterator. Update context-kind-method and context-access-get cases to include the new async-generator template set. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Decorators cannot be applied to class constructors per the ClassElement grammar. Verify this is a SyntaxError for both class declarations and class expressions. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Non-callable argument: addInitializer(123) throws TypeError during class evaluation. Uses the error template to cover all element types (methods, fields, getters, setters, accessors, class). - After decoration: saving context and calling addInitializer after class evaluation completes throws TypeError. Standalone tests since the class itself evaluates successfully. Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Would maintainers prefer this be split into smaller PRs? |
Contributor
|
@bennypowers Thanks very much for this. Smaller PRs would be better for reviews. But note that decorators are on the agenda in next week's TC39 meeting (https://github.com/tc39/agendas/blob/main/2026/05.md) so please wait and see what comes out of that discussion before doing any substantial further work on this PR, in case it would be wasted. |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add behavioral tests for the TC39 decorators proposal, covering:
kind,name,access,static,private)thisbinding@decorators[0])addInitializererror cases (non-callable argument, call after decoration)Tests use test262's template/case generation system to cover all
combinations of class declarations/expressions, public/private,
instance/static, and standard/with-init variants.
Based on #4103 by @pzuraq, with fixes for:
error/path segmentcontext-private-true/falsefilenamesesidin class expression templateValidated test behavior against ecma262 PR #2417
and V8's decorator implementation.
Co-Authored-By: Kristen Maevyn kris@bitski.com