Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[
require.resolve('@babel/plugin-syntax-decorators'),
{
decoratorsBeforeExport: true
}
]
],
presets: [require.resolve('@babel/preset-typescript')]
})
codeTransformed = code
}
// @ts-ignore
const cb = this.async()
compiler
.transform(codeTransformed, resourcePath, {
name: info.name,
namespace: info.ns,
outputConfig: compilerOutput,
stylesheetConfig,
experimentalDynamicComponent
})
.then((res: any) => {
cb(null, res.code)
})
.catch((err: any) => {
cb(err)
})
return
}
async transform(src, id) {
// Filter user-land config and lwc import
if (!filter(id)) {
return;
}
// If we don't find the moduleId, just resolve the module name/namespace
const moduleEntry = Object.values(modulePaths).find(r => id === r.entry);
const moduleRegistry = moduleEntry || getModuleQualifiedName(id, mergedPluginOptions);
const { code, map } = await compiler.transform(src, id, {
mode: DEFAULT_MODE, // Use always default mode since any other (prod or compat) will be resolved later
name: moduleRegistry.moduleName,
namespace: moduleRegistry.moduleNamespace,
moduleSpecifier: moduleRegistry.moduleSpecifier,
outputConfig: { sourcemap: mergedPluginOptions.sourcemap },
stylesheetConfig: mergedPluginOptions.stylesheetConfig,
experimentalDynamicComponent: mergedPluginOptions.experimentalDynamicComponent,
});
return { code, map };
},
};
export async function compileSource(source: string, fileName: string = 'foo.js'): Promise {
try {
const name = fileName.substring(0, fileName.lastIndexOf('.'));
const options: CompilerOptions = {
name,
namespace: 'x',
files: {},
};
const transformerResult = await transform(source, fileName, options);
const metadata = transformerResult.metadata as Metadata;
patchComments(metadata);
return { metadata, diagnostics: [] };
} catch (err) {
return { diagnostics: [toDiagnostic(err)] };
}
}