From c54daa9f62b36057044e4e8d8d89448ef0318d19 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 00:58:04 -0400 Subject: [PATCH 1/9] added tsconfig.json support --- web_generator/bin/gen_interop_bindings.dart | 8 +++++ web_generator/lib/src/config.dart | 36 +++++++++++++++++-- web_generator/lib/src/dart_main.dart | 3 ++ web_generator/lib/src/interop_gen/parser.dart | 9 +++-- web_generator/lib/src/js/typescript.dart | 1 + 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index 862624cf..a648c58c 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -68,6 +68,10 @@ $_usage'''); : null); final relativeOutputPath = p.relative(outputFile, from: bindingsGeneratorPath); + final tsConfigPath = argResult['ts-config'] as String?; + final tsConfigRelativePath = tsConfigPath != null ? + p.relative(tsConfigPath, from: bindingsGeneratorPath) + : null; // Run app with `node`. await runProc( 'node', @@ -76,6 +80,7 @@ $_usage'''); '--declaration', '--input=${p.relative(inputFile, from: bindingsGeneratorPath)}', '--output=$relativeOutputPath', + if (tsConfigRelativePath case final tsConfig?) '--ts-config=$tsConfig', if (configFile case final config?) '--config=$config' ], workingDirectory: bindingsGeneratorPath, @@ -100,6 +105,9 @@ final _parser = ArgParser() ..addFlag('compile', defaultsTo: true) ..addOption('output', abbr: 'o', help: 'The output path to generate the Dart interface code') + ..addOption('ts-config', + help: 'Path to TS Configuration Options File (tsconfig.json) to pass' + ' to the parser/transformer') ..addOption('config', hide: true, abbr: 'c', diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index 45620d29..2aed2d70 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -2,11 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:convert'; +import 'dart:js_interop'; + import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; +import 'js/filesystem_api.dart'; import 'util.dart'; class FunctionConfig { @@ -49,11 +53,16 @@ abstract interface class Config { /// If empty, all declarations will be generated by default List get includedDeclarations; + /// An object consisting of TS Configurations from a tsconfig.json file + /// used for configuring the TypeScript Program/Compiler + Map get tsConfig; + factory Config( {required List input, required String output, required Version languageVersion, FunctionConfig? functions, + Map tsConfig, List includedDeclarations}) = ConfigImpl._; } @@ -85,12 +94,17 @@ class ConfigImpl implements Config { @override List includedDeclarations; + @override + Map tsConfig; + ConfigImpl._( {required this.input, required this.output, required this.languageVersion, this.functions, - this.includedDeclarations = const []}); + Map? tsConfig, + this.includedDeclarations = const []}) : + tsConfig = tsConfig ?? {}; @override bool get singleFileOutput => input.length == 1; @@ -127,6 +141,9 @@ class YamlConfig implements Config { @override List includedDeclarations; + @override + Map tsConfig; + YamlConfig._( {required this.filename, required this.input, @@ -136,6 +153,7 @@ class YamlConfig implements Config { this.preamble, this.functions, this.includedDeclarations = const [], + required this.tsConfig, String? languageVersion}) : languageVersion = languageVersion == null ? DartFormatter.latestLanguageVersion @@ -159,6 +177,20 @@ class YamlConfig implements Config { final allFiles = expandGlobs(inputFiles, extension: '.d.ts', cwd: p.dirname(filename)); + var tsConfig = {}; + if (yaml['ts_config_file'] != null) { + tsConfig = json.decode( + (fs.readFileSync( + p.join(p.dirname(filename), yaml['ts_config_file'] as String).toJS, + JSReadFileOptions(encoding: 'utf8'.toJS) + ) as JSString).toDart + ) as Map; + } else if (yaml['ts_config'] != null && yaml['ts_config'] is YamlMap) { + tsConfig = jsonDecode( + jsonEncode(yaml['ts_config'] as YamlMap) + ) as Map; + } + return YamlConfig._( filename: Uri.file(filename), input: @@ -169,7 +201,7 @@ class YamlConfig implements Config { description: yaml['description'] as String?, languageVersion: yaml['language_version'] as String?, preamble: yaml['preamble'] as String?, - // TODO: Can we consider using `json_serializable`? + tsConfig: tsConfig, functions: FunctionConfig( varArgs: (yaml['functions'] as YamlMap?)?['varargs'] as int?), includedDeclarations: (yaml['include'] as YamlList?) diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index a6d65ba0..a22a8a6c 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -185,6 +185,9 @@ final _parser = ArgParser() negatable: false, help: '[IDL] Generate bindings for all IDL definitions, ' 'including experimental and non-standard APIs.') + ..addOption('ts-config', + help: '[TS Declarations] Path to TS Configuration Options File (tsconfig.json) to pass' + ' to the parser/transformer') ..addMultiOption('input', abbr: 'i', help: '[TS Declarations] The input file to read and generate types for') diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index aaf1f86c..056d7931 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -16,9 +16,14 @@ class ParserResult { /// Parses the given TypeScript declaration [files], provides any diagnostics, /// if any, and generates a [ts.TSProgram] for transformation -ParserResult parseDeclarationFiles(Iterable files) { +ParserResult parseDeclarationFiles(Iterable files, {Map? tsConfiguration}) { final program = ts.createProgram(files.jsify() as JSArray, - ts.TSCompilerOptions(declaration: true)); + tsConfiguration != null ? ts.TSCompilerOptions.fromJSObject({ + ...tsConfiguration, + 'declaration': true + }.jsify() as JSObject) + : ts.TSCompilerOptions(declaration: true) + ); // get diagnostics final diagnostics = [ diff --git a/web_generator/lib/src/js/typescript.dart b/web_generator/lib/src/js/typescript.dart index fd403b91..d6c935b1 100644 --- a/web_generator/lib/src/js/typescript.dart +++ b/web_generator/lib/src/js/typescript.dart @@ -43,6 +43,7 @@ external String flattenDiagnosticMessageText(JSAny? diag, String newLine, @JS('CompilerOptions') extension type TSCompilerOptions._(JSObject _) implements JSObject { external TSCompilerOptions({bool? allowJs, bool? declaration}); + factory TSCompilerOptions.fromJSObject(JSObject object) => TSCompilerOptions._(object); external bool? get allowJs; external bool? get declaration; } From 299b2afd6fccffc54e1d349a90c27e7fa71c33b9 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 01:09:57 -0400 Subject: [PATCH 2/9] formatting and analyzing --- web_generator/bin/gen_interop_bindings.dart | 12 +++++------ web_generator/lib/src/config.dart | 21 +++++++++---------- web_generator/lib/src/dart_main.dart | 6 +++--- web_generator/lib/src/interop_gen/parser.dart | 16 +++++++------- web_generator/lib/src/js/typescript.dart | 3 ++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index a648c58c..bb629b3f 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -69,9 +69,9 @@ $_usage'''); final relativeOutputPath = p.relative(outputFile, from: bindingsGeneratorPath); final tsConfigPath = argResult['ts-config'] as String?; - final tsConfigRelativePath = tsConfigPath != null ? - p.relative(tsConfigPath, from: bindingsGeneratorPath) - : null; + final tsConfigRelativePath = tsConfigPath != null + ? p.relative(tsConfigPath, from: bindingsGeneratorPath) + : null; // Run app with `node`. await runProc( 'node', @@ -105,9 +105,9 @@ final _parser = ArgParser() ..addFlag('compile', defaultsTo: true) ..addOption('output', abbr: 'o', help: 'The output path to generate the Dart interface code') - ..addOption('ts-config', - help: 'Path to TS Configuration Options File (tsconfig.json) to pass' - ' to the parser/transformer') + ..addOption('ts-config', + help: 'Path to TS Configuration Options File (tsconfig.json) to pass' + ' to the parser/transformer') ..addOption('config', hide: true, abbr: 'c', diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index 2aed2d70..3203d857 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -103,8 +103,8 @@ class ConfigImpl implements Config { required this.languageVersion, this.functions, Map? tsConfig, - this.includedDeclarations = const []}) : - tsConfig = tsConfig ?? {}; + this.includedDeclarations = const []}) + : tsConfig = tsConfig ?? {}; @override bool get singleFileOutput => input.length == 1; @@ -179,16 +179,15 @@ class YamlConfig implements Config { var tsConfig = {}; if (yaml['ts_config_file'] != null) { - tsConfig = json.decode( - (fs.readFileSync( - p.join(p.dirname(filename), yaml['ts_config_file'] as String).toJS, - JSReadFileOptions(encoding: 'utf8'.toJS) - ) as JSString).toDart - ) as Map; + tsConfig = json.decode((fs.readFileSync( + p + .join(p.dirname(filename), yaml['ts_config_file'] as String) + .toJS, + JSReadFileOptions(encoding: 'utf8'.toJS)) as JSString) + .toDart) as Map; } else if (yaml['ts_config'] != null && yaml['ts_config'] is YamlMap) { - tsConfig = jsonDecode( - jsonEncode(yaml['ts_config'] as YamlMap) - ) as Map; + tsConfig = jsonDecode(jsonEncode(yaml['ts_config'] as YamlMap)) + as Map; } return YamlConfig._( diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index a22a8a6c..bdd607ad 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -185,9 +185,9 @@ final _parser = ArgParser() negatable: false, help: '[IDL] Generate bindings for all IDL definitions, ' 'including experimental and non-standard APIs.') - ..addOption('ts-config', - help: '[TS Declarations] Path to TS Configuration Options File (tsconfig.json) to pass' - ' to the parser/transformer') + ..addOption('ts-config', + help: '[TS Declarations] Path to TS Configuration Options File ' + '(tsconfig.json) to pass to the parser/transformer') ..addMultiOption('input', abbr: 'i', help: '[TS Declarations] The input file to read and generate types for') diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index 056d7931..1a851a1e 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -16,14 +16,14 @@ class ParserResult { /// Parses the given TypeScript declaration [files], provides any diagnostics, /// if any, and generates a [ts.TSProgram] for transformation -ParserResult parseDeclarationFiles(Iterable files, {Map? tsConfiguration}) { - final program = ts.createProgram(files.jsify() as JSArray, - tsConfiguration != null ? ts.TSCompilerOptions.fromJSObject({ - ...tsConfiguration, - 'declaration': true - }.jsify() as JSObject) - : ts.TSCompilerOptions(declaration: true) - ); +ParserResult parseDeclarationFiles(Iterable files, + {Map? tsConfiguration}) { + final program = ts.createProgram( + files.jsify() as JSArray, + tsConfiguration != null + ? ts.TSCompilerOptions.fromJSObject( + {...tsConfiguration, 'declaration': true}.jsify() as JSObject) + : ts.TSCompilerOptions(declaration: true)); // get diagnostics final diagnostics = [ diff --git a/web_generator/lib/src/js/typescript.dart b/web_generator/lib/src/js/typescript.dart index d6c935b1..a9601c0c 100644 --- a/web_generator/lib/src/js/typescript.dart +++ b/web_generator/lib/src/js/typescript.dart @@ -43,7 +43,8 @@ external String flattenDiagnosticMessageText(JSAny? diag, String newLine, @JS('CompilerOptions') extension type TSCompilerOptions._(JSObject _) implements JSObject { external TSCompilerOptions({bool? allowJs, bool? declaration}); - factory TSCompilerOptions.fromJSObject(JSObject object) => TSCompilerOptions._(object); + factory TSCompilerOptions.fromJSObject(JSObject object) => + TSCompilerOptions._(object); external bool? get allowJs; external bool? get declaration; } From 964befe690ed082f18c67d0287ed92bedaed9fea Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 01:17:52 -0400 Subject: [PATCH 3/9] implemented ignoring errors --- web_generator/bin/gen_interop_bindings.dart | 4 +++- web_generator/lib/src/config.dart | 22 +++++++++++++++---- web_generator/lib/src/dart_main.dart | 19 +++++++++++----- web_generator/lib/src/interop_gen/parser.dart | 4 ++-- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index bb629b3f..e03fc544 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -81,7 +81,8 @@ $_usage'''); '--input=${p.relative(inputFile, from: bindingsGeneratorPath)}', '--output=$relativeOutputPath', if (tsConfigRelativePath case final tsConfig?) '--ts-config=$tsConfig', - if (configFile case final config?) '--config=$config' + if (configFile case final config?) '--config=$config', + if (argResult.wasParsed('ignore-errors')) '--ignore-errors' ], workingDirectory: bindingsGeneratorPath, ); @@ -108,6 +109,7 @@ final _parser = ArgParser() ..addOption('ts-config', help: 'Path to TS Configuration Options File (tsconfig.json) to pass' ' to the parser/transformer') + ..addFlag('ignore-errors', help: 'Ignore Generator Errors', negatable: false) ..addOption('config', hide: true, abbr: 'c', diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index 3203d857..b0912d6d 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -57,13 +57,18 @@ abstract interface class Config { /// used for configuring the TypeScript Program/Compiler Map get tsConfig; + /// Whether to ignore source code warnings and errors + /// (they will still be printed) + bool get ignoreErrors; + factory Config( {required List input, required String output, required Version languageVersion, FunctionConfig? functions, Map tsConfig, - List includedDeclarations}) = ConfigImpl._; + List includedDeclarations, + bool ignoreErrors}) = ConfigImpl._; } class ConfigImpl implements Config { @@ -97,13 +102,17 @@ class ConfigImpl implements Config { @override Map tsConfig; + @override + bool ignoreErrors; + ConfigImpl._( {required this.input, required this.output, required this.languageVersion, this.functions, Map? tsConfig, - this.includedDeclarations = const []}) + this.includedDeclarations = const [], + this.ignoreErrors = false}) : tsConfig = tsConfig ?? {}; @override @@ -144,6 +153,9 @@ class YamlConfig implements Config { @override Map tsConfig; + @override + bool ignoreErrors; + YamlConfig._( {required this.filename, required this.input, @@ -154,7 +166,8 @@ class YamlConfig implements Config { this.functions, this.includedDeclarations = const [], required this.tsConfig, - String? languageVersion}) + String? languageVersion, + this.ignoreErrors = false}) : languageVersion = languageVersion == null ? DartFormatter.latestLanguageVersion : Version.parse(languageVersion); @@ -206,6 +219,7 @@ class YamlConfig implements Config { includedDeclarations: (yaml['include'] as YamlList?) ?.map((node) => node.toString()) .toList() ?? - []); + [], + ignoreErrors: yaml['ignore_errors'] as bool? ?? false); } } diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index bdd607ad..b6c946db 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:convert'; import 'dart:js_interop'; import 'package:args/args.dart'; @@ -54,12 +55,18 @@ void main(List args) async { filename: filename, ); } else { + final tsConfigFile = argResult['ts-config'] as String?; config = Config( - input: - expandGlobs(argResult['input'] as List, extension: '.d.ts'), - output: argResult['output'] as String, - languageVersion: Version.parse(languageVersionString), - ); + input: expandGlobs(argResult['input'] as List, + extension: '.d.ts'), + output: argResult['output'] as String, + languageVersion: Version.parse(languageVersionString), + tsConfig: tsConfigFile != null + ? jsonDecode((fs.readFileSync(tsConfigFile.toJS, + JSReadFileOptions(encoding: 'utf8'.toJS)) as JSString) + .toDart) as Map + : {}, + ignoreErrors: argResult.wasParsed('ignore-errors')); } await generateJSInteropBindings(config); @@ -191,5 +198,7 @@ final _parser = ArgParser() ..addMultiOption('input', abbr: 'i', help: '[TS Declarations] The input file to read and generate types for') + ..addFlag('ignore-errors', + help: '[TS Declarations] Ignore Generator Errors', negatable: false) ..addOption('config', abbr: 'c', hide: true, valueHelp: '[file].yaml', help: 'Configuration'); diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index 1a851a1e..e0c24993 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -17,7 +17,7 @@ class ParserResult { /// Parses the given TypeScript declaration [files], provides any diagnostics, /// if any, and generates a [ts.TSProgram] for transformation ParserResult parseDeclarationFiles(Iterable files, - {Map? tsConfiguration}) { + {Map? tsConfiguration, bool ignoreErrors = false}) { final program = ts.createProgram( files.jsify() as JSArray, tsConfiguration != null @@ -44,7 +44,7 @@ ParserResult parseDeclarationFiles(Iterable files, } } - if (diagnostics.isNotEmpty) { + if (diagnostics.isNotEmpty && !ignoreErrors) { // exit exit(1); } From c8597d35a0af012059f0320c70918aca6180942d Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 01:26:20 -0400 Subject: [PATCH 4/9] add support for generating all declarations --- web_generator/bin/gen_interop_bindings.dart | 7 ++++++- web_generator/lib/src/config.dart | 20 ++++++++++++++++--- web_generator/lib/src/dart_main.dart | 8 +++++--- .../lib/src/interop_gen/transform.dart | 17 ++++++++++------ .../interop_gen/transform/transformer.dart | 4 +++- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index e03fc544..3ee1ba0c 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -82,7 +82,8 @@ $_usage'''); '--output=$relativeOutputPath', if (tsConfigRelativePath case final tsConfig?) '--ts-config=$tsConfig', if (configFile case final config?) '--config=$config', - if (argResult.wasParsed('ignore-errors')) '--ignore-errors' + if (argResult.wasParsed('ignore-errors')) '--ignore-errors', + if (argResult.wasParsed('generate-all')) '--generate-all', ], workingDirectory: bindingsGeneratorPath, ); @@ -110,6 +111,10 @@ final _parser = ArgParser() help: 'Path to TS Configuration Options File (tsconfig.json) to pass' ' to the parser/transformer') ..addFlag('ignore-errors', help: 'Ignore Generator Errors', negatable: false) + ..addFlag('generate-all', + help: 'Generate all declarations ' + '(including private declarations)', + negatable: false) ..addOption('config', hide: true, abbr: 'c', diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index b0912d6d..403de851 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -61,6 +61,10 @@ abstract interface class Config { /// (they will still be printed) bool get ignoreErrors; + /// Whether to generate code for all declarations, including non-exported + /// declarations + bool get generateAll; + factory Config( {required List input, required String output, @@ -68,6 +72,7 @@ abstract interface class Config { FunctionConfig? functions, Map tsConfig, List includedDeclarations, + bool generateAll, bool ignoreErrors}) = ConfigImpl._; } @@ -105,6 +110,9 @@ class ConfigImpl implements Config { @override bool ignoreErrors; + @override + bool generateAll; + ConfigImpl._( {required this.input, required this.output, @@ -112,7 +120,8 @@ class ConfigImpl implements Config { this.functions, Map? tsConfig, this.includedDeclarations = const [], - this.ignoreErrors = false}) + this.ignoreErrors = false, + this.generateAll = false}) : tsConfig = tsConfig ?? {}; @override @@ -156,6 +165,9 @@ class YamlConfig implements Config { @override bool ignoreErrors; + @override + bool generateAll; + YamlConfig._( {required this.filename, required this.input, @@ -167,7 +179,8 @@ class YamlConfig implements Config { this.includedDeclarations = const [], required this.tsConfig, String? languageVersion, - this.ignoreErrors = false}) + this.ignoreErrors = false, + this.generateAll = false}) : languageVersion = languageVersion == null ? DartFormatter.latestLanguageVersion : Version.parse(languageVersion); @@ -220,6 +233,7 @@ class YamlConfig implements Config { ?.map((node) => node.toString()) .toList() ?? [], - ignoreErrors: yaml['ignore_errors'] as bool? ?? false); + ignoreErrors: yaml['ignore_errors'] as bool? ?? false, + generateAll: yaml['generate_all'] as bool? ?? false); } } diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index b6c946db..7fd0d18b 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -66,7 +66,8 @@ void main(List args) async { JSReadFileOptions(encoding: 'utf8'.toJS)) as JSString) .toDart) as Map : {}, - ignoreErrors: argResult.wasParsed('ignore-errors')); + ignoreErrors: argResult.wasParsed('ignore-errors'), + generateAll: argResult['generate-all'] as bool); } await generateJSInteropBindings(config); @@ -190,8 +191,9 @@ final _parser = ArgParser() '(directory for IDL, file for TS Declarations)') ..addFlag('generate-all', negatable: false, - help: '[IDL] Generate bindings for all IDL definitions, ' - 'including experimental and non-standard APIs.') + help: 'Generate bindings for all IDL/TS Declaration definitions, ' + 'including experimental and non-standard APIs (IDL) ' + '/ non-exported APIs (TS Declarations).') ..addOption('ts-config', help: '[TS Declarations] Path to TS Configuration Options File ' '(tsconfig.json) to pass to the parser/transformer') diff --git a/web_generator/lib/src/interop_gen/transform.dart b/web_generator/lib/src/interop_gen/transform.dart index 62a0bca5..f60bfde6 100644 --- a/web_generator/lib/src/interop_gen/transform.dart +++ b/web_generator/lib/src/interop_gen/transform.dart @@ -146,8 +146,12 @@ class ProgramMap { final List filterDeclSet; - ProgramMap(this.program, List files, {this.filterDeclSet = const []}) + final bool generateAll; + + ProgramMap(this.program, List files, + {this.filterDeclSet = const [], bool? generateAll}) : typeChecker = program.getTypeChecker(), + generateAll = generateAll ?? false, files = p.PathSet.of(files); /// Find the node definition for a given declaration named [declName] @@ -207,7 +211,7 @@ class ProgramMap { src, file: file, )); - if (sourceSymbol == null) { + if (sourceSymbol == null || generateAll) { // fallback to transforming each node // TODO: This is a temporary fix to running this with @types/web ts.forEachChild( @@ -254,13 +258,14 @@ class TransformerManager { ts.TSTypeChecker get typeChecker => programMap.typeChecker; TransformerManager(ts.TSProgram program, List inputFiles, - {List filterDeclSet = const []}) - : programMap = - ProgramMap(program, inputFiles, filterDeclSet: filterDeclSet); + {List filterDeclSet = const [], bool? generateAll}) + : programMap = ProgramMap(program, inputFiles, + filterDeclSet: filterDeclSet, generateAll: generateAll); TransformerManager.fromParsedResults(ParserResult result, {Config? config}) : programMap = ProgramMap(result.program, result.files.toList(), - filterDeclSet: config?.includedDeclarations ?? []); + filterDeclSet: config?.includedDeclarations ?? [], + generateAll: config?.generateAll); TransformResult transform() { final outputNodeMap = {}; diff --git a/web_generator/lib/src/interop_gen/transform/transformer.dart b/web_generator/lib/src/interop_gen/transform/transformer.dart index d209f4d8..939af349 100644 --- a/web_generator/lib/src/interop_gen/transform/transformer.dart +++ b/web_generator/lib/src/interop_gen/transform/transformer.dart @@ -81,6 +81,8 @@ class Transformer { /// Get the current file handled by this transformer String get file => (_sourceFile?.fileName ?? _fileName)!; + bool get generateAll => programMap.generateAll; + Transformer(this.programMap, this._sourceFile, {Set exportSet = const {}, String? file}) : exportSet = exportSet.map((e) => ExportReference(e, as: e)).toSet(), @@ -1644,7 +1646,7 @@ class Transformer { // get decls with `export` keyword switch (node) { case final ExportableDeclaration e: - if (e.exported && + if ((e.exported || generateAll) && (filterDeclSet.isEmpty || filterDeclSetPatterns .any((pattern) => pattern.hasMatch(e.name)))) { From 8d08fb55cd27d21d7225026e11df6c37ad7bc312 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 20:25:08 -0400 Subject: [PATCH 5/9] rewrote ts config parsing using ts functions (required) Instead of manually marging objects to form compiler options, TS API requires using built-in functions to properly resolve the config into a compiler options objects, with enums, correct types, etc. Functions implemented were `parseJsonConfigFileContent` and `getParsedCommandLineOfConfigFile` --- web_generator/lib/src/config.dart | 48 +++++----- web_generator/lib/src/dart_main.dart | 9 +- web_generator/lib/src/interop_gen/parser.dart | 76 ++++++++++++--- web_generator/lib/src/js/typescript.dart | 92 +++++++++++++++++++ 4 files changed, 181 insertions(+), 44 deletions(-) diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index 403de851..bcbe7214 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -3,14 +3,12 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:convert'; -import 'dart:js_interop'; import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; -import 'js/filesystem_api.dart'; import 'util.dart'; class FunctionConfig { @@ -55,7 +53,10 @@ abstract interface class Config { /// An object consisting of TS Configurations from a tsconfig.json file /// used for configuring the TypeScript Program/Compiler - Map get tsConfig; + Map? get tsConfig; + + /// The TS Configuration file (tsconfig.json) if any + String? get tsConfigFile; /// Whether to ignore source code warnings and errors /// (they will still be printed) @@ -70,10 +71,11 @@ abstract interface class Config { required String output, required Version languageVersion, FunctionConfig? functions, - Map tsConfig, + Map? tsConfig, List includedDeclarations, bool generateAll, - bool ignoreErrors}) = ConfigImpl._; + bool ignoreErrors, + String? tsConfigFile}) = ConfigImpl._; } class ConfigImpl implements Config { @@ -105,7 +107,10 @@ class ConfigImpl implements Config { List includedDeclarations; @override - Map tsConfig; + Map? tsConfig; + + @override + String? tsConfigFile; @override bool ignoreErrors; @@ -118,11 +123,11 @@ class ConfigImpl implements Config { required this.output, required this.languageVersion, this.functions, - Map? tsConfig, + this.tsConfig, this.includedDeclarations = const [], this.ignoreErrors = false, - this.generateAll = false}) - : tsConfig = tsConfig ?? {}; + this.generateAll = false, + this.tsConfigFile}); @override bool get singleFileOutput => input.length == 1; @@ -160,7 +165,10 @@ class YamlConfig implements Config { List includedDeclarations; @override - Map tsConfig; + Map? tsConfig; + + @override + String? tsConfigFile; @override bool ignoreErrors; @@ -177,7 +185,8 @@ class YamlConfig implements Config { this.preamble, this.functions, this.includedDeclarations = const [], - required this.tsConfig, + this.tsConfig, + this.tsConfigFile, String? languageVersion, this.ignoreErrors = false, this.generateAll = false}) @@ -203,18 +212,7 @@ class YamlConfig implements Config { final allFiles = expandGlobs(inputFiles, extension: '.d.ts', cwd: p.dirname(filename)); - var tsConfig = {}; - if (yaml['ts_config_file'] != null) { - tsConfig = json.decode((fs.readFileSync( - p - .join(p.dirname(filename), yaml['ts_config_file'] as String) - .toJS, - JSReadFileOptions(encoding: 'utf8'.toJS)) as JSString) - .toDart) as Map; - } else if (yaml['ts_config'] != null && yaml['ts_config'] is YamlMap) { - tsConfig = jsonDecode(jsonEncode(yaml['ts_config'] as YamlMap)) - as Map; - } + final tsConfig = yaml['ts_config'] as YamlMap?; return YamlConfig._( filename: Uri.file(filename), @@ -226,7 +224,9 @@ class YamlConfig implements Config { description: yaml['description'] as String?, languageVersion: yaml['language_version'] as String?, preamble: yaml['preamble'] as String?, - tsConfig: tsConfig, + tsConfig: tsConfig != null ? jsonDecode(jsonEncode(tsConfig)) + as Map : null, + tsConfigFile: yaml['ts_config_file'] as String?, functions: FunctionConfig( varArgs: (yaml['functions'] as YamlMap?)?['varargs'] as int?), includedDeclarations: (yaml['include'] as YamlList?) diff --git a/web_generator/lib/src/dart_main.dart b/web_generator/lib/src/dart_main.dart index 7fd0d18b..0b4cde26 100644 --- a/web_generator/lib/src/dart_main.dart +++ b/web_generator/lib/src/dart_main.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:convert'; import 'dart:js_interop'; import 'package:args/args.dart'; @@ -61,11 +60,7 @@ void main(List args) async { extension: '.d.ts'), output: argResult['output'] as String, languageVersion: Version.parse(languageVersionString), - tsConfig: tsConfigFile != null - ? jsonDecode((fs.readFileSync(tsConfigFile.toJS, - JSReadFileOptions(encoding: 'utf8'.toJS)) as JSString) - .toDart) as Map - : {}, + tsConfigFile: tsConfigFile, ignoreErrors: argResult.wasParsed('ignore-errors'), generateAll: argResult['generate-all'] as bool); } @@ -76,7 +71,7 @@ void main(List args) async { Future generateJSInteropBindings(Config config) async { // generate - final jsDeclarations = parseDeclarationFiles(config.input); + final jsDeclarations = parseDeclarationFiles(config); // transform declarations final manager = diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index e0c24993..028273d0 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -4,6 +4,9 @@ import 'dart:js_interop'; +import 'package:path/path.dart' as p; + +import '../config.dart'; import '../js/node.dart'; import '../js/typescript.dart' as ts; @@ -16,14 +19,57 @@ class ParserResult { /// Parses the given TypeScript declaration [files], provides any diagnostics, /// if any, and generates a [ts.TSProgram] for transformation -ParserResult parseDeclarationFiles(Iterable files, - {Map? tsConfiguration, bool ignoreErrors = false}) { +ParserResult parseDeclarationFiles(Config config) { + + final files = config.input; + // final tsConfiguration = config. + final ignoreErrors = config.ignoreErrors; + + // create host for parsing TS configuration + // TODO: @srujzs we can use ts.sys as the host instead. + // Do you think we should allow TS handle such functions, or we should ourselves + final host = ts.sys; + var compilerOptions = ts.TSCompilerOptions(declaration: true); + if (config.tsConfigFile case final tsConfigFile?) { + final parsedCommandLine = ts.getParsedCommandLineOfConfigFile( + p.absolute(tsConfigFile), + ts.TSCompilerOptions(declaration: true), + host + ); + + if (parsedCommandLine != null) { + compilerOptions = parsedCommandLine.options; + + final diagnostics = parsedCommandLine.errors.toDart; + + // handle any diagnostics + handleDiagnostics(diagnostics); + if (!ignoreErrors && diagnostics.isNotEmpty) { + exit(1); + } + } + } else if (config.tsConfig case final tsConfig? when config.filename != null) { + final parsedCommandLine = ts.parseJsonConfigFileContent( + tsConfig.jsify() as JSObject, + host, + p.dirname(config.filename!.toFilePath()), + ts.TSCompilerOptions(declaration: true) + ); + + compilerOptions = parsedCommandLine.options; + + final diagnostics = parsedCommandLine.errors.toDart; + + // handle any diagnostics + handleDiagnostics(diagnostics); + if (!ignoreErrors && diagnostics.isNotEmpty) { + exit(1); + } + } + final program = ts.createProgram( files.jsify() as JSArray, - tsConfiguration != null - ? ts.TSCompilerOptions.fromJSObject( - {...tsConfiguration, 'declaration': true}.jsify() as JSObject) - : ts.TSCompilerOptions(declaration: true)); + compilerOptions); // get diagnostics final diagnostics = [ @@ -33,6 +79,17 @@ ParserResult parseDeclarationFiles(Iterable files, ]; // handle diagnostics + handleDiagnostics(diagnostics); + + if (diagnostics.isNotEmpty && !ignoreErrors) { + // exit + exit(1); + } + + return ParserResult(program: program, files: files); +} + +void handleDiagnostics(List diagnostics) { for (final diagnostic in diagnostics) { if (diagnostic.file case final diagnosticFile?) { final ts.TSLineAndCharacter(line: line, character: char) = @@ -43,11 +100,4 @@ ParserResult parseDeclarationFiles(Iterable files, '(${line.toDartInt + 1},${char.toDartInt + 1}): $message'); } } - - if (diagnostics.isNotEmpty && !ignoreErrors) { - // exit - exit(1); - } - - return ParserResult(program: program, files: files); } diff --git a/web_generator/lib/src/js/typescript.dart b/web_generator/lib/src/js/typescript.dart index a9601c0c..89cb5860 100644 --- a/web_generator/lib/src/js/typescript.dart +++ b/web_generator/lib/src/js/typescript.dart @@ -40,6 +40,98 @@ external TSLineAndCharacter getLineAndCharacterOfPosition( external String flattenDiagnosticMessageText(JSAny? diag, String newLine, [int indent]); +@JS() +external TSParsedCommandLine? getParsedCommandLineOfConfigFile( + String configFileName, + TSCompilerOptions? optionsToExtend, + TSParseConfigFileHost host +); + +@JS() +external TSParsedCommandLine parseJsonConfigFileContent( + JSObject json, + TSParseConfigFileHost host, + String basePath, [ + TSCompilerOptions existingOptions, + String configFileName + ]); + +@JS() +external TSParseConfigFileHost sys; + +@JS('ParsedCommandLine') +extension type TSParsedCommandLine._(JSObject _) implements JSObject { + external TSCompilerOptions options; + external JSArray errors; +} + +@JS('ParseConfigFileHost') +extension type TSParseConfigFileHost._(JSObject _) + implements TSParseConfigHost { + external TSParseConfigFileHost({ + FileExistsFunc fileExists, + ReadFileFunc readFile, + ReadDirectoryFunc readDirectory, + GetCurrentDirectoryFunc getCurrentDirectory, + OnUnRecoverableConfigFileDiagnosticFunc onUnRecoverableConfigFileDiagnostic, + bool useCaseSensitiveFileNames, + }); + + external String getCurrentDirectory(); + @doNotStore + external JSAny onUnRecoverableConfigFileDiagnostic(TSDiagnostic diagnostic); +} + +@JS('ParseConfigHost') +extension type TSParseConfigHost._(JSObject _) implements JSObject { + // TODO: This would be a useful place to have the JSFunction generic + // as the given constructor needs the object to be formed via closures/function tearoffs + external TSParseConfigHost({ + FileExistsFunc fileExists, + ReadFileFunc readFile, + ReadDirectoryFunc readDirectory, + bool useCaseSensitiveFileNames, + }); + + external bool fileExists(String path); + external String? readFile(String path); + external JSArray readDirectory( + String rootDir, + JSArray extensions, + JSArray? excludes, + JSArray includes, [ + int depth + ]); + external bool get useCaseSensitiveFileNames; +} + +extension type FileExistsFunc(JSFunction _) implements JSFunction { + external bool call(String path); +} + +extension type ReadFileFunc(JSFunction _) implements JSFunction { + external String? call(String path); +} + +extension type ReadDirectoryFunc(JSFunction _) implements JSFunction { + external JSArray call( + String rootDir, + JSArray extensions, + JSArray? excludes, + JSArray includes, [ + int depth + ]); +} + +extension type GetCurrentDirectoryFunc(JSFunction _) implements JSFunction { + external String call(); +} + +extension type OnUnRecoverableConfigFileDiagnosticFunc(JSFunction _) implements JSFunction { + @doNotStore + external JSAny call(TSDiagnostic diagnostic); +} + @JS('CompilerOptions') extension type TSCompilerOptions._(JSObject _) implements JSObject { external TSCompilerOptions({bool? allowJs, bool? declaration}); From 20ffa49062273ddc49e0ec808e1255a1c229ec8a Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 20:27:00 -0400 Subject: [PATCH 6/9] formatting and doc for previous commit --- web_generator/lib/src/config.dart | 5 +- web_generator/lib/src/interop_gen/parser.dart | 46 ++++++++++--------- web_generator/lib/src/js/typescript.dart | 43 +++++++---------- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/web_generator/lib/src/config.dart b/web_generator/lib/src/config.dart index bcbe7214..a20227ac 100644 --- a/web_generator/lib/src/config.dart +++ b/web_generator/lib/src/config.dart @@ -224,8 +224,9 @@ class YamlConfig implements Config { description: yaml['description'] as String?, languageVersion: yaml['language_version'] as String?, preamble: yaml['preamble'] as String?, - tsConfig: tsConfig != null ? jsonDecode(jsonEncode(tsConfig)) - as Map : null, + tsConfig: tsConfig != null + ? jsonDecode(jsonEncode(tsConfig)) as Map + : null, tsConfigFile: yaml['ts_config_file'] as String?, functions: FunctionConfig( varArgs: (yaml['functions'] as YamlMap?)?['varargs'] as int?), diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index 028273d0..ab21837d 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -17,49 +17,52 @@ class ParserResult { ParserResult({required this.program, required this.files}); } -/// Parses the given TypeScript declaration [files], provides any diagnostics, -/// if any, and generates a [ts.TSProgram] for transformation +/// Parses the given TypeScript declaration files in the [config], +/// provides diagnostics if any, and generates a [ts.TSProgram] +/// for transformation. +/// +/// If a TS Config is passed, this function also produces compiler +/// options from the TS config file/config object to use alongside the compiler ParserResult parseDeclarationFiles(Config config) { - final files = config.input; // final tsConfiguration = config. final ignoreErrors = config.ignoreErrors; // create host for parsing TS configuration - // TODO: @srujzs we can use ts.sys as the host instead. - // Do you think we should allow TS handle such functions, or we should ourselves + // TODO: @srujzs we can also create our own host + // Do you think we should allow TS handle such functions, + // or we should ourselves final host = ts.sys; var compilerOptions = ts.TSCompilerOptions(declaration: true); if (config.tsConfigFile case final tsConfigFile?) { final parsedCommandLine = ts.getParsedCommandLineOfConfigFile( - p.absolute(tsConfigFile), - ts.TSCompilerOptions(declaration: true), - host - ); + p.absolute(tsConfigFile), + ts.TSCompilerOptions(declaration: true), + host); if (parsedCommandLine != null) { compilerOptions = parsedCommandLine.options; final diagnostics = parsedCommandLine.errors.toDart; - + // handle any diagnostics handleDiagnostics(diagnostics); if (!ignoreErrors && diagnostics.isNotEmpty) { exit(1); } } - } else if (config.tsConfig case final tsConfig? when config.filename != null) { + } else if (config.tsConfig case final tsConfig? + when config.filename != null) { final parsedCommandLine = ts.parseJsonConfigFileContent( - tsConfig.jsify() as JSObject, - host, - p.dirname(config.filename!.toFilePath()), - ts.TSCompilerOptions(declaration: true) - ); - + tsConfig.jsify() as JSObject, + host, + p.dirname(config.filename!.toFilePath()), + ts.TSCompilerOptions(declaration: true)); + compilerOptions = parsedCommandLine.options; - + final diagnostics = parsedCommandLine.errors.toDart; - + // handle any diagnostics handleDiagnostics(diagnostics); if (!ignoreErrors && diagnostics.isNotEmpty) { @@ -67,9 +70,8 @@ ParserResult parseDeclarationFiles(Config config) { } } - final program = ts.createProgram( - files.jsify() as JSArray, - compilerOptions); + final program = + ts.createProgram(files.jsify() as JSArray, compilerOptions); // get diagnostics final diagnostics = [ diff --git a/web_generator/lib/src/js/typescript.dart b/web_generator/lib/src/js/typescript.dart index 89cb5860..5e2bfe70 100644 --- a/web_generator/lib/src/js/typescript.dart +++ b/web_generator/lib/src/js/typescript.dart @@ -42,19 +42,14 @@ external String flattenDiagnosticMessageText(JSAny? diag, String newLine, @JS() external TSParsedCommandLine? getParsedCommandLineOfConfigFile( - String configFileName, - TSCompilerOptions? optionsToExtend, - TSParseConfigFileHost host -); + String configFileName, + TSCompilerOptions? optionsToExtend, + TSParseConfigFileHost host); @JS() external TSParsedCommandLine parseJsonConfigFileContent( - JSObject json, - TSParseConfigFileHost host, - String basePath, [ - TSCompilerOptions existingOptions, - String configFileName - ]); + JSObject json, TSParseConfigFileHost host, String basePath, + [TSCompilerOptions existingOptions, String configFileName]); @JS() external TSParseConfigFileHost sys; @@ -66,8 +61,8 @@ extension type TSParsedCommandLine._(JSObject _) implements JSObject { } @JS('ParseConfigFileHost') -extension type TSParseConfigFileHost._(JSObject _) - implements TSParseConfigHost { +extension type TSParseConfigFileHost._(JSObject _) + implements TSParseConfigHost { external TSParseConfigFileHost({ FileExistsFunc fileExists, ReadFileFunc readFile, @@ -96,12 +91,11 @@ extension type TSParseConfigHost._(JSObject _) implements JSObject { external bool fileExists(String path); external String? readFile(String path); external JSArray readDirectory( - String rootDir, - JSArray extensions, - JSArray? excludes, - JSArray includes, [ - int depth - ]); + String rootDir, + JSArray extensions, + JSArray? excludes, + JSArray includes, + [int depth]); external bool get useCaseSensitiveFileNames; } @@ -114,20 +108,17 @@ extension type ReadFileFunc(JSFunction _) implements JSFunction { } extension type ReadDirectoryFunc(JSFunction _) implements JSFunction { - external JSArray call( - String rootDir, - JSArray extensions, - JSArray? excludes, - JSArray includes, [ - int depth - ]); + external JSArray call(String rootDir, JSArray extensions, + JSArray? excludes, JSArray includes, + [int depth]); } extension type GetCurrentDirectoryFunc(JSFunction _) implements JSFunction { external String call(); } -extension type OnUnRecoverableConfigFileDiagnosticFunc(JSFunction _) implements JSFunction { +extension type OnUnRecoverableConfigFileDiagnosticFunc(JSFunction _) + implements JSFunction { @doNotStore external JSAny call(TSDiagnostic diagnostic); } From ac2aff254c4941e99b167f298266a851acef5588 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 21:23:45 -0400 Subject: [PATCH 7/9] allowed for anonymous diagnostics and updated entrypoint --- web_generator/bin/gen_interop_bindings.dart | 17 +++++++++++------ web_generator/lib/src/interop_gen/parser.dart | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index 3ee1ba0c..c8041cca 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -29,7 +29,7 @@ $_usage'''); return; } - if (argResult.rest.isEmpty) { + if (argResult.rest.isEmpty && !argResult.wasParsed('config')) { print(''' ${ansi.lightRed.wrap('At least one argument is needed')} @@ -58,14 +58,17 @@ $_usage'''); await compileDartMain(); } - final inputFile = argResult.rest.first; + final inputFile = argResult.rest.firstOrNull; final outputFile = argResult['output'] as String? ?? - p.join(p.current, inputFile.replaceAll('.d.ts', '.dart')); + p.join(p.current, inputFile?.replaceAll('.d.ts', '.dart')); final defaultWebGenConfigPath = p.join(p.current, 'webgen.yaml'); final configFile = argResult['config'] as String? ?? (File(defaultWebGenConfigPath).existsSync() ? defaultWebGenConfigPath : null); + final relativeConfigFile = configFile != null ? + p.relative(configFile, from: bindingsGeneratorPath) + : null; final relativeOutputPath = p.relative(outputFile, from: bindingsGeneratorPath); final tsConfigPath = argResult['ts-config'] as String?; @@ -78,10 +81,12 @@ $_usage'''); [ 'main.mjs', '--declaration', - '--input=${p.relative(inputFile, from: bindingsGeneratorPath)}', - '--output=$relativeOutputPath', + if (argResult.rest.isNotEmpty) ...[ + '--input=${p.relative(inputFile!, from: bindingsGeneratorPath)}', + '--output=$relativeOutputPath', + ], if (tsConfigRelativePath case final tsConfig?) '--ts-config=$tsConfig', - if (configFile case final config?) '--config=$config', + if (relativeConfigFile case final config?) '--config=$config', if (argResult.wasParsed('ignore-errors')) '--ignore-errors', if (argResult.wasParsed('generate-all')) '--generate-all', ], diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index ab21837d..89274a83 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -100,6 +100,10 @@ void handleDiagnostics(List diagnostics) { ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); printErr('${diagnosticFile.fileName} ' '(${line.toDartInt + 1},${char.toDartInt + 1}): $message'); + } else { + final message = + ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + printErr('(anonymous): $message'); } } } From 266e037417c1469ee8dc63aa2162f896d4537d7e Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Tue, 12 Aug 2025 21:34:15 -0400 Subject: [PATCH 8/9] formatting --- web_generator/bin/gen_interop_bindings.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web_generator/bin/gen_interop_bindings.dart b/web_generator/bin/gen_interop_bindings.dart index c8041cca..6d2df550 100644 --- a/web_generator/bin/gen_interop_bindings.dart +++ b/web_generator/bin/gen_interop_bindings.dart @@ -66,9 +66,9 @@ $_usage'''); (File(defaultWebGenConfigPath).existsSync() ? defaultWebGenConfigPath : null); - final relativeConfigFile = configFile != null ? - p.relative(configFile, from: bindingsGeneratorPath) - : null; + final relativeConfigFile = configFile != null + ? p.relative(configFile, from: bindingsGeneratorPath) + : null; final relativeOutputPath = p.relative(outputFile, from: bindingsGeneratorPath); final tsConfigPath = argResult['ts-config'] as String?; From 2bac1a4955ffd4fd159ca43628116cdcd020668c Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Wed, 13 Aug 2025 22:02:33 -0400 Subject: [PATCH 9/9] stray comment --- web_generator/lib/src/interop_gen/parser.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/web_generator/lib/src/interop_gen/parser.dart b/web_generator/lib/src/interop_gen/parser.dart index 89274a83..781ffc37 100644 --- a/web_generator/lib/src/interop_gen/parser.dart +++ b/web_generator/lib/src/interop_gen/parser.dart @@ -25,7 +25,6 @@ class ParserResult { /// options from the TS config file/config object to use alongside the compiler ParserResult parseDeclarationFiles(Config config) { final files = config.input; - // final tsConfiguration = config. final ignoreErrors = config.ignoreErrors; // create host for parsing TS configuration