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