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 11## 4.9.0
22
33* Add ` Library.generatedByComment ` to support emitting 'generated by' comments.
4+ * Support emitting an unnamed library with annotations.
45
56## 4.8.0
67
Original file line number Diff line number Diff line change @@ -512,13 +512,16 @@ class DartEmitter extends Object
512512 }
513513 }
514514
515+ for (var a in spec.annotations) {
516+ visitAnnotation (a, output);
517+ }
515518 if (spec.name != null ) {
516- for (var a in spec.annotations) {
517- visitAnnotation (a, output);
518- }
519519 output.write ('library ${spec .name !};' );
520520 } 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;' );
522525 }
523526
524527 final directives = < Directive > [...allocator.imports, ...spec.directives];
Original file line number Diff line number Diff line change @@ -277,17 +277,19 @@ void main() {
277277 );
278278 });
279279
280- test ('should error on unnamed library with annotations' , () {
280+ test ('should emit an unnamed library source file with annotations' , () {
281281 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 ())),
291293 );
292294 });
293295 });
You can’t perform that action at this time.
0 commit comments