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/src/index.js

37 lines
999 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';
import generateSSR from './server-side-rendering/compile.js';
8 years ago
function normalizeOptions ( options ) {
return Object.assign( {
generate: 'dom',
// a filename is necessary for sourcemap generation
filename: 'SvelteComponent.html',
8 years ago
onwarn: warning => {
if ( warning.loc ) {
console.warn( `(${warning.loc.line}:${warning.loc.column}) ${warning.message}` ); // eslint-disable-line no-console
} else {
console.warn( warning.message ); // eslint-disable-line no-console
}
}
}, options );
}
export function compile ( source, _options ) {
const options = normalizeOptions( _options );
const parsed = parse( source, options );
8 years ago
const { names } = validate( parsed, source, options );
8 years ago
const compiler = options.generate === 'ssr'
? generateSSR
: generate;
return compiler( parsed, source, options, names );
8 years ago
}
8 years ago
8 years ago
export { parse, validate };