Skip to content

Commit 60022a8

Browse files
committed
[INTERNAL] lib/processors/jsdoc: support property names that are not identifiers
JSDoc allows to quote property names when they contain characters that are not valid in identifiers. So far, the UI5 template failed to support such names, esp. when used in nested parameter properties. With this change, support for such names is added. Cherry-picked from UI5/openui5@9b2a1914b.
1 parent 40f1489 commit 60022a8

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lib/processors/jsdoc/lib/ui5/template/publish.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,13 @@ function normalizeWS(text) {
889889

890890
}
891891

892+
const rStartsWithValidPropertyName = /^(?:[^'"][^\s.]+|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")/;
893+
894+
function isNestedPropertyName(name) {
895+
const match = rStartsWithValidPropertyName.exec(name);
896+
return match && match[0].length < name.length && name[match[0].length] === ".";
897+
}
898+
892899
//---- add on: API JSON -----------------------------------------------------------------
893900

894901
function createAPIJSON(symbols, filename) {
@@ -1411,7 +1418,7 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
14111418
continue;
14121419
}
14131420

1414-
if ( name.indexOf('.') >= 0 ) {
1421+
if ( isNestedPropertyName(name) ) {
14151422
continue;
14161423
}
14171424

@@ -2276,6 +2283,19 @@ function validateAPIJSON(api) {
22762283
}
22772284
}
22782285

2286+
/**
2287+
* Checks the name of a property in an object-like structure.
2288+
* As in JavaScript, the rules for such names are less strict than
2289+
* for classes, interfaces or function declarations.
2290+
*/
2291+
function checkPropertyName(name, hint) {
2292+
const match = rStartsWithValidPropertyName.exec(name);
2293+
if ( match == null || match[0].length !== name.length ) {
2294+
naming[name] ??= [];
2295+
naming[name].push(hint);
2296+
}
2297+
}
2298+
22792299
function checkModuleName(name, hint) {
22802300
if ( !rValidModuleNames.test(name) ) {
22812301
naming[name] = naming[name] || [];
@@ -2386,7 +2406,12 @@ function validateAPIJSON(api) {
23862406
}
23872407

23882408
function checkParam(param, prefix, hint) {
2389-
checkName(param.name, `name of param ${prefix}${param.name} of ${hint}`);
2409+
if (prefix) {
2410+
// nested parameter properties follow the naming conventions for object properties
2411+
checkPropertyName(param.name, `name of param ${prefix}${param.name} of ${hint}`);
2412+
} else {
2413+
checkName(param.name, `name of param ${prefix}${param.name} of ${hint}`);
2414+
}
23902415
checkType(param, `param ${prefix}${param.name} of ${hint}`);
23912416
if ( param.parameterProperties ) {
23922417
Object.keys(param.parameterProperties).forEach((sub) =>
@@ -2508,7 +2533,7 @@ function validateAPIJSON(api) {
25082533
if ( symbol.properties ) {
25092534
symbol.properties.forEach((prop) => {
25102535
const qualifiedName = `${symbol.name}.${prop.name}`;
2511-
checkName(prop.name, `name of ${qualifiedName}`);
2536+
checkPropertyName(prop.name, `name of ${qualifiedName}`);
25122537
if ( prop.type ) {
25132538
checkType(prop, `type of ${qualifiedName}`);
25142539
}

0 commit comments

Comments
 (0)