You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
This file contains 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
Please note that the PR doesn't use JsDecoratorList but adds JsDecorator to AnyJsPropertyModifier and AnyJsMethodModifier.
This allows better error diagnostic:
pub(crate) fn decorator_must_precede_modifier(p: &JsParser, range: TextRange) -> ParseDiagnostic {
p.err_builder(
"Decorators must precede the name and all keywords of property declarations.",
range,
)
}
The PR adds syntax:
class Foo {
// properties
@dec foo = 2;
@dec public foo = 1;
@dec static foo = 2;
@dec accessor foo = 2;
@dec readonly foo = 2;
@dec override foo = 2;
// methods
@dec foo() {}
@dec public foo() {}
@dec static foo() {}
@dec override foo() {}
// getters
@dec get foo() {}
@dec public get foo() {}
@dec static get foo() {}
@dec override get foo() {}
// setters
@dec set foo(val) {}
@dec public set foo(val) {}
@dec static set foo(val) {}
@dec override set foo(val) {}
}
//typescript
abstract class Qux {
@dec declare static foo: string;
}
class Bar {
@dec readonly foo = '123';
}
Test Plan
cargo test
Changelog
The PR requires a changelog line
Documentation
The PR requires documentation
I will create a new PR to update the documentation
Please note that the PR doesn't use JsDecoratorList but adds JsDecorator to AnyJsPropertyModifier and AnyJsMethodModifier.
Does that mean we can only apply one decorator to a class method?
No, we can apply any number of decorators. The difference between class member decorators and class decorators is that class member decorators are part of the modifiers array.
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.
Summary
Implement decorators for class methods, class fields, class accessors.
ECMA spec page of the decorators:
https://arai-a.github.io/ecma262-compare/?pr=2417
https://github.com/tc39/proposal-decorators
Please note that the PR doesn't use
JsDecoratorList
but addsJsDecorator
toAnyJsPropertyModifier
andAnyJsMethodModifier
.This allows better error diagnostic:
The PR adds syntax:
Test Plan
cargo test
Changelog
Documentation