Skip to content

Commit ebb05f5

Browse files
authored
[builder][FEATURE] jsdoc: Improve support for ES6+ syntax (SAP/ui5-builder#785)
JIRA: CPOUI5FOUNDATION-374 ### Enabled features: * ArrowFunctions + ArrowFunctionExpression.expression * Avoid "computed" Identifier to be used at it might lead to hidden bugs * Optional Chaining for MemberExpression & CallExpression * Literals for Syntax.OptionalMemberExpression/OptionalCallExpression * Enhance LogicalExpression to support "||" and "??" oprators * Cover ChainExpression * Wrapper Expressions generic approach * Cover possible returning statements in JS * Support alternate definitions of modules * ES6 Class definition export * Support of TemplateLiterals - only withput expression - treated like normal strings
1 parent c967b83 commit ebb05f5

File tree

10 files changed

+486
-138
lines changed

10 files changed

+486
-138
lines changed

packages/builder/lib/processors/jsdoc/lib/ui5/plugin.js

Lines changed: 277 additions & 115 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - ArrowFunction
8+
* - ChainExpression
9+
* - ClassDeclaration
10+
*/
11+
(sap?.ui).define([`Bar`], (Bar) => {
12+
/**
13+
* @class
14+
* My super documentation of this class
15+
*
16+
* @extends library.j.Bar
17+
*
18+
* @author SAP SE
19+
* @version ${version}
20+
*
21+
* @public
22+
* @alias library.j.Foo
23+
*/
24+
class Foo extends Bar {
25+
make() {
26+
sap.ui.require("conditional/module1");
27+
}
28+
}
29+
30+
return Foo;
31+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - ArrowFunctionExpression
8+
*/
9+
window.someRandomModule ||
10+
sap.ui.define(
11+
["./a"],
12+
/**
13+
* Constructor for a new library.j.aaa.
14+
*
15+
* @param {string} [sId] ID for the new control, generated automatically if no ID is given
16+
* @param {object} [mSettings] Initial settings for the new control
17+
*
18+
* @class
19+
*
20+
* @author SAP SE
21+
* @version ${version}
22+
*
23+
* @constructor
24+
* @extends library.j.a
25+
* @public
26+
* @since 1.22
27+
* @alias library.j.aaa
28+
* @ui5-metamodel This control will also be described in the UI5 (legacy) design time meta model.
29+
*/
30+
(a) =>
31+
a.extend(`library.j.aaa`, {
32+
metadata: {
33+
properties: {
34+
/**
35+
* MyProp property
36+
* @since 1.46
37+
*/
38+
MyProp: {
39+
type: "boolean",
40+
group: `Misc`,
41+
defaultValue: false,
42+
},
43+
},
44+
},
45+
})
46+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - Generators
8+
* - YeldExpression
9+
*/
10+
sap.ui.define([], function* someGenerator(genVar) {
11+
yield genVar++;
12+
});

packages/builder/test/expected/build/library.j/dest/resources/library/j/some.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
* ${copyright}
33
*/
44

5-
sap.ui.define([],
6-
function() {
7-
"use strict";
5+
sap.ui.define(
6+
["./dependency-es6-1"],
7+
["./dependency-es6-2"],
8+
["./dependency-es6-3"],
9+
function (dep1, dep2, dep3) {
10+
"use strict";
811

9-
/**
10-
* @alias library.j
11-
* @namespace
12-
* @public
13-
*/
14-
var SomeFunction = function() {};
15-
16-
}, /* bExport= */ true);
12+
/**
13+
* @alias library.j
14+
* @namespace
15+
* @public
16+
*/
17+
var SomeFunction = function () {};
18+
},
19+
/* bExport= */ true
20+
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"$schema-ref":"http://schemas.sap.com/sapui5/designtime/api.json/1.0","version":"1.0.0","library":"library.j","symbols":[{"kind":"namespace","name":"library.j","basename":"j","resource":"library/j/some.js","module":"library/j/some","static":true,"visibility":"public"}]}
1+
{"$schema-ref":"http://schemas.sap.com/sapui5/designtime/api.json/1.0","version":"1.0.0","library":"library.j","symbols":[{"kind":"namespace","name":"library.j","basename":"j","resource":"library/j/some.js","module":"library/j/some","static":true,"visibility":"public"},{"kind":"class","name":"library.j.aaa","basename":"aaa","resource":"library/j/dependency-es6-2.js","module":"library/j/dependency-es6-2","export":"","static":true,"visibility":"public","since":"1.22","extends":"library.j.a","ui5-metamodel":true,"ui5-metadata":{"properties":[{"name":"MyProp","type":"boolean","defaultValue":false,"group":"undefined","visibility":"public","since":"1.46","description":"MyProp property","methods":["getMyProp","setMyProp"]}]},"constructor":{"visibility":"public","parameters":[{"name":"sId","type":"string","optional":true,"description":"ID for the new control, generated automatically if no ID is given"},{"name":"mSettings","type":"object","optional":true,"description":"Initial settings for the new control"}],"description":"Constructor for a new library.j.aaa."},"methods":[{"name":"extend","visibility":"public","static":true,"returnValue":{"type":"function","description":"Created class / constructor function"},"parameters":[{"name":"sClassName","type":"string","optional":false,"description":"Name of the class being created"},{"name":"oClassInfo","type":"object","optional":true,"description":"Object literal with information about the class"},{"name":"FNMetaImpl","type":"function","optional":true,"description":"Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class"}],"description":"Creates a new subclass of class library.j.aaa with name <code>sClassName</code> and enriches it with the information contained in <code>oClassInfo</code>.\n\n<code>oClassInfo</code> might contain the same kind of information as described in {@link library.j.a.extend}."},{"name":"getMetadata","visibility":"public","static":true,"returnValue":{"type":"sap.ui.base.Metadata","description":"Metadata object describing this class"},"description":"Returns a metadata object for class library.j.aaa."},{"name":"getMyProp","visibility":"public","since":"1.46","returnValue":{"type":"boolean","description":"Value of property <code>MyProp</code>"},"description":"Gets current value of property {@link #getMyProp MyProp}.\n\nMyProp property\n\nDefault value is <code>false</code>."},{"name":"setMyProp","visibility":"public","since":"1.46","returnValue":{"type":"this","description":"Reference to <code>this</code> in order to allow method chaining"},"parameters":[{"name":"bMyProp","type":"boolean","optional":true,"defaultValue":false,"description":"New value for property <code>MyProp</code>"}],"description":"Sets a new value for property {@link #getMyProp MyProp}.\n\nMyProp property\n\nWhen called with a value of <code>null</code> or <code>undefined</code>, the default value of the property will be restored.\n\nDefault value is <code>false</code>."}]},{"kind":"class","name":"library.j.Foo","basename":"Foo","resource":"library/j/dependency-es6-1.js","module":"library/j/dependency-es6-1","static":true,"visibility":"public","extends":"library.j.Bar","description":"My super documentation of this class","constructor":{"visibility":"public"}}]}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - ArrowFunction
8+
* - ChainExpression
9+
* - ClassDeclaration
10+
*/
11+
(sap?.ui).define([`Bar`], (Bar) => {
12+
/**
13+
* @class
14+
* My super documentation of this class
15+
*
16+
* @extends library.j.Bar
17+
*
18+
* @author SAP SE
19+
* @version ${version}
20+
*
21+
* @public
22+
* @alias library.j.Foo
23+
*/
24+
class Foo extends Bar {
25+
make() {
26+
sap.ui.require("conditional/module1");
27+
}
28+
}
29+
30+
return Foo;
31+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - ArrowFunctionExpression
8+
*/
9+
window.someRandomModule ||
10+
sap.ui.define(
11+
["./a"],
12+
/**
13+
* Constructor for a new library.j.aaa.
14+
*
15+
* @param {string} [sId] ID for the new control, generated automatically if no ID is given
16+
* @param {object} [mSettings] Initial settings for the new control
17+
*
18+
* @class
19+
*
20+
* @author SAP SE
21+
* @version ${version}
22+
*
23+
* @constructor
24+
* @extends library.j.a
25+
* @public
26+
* @since 1.22
27+
* @alias library.j.aaa
28+
* @ui5-metamodel This control will also be described in the UI5 (legacy) design time meta model.
29+
*/
30+
(a) =>
31+
a.extend(`library.j.aaa`, {
32+
metadata: {
33+
properties: {
34+
/**
35+
* MyProp property
36+
* @since 1.46
37+
*/
38+
MyProp: {
39+
type: "boolean",
40+
group: `Misc`,
41+
defaultValue: false,
42+
},
43+
},
44+
},
45+
})
46+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*!
2+
* ${copyright}
3+
*/
4+
5+
/**
6+
* Covers:
7+
* - Generators
8+
* - YeldExpression
9+
*/
10+
sap.ui.define([], function* someGenerator(genVar) {
11+
yield genVar++;
12+
});

packages/builder/test/fixtures/library.j/main/src/library/j/some.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
* ${copyright}
33
*/
44

5-
sap.ui.define([],
6-
function() {
7-
"use strict";
5+
sap.ui.define(
6+
["./dependency-es6-1"],
7+
["./dependency-es6-2"],
8+
["./dependency-es6-3"],
9+
function (dep1, dep2, dep3) {
10+
"use strict";
811

9-
/**
10-
* @alias library.j
11-
* @namespace
12-
* @public
13-
*/
14-
var SomeFunction = function() {};
15-
16-
}, /* bExport= */ true);
12+
/**
13+
* @alias library.j
14+
* @namespace
15+
* @public
16+
*/
17+
var SomeFunction = function () {};
18+
},
19+
/* bExport= */ true
20+
);

0 commit comments

Comments
 (0)