Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile decorators properly when googmodule is false and transformTypesToClosure is true #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

claydiffrient
Copy link
Member

@claydiffrient claydiffrient commented Oct 1, 2024

This adds a few example decorators to test if they are doing what we need them to do.

Modifies the handling of decorators to make sure they don't do anything that closure gets mad about.

The instructions here should still work for testing: #1

@claydiffrient
Copy link
Member Author

This is the error I keep getting:

❯ npx google-closure-compiler \
--js='*.js' \
--js_output_file=out.js \
--source_map_include_content \
--generate_exports \
--export_local_property_definitions \
--language_in=UNSTABLE \
--module_resolution=NODE
./using_decorators.js:1:18: WARNING - [ES6_MODULE_REFERENCES_THIS] The body of an ES6 module cannot reference this.
  1| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
                       ^^^^

./using_decorators.js:1:26: WARNING - [ES6_MODULE_REFERENCES_THIS] The body of an ES6 module cannot reference this.
  1| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
                               ^^^^

./using_decorators.js:21:13: ERROR - [JSC_CANNOT_CONVERT_YET] Transpilation of 'Classes with possible name shadowing' is not yet implemented.
  21| let Person = class Person {
                   ^^^^^^^^^^^^^^
  22|     name_;
      ^^^^^^^^^^
...
  43|     }
      ^^^^^
  44| };

@claydiffrient claydiffrient requested a review from ribrdb October 1, 2024 18:04
Copy link

@ribrdb ribrdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the ts option to import tslib? Tsickle has its own version of tslib.

@claydiffrient claydiffrient requested a review from ribrdb October 10, 2024 22:58
@claydiffrient claydiffrient marked this pull request as ready for review October 11, 2024 16:18
@claydiffrient claydiffrient changed the title WIP: Figure out decorators Compile decorators properly when googmodule is false and transformTypesToClosure is true Oct 11, 2024
test/golden_tsickle_test.ts Outdated Show resolved Hide resolved
demo/decorators.ts Show resolved Hide resolved
src/export_star_transformer.ts Show resolved Hide resolved
@claydiffrient claydiffrient requested a review from ribrdb December 10, 2024 18:54
}

@annotatedAccessorDecorator(true)
get age() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the demo this is getting emitted as a normal decorator, not converted to an annotation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In demo/tsickle-out/using_decorators.js I'm seeing it get output as:

/** @type {!Object<string, !Array<{type: !Function, args: (undefined|!Array<?>)}>>} */
static propDecorators = {
    age: [{ type: annotatedAccessorDecorator, args: [true,] }]
};

whereas the other decorators get output as:

__decorate([
    accessorDecorator(true)
], Person.prototype, JSCompiler_renameProperty("name", Person.prototype), null);

is that not the correct behavior?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, when I followed the testing directions from the other pr I get this output:

__decorate([
    annotatedAccessorDecorator(true)
], Person.prototype, "age", null);

I also just noticed __decorate is defined inline instead of being imported too, which doesn't seem right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What??? That doesn't make any sense :(

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