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/generators/shared/utils/getOutro.ts

38 lines
796 B

import getGlobals from './getGlobals';
import { CompileOptions, Node } from '../../../interfaces';
export default function getOutro(
format: string,
name: string,
options: CompileOptions,
imports: Node[]
) {
if (format === 'es') {
return `export default ${name};`;
}
if (format === 'amd') {
return `return ${name};\n\n});`;
}
if (format === 'cjs') {
return `module.exports = ${name};`;
}
if (format === 'iife') {
const globals = getGlobals(imports, options);
return `return ${name};\n\n}(${globals.join(', ')}));`;
}
if (format === 'eval') {
const globals = getGlobals(imports, options);
return `return ${name};\n\n}(${globals.join(', ')}));`;
}
if (format === 'umd') {
return `return ${name};\n\n})));`;
}
throw new Error(`Not implemented: ${format}`);
}