Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_parser): EcmaScript @decorators class #4252 #4381

Merged
merged 5 commits into from
Apr 19, 2023

Conversation

denbezrukov
Copy link
Contributor

Implement basic decorator cases for classes

Summary

ECMA spec page of the decorators:
https://arai-a.github.io/ecma262-compare/?pr=2417
https://github.com/tc39/proposal-decorators

This PR adds basic decorators syntax for classes:

// class expressions
let a = @decorator class {};
let b = @decorator @functionDecorator(1,2,3) class {};
let c = @first @second class Foo {}

// class declarations
@decorator class Foo {};
@decorator @functionDecorator(1,2,3) class Bar {};
@first @second class Baz {}

// abstract class declarations
@decorator abstract class Foo {};
@decorator @functionDecorator(1,2,3) abstract class Bar {};
@first @second abstract class Baz {}

// exported class declarations
export @decorator class Foo {};
export @decorator @functionDecorator(1,2,3) class Bar {};
export @first @second class Baz {}

It's important to mention that decorator can be before and after export keyword. This PR doesn't implement before syntax:
https://babeljs.io/blog/2023/02/20/7.21.0#decorators-updates
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-rc/#whats-new-since-the-beta

@decorator 
export class Foo {};

It's still invalid syntax for Rome. I'm going to implement it in another PR.

Test Plan

Changelog

  • The PR requires a changelog line

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

@netlify
Copy link

netlify bot commented Apr 17, 2023

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit 8f57744
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/643f8313d69fcd0008397ed9

@github-actions github-actions bot added A-Formatter Area: formatter A-Parser Area: parser A-Tooling Area: our own build, development, and release tooling labels Apr 17, 2023
@github-actions
Copy link

github-actions bot commented Apr 17, 2023

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 48863 48863 0
Passed 47788 47796 ✅ ⏫ +8
Failed 1075 1067 ✅ ⏬ -8
Panics 0 0 0
Coverage 97.80% 97.82% +0.02%
🎉 Fixed (8):
language/expressions/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js
language/expressions/class/decorator/syntax/valid/decorator-call-expr-identifier-reference-yield.js
language/expressions/class/decorator/syntax/valid/decorator-call-expr-identifier-reference.js
language/expressions/class/decorator/syntax/valid/decorator-member-expr-decorator-member-expr.js
language/expressions/class/decorator/syntax/valid/decorator-member-expr-identifier-reference-yield.js
language/expressions/class/decorator/syntax/valid/decorator-member-expr-identifier-reference.js
language/expressions/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference-yield.js
language/expressions/class/decorator/syntax/valid/decorator-parenthesized-expr-identifier-reference.js

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6212 6212 0
Passed 1761 1763 ✅ ⏫ +2
Failed 4451 4449 ✅ ⏬ -2
Panics 0 0 0
Coverage 28.35% 28.38% +0.03%
🎉 Fixed (2):
decoratedClassFromExternalModule.symbols
decoratorOnClassConstructor4.symbols

ts/babel

Test result main count This PR count Difference
Total 639 639 0
Passed 568 573 ✅ ⏫ +5
Failed 71 66 ✅ ⏬ -5
Panics 0 0 0
Coverage 88.89% 89.67% +0.78%
🎉 Fixed (5):
decorators/type-arguments-invalid
type-arguments-bit-shift-left-like-babel-7/decorator-call-expression
type-arguments-bit-shift-left-like-babel-7/decorator-legacy-call-expression
type-arguments-bit-shift-left-like/decorator-call-expression
type-arguments-bit-shift-left-like/decorator-legacy-call-expression

ts/microsoft

Test result main count This PR count Difference
Total 17224 17224 0
Passed 13114 13087 ❌ ⏬ -27
Failed 4110 4137 ❌ ⏫ +27
Panics 0 0 0
Coverage 76.14% 75.98% -0.16%
🔥 Regression (54):
compiler/classExpressionWithDecorator1.ts
compiler/decoratorMetadataRestParameterWithImportedType.ts
compiler/emitHelpersWithLocalCollisions.ts
compiler/importHelpersES6.ts
compiler/importHelpersWithLocalCollisions.ts
conformance/decorators/class/decoratedClassExportsCommonJS1.ts
conformance/decorators/class/decoratedClassExportsCommonJS2.ts
conformance/decorators/class/decoratedClassExportsSystem1.ts
conformance/decorators/class/decoratedClassExportsSystem2.ts
conformance/decorators/class/decoratedClassFromExternalModule.ts
conformance/decorators/class/decoratorOnClass2.ts
conformance/es6/decorators/class/decoratorOnClass2.es6.ts
conformance/es6/decorators/class/decoratorOnClass3.es6.ts
conformance/es6/decorators/class/decoratorOnClass4.es6.ts
conformance/es6/decorators/class/decoratorOnClass6.es6.ts
conformance/es6/decorators/class/decoratorOnClass7.es6.ts
conformance/es6/decorators/class/decoratorOnClass8.es6.ts
conformance/es6/moduleExportsAmd/decoratedDefaultExportsGetExportedAmd.ts
conformance/es6/moduleExportsCommonjs/decoratedDefaultExportsGetExportedCommonjs.ts
conformance/es6/moduleExportsSystem/decoratedDefaultExportsGetExportedSystem.ts
conformance/es6/moduleExportsUmd/decoratedDefaultExportsGetExportedUmd.ts
conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts
conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-commonjs.ts
conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-missingEmitHelpers-classDecorator.2.ts
conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-setFunctionName.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.1.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.10.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.11.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.12.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.13.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.14.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.15.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.16.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.17.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.2.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.3.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.4.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.5.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.6.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.7.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.8.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-missingEmitHelpers-classDecorator.9.ts
conformance/esDecorators/esDecorators-emitDecoratorMetadata.ts
conformance/externalModules/es6/es6modulekindWithES5Target.ts
conformance/externalModules/es6/es6modulekindWithES5Target11.ts
conformance/externalModules/es6/es6modulekindWithES5Target3.ts
conformance/externalModules/esnext/esnextmodulekindWithES5Target.ts
conformance/externalModules/esnext/esnextmodulekindWithES5Target11.ts
conformance/externalModules/esnext/esnextmodulekindWithES5Target3.ts
projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModule/main.ts
projects/decoratorMetadata/emitDecoratorMetadataCommonJSIsolatedModuleNoResolve/main.ts
projects/decoratorMetadata/emitDecoratorMetadataSystemJS/main.ts
projects/decoratorMetadata/emitDecoratorMetadataSystemJSIsolatedModule/main.ts
projects/decoratorMetadata/emitDecoratorMetadataSystemJSIsolatedModuleNoResolve/main.ts
🎉 Fixed (27):
conformance/decorators/class/decoratorOnClass3.ts
conformance/decorators/invalid/decoratorOnEnum.ts
conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts
conformance/decorators/invalid/decoratorOnImportEquals1.ts
conformance/decorators/invalid/decoratorOnImportEquals2.ts
conformance/decorators/invalid/decoratorOnInterface.ts
conformance/decorators/invalid/decoratorOnInternalModule.ts
conformance/decorators/invalid/decoratorOnTypeAlias.ts
conformance/decorators/invalid/decoratorOnVar.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.1.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.2.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.3.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.4.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.5.ts
conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.6.ts
conformance/esDecorators/classExpression/esDecorators-classExpression-commentPreservation.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.1.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.10.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.11.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.2.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.3.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.4.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.5.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.6.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.7.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.8.ts
conformance/esDecorators/classExpression/namedEvaluation/esDecorators-classExpression-namedEvaluation.9.ts

@denbezrukov
Copy link
Contributor Author

I've checked regression.
It's connected with export cases.
#4383 should fix it.
We can merge this branch to main or #4383 to this branch.

@Boshen
Copy link
Contributor

Boshen commented Apr 18, 2023

@ematipico You may want to update test262 submodule on main, it's four months old where they may have changed the decorator tests.

crates/rome_js_parser/src/syntax/class.rs Outdated Show resolved Hide resolved
@denbezrukov denbezrukov merged commit f446f1a into main Apr 19, 2023
@denbezrukov denbezrukov deleted the feat/class-decorators branch April 19, 2023 06:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter A-Parser Area: parser A-Tooling Area: our own build, development, and release tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants