Merge branch 'master' into readonly-dev-warning

pull/463/head
Rich Harris 9 years ago committed by GitHub
commit 7176001963

@ -39,7 +39,7 @@ export default class Generator {
// Svelte's builtin `import { get, ... } from 'svelte/shared.js'`; // Svelte's builtin `import { get, ... } from 'svelte/shared.js'`;
this.importedNames = new Set(); this.importedNames = new Set();
this._aliases = new Map(); this._aliases = new Map();
this._usedNames = new Set(); this._usedNames = new Set( [ name ] );
} }
addSourcemapLocations ( node ) { addSourcemapLocations ( node ) {

@ -44,7 +44,7 @@ export default function visitEventHandler ( generator, block, state, node, attri
// get a name for the event handler that is globally unique // get a name for the event handler that is globally unique
// if hoisted, locally unique otherwise // if hoisted, locally unique otherwise
const handlerName = shouldHoist ? const handlerName = shouldHoist ?
generator.alias( `${name}_handler` ) : generator.getUniqueName( `${name}_handler` ) :
block.getUniqueName( `${name}_handler` ); block.getUniqueName( `${name}_handler` );
// create the handler body // create the handler body

@ -44,6 +44,15 @@ export default function validate ( parsed, source, { onerror, onwarn, name, file
onerror( error ); onerror( error );
} }
if ( name && !/^[A-Z]/.test( name ) ) {
const message = `options.name should be capitalised`;
onwarn({
message,
filename,
toString: () => message
});
}
if ( parsed.js ) { if ( parsed.js ) {
validateJs( validator, parsed.js ); validateJs( validator, parsed.js );
} }

@ -11,8 +11,7 @@ export default function components ( validator, prop ) {
checkForComputedKeys( validator, prop.value.properties ); checkForComputedKeys( validator, prop.value.properties );
prop.value.properties.forEach( component => { prop.value.properties.forEach( component => {
const char = component.key.name[0]; if ( !/^[A-Z]/.test( component.key.name ) ) {
if ( char === char.toLowerCase() ) {
validator.warn( `Component names should be capitalised`, component.start ); validator.warn( `Component names should be capitalised`, component.start );
} }
}); });

@ -0,0 +1,36 @@
export default {
data: {
foo: [ 1 ],
bar: [ 2 ],
clicked: 'neither'
},
html: `
<button>foo</button>
<button>bar</button>
<p>clicked: neither</p>
`,
test ( assert, component, target, window ) {
const buttons = target.querySelectorAll( 'button' );
const event = new window.MouseEvent( 'click' );
buttons[0].dispatchEvent( event );
assert.equal( component.get( 'clicked' ), 'foo' );
assert.htmlEqual( target.innerHTML, `
<button>foo</button>
<button>bar</button>
<p>clicked: foo</p>
` );
buttons[1].dispatchEvent( event );
assert.equal( component.get( 'clicked' ), 'bar' );
assert.htmlEqual( target.innerHTML, `
<button>foo</button>
<button>bar</button>
<p>clicked: bar</p>
` );
component.destroy();
}
};

@ -0,0 +1,9 @@
{{#each foo as f}}
<button on:click='set({ clicked: "foo" })'>foo</button>
{{/each}}
{{#each bar as b}}
<button on:click='set({ clicked: "bar" })'>bar</button>
{{/each}}
<p>clicked: {{clicked}}</p>

@ -69,4 +69,19 @@ describe( 'validate', () => {
}); });
}, /options\.name must be a valid identifier/ ); }, /options\.name must be a valid identifier/ );
}); });
it( 'warns if options.name is not capitalised', () => {
const warnings = [];
svelte.compile( '<div></div>', {
name: 'lowercase',
onwarn ( warning ) {
warnings.push({
message: warning.message,
pos: warning.pos,
loc: warning.loc
});
}
});
assert.deepEqual( warnings, [ { message: 'options.name should be capitalised', pos: undefined, loc: undefined } ] );
});
}); });

Loading…
Cancel
Save