10
10
"use strict" ;
11
11
const cheerio = require ( "cheerio" ) ;
12
12
const path = require ( 'path' ) ;
13
+ const { TypeParser} = require ( "./ui5/template/utils/typeParser" ) ;
13
14
const log = ( function ( ) {
14
15
try {
15
16
return require ( "@ui5/logger" ) . getLogger ( "builder:processors:jsdoc:transformApiJson" ) ;
@@ -36,6 +37,7 @@ function normalizeToUI5GlobalNotation(sModuleName){
36
37
return sModuleName . replace ( / \/ / g, "." ) ;
37
38
}
38
39
40
+ const typeParser = new TypeParser ( ) ;
39
41
40
42
/**
41
43
* Transforms the api.json as created by the JSDoc build into a pre-processed api.json file suitable for the SDK.
@@ -110,15 +112,78 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
110
112
return func ;
111
113
}
112
114
113
- function fnCreateTypesArr ( sTypes ) {
114
- return sTypes . split ( "|" ) . map ( function ( sType ) {
115
- const bLinkEnabled = ! isBuiltInType ( sType ) && possibleUI5Symbol ( sType . replace ( / \[ \] $ / , "" ) ) ;
116
- const oTypeInfo = { value : sType } ;
117
- if ( bLinkEnabled ) { // default is false, so omit if not required
118
- oTypeInfo . linkEnabled = true ;
119
- }
120
- return oTypeInfo ;
121
- } ) ;
115
+ function isUI5Type ( sType ) {
116
+ return ! isBuiltInType ( sType ) && possibleUI5Symbol ( sType ) ;
117
+ }
118
+
119
+ /**
120
+ * Returns an object with the parsed custom-type information, namely:
121
+ * - types: array of the parsed UI5 types inside the given complex type
122
+ * - template: the template string with placeholders for the parsed UI5 types
123
+ *
124
+ * Examples:
125
+ *
126
+ * - parseUI5Types("sap.ui.core.ID | sap.ui.core.Control") returns
127
+ * {
128
+ * template: "${0} | ${1}",
129
+ * UI5Types: ["sap.ui.core.ID", "sap.ui.core.Control"]
130
+ * }
131
+ *
132
+ * - parseUI5Types("Array<sap.ui.core.Control>") returns
133
+ * {
134
+ * template: "Array<${0}>",
135
+ * UI5Types: ["sap.ui.core.Control"]
136
+ * }
137
+ *
138
+ * - parseUI5Types("Array<sap.ui.core.ID|string>") returns
139
+ * {
140
+ * template: "Array<${0} | string>", // built-in types remain unchanged in the template
141
+ * UI5Types: ["sap.ui.core.ID"]
142
+ * }
143
+ *
144
+ * - parseUI5Types("Object<string, sap.ui.core.Control>") returns
145
+ * {
146
+ * template: "Object<string, ${0}>", // built-in types remain unchanged in the template
147
+ * UI5Types: ["sap.ui.core.Control"]
148
+ * }
149
+ *
150
+ * - parseUI5Types("string") returns
151
+ * {
152
+ * template: "string" // skip the types array if empty
153
+ * }
154
+ *
155
+ * - parseUI5Types("sap.ui.core.Control") returns
156
+ * {
157
+ * UI5Types: ["sap.ui.core.Control"] // skip template if its value is "${0}" (default value)
158
+ * }
159
+ * @param {string } sComplexType
160
+ * @returns {?template: string, ?UI5Types: string[] }
161
+ */
162
+ function parseUI5Types ( sComplexType ) {
163
+ let oParsed ;
164
+ try {
165
+ oParsed = typeParser . parseSimpleTypes ( sComplexType , isUI5Type ) ;
166
+ } catch ( e ) {
167
+ log . error ( "Error parsing type: " + sComplexType ) ;
168
+ log . error ( e ) ;
169
+ oParsed = { template : sComplexType } ;
170
+ }
171
+
172
+ const result = { } ;
173
+
174
+ if ( oParsed . template !== '${0}' ) { // default is '${0}', so omit if not required
175
+ result . template = oParsed . template ;
176
+ }
177
+
178
+ if ( oParsed . simpleTypes ?. length ) { // it can be empty if none of the included simple types satisfied the filter function
179
+ result . UI5Types = oParsed . simpleTypes
180
+ }
181
+
182
+ return result ;
183
+ }
184
+
185
+ function includesIgnoreCase ( array , string ) {
186
+ return array . some ( item => item . toLowerCase ( ) === string . toLowerCase ( ) ) ;
122
187
}
123
188
124
189
/**
@@ -132,7 +197,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
132
197
const builtInTypes = formatters . _baseTypes ;
133
198
134
199
// Early return if the type is directly in baseTypes
135
- if ( builtInTypes . includes ( type ) ) {
200
+ if ( includesIgnoreCase ( builtInTypes , type ) ) {
136
201
return true ;
137
202
}
138
203
@@ -193,7 +258,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
193
258
* @returns {boolean }
194
259
*/
195
260
function possibleUI5Symbol ( sName ) {
196
- const ui5SymbolRegex = / ^ ( m o d u l e : ) ? [ a - z A - Z ] [ a - z A - Z 0 - 9 / . ] * [ a - z A - Z 0 - 9 ] $ / ;
261
+ const ui5SymbolRegex = / ^ ( m o d u l e : ) ? s a p [ / . ] [ a - z A - Z ] [ a - z A - Z 0 - 9 / . $ ] * [ a - z A - Z 0 - 9 ] $ /
197
262
return ui5SymbolRegex . test ( sName ) ;
198
263
}
199
264
@@ -373,7 +438,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
373
438
// Types
374
439
oParameter . types = [ ] ;
375
440
if ( oParameter . type ) {
376
- oParameter . types = fnCreateTypesArr ( oParameter . type ) ;
441
+ oParameter . typeInfo = parseUI5Types ( oParameter . type ) ;
377
442
// Keep file size in check
378
443
delete oParameter . type ;
379
444
}
@@ -458,7 +523,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
458
523
// Type
459
524
if ( oSymbol . kind !== "enum" ) { // enum properties don't have an own type
460
525
if ( oProperty . type ) {
461
- oProperty . types = fnCreateTypesArr ( oProperty . type ) ;
526
+ oProperty . typeInfo = parseUI5Types ( oProperty . type ) ;
462
527
// Keep file size in check
463
528
delete oProperty . type ;
464
529
}
@@ -498,7 +563,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
498
563
499
564
// Type
500
565
if ( oProperty . type ) {
501
- oProperty . types = fnCreateTypesArr ( oProperty . type ) ;
566
+ oProperty . typeInfo = parseUI5Types ( oProperty . type ) ;
502
567
// Keep file size in check
503
568
delete oProperty . type ;
504
569
}
@@ -622,8 +687,9 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
622
687
oMeta . specialSettings . forEach ( oSetting => {
623
688
624
689
// Link Enabled
625
- if ( ! isBuiltInType ( oSetting . type ) ) {
626
- oSetting . linkEnabled = true ;
690
+ if ( oSetting . type ) {
691
+ oSetting . typeInfo = parseUI5Types ( oSetting . type ) ;
692
+ delete oSetting . type ; // Keep file size in check
627
693
}
628
694
629
695
// Description
@@ -682,9 +748,9 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
682
748
if ( oEvent . parameters && Array . isArray ( oEvent . parameters ) ) {
683
749
oEvent . parameters . forEach ( oParameter => {
684
750
685
- // Link Enabled
686
- if ( ! isBuiltInType ( oParameter . type ) ) {
687
- oParameter . linkEnabled = true ;
751
+ if ( oParameter . type ) {
752
+ oParameter . typeInfo = parseUI5Types ( oParameter . type ) ;
753
+ delete oParameter . type ; // Keep file size in check
688
754
}
689
755
690
756
// Description
@@ -1153,9 +1219,14 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
1153
1219
"array" ,
1154
1220
"element" ,
1155
1221
"Element" ,
1222
+ "HTMLElement" ,
1223
+ "Node" ,
1224
+ "Attr" ,
1156
1225
"Date" ,
1157
1226
"DomRef" ,
1227
+ "jQuery" ,
1158
1228
"jQuery.promise" ,
1229
+ "jQuery.event" ,
1159
1230
"QUnit.Assert" ,
1160
1231
"object" ,
1161
1232
"Object" ,
@@ -1174,6 +1245,10 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
1174
1245
"TouchList" ,
1175
1246
"undefined" ,
1176
1247
"this" ,
1248
+ "Blob" ,
1249
+ "RegExp" ,
1250
+ "void" ,
1251
+ "ArrayBuffer" ,
1177
1252
"[object Object]"
1178
1253
] ,
1179
1254
ANNOTATIONS_LINK : 'http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part3-csdl.html' ,
@@ -2092,7 +2167,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
2092
2167
2093
2168
// Handle types
2094
2169
if ( oProperty . type ) {
2095
- oProperty . types = fnCreateTypesArr ( oProperty . type ) ;
2170
+ oProperty . typeInfo = parseUI5Types ( oProperty . type ) ;
2096
2171
// Keep file size in check
2097
2172
delete oProperty . type ;
2098
2173
}
@@ -2124,7 +2199,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
2124
2199
if ( oMethod . parameters ) {
2125
2200
oMethod . parameters . forEach ( function ( oParameter ) {
2126
2201
if ( oParameter . type ) {
2127
- oParameter . types = fnCreateTypesArr ( oParameter . type ) ;
2202
+ oParameter . typeInfo = parseUI5Types ( oParameter . type ) ;
2128
2203
// Keep file size in check
2129
2204
delete oParameter . type ;
2130
2205
}
@@ -2145,7 +2220,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
2145
2220
// Handle return values
2146
2221
if ( oMethod . returnValue && oMethod . returnValue . type ) {
2147
2222
// Handle types
2148
- oMethod . returnValue . types = fnCreateTypesArr ( oMethod . returnValue . type ) ;
2223
+ oMethod . returnValue . typeInfo = parseUI5Types ( oMethod . returnValue . type ) ;
2149
2224
}
2150
2225
2151
2226
} ) ;
0 commit comments