pull/366/merge
Cristian Necula 9 years ago committed by GitHub
commit 75aacff703

@ -207,8 +207,19 @@ export default function dom ( parsed, source, options, names ) {
_set: new CodeBuilder()
};
if ( parsed.css && options.css !== false ) {
generator.current.builders.mount.addLine( `if ( !target.ownerDocument.__sveltecss_${parsed.hash} ) addCss( target.ownerDocument );` );
const includeCss = parsed.css && options.css !== false;
if ( includeCss ) {
generator.current.builders.mount.addBlock( deindent`
var _addCss = function() {
if ( !target.ownerDocument.__sveltecss_${parsed.hash} ) addCss( target.ownerDocument );
}
if ( component._root ) {
component._root._renderHooks.push({ fn: _addCss, context: this });
} else {
component._renderHooks.push({ fn: _addCss, context: this })
}
` );
builders.main.addBlock( deindent`
function addCss ( document ) {
@ -272,7 +283,7 @@ export default function dom ( parsed, source, options, names ) {
builders.init.addLine( `this._torndown = false;` );
if ( generator.hasComponents ) {
if ( generator.hasComponents || includeCss ) {
builders.init.addLine( `this._renderHooks = [];` );
}
@ -292,11 +303,13 @@ export default function dom ( parsed, source, options, names ) {
` );
}
if ( generator.hasComponents ) {
if ( generator.hasComponents || includeCss ) {
const statement = `this._flush();`;
builders.init.addBlock( statement );
builders._set.addBlock( statement );
if ( generator.hasComponents ) {
builders._set.addBlock( statement );
}
}
if ( templateProperties.oncreate ) {

@ -0,0 +1,7 @@
<p>test</p>
<style>
p {
color: red;
}
</style>

@ -1,21 +1,19 @@
export default {
test ( assert, component, target, window ) {
const testStyles = ([control, test]) => {
assert.equal( window.getComputedStyle( control ).color, 'blue' );
assert.equal( window.getComputedStyle( test ).color, 'red' );
};
const iframe = window.document.createElement('iframe');
window.document.body.appendChild(iframe);
const otherTarget = iframe.contentWindow.document.body;
new component.constructor({
target: otherTarget
});
assert.equal(
window.getComputedStyle(target.querySelector('h1')).color,
'rgb(255, 0, 0)'
);
assert.equal(
window.getComputedStyle(otherTarget.querySelector('h1')).color,
'rgb(255, 0, 0)'
);
testStyles(target.querySelectorAll( 'p' ));
testStyles(otherTarget.querySelectorAll( 'p' ));
}
};

@ -1,6 +1,18 @@
<h1>Just some static HTML</h1>
<p>control</p>
<div>
<Widget/>
</div>
<style>
h1 {
color: rgb(255, 0, 0);
}
p {
color: blue;
}
</style>
<script>
import Widget from './Widget.html';
export default {
components: { Widget }
};
</script>

Loading…
Cancel
Save