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

Property getters and setters #25

Closed
Elberet opened this issue Apr 25, 2019 · 0 comments · Fixed by #100
Closed

Property getters and setters #25

Elberet opened this issue Apr 25, 2019 · 0 comments · Fixed by #100
Assignees

Comments

@Elberet
Copy link

Elberet commented Apr 25, 2019

ES6 defines classes with property getters / setters:

class Dummy {
  get thing() { return this._thing }
  set thing(value) { this._thing = value }
}

Unfortunately, classes handled by the UI5 transformation are missing out on a lot of Babel's class features (see e.g. #23), and getters/setters are among those. The plugin produces a class declaration such as this:

var Dummy = ManagedObject.extend("dummy.Dummy", {
  // ...
  get thing() { /* ... */ },
}

There are two problems with this:

  1. This won't work with IE11. Babel's preset-env handles getters/setters in normal ES6 classes, but fails to fix this; ordering of presets in the Babel config doesn't affect the result.
  2. UI5 will iterate over all properties of the object given to extend which "accidentally" triggers execution of the getter with this being the aforementioned object instead of an instance of the class.

Would it be possible to change the UI5 transformation so that it only creates a skeleton class through UI5's .extend with the metadata, renderer and constructor set, and delegates creation/declaration of everything else to the usual Babel mechanisms?

petermuessig added a commit that referenced this issue May 29, 2023
To ensure that other plugins can be used upfront the conversion of
the ES6 imports and classes to UI5 AMD-like syntax and Object.extend,
the plugin now runs in the exit phase of the visitor. This allows
other plugins, e.g. decorators to run before and convert the code
accordingly. This plugin only sanitizes the decorators to remove the
plugin proprietary ones to avoid conflicts with other plugins.

The plugin is now also not dependent on the plugin order anymore and
using the preset-env ensures a proper transpilation of code to a
specific target browser set.

Added tests to ensure that a proper decorator handling works when
using the plugin-proposal-decorators or that e.g the conversion of
getters/setters takes place when using the babel plugin named
plugin-transform-property-mutators as this is not part of the
preset-env by default.

Updated all dependencies of the project with this change.

Fixes #23
Fixes #25
@petermuessig petermuessig self-assigned this May 29, 2023
petermuessig added a commit that referenced this issue May 30, 2023
To ensure that other plugins can be used upfront the conversion of
the ES6 imports and classes to UI5 AMD-like syntax and Object.extend,
the plugin now runs in the exit phase of the visitor. This allows
other plugins, e.g. decorators to run before and convert the code
accordingly. This plugin only sanitizes the decorators to remove the
plugin proprietary ones to avoid conflicts with other plugins.

Added tests to ensure that a proper decorator handling works when
using the plugin-proposal-decorators or that e.g the conversion of
getters/setters takes place when using the babel plugin named
plugin-transform-property-mutators as this is not part of the
preset-env by default.

Updated all dependencies of the project with this change.

Fixes #23
Fixes #25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants