Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async processString(content, relativePath) {
const options = {...this.swcOptions};
options.module = {...options.module} || {};
if (options.module.type === 'amd' && this.options.namedAmd || options.module.moduleId === true) {
options.module.moduleId = relativePath.replace(/\.(?:js|ts)$/, '');
}
options.jsc = options.jsc || {};
if (relativePath.endsWith('.ts') && options.jsc.parser === undefined) {
options.jsc.parser = {
"syntax": "typescript",
}
}
const { code } = await swc.transform(content, options);
return code;
}
const compileSWC = async (code, minify) => {
const {transform} = require("@swc/core");
return (await transform(code, {
"minify": minify,
"module": {
"type": "commonjs",
"strict": false,
"strictMode": false,
},
"jsc": {
"parser": {
"syntax": "ecmascript",
"classProperty": true
},
"target": "es5",
"transform": {
"optimizer": undefined
}
}