fix bare imports in `format: 'cjs'` mode (#4050)

pull/4062/head
Conduitry 5 years ago
parent e996ef750d
commit aa2b4e72f7

@ -152,7 +152,12 @@ function cjs(
const internal_globals = get_internal_globals(globals, helpers);
const user_requires = imports.map(node => ({
const user_requires = imports.map(node => {
const init = x`require("${edit_source(node.source.value, sveltePath)}")`;
if (node.specifiers.length === 0) {
return b`${init};`;
}
return {
type: 'VariableDeclaration',
kind: 'const',
declarations: [{
@ -171,9 +176,10 @@ function cjs(
kind: 'init'
}))
},
init: x`require("${edit_source(node.source.value, sveltePath)}")`
init
}]
}));
};
});
const exports = module_exports.map(x => b`exports.${{ type: 'Identifier', name: x.as }} = ${{ type: 'Identifier', name: x.name }};`);

Loading…
Cancel
Save