Skip to content

Commit 0447807

Browse files
authored
Add info on generation conventions (#171)
This makes it easier for users to determine why some APIs are emitted the way they are.
1 parent a54a1f0 commit 0447807

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ void main() {
2525
}
2626
```
2727

28+
## Generation conventions
29+
30+
The generator scripts use a number of conventions to consistently handle Web IDL
31+
definitions:
32+
33+
### Interfaces
34+
35+
- Interfaces are emitted as extension types that wrap and implement `JSObject`.
36+
- Interface inheritance is maintained using `implements` between extension
37+
types.
38+
- Members of partial interfaces, partial mixins, and mixins are added to the
39+
interfaces that include them, and therefore do not have separate declarations.
40+
41+
### Types
42+
43+
- Generic types include the generic in the case of `JSArray` and `JSPromise`.
44+
- Enums are typedef'd to `String`.
45+
- Callbacks and callback interfaces are typedef'd to `JSFunction`.
46+
- In general, we prefer the Dart primitive over the JS type equivalent wherever
47+
possible. For example, APIs use `String` instead of `JSString`.
48+
- If a type appears in a generic position and it was typedef'd to a Dart
49+
primitive type, it is replaced with the JS type equivalent to respect the type
50+
bound of `JSAny?`.
51+
- Union types are computed by picking the least upper bound of the types in the
52+
JS type hierarchy, where every interface is equivalent to `JSObject`.
53+
54+
### Compatibility
55+
56+
- The generator uses the
57+
[MDN compatibility data](https://github.com/mdn/browser-compat-data) to
58+
determine what members and interfaces to emit. Currently, we only emit code
59+
that is standards track and supported on Chrome, Firefox, and Safari to reduce
60+
the number of breaking changes. This is currently WIP and some members may be
61+
added or removed.
62+
2863
## Web IDL version
2964

3065
Based on:

tool/generator/bcd.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ abstract class BCDItem {
117117
}
118118

119119
extension BCDJsonDataExtension on Map<String, dynamic> {
120-
/// Return keys which coorespond to symbol names (i.e., filter out non-symbol
120+
/// Return keys which correspond to symbol names (i.e., filter out non-symbol
121121
/// metadata (`__meta`, `__compat`, ...).
122122
Iterable<String> get symbolNames => keys.where((key) => !key.startsWith('_'));
123123
}

0 commit comments

Comments
 (0)