normalize url attributes on entry point elements

BUG= http://dartbug.com/20092
R=sigmund@google.com

Review URL: https://codereview.chromium.org//404623002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38356 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
jakemac@google.com 2014-07-17 22:38:31 +00:00
parent 9d77c9ea73
commit 5c6f5d1045
3 changed files with 31 additions and 3 deletions

1
pkg/.gitignore vendored
View file

@ -7,3 +7,4 @@
/*.vcxproj.user
/*.vcxproj.filters
/*.xcodeproj
.idea/

View file

@ -45,14 +45,16 @@ class _HtmlInliner extends PolymerTransformer {
seen.add(docId);
Document document;
bool changed;
bool changed = false;
return readPrimaryAsHtml(transform).then((doc) {
document = doc;
changed = new _UrlNormalizer(transform, docId).visit(document) || changed;
experimentalBootstrap = document.querySelectorAll('link').any((link) =>
link.attributes['rel'] == 'import' &&
link.attributes['href'] == POLYMER_EXPERIMENTAL_HTML);
changed = _extractScripts(document);
changed = _extractScripts(document) || changed;
return _visitImports(document);
}).then((importsFound) {
changed = changed || importsFound;
@ -302,11 +304,19 @@ class _UrlNormalizer extends TreeVisitor {
/// This should just be some arbitrary # of ../'s.
final String topLevelPath;
/// Whether or not the normalizer has changed something in the tree.
bool changed = false;
_UrlNormalizer(transform, this.sourceId)
: transform = transform,
topLevelPath =
'../' * (transform.primaryInput.id.path.split('/').length - 2);
visit(Element node) {
super.visit(node);
return changed;
}
visitElement(Element node) {
// TODO(jakemac): Support custom elements that extend html elements which
// have url-like attributes. This probably means keeping a list of which
@ -316,20 +326,23 @@ class _UrlNormalizer extends TreeVisitor {
if (_urlAttributes.contains(name)) {
if (value != '' && !value.trim().startsWith('{{')) {
node.attributes[name] = _newUrl(value, node.sourceSpan);
changed = changed || value != node.attributes[name];
}
}
});
}
if (node.localName == 'style') {
node.text = visitCss(node.text);
changed = true;
} else if (node.localName == 'script' &&
node.attributes['type'] == TYPE_DART &&
!node.attributes.containsKey('src')) {
// TODO(jmesserly): we might need to visit JS too to handle ES Harmony
// modules.
node.text = visitInlineDart(node.text);
changed = true;
}
super.visitElement(node);
return super.visitElement(node);
}
static final _URL = new RegExp(r'url\(([^)]*)\)', multiLine: true);

View file

@ -843,6 +843,20 @@ void entryPointTests() {
'</body></html>',
});
testPhases('includes in entry points normalize correctly', phases, {
'a|web/test/test.html':
'<!DOCTYPE html><html><head>'
'<script src="packages/a/foo/bar.js"></script>'
'</head></html>',
'a|lib/foo/bar.js':
'console.log("here");',
}, {
'a|web/test/test.html':
'<!DOCTYPE html><html><head></head><body>'
'<script src="../packages/a/foo/bar.js"></script>'
'</body></html>',
});
testPhases('two level deep entry points normalize correctly', phases, {
'a|web/test/well/test.html':
'<!DOCTYPE html><html><head>'