Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #354 from Polymer/no-inline-in-template
Browse files Browse the repository at this point in the history
Do not inline imports in templates
  • Loading branch information
dfreedm committed Jul 19, 2016
2 parents d8b4681 + 1fc1eaa commit 1000640
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/vulcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ Vulcan.prototype = {
return false;
},

isTemplated: function(node) {
while(node) {
if (dom5.isDocumentFragment(node)) {
return true;
}
node = node.parentNode;
}
return false;
},

flatten: function flatten(tree, isMainDoc) {
var doc = tree.html.ast;
var imports = tree.imports;
Expand Down Expand Up @@ -233,6 +243,9 @@ Vulcan.prototype = {
if (this.isExcludedImport(im)) {
continue;
}
if (this.isTemplated(thisImport)) {
continue;
}
var bodyFragment = dom5.constructors.fragment();
var importDoc = this.flatten(im);
// rewrite urls
Expand Down
13 changes: 13 additions & 0 deletions test/html/inside-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<template>
<link rel="import" href="external.html">
</template>
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,5 +1065,28 @@ suite('Vulcan', function() {
done();
}, {inlineScripts: true});
});

test('Imports in templates should not inline', function(done) {
process('test/html/inside-template.html', function(err, doc) {
var importMatcher = preds.AND(
preds.hasTagName('link'),
preds.hasAttrValue('rel', 'import'),
preds.hasAttr('href')
);
var externalScriptMatcher = preds.AND(
preds.hasTagName('script'),
preds.hasAttrValue('src', 'external/external.js')
);
if (err) {
return done(err);
}
assert(doc);
var imports = dom5.queryAll(doc, importMatcher);
assert.equal(imports.length, 1, 'import in template was inlined');
var unexpectedScript = dom5.query(doc, externalScriptMatcher);
assert.equal(unexpectedScript, null, 'script in external.html should not be present');
done();
});
});
});
});

0 comments on commit 1000640

Please sign in to comment.