mirror of https://github.com/sveltejs/svelte
commit
3ead9bfc3f
@ -1,14 +1,17 @@
|
||||
export default function counter ( used ) {
|
||||
const counts = {};
|
||||
const counts = new Map();
|
||||
|
||||
used.forEach( name => counts[ name ] = 1 );
|
||||
used.forEach( name => counts.set( name, 1 ) );
|
||||
|
||||
return function ( name ) {
|
||||
if ( name in counts ) {
|
||||
return `${name}${counts[ name ]++}`;
|
||||
if ( counts.has( name ) ) {
|
||||
const count = counts.get( name );
|
||||
const newName = `${name}${count}`;
|
||||
counts.set( name, count + 1 );
|
||||
return newName;
|
||||
}
|
||||
|
||||
counts[ name ] = 1;
|
||||
counts.set( name, 1 );
|
||||
return name;
|
||||
};
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
const disallowed = {
|
||||
Literal: true,
|
||||
ObjectExpression: true,
|
||||
ArrayExpression: true
|
||||
};
|
||||
const disallowed = new Set( [ 'Literal', 'ObjectExpression', 'ArrayExpression' ] );
|
||||
|
||||
export default function data ( validator, prop ) {
|
||||
while ( prop.type === 'ParenthesizedExpression' ) prop = prop.expression;
|
||||
|
||||
// TODO should we disallow references and expressions as well?
|
||||
|
||||
if ( disallowed[ prop.value.type ] ) {
|
||||
if ( disallowed.has( prop.value.type ) ) {
|
||||
validator.error( `'data' must be a function`, prop.value.start );
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
export default function checkForDupes ( validator, properties ) {
|
||||
const seen = Object.create( null );
|
||||
const seen = new Set();
|
||||
|
||||
properties.forEach( prop => {
|
||||
if ( seen[ prop.key.name ] ) {
|
||||
if ( seen.has( prop.key.name ) ) {
|
||||
validator.error( `Duplicate property '${prop.key.name}'`, prop.start );
|
||||
}
|
||||
|
||||
seen[ prop.key.name ] = true;
|
||||
seen.add( prop.key.name );
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in new issue