mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
|
let settings =
|
||
|
{
|
||
|
"jsc": {
|
||
|
"target": "es2016",
|
||
|
"parser": {
|
||
|
"syntax": "ecmascript",
|
||
|
"jsx": true,
|
||
|
"dynamicImport": false,
|
||
|
"numericSeparator": false,
|
||
|
"privateMethod": false,
|
||
|
"functionBind": false,
|
||
|
"exportDefaultFrom": false,
|
||
|
"exportNamespaceFrom": false,
|
||
|
"decorators": false,
|
||
|
"decoratorsBeforeExport": false,
|
||
|
"topLevelAwait": false,
|
||
|
"importMeta": false
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
let code = `
|
||
|
let a = 1;
|
||
|
let b = {
|
||
|
c: {
|
||
|
d: 1
|
||
|
}
|
||
|
|
||
|
};
|
||
|
console.log(b?.c?.d);
|
||
|
|
||
|
let MyComponent = () => {
|
||
|
return (<div a={10}>
|
||
|
<p>Hello World!</p>
|
||
|
</div>);
|
||
|
}
|
||
|
`;
|
||
|
|
||
|
const swc = import("./pkg/wasm.js");
|
||
|
swc.then(swc => {
|
||
|
console.log("SWC Loaded", swc);
|
||
|
let result = swc.transformSync(code, settings);
|
||
|
console.log("result from transformSync", result);
|
||
|
console.log(result.code);
|
||
|
document.getElementById("result").innerHTML = "<xmp>" + result.code + "</xmp>";
|
||
|
document.getElementById("source").innerHTML = "<xmp>" + code + "</xmp>";
|
||
|
});
|