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

[FEATURE] jsdoc: Support destructuring of enums for defaultValue #775

Merged
merged 69 commits into from
Nov 29, 2022

Conversation

d3xter666
Copy link
Contributor

@d3xter666 d3xter666 commented Aug 4, 2022

JIRA: CPOUI5FOUNDATION-503

This PULL request tries to enable ES6+ destructuring for UI5 enums.

There might be different cases and ways to achieve this and with this change, we try to cover the ones we already know. (Note: There might be more we're not aware of).

Here are the cases we try to cover:

  1. Destructuring from fully quantified name
// shortcut for sap.ui.core.TitleLevel
var {TitleLevel} = sap.ui.core;
  1. Destructuring from fully quantified name
// shortcut for sap.ui.core.TitleLevel
var {TitleLevel} = sap.ui.core;
  1. Chained destructuring
const library = {
  MyEnum: {
    Foo: "FooValue",
  },
};


const { MyEnum } = library;
const { Foo } = MyEnum;
  1. Destructuring with a rename
 const { Foo: Bar } = MyEnum; 
  1. Destructuring as an argument of an arrow function
sap.ui.define([
	"sap/ui/core/Control", 
	"./library"
], (Control, { MyEnumFromLib } ) => {
...
});
  1. Not a destructuring, but a pattern close to # 3 and already covered by the builder. However, we need to be aware of it and should consider it as the chain in AST is (almost) the same as the one in # 3
var MyTitleLevelVar = sap.ui.core.TitleLevel;
  1. Any mixtures from the cases above

@coveralls
Copy link

coveralls commented Aug 5, 2022

Coverage Status

Coverage decreased (-0.01%) to 94.703% when pulling fd369cf on es6-enum-destructuring into 36a99f5 on main.

@@ -646,6 +835,11 @@ function convertValueWithRaw(node, type, propertyName) {
raw: local.raw
};
}

const potentialEnum = resolvePotemtialEnum(node, type);
Copy link
Contributor Author

@d3xter666 d3xter666 Aug 5, 2022

Choose a reason for hiding this comment

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

This is the case where the ENUM could be just the element.

For example, const { TitleLevel } = sap.ui.core;

@d3xter666 d3xter666 changed the title [WIP] [FEATURE] ES6+ enum destructuring [FEATURE] ES6+ enum destructuring Aug 5, 2022
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
Copy link
Member

@matz3 matz3 left a comment

Choose a reason for hiding this comment

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

I only briefly looked through the code, but will need to run it locally to fully verify the resolve logic

lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
@d3xter666 d3xter666 requested a review from matz3 September 1, 2022 06:32
@matz3 matz3 changed the title [FEATURE] ES6+ enum destructuring [FEATURE] jsdoc: Support destructuring of enums for defaultValue Sep 8, 2022
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
lib/processors/jsdoc/lib/ui5/plugin.js Outdated Show resolved Hide resolved
@d3xter666 d3xter666 requested a review from matz3 October 3, 2022 07:27
- Use escope to go up through the chain
- Cover destructuring and build up a fully quantified name up to the imported module name
- Cover renaming
- Cover multiple destructuring
@d3xter666 d3xter666 merged commit 523f365 into main Nov 29, 2022
@d3xter666 d3xter666 deleted the es6-enum-destructuring branch November 29, 2022 14:01
openui5bot pushed a commit to SAP/openui5 that referenced this pull request Nov 29, 2022
This change integrates the following Pull request from ui5-builder
project: SAP/ui5-builder#775

Change-Id: Id0cc3e903dbb3b0733add647ca9096d31b163051
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.

5 participants