swc/crates/swc_ecma_codegen/tests/srcmap.mjs
2022-09-26 18:12:42 +09:00

29 lines
586 B
JavaScript

import { minify } from "terser";
try {
const code = process.argv[1];
const output = await minify(code, {
sourceMap: {
filename: 'input.js',
includeSources: true,
},
compress: false,
mangle: false,
});
console.log(JSON.stringify({
code: output.code,
map: output.map,
}))
} catch (e) {
// Ignore syntax error
if (e.toString().includes("SyntaxError")) {
console.log(JSON.stringify({
code: '',
map: '{}',
}));
} else {
throw e;
}
}