Skip to content
This repository was archived by the owner on Jan 20, 2018. It is now read-only.

Publish 0.6.2+7 #59

Merged
merged 2 commits into from
Aug 30, 2017
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.2+7

* Strong mode fixes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did these come in previous commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see #58


## 0.6.2+6

* Small bug fixes for https://github.com/dart-lang/web-components/issues/54.
Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analyzer:
strong-mode: true
5 changes: 2 additions & 3 deletions lib/build/initializer_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/src/init_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 3 additions & 1 deletion lib/src/initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 11 additions & 8 deletions lib/src/mirror_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}

Expand Down Expand Up @@ -124,10 +122,14 @@ class InitializationCrawler {
Iterable<DeclarationMirror> _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<DeclarationMirror> _sortDeclarations(
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions lib/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -258,6 +257,7 @@ class _BootstrapFileBuilder {
'(possibly transitive).');
}
}

readSuperClassAnnotations(clazz.supertype);
_readAnnotations(clazz);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: initialize
version: 0.6.2+6
version: 0.6.2+7
author: Polymer.dart Authors <[email protected]>
description: Generic building blocks for doing static initialization.
homepage: https://github.com/dart-lang/initialize
Expand Down
5 changes: 3 additions & 2 deletions test/deferred_library_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
36 changes: 22 additions & 14 deletions test/initializer_custom_filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

Expand Down
5 changes: 3 additions & 2 deletions test/initializer_cycle_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
9 changes: 5 additions & 4 deletions test/initializer_from_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
8 changes: 7 additions & 1 deletion test/initializer_super_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
29 changes: 19 additions & 10 deletions test/initializer_type_filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

Expand All @@ -48,6 +55,7 @@ class _Adder implements Initializer<dynamic> {
@override
initialize(_) => total++;
}

const adder = const _Adder();

// Initializer that decrements `total` by one.
Expand All @@ -57,4 +65,5 @@ class _Subtractor implements Initializer<dynamic> {
@override
initialize(_) => total--;
}

const subtractor = const _Subtractor();
18 changes: 14 additions & 4 deletions test/transformer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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': '''
<html><head></head><body>
<script type="application/dart" src="index.dart"></script>
</body></html>
'''.replaceAll(' ', ''),
'''
.replaceAll(' ', ''),
'a|web/index.dart': '''
library web_foo;

Expand Down Expand Up @@ -77,7 +82,8 @@ void htmlEntryPointTests() {
<html><head></head><body>
<script type="application/dart" src="index.initialize.dart"></script>

</body></html>'''.replaceAll(' ', ''),
</body></html>'''
.replaceAll(' ', ''),
'a|web/index.initialize.dart': formatter.format('''
import 'package:initialize/src/static_loader.dart';
import 'package:initialize/initialize.dart';
Expand Down Expand Up @@ -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': '''
Expand Down
2 changes: 2 additions & 0 deletions tool/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down