Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import { LWC_MAPPINGS_FINAL_JSON } from '../../constants.js';
import { readJSON } from '../../services/file-service.js';
import { CSVRowProcessor } from '../../types.js';
export type LWCMappingsProcessorResults = Record<string, {
deprecated: boolean;
continueToUse: boolean;
okForValidator: boolean;
replacement: string | string[];
alternate: string | string[];
}>;
export class LWCMappingsProcessor implements CSVRowProcessor<LWCMappingsProcessorResults> {
private mappings: LWCMappingsProcessorResults = {};
private isDeprecated(cellVal: string): boolean {
return !cellVal || cellVal.includes("No replacement") || cellVal.includes("No recommendation");
}
private isContinueToUse(cellVal: string): boolean {
return cellVal.includes("continue to use");
}
private sanitizeCellValue(cellVal: string): string |string[] {
if(this.isDeprecated(cellVal)){
return '';
}
const correctedVal = cellVal
.replace("*", "")
.replace("continue to use", "")
.replace("color:","")
.replace("color-mix + ","")
.replace("Use raw value, ","")
.replace("<code>", "")
.replace("</code>", "")
.replace(" for checkbox", "")
.trim();
if(correctedVal.includes(" or ")){
return correctedVal.split(" or ").map(a => a.trim());
}
return correctedVal;
}
private isOkForValidator(colValue: string): boolean {
return colValue.includes("✅");
}
processRow(row: string[]): void {
// refer lwc_to_slds.csv for the format of the csv file
const [tokenName, quickFix, secondary,,,okForValidator] = row;
const lwcToken = tokenName.replace(/\n/g, "");
// if the lwcToken starts with --lwc, then check quickfix and secondary
if (!lwcToken.startsWith('--lwc')) {
//console.debug("Skipping row", lwcToken);
return;
}
this.mappings[lwcToken] = {
deprecated: this.isDeprecated(quickFix),
continueToUse: this.isContinueToUse(quickFix),
okForValidator: this.isOkForValidator(okForValidator),
replacement: this.sanitizeCellValue(quickFix),
alternate: this.sanitizeCellValue(secondary)
};
}
async loadUpdatedMappings(): Promise<void> {
const updatedMappings:Record<string, {stylingHook:string}> = await readJSON(LWC_MAPPINGS_FINAL_JSON);
Object.entries(updatedMappings).forEach(([key, value]) => {
if(this.mappings[key]){
this.mappings[key].replacement = value.stylingHook;
}
});
}
getResults(): LWCMappingsProcessorResults {
return this.mappings;
}
} |