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

Commit 068750c

Browse files
committed
more updates to make the bots happy
1 parent 220636c commit 068750c

14 files changed

+192
-32
lines changed

lib/transformer.dart

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ export 'build/initializer_plugin.dart';
2424
/// a new file that bootstraps your application.
2525
Asset generateBootstrapFile(Resolver resolver, Transform transform,
2626
AssetId primaryAssetId, AssetId newEntryPointId,
27-
{bool errorIfNotFound: true, List<InitializerPlugin> plugins,
27+
{bool errorIfNotFound: true,
28+
List<InitializerPlugin> plugins,
2829
bool appendDefaultPlugin: true}) {
2930
if (appendDefaultPlugin) {
3031
if (plugins == null) plugins = [];
3132
plugins.add(const DefaultInitializerPlugin());
3233
}
3334
return new _BootstrapFileBuilder(
34-
resolver, transform, primaryAssetId, newEntryPointId, errorIfNotFound,
35-
plugins: plugins).run();
35+
resolver, transform, primaryAssetId, newEntryPointId, errorIfNotFound,
36+
plugins: plugins)
37+
.run();
3638
}
3739

3840
/// Transformer which removes the mirror-based initialization logic and replaces
@@ -98,18 +100,19 @@ class InitializeTransformer extends Transformer {
98100
});
99101
});
100102
}
103+
101104
// Finds the first (and only) dart script on an html page and returns the
102105
// [AssetId] that points to it
103106
AssetId _findMainScript(
104107
dom.Document document, AssetId entryPoint, Transform transform) {
105-
var scripts = document.querySelectorAll('script[type="application/dart"]');
108+
var scripts = _getScripts(document);
106109
if (scripts.length != 1) {
107110
transform.logger.error('Expected exactly one dart script in $entryPoint '
108111
'but found ${scripts.length}.');
109112
return null;
110113
}
111114

112-
var src = scripts[0].attributes['src'];
115+
var src = _getScriptAttribute(scripts[0]);
113116
if (src == null) {
114117
// TODO(jakemac): Support inline scripts,
115118
transform.logger.error('Inline scripts are not supported at this time, '
@@ -127,24 +130,51 @@ class InitializeTransformer extends Transformer {
127130
AssetId entryPoint, AssetId originalDartFile, AssetId newDartFile) {
128131
var found = false;
129132

130-
var scripts = document
131-
.querySelectorAll('script[type="application/dart"]')
133+
var scripts = _getScripts(document)
132134
.where((script) {
133-
var assetId = uriToAssetId(entryPoint, script.attributes['src'],
135+
var assetId = uriToAssetId(entryPoint, _getScriptAttribute(script),
134136
transform.logger, script.sourceSpan);
135137
return assetId == originalDartFile;
136138
}).toList();
137139

138140
if (scripts.length != 1) {
139-
transform.logger.error(
140-
'Expected exactly one script pointing to $originalDartFile in '
141-
'$entryPoint, but found ${scripts.length}.');
141+
transform.logger
142+
.error('Expected exactly one script pointing to $originalDartFile in '
143+
'$entryPoint, but found ${scripts.length}.');
142144
return;
143145
}
144-
scripts[0].attributes['src'] = path.url.relative(newDartFile.path,
145-
from: path.dirname(entryPoint.path));
146+
_setScriptAttribute(
147+
scripts[0],
148+
path.url
149+
.relative(newDartFile.path, from: path.dirname(entryPoint.path)));
146150
transform.addOutput(new Asset.fromString(entryPoint, document.outerHtml));
147151
}
152+
153+
String _getScriptAttribute(dom.Element element) {
154+
switch (element.localName) {
155+
case 'script':
156+
return element.attributes['src'];
157+
case 'link':
158+
return element.attributes['href'];
159+
default:
160+
throw 'Unrecognized element $element';
161+
}
162+
}
163+
164+
void _setScriptAttribute(dom.Element element, String path) {
165+
switch (element.localName) {
166+
case 'script':
167+
element.attributes['src'] = path;
168+
break;
169+
case 'link':
170+
element.attributes['href'] = path;
171+
break;
172+
}
173+
}
174+
175+
List<dom.Element> _getScripts(dom.Document document) =>
176+
document.querySelectorAll(
177+
'script[type="application/dart"], link[rel="x-dart-test"]');
148178
}
149179

150180
// Class which builds a bootstrap file.
@@ -157,11 +187,13 @@ class _BootstrapFileBuilder {
157187

158188
/// The resolved initialize library.
159189
LibraryElement _initializeLibrary;
190+
160191
/// The resolved Initializer class from the initialize library.
161192
ClassElement _initializer;
162193

163194
/// Queue for intialization annotations.
164195
final _initQueue = new Queue<InitializerData>();
196+
165197
/// All the annotations we have seen for each element
166198
final _seenAnnotations = new Map<Element, Set<ElementAnnotation>>();
167199

@@ -326,8 +358,8 @@ $initializersBuffer
326358
_logger.error("Can't import `${id}` from `${_newEntryPoint}`");
327359
} else if (path.url.split(id.path)[0] ==
328360
path.url.split(_newEntryPoint.path)[0]) {
329-
var relativePath = path.url.relative(id.path,
330-
from: path.url.dirname(_newEntryPoint.path));
361+
var relativePath = path.url
362+
.relative(id.path, from: path.url.dirname(_newEntryPoint.path));
331363
buffer.write("import '${relativePath}'");
332364
} else {
333365
_logger.error("Can't import `${id}` from `${_newEntryPoint}`");
@@ -409,8 +441,9 @@ $initializersBuffer
409441
}
410442

411443
return (new List.from(library.imports)
412-
..addAll(library.exports)
413-
..sort((a, b) => a.nameOffset.compareTo(b.nameOffset))).map(getLibrary);
444+
..addAll(library.exports)
445+
..sort((a, b) => a.nameOffset.compareTo(b.nameOffset)))
446+
.map(getLibrary);
414447
}
415448
}
416449

pubspec.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ transformers:
2222
- initialize/build/loader_replacer:
2323
$include: lib/initialize.dart
2424
- initialize:
25-
$include: '**/*_test.dart'
25+
$include: '**/*_test.*'
2626
entry_points:
27-
- test/deferred_library_test.dart
28-
- test/initializer_test.dart
29-
- test/initializer_from_test.dart
30-
- test/initializer_parts_test.dart
31-
- test/initializer_super_test.dart
32-
- test/initializer_cycle_error_test.dart
33-
- test/initializer_custom_filter_test.dart
34-
- test/initializer_type_filter_test.dart
35-
- test/init_method_test.dart
27+
- test/deferred_library_test.html
28+
- test/initializer_test.html
29+
- test/initializer_from_test.html
30+
- test/initializer_parts_test.html
31+
- test/initializer_super_test.html
32+
- test/initializer_cycle_error_test.html
33+
- test/initializer_custom_filter_test.html
34+
- test/initializer_type_filter_test.html
35+
- test/init_method_test.html
3636
- test/pub_serve:
3737
$include: test/**_test{.*,}.dart
38-
- $dart2js:
39-
$exclude: '**/*.dart'

test/deferred_library_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ main() {
2020
expect(InitializeTracker.seen.length, 5);
2121
});
2222
});
23-
});
23+
}, skip: 'Should be skipped only in pub-serve mode, blocked on '
24+
'https://github.com/dart-lang/test/issues/388.');
2425
}

test/deferred_library_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="deferred_library_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/init_method_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="init_method_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_custom_filter_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/initializer_cycle_error_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ import 'package:test/test.dart';
1010
main() {
1111
test('super class cycles are not supported', () {
1212
expect(run, throwsUnsupportedError);
13-
});
13+
}, skip: 'Should be skipped only in pub-serve mode, blocked on '
14+
'https://github.com/dart-lang/test/issues/388.');
1415
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_cycle_error_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/initializer_from_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ main() {
3030
expect(InitializeTracker.seen[1].package, isNull);
3131
expect(
3232
InitializeTracker.seen[1].path, endsWith('initializer_from_test.dart'));
33-
});
33+
}, skip: 'Should be skipped only in pub-serve mode, blocked on '
34+
'https://github.com/dart-lang/test/issues/388.');
3435
}

test/initializer_from_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_from_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/initializer_parts_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_parts_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/initializer_super_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_super_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

test/initializer_test.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<!--
3+
Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
4+
for details. All rights reserved. Use of this source code is governed by a
5+
BSD-style license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
<head>
9+
<link rel="x-dart-test" href="initializer_type_filter_test.dart">
10+
<script src="packages/test/dart.js"></script>
11+
</head>
12+
<body>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)