Skip to content

Commit

Permalink
Remove optional chaining
Browse files Browse the repository at this point in the history
MVN build would fail with optional chaining as it still useses Node 12
  • Loading branch information
d3xter666 committed Sep 12, 2022
1 parent 28ac63d commit 321e696
Showing 1 changed file with 56 additions and 50 deletions.
106 changes: 56 additions & 50 deletions lib/processors/jsdoc/lib/ui5/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,10 @@ function stripChainWrappers(rootNode, path) {

function isTemplateLiteralWithoutExpression(node) {
return (
node?.type === Syntax.TemplateLiteral &&
node?.expressions?.length === 0 &&
node?.quasis?.length === 1
node &&
node.type === Syntax.TemplateLiteral &&
node.expressions && node.expressions.length === 0 &&
node.quasis && node.quasis.length === 1
);
}

Expand Down Expand Up @@ -919,103 +920,108 @@ function convertValueWithRaw(node, type, propertyName) {

let value;

if ( node.type === Syntax.Literal ) {

if (node.type === Syntax.Literal) {
// 'string' or number or true or false
return {
value: node.value,
raw: node.raw
raw: node.raw,
};

} else if ( node.type === Syntax.UnaryExpression
&& node.prefix
&& node.argument.type === Syntax.Literal
&& typeof node.argument.value === 'number'
&& ( node.operator === '-' || node.operator === '+' )) {

} else if (
node.type === Syntax.UnaryExpression &&
node.prefix &&
node.argument.type === Syntax.Literal &&
typeof node.argument.value === "number" &&
(node.operator === "-" || node.operator === "+")
) {
// -n or +n
value = node.argument.value;
return {
value: node.operator === '-' ? -value : value,
raw: node.operator + node.argument.raw
value: node.operator === "-" ? -value : value,
raw: node.operator + node.argument.raw,
};

} else if ( isMemberExpression(node) && type ) {

} else if (isMemberExpression(node) && type) {
// enum value (a.b.c)
const potentialEnum = resolvePotentialEnum(node, type);

if ( potentialEnum ) {
if (potentialEnum) {
return potentialEnum;
// } else if ( value.indexOf(type.split(".").slice(-1)[0] + ".") === 0 ) {
// // unqualified name might be a local name (just a guess - would need static code analysis for proper solution)
// return value.slice(type.split(".").slice(-1)[0].length + 1);
// } else if ( value.indexOf(type.split(".").slice(-1)[0] + ".") === 0 ) {
// // unqualified name might be a local name (just a guess - would need static code analysis for proper solution)
// return value.slice(type.split(".").slice(-1)[0].length + 1);
} else {
value = getResolvedObjectName(node);
warning(`did not understand default value '${value}'${propertyName ? " of property '" + propertyName + "'" : ""}, falling back to source`);
warning(
`did not understand default value '${value}'${
propertyName ? " of property '" + propertyName + "'" : ""
}, falling back to source`
);
let raw = value;
if ( currentSource && node.range ) {
raw = currentSource.slice( node.range[0], node.range[1] );
if (currentSource && node.range) {
raw = currentSource.slice(node.range[0], node.range[1]);
}
return {
value: value,
raw: raw
raw: raw,
};
}

} else if ( node.type === Syntax.Identifier ) {
if ( node.name === 'undefined') {
} else if (node.type === Syntax.Identifier) {
if (node.name === "undefined") {
return {
value: undefined,
raw: node.name
raw: node.name,
};
}
const local = currentModule.localNames[node.name];
if ( typeof local === 'object' && 'value' in local ) {
if (typeof local === "object" && "value" in local) {
// a locally defined constant
// TODO check type
return {
value: local.value,
raw: local.raw
raw: local.raw,
};
}

const potentialEnum = resolvePotentialEnum(node, type);
if ( potentialEnum ) {
if (potentialEnum) {
return potentialEnum;
}
} else if ( node.type === Syntax.ArrayExpression ) {

if ( node.elements.length === 0 ) {
} else if (node.type === Syntax.ArrayExpression) {
if (node.elements.length === 0) {
// empty array literal
return {
value: [],
raw: "[]"
raw: "[]",
};
}

if ( type && type.slice(-2) === "[]" ) {
const componentType = type.slice(0, -2);
const array = node.elements.map((elem) => convertValueWithRaw(elem, componentType, propertyName));
if (type && type.slice(-2) === "[]") {
const componentType = type.slice(0, -2);
const array = node.elements.map((elem) =>
convertValueWithRaw(elem, componentType, propertyName)
);
return {
value: array.map((value) => value.value),
raw: "[" + array.map((value) => value.raw).join(", ") + "]"
raw: "[" + array.map((value) => value.raw).join(", ") + "]",
};
}

} else if ( node.type === Syntax.ObjectExpression ) {

if ( node.properties.length === 0 && (type === 'object' || type === 'any') ) {
} else if (node.type === Syntax.ObjectExpression) {
if (
node.properties.length === 0 &&
(type === "object" || type === "any")
) {
return {
value: {},
raw: "{}"
raw: "{}",
};
}

} else if ( isTemplateLiteralWithoutExpression(node) ) {
} else if (isTemplateLiteralWithoutExpression(node)) {
let value = {};
if (node && node.quasis && node.quasis[0] && node.quasis[0].value) {
value = node.quasis[0].value;
}
return {
value: node?.quasis?.[0]?.value?.cooked,
raw: node?.quasis?.[0]?.value?.raw,
value: value.cooked,
raw: value.raw,
};
}

Expand Down

0 comments on commit 321e696

Please sign in to comment.