You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/compiler/index.js

26 lines
740 B

8 years ago
import parse from './parse/index.js';
8 years ago
import validate from './validate/index.js';
8 years ago
import generate from './generate/index.js';
8 years ago
export function compile ( source, options = {} ) {
const parsed = parse( source, options );
8 years ago
8 years ago
const { errors, warnings } = validate( parsed, source, options );
if ( errors.length ) {
// TODO optionally show all errors?
throw errors[0];
}
if ( warnings.length ) {
console.warn( `Svelte: ${warnings.length} ${warnings.length === 1 ? 'error' : 'errors'} in ${options.filename || 'template'}:` );
warnings.forEach( warning => {
console.warn( `(${warning.loc.line}:${warning.loc.column}) ${warning.message}` );
});
}
return generate( parsed, source, options );
8 years ago
}
8 years ago
8 years ago
export { parse, validate };