-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_wasm_usage.js
More file actions
60 lines (50 loc) · 1.57 KB
/
example_wasm_usage.js
File metadata and controls
60 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import fs from 'fs';
// Configuration object as specified
const config = {
"build": {
"target": "production"
},
"device": {
"isMobile": false
},
"user": {
"language": "en",
"isLoggedIn": true
},
"experiment": {
"group": "B"
},
"featureFlags": {
"newMobileUI": true,
"enableNewFeature": false,
"newUserProfile": false
}
};
async function processTestFile() {
try {
// Read the test.js file
const sourceCode = fs.readFileSync('./test.js', 'utf8');
console.log('Original source code:');
console.log('='.repeat(50));
console.log(sourceCode);
console.log('\n');
// Convert config to JSON string
const configString = JSON.stringify(config);
console.log('Configuration:');
console.log('='.repeat(50));
console.log(JSON.stringify(config, null, 2));
console.log('\n');
// Import the background JS file
const wasmBg = await import('./crates/swc_macro_wasm/pkg/swc_macro_wasm_bg.js');
// Process the code using the wasm optimize function from background module
const optimizedCode = wasmBg.optimize(sourceCode, configString);
console.log('Optimized code:');
console.log('='.repeat(50));
console.log(optimizedCode);
} catch (error) {
console.error('Error processing file:', error);
console.error('Stack trace:', error.stack);
}
}
// Run the example
processTestFile();