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

fix(babel-plugin-component): skip unnecessary registerDecorators (BREAKING CHANGE) #3660

Merged
merged 6 commits into from
Oct 20, 2023

Conversation

nolanlawson
Copy link
Collaborator

Details

Fixes #2701. New version of #2741

In API version 60+, registerDecorators is no longer called for classes that do not extend a superclass (and thus cannot possibly be LightningElement classes).

Does this pull request introduce a breaking change?

  • 🚨 Yes, it does introduce a breaking change.

Previously, the following would not be a syntax error:

class MyCustomClass {
  @track foo = 'foo';
}

In v60+, this will be a syntax error. The decorators @track, @wire, and @api can only be used on LightningElement classes. In the above case, MyCustomClass does not extend another class, so it cannot possibly be a LightningElement class. The fix is to remove the unnecessary @track, @wire, and @api decorators.

Does this pull request introduce an observable change?

  • ⚠️ Yes, it does include an observable change.

See above.

GUS work item

W-10736098

@nolanlawson nolanlawson added this to the 4.0.0 milestone Aug 7, 2023
@nolanlawson nolanlawson requested a review from a team as a code owner August 7, 2023 15:54
@nolanlawson

This comment was marked as outdated.

1 similar comment
@nolanlawson

This comment was marked as outdated.

@salesforce-nucleus

This comment was marked as outdated.

@nolanlawson nolanlawson changed the base branch from release-v4.0.0 to prerelease-v4.0.0 August 8, 2023 22:31
@nolanlawson

This comment was marked as outdated.

@salesforce-nucleus

This comment was marked as outdated.

@nolanlawson

This comment was marked as outdated.

@salesforce-nucleus

This comment was marked as outdated.

@nolanlawson nolanlawson changed the base branch from prerelease-v4.0.0 to milestone-v4.0.0 August 10, 2023 16:38
@nolanlawson nolanlawson changed the base branch from milestone-v4.0.0 to master August 10, 2023 19:09
Copy link
Contributor

@divmain divmain left a comment

Choose a reason for hiding this comment

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

Many of the diffs in test fixtures appear to be incidental to the changes you've made in the PR. If there are tests that need 👀 , please call that out explicitly.

Copy link
Contributor

@divmain divmain left a comment

Choose a reason for hiding this comment

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

This looks really good to me.

import { api } from "lwc";
import MyCoolMixin from './mixin.js'

const foo = class extends MyCoolMixin {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you only fail when it doesn't extend anything, since it couldn't possibly be extending LightningElement indirectly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. extends is a sniff for "might be a LightningElement."

// Any class exposing a field *must* extend either LightningElement or some other superclass.
// Even in the case of superclasses and mixins that expose fields, those must extend something as well.
// So we can skip classes without a superclass to avoid adding unnecessary registerDecorators calls.
// However, we only do this in later API versions to avoid a breaking change.
Copy link
Contributor

Choose a reason for hiding this comment

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

Helpful comment, thank you.

@@ -10,15 +10,20 @@ import { isNumber } from './language';
export const enum APIVersion {
V58_244_SUMMER_23 = 58,
V59_246_WINTER_24 = 59,
V60_248_SPRING_24 = 60,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: Since we're going to be seeing more of these, it'd be nice to have them introduced in a separate PR to keep commit history clean & PRs more readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough. I avoided it since it was like 3 lines though, and since I knew I would have to deal with conflicts anyway once I merged everything all together.

@nolanlawson nolanlawson merged commit c7bd330 into master Oct 20, 2023
7 of 11 checks passed
@nolanlawson nolanlawson deleted the nolan/no-register-decorators-redux branch October 20, 2023 16:57
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.

[JS compiler] remove registerDecorators for non-LightningElement classes
2 participants