Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse spec info for generated libraries #111

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ void main() {

## Web IDL version

<!-- START updated by /tool/update_bindings.dart. Do not modify by hand -->
<!-- START updated by tool/update_bindings.dart. Do not modify by hand -->
Based on [`@webref/idl 3.39.1`](https://www.npmjs.com/package/@webref/idl/v/3.39.1).
<!-- END updated by /tool/update_bindings.dart. Do not modify by hand -->
<!-- END updated by tool/update_bindings.dart. Do not modify by hand -->
5 changes: 0 additions & 5 deletions lib/src/dom/badging.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/beacon.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/compat.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/csp_embedded_enforcement.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/css_images_4.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/css_shadow_parts.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/device_memory.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/html_media_capture.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/input_events.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/permissions_request.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/permissions_revoke.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/pointerlock.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/prefer_current_tab.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/prerendering_revamped.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/private_click_measurement.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/savedata.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/storage_access.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/wai_aria.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/wasm_web_api.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/webdriver.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/webrtc_svc.dart

This file was deleted.

5 changes: 0 additions & 5 deletions lib/src/dom/webxr_gamepads_module.dart

This file was deleted.

22 changes: 0 additions & 22 deletions lib/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ export 'src/dom/audio_session.dart';
export 'src/dom/autoplay_detection.dart';
export 'src/dom/background_fetch.dart';
export 'src/dom/background_sync.dart';
export 'src/dom/badging.dart';
export 'src/dom/battery_status.dart';
export 'src/dom/beacon.dart';
export 'src/dom/capture_handle_identity.dart';
export 'src/dom/captured_mouse_events.dart';
export 'src/dom/clipboard_apis.dart';
export 'src/dom/compat.dart';
export 'src/dom/compression.dart';
export 'src/dom/compute_pressure.dart';
export 'src/dom/console.dart';
Expand All @@ -28,7 +25,6 @@ export 'src/dom/cookie_store.dart';
export 'src/dom/crash_reporting.dart';
export 'src/dom/credential_management.dart';
export 'src/dom/csp.dart';
export 'src/dom/csp_embedded_enforcement.dart';
export 'src/dom/csp_next.dart';
export 'src/dom/css_anchor_position.dart';
export 'src/dom/css_animation_worklet.dart';
Expand All @@ -44,7 +40,6 @@ export 'src/dom/css_counter_styles.dart';
export 'src/dom/css_font_loading.dart';
export 'src/dom/css_fonts.dart';
export 'src/dom/css_highlight_api.dart';
export 'src/dom/css_images_4.dart';
export 'src/dom/css_layout_api.dart';
export 'src/dom/css_masking.dart';
export 'src/dom/css_nav.dart';
Expand All @@ -53,7 +48,6 @@ export 'src/dom/css_parser_api.dart';
export 'src/dom/css_properties_values_api.dart';
export 'src/dom/css_pseudo.dart';
export 'src/dom/css_regions.dart';
export 'src/dom/css_shadow_parts.dart';
export 'src/dom/css_transitions.dart';
export 'src/dom/css_transitions_2.dart';
export 'src/dom/css_typed_om.dart';
Expand All @@ -64,7 +58,6 @@ export 'src/dom/cssom_view.dart';
export 'src/dom/custom_state_pseudo_class.dart';
export 'src/dom/datacue.dart';
export 'src/dom/deprecation_reporting.dart';
export 'src/dom/device_memory.dart';
export 'src/dom/device_posture.dart';
export 'src/dom/digital_goods.dart';
export 'src/dom/document_picture_in_picture.dart';
Expand Down Expand Up @@ -111,14 +104,12 @@ export 'src/dom/get_installed_related_apps.dart';
export 'src/dom/gyroscope.dart';
export 'src/dom/hr_time.dart';
export 'src/dom/html.dart';
export 'src/dom/html_media_capture.dart';
export 'src/dom/idle_detection.dart';
export 'src/dom/image_capture.dart';
export 'src/dom/image_resource.dart';
export 'src/dom/indexeddb.dart';
export 'src/dom/ink_enhancement.dart';
export 'src/dom/input_device_capabilities.dart';
export 'src/dom/input_events.dart';
export 'src/dom/intersection_observer.dart';
export 'src/dom/intervention_reporting.dart';
export 'src/dom/is_input_pending.dart';
Expand Down Expand Up @@ -171,16 +162,10 @@ export 'src/dom/performance_timeline.dart';
export 'src/dom/periodic_background_sync.dart';
export 'src/dom/permissions.dart';
export 'src/dom/permissions_policy.dart';
export 'src/dom/permissions_request.dart';
export 'src/dom/permissions_revoke.dart';
export 'src/dom/picture_in_picture.dart';
export 'src/dom/pointerevents.dart';
export 'src/dom/pointerlock.dart';
export 'src/dom/portals.dart';
export 'src/dom/prefer_current_tab.dart';
export 'src/dom/prerendering_revamped.dart';
export 'src/dom/presentation_api.dart';
export 'src/dom/private_click_measurement.dart';
export 'src/dom/private_network_access.dart';
export 'src/dom/proximity.dart';
export 'src/dom/push_api.dart';
Expand All @@ -194,7 +179,6 @@ export 'src/dom/requeststorageaccessfor.dart';
export 'src/dom/resize_observer.dart';
export 'src/dom/resource_timing.dart';
export 'src/dom/sanitizer_api.dart';
export 'src/dom/savedata.dart';
export 'src/dom/scheduling_apis.dart';
export 'src/dom/screen_capture.dart';
export 'src/dom/screen_orientation.dart';
Expand All @@ -210,7 +194,6 @@ export 'src/dom/shape_detection_api.dart';
export 'src/dom/shared_storage.dart';
export 'src/dom/speech_api.dart';
export 'src/dom/storage.dart';
export 'src/dom/storage_access.dart';
export 'src/dom/storage_buckets.dart';
export 'src/dom/streams.dart';
export 'src/dom/svg.dart';
Expand All @@ -229,9 +212,7 @@ export 'src/dom/user_timing.dart';
export 'src/dom/vibration.dart';
export 'src/dom/video_rvfc.dart';
export 'src/dom/virtual_keyboard.dart';
export 'src/dom/wai_aria.dart';
export 'src/dom/wasm_js_api.dart';
export 'src/dom/wasm_web_api.dart';
export 'src/dom/web_animations.dart';
export 'src/dom/web_animations_2.dart';
export 'src/dom/web_app_launch.dart';
Expand All @@ -252,7 +233,6 @@ export 'src/dom/webcodecs_opus_codec_registration.dart';
export 'src/dom/webcodecs_vp9_codec_registration.dart';
export 'src/dom/webcrypto_secure_curves.dart';
export 'src/dom/webcryptoapi.dart';
export 'src/dom/webdriver.dart';
export 'src/dom/webgl1.dart';
export 'src/dom/webgl2.dart';
export 'src/dom/webgl_blend_equation_advanced_coherent.dart';
Expand Down Expand Up @@ -284,7 +264,6 @@ export 'src/dom/webrtc_ice.dart';
export 'src/dom/webrtc_identity.dart';
export 'src/dom/webrtc_priority.dart';
export 'src/dom/webrtc_stats.dart';
export 'src/dom/webrtc_svc.dart';
export 'src/dom/websockets.dart';
export 'src/dom/webtransport.dart';
export 'src/dom/webusb.dart';
Expand All @@ -293,7 +272,6 @@ export 'src/dom/webxr.dart';
export 'src/dom/webxr_ar_module.dart';
export 'src/dom/webxr_depth_sensing.dart';
export 'src/dom/webxr_dom_overlays.dart';
export 'src/dom/webxr_gamepads_module.dart';
export 'src/dom/webxr_hand_input.dart';
export 'src/dom/webxr_hit_test.dart';
export 'src/dom/webxr_lighting_estimation.dart';
Expand Down
22 changes: 17 additions & 5 deletions tool/bindings_generator/dart_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ void main(List<String> args) async {

Future<void> _generateAndWriteBindings(String dir) async {
const librarySubDir = 'src/dom';

ensureDirectoryExists('$dir/$librarySubDir');

final bindings = await generateBindings(packageRoot, librarySubDir);
for (var entry in bindings.entries) {
final formattedContents = _runDartFormat(entry.value).toJS;
fs.writeFileSync('$dir/${entry.key}'.toJS, formattedContents);
final libraryPath = entry.key;
final library = entry.value;

final contents = _emitLibrary(library).toJS;
fs.writeFileSync('$dir/$libraryPath'.toJS, contents);
}
}

String _runDartFormat(code.Library library) => DartFormatter().format(
'''${library.accept(code.DartEmitter(allocator: code.Allocator(), orderDirectives: true, useNullSafetySyntax: true))}''',
);
String _emitLibrary(code.Library library) {
final emitter = code.DartEmitter(
allocator: code.Allocator(),
orderDirectives: true,
useNullSafetySyntax: true,
);

final source = library.accept(emitter);
return DartFormatter().format(source.toString());
}
12 changes: 12 additions & 0 deletions tool/bindings_generator/filesystem_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ class JSMkdirOptions {
external factory JSMkdirOptions({JSBoolean? recursive});
}

@JS()
@anonymous
@staticInterop
class JSReadFileOptions {
external factory JSReadFileOptions({JSString? encoding});
}

@JS()
@staticInterop
class FileSystem {}

// TODO(joshualitt): Replace `void` with `JSVoid`
extension FileSystemExtension on FileSystem {
external JSBoolean existsSync(JSString path);

@JS('mkdirSync')
external void mkdirSyncOneArg(JSString path);

@JS('mkdirSync')
external void mkdirSyncTwoArg(JSString path, JSMkdirOptions options);

void mkdirSync(JSString path, [JSMkdirOptions? options]) {
if (options == null) {
return mkdirSyncOneArg(path);
Expand All @@ -33,5 +43,7 @@ extension FileSystemExtension on FileSystem {
}
}

external JSAny readFileSync(JSString path, [JSReadFileOptions options]);

external void writeFileSync(JSString path, JSString contents);
}
5 changes: 3 additions & 2 deletions tool/bindings_generator/generate_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ Future<List<String>> _generateCSSStyleDeclarations() async {
Future<TranslationResult> generateBindings(
String packageRoot, String librarySubDir) async {
final cssStyleDeclarations = await _generateCSSStyleDeclarations();
final translator = Translator(librarySubDir, cssStyleDeclarations);
final translator =
Translator(packageRoot, librarySubDir, cssStyleDeclarations);
final array = objectEntries(await idl.parseAll().toDart as JSObject);
for (var i = 0; i < array.length; i++) {
final entry = array[i] as JSArray;
final shortname = (entry[0] as JSString).toDart.kebabToSnake;
final shortname = (entry[0] as JSString).toDart;
final ast = entry[1] as JSArray;
translator.collect(shortname, ast);
}
Expand Down
2 changes: 1 addition & 1 deletion tool/bindings_generator/js_type_supertypes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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.

// Updated by /tool/update_bindings.dart. Do not modify by hand.
// Updated by tool/update_bindings.dart. Do not modify by hand.

const Map<String, String?> jsTypeSupertypes = {
'JSAny': null,
Expand Down
Loading
Loading