mirror of https://github.com/sveltejs/svelte
Merge pull request #1 from sveltejs/spread-attribute-updates
Updating and component-friendly spread attributespull/280/head
commit
24212cf102
@ -1,12 +1,19 @@
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
const { snippet } = generator.contextualise( node.expression );
|
||||
|
||||
generator.append( '${ ' + snippet + ' ? `' );
|
||||
|
||||
generator.push({
|
||||
conditions: generator.current.conditions.concat( snippet )
|
||||
});
|
||||
},
|
||||
|
||||
leave ( generator, node ) {
|
||||
generator.append( '` : `' );
|
||||
if ( node.else ) node.else.children.forEach( child => generator.visit( child ) );
|
||||
generator.append( '` }' );
|
||||
|
||||
generator.pop();
|
||||
}
|
||||
};
|
||||
|
@ -1,10 +1,17 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { compile } from '../index.js';
|
||||
|
||||
function capitalise ( name ) {
|
||||
return name[0].toUpperCase() + name.slice( 1 );
|
||||
}
|
||||
|
||||
require.extensions[ '.html' ] = function ( module, filename ) {
|
||||
const { code } = compile( fs.readFileSync( filename, 'utf-8' ), {
|
||||
filename,
|
||||
name: capitalise( path.basename( filename ).replace( /\.html$/, '' ) ),
|
||||
generate: 'ssr'
|
||||
});
|
||||
|
||||
return module._compile( code, filename );
|
||||
};
|
||||
|
@ -1,3 +1,15 @@
|
||||
export default {
|
||||
html: '<input type="text" value="Hello World"/>',
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({
|
||||
options: {
|
||||
type: 'text',
|
||||
value: 'changed'
|
||||
}
|
||||
});
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `<input type="text" value="changed"/>` );
|
||||
component.teardown();
|
||||
}
|
||||
};
|
||||
|
@ -1 +1,2 @@
|
||||
<input {{options}}/>
|
||||
<p>foo: {{foo}}</p>
|
||||
<p>bar: {{bar}}</p>
|
||||
|
@ -1,3 +1,22 @@
|
||||
export default {
|
||||
html: '<input type="text" value="Hello World"/>',
|
||||
html: `
|
||||
<p>foo: 1</p>
|
||||
<p>bar: 2</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target ) {
|
||||
component.set({
|
||||
options: {
|
||||
foo: 3,
|
||||
bar: 4
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal( component.refs.widget.get( 'foo' ), 3 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<p>foo: 3</p>
|
||||
<p>bar: 4</p>
|
||||
` );
|
||||
component.teardown();
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,11 @@
|
||||
:foo:
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
x: 1
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
1:foo:1
|
@ -0,0 +1 @@
|
||||
1:foo:1
|
@ -0,0 +1,11 @@
|
||||
{{y}}<Foo bind:y='x'/>{{y}}
|
||||
|
||||
<script>
|
||||
import Foo from './Foo.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Foo
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,11 @@
|
||||
:foo:
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
x: 1
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
1:foo:1
|
@ -0,0 +1 @@
|
||||
1:foo:1
|
@ -0,0 +1,11 @@
|
||||
{{x}}<Foo bind:x/>{{x}}
|
||||
|
||||
<script>
|
||||
import Foo from './Foo.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Foo
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue