From bc6dc1d108110f73a5231add88cc345494b3d6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 29 Mar 2021 05:22:06 -0300 Subject: [PATCH] chore(dotnet): treat file as a reserved word (#5960) Avoid collision with System.IO.File and unify handling reserved file names and enum values. --- utils/doclint/generateDotnetApi.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/utils/doclint/generateDotnetApi.js b/utils/doclint/generateDotnetApi.js index f2cf2aea32..5e74542b4f 100644 --- a/utils/doclint/generateDotnetApi.js +++ b/utils/doclint/generateDotnetApi.js @@ -40,6 +40,13 @@ let documentation; /** @type {Map} */ let classNameMap; +/** @type {Map} */ +const customTypeNames = new Map([ + ['domcontentloaded', 'DOMContentLoaded'], + ['networkidle', 'NetworkIdle'], + ['File', 'FilePayload'], +]); + { const typesDir = process.argv[2] || '../generate_types/csharp/'; let checkAndMakeDir = (path) => { @@ -179,17 +186,13 @@ let classNameMap; enumTypes.forEach((values, name) => innerRenderElement('enum', name, null, (out) => { - const knownEnumValues = new Map([ - ['domcontentloaded', 'DOMContentLoaded'], - ['networkidle', 'NetworkIdle'] - ]); out.push('\tUndefined = 0,'); values.forEach((v, i) => { // strip out the quotes v = v.replace(/[\"]/g, ``) let escapedName = v.replace(/[-]/g, ' ') .split(' ') - .map(word => knownEnumValues.get(word) || word[0].toUpperCase() + word.substring(1)).join(''); + .map(word => customTypeNames.get(word) || word[0].toUpperCase() + word.substring(1)).join(''); out.push(`\t[EnumMember(Value = "${v}")]`); out.push(`\t${escapedName},`); @@ -341,6 +344,8 @@ function generateNameDefault(member, name, t, parent) { if (attemptedName.endsWith('s') && !["properties", "httpcredentials"].includes(attemptedName.toLowerCase())) attemptedName = attemptedName.substring(0, attemptedName.length - 1); + if (customTypeNames.get(attemptedName)) + attemptedName = customTypeNames.get(attemptedName); let probableType = additionalTypes.get(attemptedName); if ((probableType && typesDiffer(t, probableType)) || (["Value"].includes(attemptedName))) {