This repository was archived by the owner on Apr 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 1
1
## 4.9.0
2
2
3
3
* Add ` Library.generatedByComment ` to support emitting 'generated by' comments.
4
+ * Support emitting an unnamed library with annotations.
4
5
5
6
## 4.8.0
6
7
Original file line number Diff line number Diff line change @@ -512,13 +512,16 @@ class DartEmitter extends Object
512
512
}
513
513
}
514
514
515
+ for (var a in spec.annotations) {
516
+ visitAnnotation (a, output);
517
+ }
515
518
if (spec.name != null ) {
516
- for (var a in spec.annotations) {
517
- visitAnnotation (a, output);
518
- }
519
519
output.write ('library ${spec .name !};' );
520
520
} else if (spec.annotations.isNotEmpty) {
521
- throw StateError ('a library name is required for annotations' );
521
+ // An explicit _unnamed_ library directive is only required if there are
522
+ // annotations or doc comments on the library (though doc comments are not
523
+ // currently supported in code_builder).
524
+ output.write ('library;' );
522
525
}
523
526
524
527
final directives = < Directive > [...allocator.imports, ...spec.directives];
Original file line number Diff line number Diff line change @@ -277,17 +277,19 @@ void main() {
277
277
);
278
278
});
279
279
280
- test ('should error on unnamed library with annotations' , () {
280
+ test ('should emit an unnamed library source file with annotations' , () {
281
281
expect (
282
- () {
283
- Library (
284
- (b) => b
285
- ..annotations.add (
286
- refer ('JS' , 'package:js/js.dart' ).call ([]),
287
- ),
288
- ).accept (DartEmitter ());
289
- },
290
- throwsStateError,
282
+ Library (
283
+ (b) => b
284
+ ..annotations.add (
285
+ refer ('JS' , 'package:js/js.dart' ).call ([]),
286
+ ),
287
+ ),
288
+ equalsDart (r'''
289
+ @JS()
290
+ library;
291
+ import 'package:js/js.dart';
292
+ ''' , DartEmitter (allocator: Allocator ())),
291
293
);
292
294
});
293
295
});
You can’t perform that action at this time.
0 commit comments