diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7d38e..3f39873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2+7 + +* Strong mode fixes. + ## 0.6.2+6 * Small bug fixes for https://github.com/dart-lang/web-components/issues/54. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a10d4c5 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/lib/build/initializer_plugin.dart b/lib/build/initializer_plugin.dart index cc8a7d2..1a004dd 100644 --- a/lib/build/initializer_plugin.dart +++ b/lib/build/initializer_plugin.dart @@ -235,7 +235,7 @@ class DefaultInitializerPlugin implements InitializerPlugin { buffer.write(_evaluateExpression(expression, pluginData)); } else { libraryPrefixes.putIfAbsent( - element.library, () => 'i${libraryPrefixes.length}'); + element.library, () => 'i${libraryPrefixes.length}'); buffer.write('${libraryPrefixes[element.library]}.'); if (element is ClassElement) { @@ -263,8 +263,7 @@ class DefaultInitializerPlugin implements InitializerPlugin { return buffer.toString(); } - _evaluateExpression( - Expression expression, InitializerPluginData pluginData) { + _evaluateExpression(Expression expression, InitializerPluginData pluginData) { var logger = pluginData.logger; var result = pluginData.resolver.evaluateConstant( pluginData.initializer.targetElement.library, expression); diff --git a/lib/src/init_method.dart b/lib/src/init_method.dart index ebc8f93..1ddb83c 100644 --- a/lib/src/init_method.dart +++ b/lib/src/init_method.dart @@ -8,6 +8,7 @@ part of initialize; /// it shouldn't be used directly in annotations, instead use the `initMethod` /// singleton below. typedef dynamic _ZeroArg(); + class _InitMethod implements Initializer<_ZeroArg> { const _InitMethod(); diff --git a/lib/src/initializer.dart b/lib/src/initializer.dart index bb50558..1b9f32f 100644 --- a/lib/src/initializer.dart +++ b/lib/src/initializer.dart @@ -42,7 +42,9 @@ class LibraryIdentifier { const LibraryIdentifier(this.name, this.package, this.path); bool operator ==(dynamic other) => - other is LibraryIdentifier && name == other.name && package == other.package && + other is LibraryIdentifier && + name == other.name && + package == other.package && path == other.path; String toString() => '$name: $package:$path'; diff --git a/lib/src/mirror_loader.dart b/lib/src/mirror_loader.dart index cbd2a60..95da50d 100644 --- a/lib/src/mirror_loader.dart +++ b/lib/src/mirror_loader.dart @@ -37,9 +37,7 @@ class InitializationCrawler { /// Note: The [from] argument is only supported in the mirror_loader.dart. It /// is not supported statically. InitializationCrawler(this.typeFilter, this.customFilter, {Uri from}) - : _rootLibrary = from == null - ? _root - : _libs[from] { + : _rootLibrary = from == null ? _root : _libs[from] { if (_rootLibrary == null) throw 'Unable to find library at $from.'; } @@ -124,10 +122,14 @@ class InitializationCrawler { Iterable _sortedDeclarationsWithMetadata( LibraryMirror lib) { return new List() - ..addAll(_sortDeclarations(lib, lib.declarations.values - .where((d) => d is MethodMirror && d.metadata.isNotEmpty))) - ..addAll(_sortDeclarations(lib, lib.declarations.values - .where((d) => d is ClassMirror && d.metadata.isNotEmpty))); + ..addAll(_sortDeclarations( + lib, + lib.declarations.values + .where((d) => d is MethodMirror && d.metadata.isNotEmpty))) + ..addAll(_sortDeclarations( + lib, + lib.declarations.values + .where((d) => d is ClassMirror && d.metadata.isNotEmpty))); } List _sortDeclarations( @@ -202,7 +204,8 @@ class InitializationCrawler { throw _TOP_LEVEL_FUNCTIONS_ONLY; } annotatedValue = (declaration.owner as ObjectMirror) - .getField(declaration.simpleName).reflectee; + .getField(declaration.simpleName) + .reflectee; } else if (declaration is LibraryMirror) { var package; var filePath; diff --git a/lib/transformer.dart b/lib/transformer.dart index 25adeef..06ae76e 100644 --- a/lib/transformer.dart +++ b/lib/transformer.dart @@ -129,8 +129,7 @@ class InitializeTransformer extends Transformer { // [entryPoint]. void _replaceEntryWithBootstrap(Transform transform, dom.Document document, AssetId entryPoint, AssetId originalDartFile, AssetId newDartFile) { - var scripts = _getScripts(document) - .where((script) { + var scripts = _getScripts(document).where((script) { var assetId = uriToAssetId(entryPoint, _getScriptAttribute(script), transform.logger, script.sourceSpan); return assetId == originalDartFile; @@ -258,6 +257,7 @@ class _BootstrapFileBuilder { '(possibly transitive).'); } } + readSuperClassAnnotations(clazz.supertype); _readAnnotations(clazz); } @@ -285,7 +285,8 @@ class _BootstrapFileBuilder { if (e is PropertyAccessorElement) { // 'as dynamic' is because evaluationResult is a property on an impl class, e.g. one that // isn't supposed to be used externally. - return _isInitializer((e.variable as dynamic).evaluationResult.value.type); + return _isInitializer( + (e.variable as dynamic).evaluationResult.value.type); } else if (e is ConstructorElement) { return _isInitializer(e.returnType); } diff --git a/pubspec.yaml b/pubspec.yaml index 887267f..f2f354a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: initialize -version: 0.6.2+6 +version: 0.6.2+7 author: Polymer.dart Authors description: Generic building blocks for doing static initialization. homepage: https://github.com/dart-lang/initialize diff --git a/test/deferred_library_test.dart b/test/deferred_library_test.dart index 0bff187..e38542c 100644 --- a/test/deferred_library_test.dart +++ b/test/deferred_library_test.dart @@ -24,6 +24,7 @@ main() { expect(InitializeTracker.seen.length, 5); }); }); - }, skip: 'Should be skipped only in pub-serve mode, blocked on ' - 'https://github.com/dart-lang/test/issues/388.'); + }, + skip: 'Should be skipped only in pub-serve mode, blocked on ' + 'https://github.com/dart-lang/test/issues/388.'); } diff --git a/test/initializer_custom_filter_test.dart b/test/initializer_custom_filter_test.dart index 302db1b..1911ee3 100644 --- a/test/initializer_custom_filter_test.dart +++ b/test/initializer_custom_filter_test.dart @@ -15,26 +15,34 @@ import 'package:initialize/src/initialize_tracker.dart'; main() { test('filter option limits which types of annotations will be ran', () { var originalSize; - return runPhase(1).then((_) { - // Even though Baz extends Bar, only Baz should be run. - expect(InitializeTracker.seen, [Baz]); - }).then((_) => runPhase(2)).then((_) { - expect(InitializeTracker.seen, [Baz, foo]); - }).then((_) => runPhase(3)).then((_) { - expect(InitializeTracker.seen, [Baz, foo, Foo]); - }).then((_) => runPhase(4)).then((_) { - expect(InitializeTracker.seen, [Baz, foo, Foo, Bar]); - }).then((_) { - originalSize = InitializeTracker.seen.length; - }) + return runPhase(1) + .then((_) { + // Even though Baz extends Bar, only Baz should be run. + expect(InitializeTracker.seen, [Baz]); + }) + .then((_) => runPhase(2)) + .then((_) { + expect(InitializeTracker.seen, [Baz, foo]); + }) + .then((_) => runPhase(3)) + .then((_) { + expect(InitializeTracker.seen, [Baz, foo, Foo]); + }) + .then((_) => runPhase(4)) + .then((_) { + expect(InitializeTracker.seen, [Baz, foo, Foo, Bar]); + }) + .then((_) { + originalSize = InitializeTracker.seen.length; + }) .then((_) => runPhase(1)) .then((_) => runPhase(2)) .then((_) => runPhase(3)) .then((_) => runPhase(4)) .then((_) => run()) .then((_) { - expect(InitializeTracker.seen.length, originalSize); - }); + expect(InitializeTracker.seen.length, originalSize); + }); }); } diff --git a/test/initializer_cycle_error_test.dart b/test/initializer_cycle_error_test.dart index 365e64f..200a8ec 100644 --- a/test/initializer_cycle_error_test.dart +++ b/test/initializer_cycle_error_test.dart @@ -15,6 +15,7 @@ import 'package:test/test.dart'; main() { test('super class cycles are not supported', () { expect(run, throwsUnsupportedError); - }, skip: 'Should be skipped only in pub-serve mode, blocked on ' - 'https://github.com/dart-lang/test/issues/388.'); + }, + skip: 'Should be skipped only in pub-serve mode, blocked on ' + 'https://github.com/dart-lang/test/issues/388.'); } diff --git a/test/initializer_from_test.dart b/test/initializer_from_test.dart index aa7172b..74449a6 100644 --- a/test/initializer_from_test.dart +++ b/test/initializer_from_test.dart @@ -29,11 +29,12 @@ main() { expect(InitializeTracker.seen.length, 2); // Don't know what the path will be, so have to explicitly check fields // and use an [endsWith] matcher for the path. - expect(InitializeTracker.seen[1].name, - #initialize.test.initializer_from_test); + expect( + InitializeTracker.seen[1].name, #initialize.test.initializer_from_test); expect(InitializeTracker.seen[1].package, isNull); expect( InitializeTracker.seen[1].path, endsWith('initializer_from_test.dart')); - }, skip: 'Should be skipped only in pub-serve mode, blocked on ' - 'https://github.com/dart-lang/test/issues/388.'); + }, + skip: 'Should be skipped only in pub-serve mode, blocked on ' + 'https://github.com/dart-lang/test/issues/388.'); } diff --git a/test/initializer_super_test.dart b/test/initializer_super_test.dart index 512ef51..430d796 100644 --- a/test/initializer_super_test.dart +++ b/test/initializer_super_test.dart @@ -15,7 +15,13 @@ main() { // Run all initializers. return run().then((_) { test('annotations are seen in post-order with superclasses first', () { - var expectedNames = [A, C, B, E, D,]; + var expectedNames = [ + A, + C, + B, + E, + D, + ]; expect(InitializeTracker.seen, expectedNames); }); }); diff --git a/test/initializer_type_filter_test.dart b/test/initializer_type_filter_test.dart index 87e0196..1cd57d3 100644 --- a/test/initializer_type_filter_test.dart +++ b/test/initializer_type_filter_test.dart @@ -20,16 +20,23 @@ main() { }); test('filter option limits which types of annotations will be ran', () { - return run(typeFilter: const [_Adder]).then((_) { - expect(total, 2); - }).then((_) => run(typeFilter: const [_Subtractor])).then((_) { - expect(total, 0); - }).then((_) => run(typeFilter: const [_Adder])).then((_) { - // Sanity check, future calls should be no-ops - expect(total, 0); - }).then((_) => run(typeFilter: const [_Subtractor])).then((_) { - expect(total, 0); - }); + return run(typeFilter: const [_Adder]) + .then((_) { + expect(total, 2); + }) + .then((_) => run(typeFilter: const [_Subtractor])) + .then((_) { + expect(total, 0); + }) + .then((_) => run(typeFilter: const [_Adder])) + .then((_) { + // Sanity check, future calls should be no-ops + expect(total, 0); + }) + .then((_) => run(typeFilter: const [_Subtractor])) + .then((_) { + expect(total, 0); + }); }); } @@ -48,6 +55,7 @@ class _Adder implements Initializer { @override initialize(_) => total++; } + const adder = const _Adder(); // Initializer that decrements `total` by one. @@ -57,4 +65,5 @@ class _Subtractor implements Initializer { @override initialize(_) => total--; } + const subtractor = const _Subtractor(); diff --git a/test/transformer_test.dart b/test/transformer_test.dart index 8342c03..c8e017f 100644 --- a/test/transformer_test.dart +++ b/test/transformer_test.dart @@ -19,14 +19,19 @@ main() { } void htmlEntryPointTests() { - var phases = [[new InitializeTransformer(['web/*.html'])]]; + var phases = [ + [ + new InitializeTransformer(['web/*.html']) + ] + ]; testPhases('basic', phases, { 'a|web/index.html': ''' - '''.replaceAll(' ', ''), + ''' + .replaceAll(' ', ''), 'a|web/index.dart': ''' library web_foo; @@ -77,7 +82,8 @@ void htmlEntryPointTests() { - '''.replaceAll(' ', ''), + ''' + .replaceAll(' ', ''), 'a|web/index.initialize.dart': formatter.format(''' import 'package:initialize/src/static_loader.dart'; import 'package:initialize/initialize.dart'; @@ -109,7 +115,11 @@ void htmlEntryPointTests() { } void dartEntryPointTests() { - var phases = [[new InitializeTransformer(['web/index.dart'])]]; + var phases = [ + [ + new InitializeTransformer(['web/index.dart']) + ] + ]; testPhases('constructor arguments', phases, { 'a|web/index.dart': ''' diff --git a/tool/all_tests.sh b/tool/all_tests.sh index 312cda2..d5c23c1 100755 --- a/tool/all_tests.sh +++ b/tool/all_tests.sh @@ -7,6 +7,8 @@ # Fast fail the script on failures. set -e +dartanalyzer --fatal-warnings lib/initialize.dart lib/transformer.dart + # Run the un-transformed command-line tests. dart test/deferred_library_test.dart dart test/init_method_test.dart