generate JsDoc api.json fails on MemberExpressions with Literals
@RandomByte ci sta già lavorando.
Dal 1/10/2021.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Expected Behavior
Running the build process to generate the api.json without errors:
await builder.build({
tree: tree,
destPath: params.destPath,
cleanDest: false,
jsdoc: true,
buildDependencies: true
});
Current Behavior
.../node_modules/@ui5/builder/lib/processors/jsdoc/lib/ui5/plugin.js:294
path: getObjectName(valueNode).split('.').slice(1).join('.') // TODO chaining if local has path
^
TypeError: Cannot read property 'split' of null
(Exception is generated here: https://github.com/SAP/ui5-builder/blob/master/lib/processors/jsdoc/lib/ui5/plugin.js#L294)
Steps to Reproduce the Issue
When you use babel-plugin-transform-modules-ui5 for TypeScript coding, you will import library enums like this:
import { FlexRendertype, ButtonType } from "sap/m/library";
Babel will transform that into an sap.ui.define() call with "sap/m/library" which produces a variable sap_m_library. After that, it will generate the enums as follows:
const FlexRendertype = sap_m_library["FlexRendertype"];
const ButtonType = sap_m_library["ButtonType"];
To reproduce, you only need to use this syntax, no TypeScript or other transformations are necessary.
The problem is gone when you rewrite the code as follows:
const FlexRendertype = sap_m_library.FlexRendertype;
const ButtonType = sap_m_library.ButtonType;
The reason for this is that in the getObjectName() function, only specific AST nodes are parsed: https://github.com/SAP/ui5-builder/blob/master/lib/processors/jsdoc/lib/ui5/plugin.js#L523
function getObjectName(node) {
if ( node.type === Syntax.MemberExpression && !node.computed && node.property.type === Syntax.Identifier ) {
const prefix = getObjectName(node.object);
return prefix ? prefix + "." + node.property.name : null;
} else if ( node.type === Syntax.Identifier ) {
return /* scope[node.name] ? scope[node.name] : */ node.name;
} else {
return null;
}
}
The error occurs if the node.type is MemberExpression, but node.computed is true and node.property.type is Literal.
This is how the AST looks like in the error case:

My suggestion is to add another else if clause which covers this case:
function getObjectName (node) {
if( node.type === Syntax.MemberExpression && !node.computed && node.property.type === Syntax.Identifier ) {
const prefix = getObjectName(node.object);
return prefix ? prefix + "." + node.property.name : null;
} else if( node.type === Syntax.MemberExpression && node.computed && node.property.type === Syntax.Literal ) {
const prefix = getObjectName(node.object);
return prefix ? prefix + "." + node.property.value : null;
} else if( node.type === Syntax.Identifier ) {
return /* scope[node.name] ? scope[node.name] : */ node.name;
} else {
return null;
}
}
Context
- UI5 Module Version (output of
ui5 --versionwhen using the CLI): 2.12.1 - Node.js Version: 10.22.1
- OS/Platform: OpenSUSE 15.2
Solution
I could also create a pull request if you don't have any better idea?
- Lingua principale
- JavaScript
- Stelle
- 511
- Fork
- 83
- Merge medio
- 1g 5h
- PR unite (30g)
- 55
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di UI5/cli
-
module/ui5-builder
-
Build cache: buildThemes cache is invalidated by irrelevant library.js / .library content changes Apertamodule/ui5-builder module/ui5-fs module/ui5-project
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
-
module/ui5-project
Difficoltà 4/5 3-5 giorni Idoneità per principianti 64/100
-
roadmap
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
curation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
amponce/archive-movie-browser#186 ·
-
light
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
aemdemos/patients-stryker#253 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
clerk/javascript#9852 ·