Skip to content

Add decorator tests#5048

Open
bennypowers wants to merge 13 commits into
tc39:mainfrom
bennypowers:add-decorator-tests
Open

Add decorator tests#5048
bennypowers wants to merge 13 commits into
tc39:mainfrom
bennypowers:add-decorator-tests

Conversation

@bennypowers
Copy link
Copy Markdown

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 (@decorators[0])
  • Constructor decoration syntax errors
  • addInitializer error cases (non-callable argument, call after decoration)
  • Async generator method decorator support

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:

  • Class expression error template decorating a method instead of the class
  • Generator method template path collisions with standard method templates
  • Getter template spurious error/ path segment
  • Copy-paste description errors across multiple case files
  • Inverted context-private-true/false filenames
  • Wrong esid in class expression template
  • "acessor" typo in accessor template names
  • Missing generator/async qualifiers in template name fields
  • Unused variable in proxy test case

Validated test behavior against ecma262 PR #2417
and V8's decorator implementation.

Co-Authored-By: Kristen Maevyn kris@bitski.com

bennypowers and others added 12 commits May 10, 2026 08:34
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>
@bennypowers
Copy link
Copy Markdown
Author

Would maintainers prefer this be split into smaller PRs?

@ptomato
Copy link
Copy Markdown
Contributor

ptomato commented May 13, 2026

@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.

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.

2 participants