chore(dotnet): fix channel generation for 1.17 (#10711)

This commit is contained in:
Max Schmitt 2021-12-06 13:40:26 -08:00 committed by GitHub
parent 7765131a14
commit c3687a693b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -96,7 +96,7 @@ classNameMap.set('Readable', 'Stream');
* @param {string} folder
* @param {string} extendsName
*/
function writeFile(kind, name, spec, body, folder, extendsName = null, namespace = "Microsoft.Playwright") {
function writeFile(kind, name, spec, body, folder, extendsName = null) {
const out = [];
// console.log(`Generating ${name}`);
@ -122,7 +122,7 @@ function writeFile(kind, name, spec, body, folder, extendsName = null, namespace
out.push(...body);
out.push('}');
let content = template.replace('[NAMESPACE]', namespace).replace('[CONTENT]', out.join(EOL));
let content = template.replace('[CONTENT]', out.join(EOL));
fs.writeFileSync(path.join(folder, name + '.cs'), content);
}

View File

@ -37,7 +37,7 @@ using System.Threading.Tasks;
#nullable enable
namespace [NAMESPACE]
namespace Microsoft.Playwright
{
[CONTENT]
}

9
utils/generate_dotnet_channels.js Executable file → Normal file
View File

@ -18,7 +18,6 @@
// @ts-check
const fs = require('fs');
const os = require('os');
const path = require('path');
const yaml = require('yaml');
@ -41,8 +40,13 @@ function mapType(type) {
return 'bool';
if (type === 'number')
return 'int';
// TODO: keep the same names in .NET as upstream
if (type === 'ResourceTiming')
return 'RequestTimingResult';
if (type === 'LifecycleEvent')
return 'WaitUntilState';
if (type === 'NameValue')
return 'HeaderEntry';
return type;
}
@ -65,7 +69,7 @@ function inlineType(type, indent = '', wrapEnums = false) {
return { ts: mapType(type), scheme: `t${titleCase(type)}`, optional };
}
if (channels.has(type))
return { ts: `${type}`, scheme: `tChannel('${type}')` , optional };
return { ts: `Core.${type}`, scheme: `tChannel('${type}')` , optional };
if (type === 'Channel')
return { ts: `Channel`, scheme: `tChannel('*')`, optional };
return { ts: mapType(type), scheme: `tType('${type}')`, optional };
@ -179,7 +183,6 @@ for (const [name, item] of Object.entries(protocol)) {
*/
`)
channels_ts.push('using System.Collections.Generic;');
channels_ts.push('using Microsoft.Playwright.Core;');
channels_ts.push(``);
channels_ts.push(`namespace Microsoft.Playwright.Transport.Protocol`);
channels_ts.push(`{`);