tidy rewriting of imports

pull/6842/head
Conduitry 5 years ago
parent 3f43f4aaf3
commit 9cb69c708b

@ -26,7 +26,7 @@ export default function create_module(
helpers.sort((a, b) => (a.name < b.name) ? -1 : 1); helpers.sort((a, b) => (a.name < b.name) ? -1 : 1);
globals.sort((a, b) => (a.name < b.name) ? -1 : 1); globals.sort((a, b) => (a.name < b.name) ? -1 : 1);
const formatter = wrappers[format]; const formatter = wrappers[format];
if (!formatter) { if (!formatter) {
@ -43,7 +43,7 @@ function edit_source(source, sveltePath) {
} }
function get_internal_globals( function get_internal_globals(
globals: Array<{ name: string; alias: Identifier }>, globals: Array<{ name: string; alias: Identifier }>,
helpers: Array<{ name: string; alias: Identifier }> helpers: Array<{ name: string; alias: Identifier }>
) { ) {
return globals.length > 0 && { return globals.length > 0 && {
@ -66,7 +66,7 @@ function get_internal_globals(
init: helpers.find(({ name }) => name === 'globals').alias init: helpers.find(({ name }) => name === 'globals').alias
}] }]
}; };
} }
function esm( function esm(
program: any, program: any,
@ -95,16 +95,16 @@ function esm(
// edit user imports // edit user imports
imports.forEach(node => { imports.forEach(node => {
const value = edit_source(node.source.value, sveltePath); const value = edit_source(node.source.value, sveltePath);
node.source.value = value; if (node.source.value !== value) {
if (node.source.raw) { node.source.value = value;
node.source.raw = JSON.stringify(value); node.source.raw = null;
} }
}); });
exports_from.forEach(node => { exports_from.forEach(node => {
const value = edit_source(node.source!.value, sveltePath); const value = edit_source(node.source.value, sveltePath);
node.source!.value = value; if (node.source.value !== value) {
if (node.source?.raw) { node.source.value = value;
node.source.raw = JSON.stringify(value); node.source.raw = null;
} }
}); });

Loading…
Cancel
Save