Skip to content

Commit

Permalink
inject polyfills after base tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed May 21, 2015
1 parent 762d783 commit 730b6ea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.16.3+3
* Inject the polyfills after any `<base>` tags in the head.

#### 0.16.3+2
* Fix invalid warning about missing polymer.html import from the linter.
* Update logging package to `<0.12.0`.
Expand Down
11 changes: 10 additions & 1 deletion lib/src/build/polyfill_injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ class PolyfillInjector extends Transformer with PolymerTransformer {
parseFragment('<script src="packages/browser/dart.js"></script>'));
}

_addScript(urlSegment, [Node parent, int position = 0]) {
_addScript(urlSegment, [Element parent, int position]) {
if (parent == null) parent = document.head;
// Default to either the top of `parent` or right after the <base> tag.
if (position == null) {
var base = parent.querySelector('base');
if (base != null) {
position = parent.nodes.indexOf(base) + 1;
} else {
position = 0;
}
}
var pathToPackages =
'../' * (path.url.split(transform.primaryInput.id.path).length - 2);
parent.nodes.insert(position, parseFragment(
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: polymer
version: 0.16.3+2
version: 0.16.3+3
author: Polymer.dart Authors <[email protected]>
description: >
Polymer.dart is a new type of library for the web, built on top of Web
Expand Down
16 changes: 16 additions & 0 deletions test/build/polyfill_injector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ void runTests({bool js: true}) {
'</body></html>',
});

testPhases('polyfills after base tags', phases, {
'a|web/test.html': '<!DOCTYPE html><html><head>'
'<base href="/">'
'</head><body>'
'<script type="application/dart" src="a.dart"></script>'
'$dartJsTag'
}, {
'a|web/test.html': '<!DOCTYPE html><html><head>'
'<base href="/">'
'$COMPATIBILITY_JS_TAGS'
'</head><body>'
'<script ${type}src="a.dart$ext"$async></script>'
'$dartJsTag'
'</body></html>',
});

testPhases('platform.js -> webcomponents.js', phases, {
'a|web/test.html': '<!DOCTYPE html><html><head>'
'$PLATFORM_JS_TAG'
Expand Down

0 comments on commit 730b6ea

Please sign in to comment.