@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
51 lines (49 loc) • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IiFUpdaterUtil = void 0;
const common_1 = require("../../../common");
const logger_1 = require("../../utils/logger");
/**
* Updater for iif errors.
*/
class IiFUpdaterUtil {
/**
* the update function.
* @param fileData the file data.
* @param error the error object.
* @returns the updated file data.
*/
update(fileData, error) {
if (!fileData) {
logger_1.Logger.error(`Cannot find file data`);
}
const result = this.regexFixer(fileData);
error.resolved = common_1.ResolveState.Resolved;
return result;
}
/**
* the update function.
* @param inputString the input file data string.
* @returns the updated file data string.
*/
regexFixer(inputString) {
const regexPattern = /iif\s*\(\s*((?:[^,\r\n]+|\([^)]*\))*)(?:\s*,\s*((?:[^,\r\n]+|\([^)]*\))*))?(?:\s*,\s*((?:[^,\r\n]+|\([^)]*\))))?\s*\)/g;
logger_1.Logger.error(regexPattern.test(inputString).toString());
const replacedCode = inputString.replace(regexPattern, (match, condition, valueIfTrue, valueIfFalse) => {
logger_1.Logger.log('match: ' + match);
if (valueIfTrue === undefined && valueIfFalse === undefined) {
logger_1.Logger.log('added valueIfTrue and valueIfFalse');
return `iif(${condition}, of(null), of(null))`;
}
if (valueIfFalse === undefined) {
logger_1.Logger.log('added valueIfFalse');
return `iif(${condition}, ${valueIfTrue}, of(null))`;
}
logger_1.Logger.log('no-op');
return match;
});
return replacedCode;
}
}
exports.IiFUpdaterUtil = IiFUpdaterUtil;
//# sourceMappingURL=iif-updater-util.js.map