throw if options.name is illegal

pull/207/head
Rich-Harris 8 years ago
parent c1fc808641
commit b90ad17ad1

@ -3,7 +3,7 @@ import validateHtml from './html/index.js';
import { getLocator } from 'locate-character';
import getCodeFrame from '../utils/getCodeFrame.js';
export default function validate ( parsed, source, { onerror, onwarn, filename } ) {
export default function validate ( parsed, source, { onerror, onwarn, name, filename } ) {
const locator = getLocator( source );
const validator = {
@ -47,6 +47,16 @@ export default function validate ( parsed, source, { onerror, onwarn, filename }
namespace: null
};
if ( name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test( name ) ) {
const error = new Error( `options.name must be a valid identifier` );
if ( onerror ) {
onerror( error );
} else {
throw error;
}
}
if ( parsed.js ) {
validateJs( validator, parsed.js );
}

@ -58,4 +58,12 @@ describe( 'validate', () => {
}
});
});
it( 'errors if options.name is illegal', () => {
assert.throws( () => {
svelte.compile( '<div></div>', {
name: 'not.valid'
});
}, /options\.name must be a valid identifier/ );
});
});

Loading…
Cancel
Save