Skip to content

Commit 76bbe70

Browse files
authored
Add Prettier, reformat JS code (swiftwasm#69)
* Add Prettier, reformat JS code * Hopefully this fixes the issues * Update Makefile * Update package.json * Reformat * That’s why there was an error… oops!
1 parent c52ea09 commit 76bbe70

18 files changed

+382
-298
lines changed

.github/workflows/documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Documentation
22

3-
on:
3+
on:
44
push:
55
branches: [master]
66

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": ["tsconfig.json", "*.js", "*.ts"],
5+
"options": {
6+
"tabWidth": 4
7+
}
8+
}
9+
]
10+
}

Example/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Example project of JavaScriptKit
22

3-
43
## Bootstrap
54

65
```sh
76
$ make build
87
$ npm run start
9-
$ # Open http://localhost:8080 on your browser
8+
$ # Open http://localhost:8080 on your browser
109
```

Example/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<title>Getting Started</title>

Example/src/index.js

+32-33
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,53 @@ import { SwiftRuntime } from "javascript-kit-swift";
22
import { WASI } from "@wasmer/wasi";
33
import { WasmFs } from "@wasmer/wasmfs";
44

5-
65
const swift = new SwiftRuntime();
76
// Instantiate a new WASI Instance
87
const wasmFs = new WasmFs();
98

109
// Output stdout and stderr to console
1110
const originalWriteSync = wasmFs.fs.writeSync;
1211
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
13-
const text = new TextDecoder("utf-8").decode(buffer);
14-
15-
// Filter out standalone "\n" added by every `print`, `console.log`
16-
// always adds its own "\n" on top.
17-
if (text !== "\n") {
18-
switch (fd) {
19-
case 1:
20-
console.log(text);
21-
break;
22-
case 2:
23-
console.error(text);
24-
break;
12+
const text = new TextDecoder("utf-8").decode(buffer);
13+
14+
// Filter out standalone "\n" added by every `print`, `console.log`
15+
// always adds its own "\n" on top.
16+
if (text !== "\n") {
17+
switch (fd) {
18+
case 1:
19+
console.log(text);
20+
break;
21+
case 2:
22+
console.error(text);
23+
break;
24+
}
2525
}
26-
}
27-
return originalWriteSync(fd, buffer, offset, length, position);
26+
return originalWriteSync(fd, buffer, offset, length, position);
2827
};
2928

3029
let wasi = new WASI({
31-
args: [],
32-
env: {},
33-
bindings: {
34-
...WASI.defaultBindings,
35-
fs: wasmFs.fs
36-
}
30+
args: [],
31+
env: {},
32+
bindings: {
33+
...WASI.defaultBindings,
34+
fs: wasmFs.fs,
35+
},
3736
});
3837

3938
const startWasiTask = async () => {
40-
// Fetch our Wasm File
41-
const response = await fetch("JavaScriptKitExample.wasm");
42-
const responseArrayBuffer = await response.arrayBuffer();
39+
// Fetch our Wasm File
40+
const response = await fetch("JavaScriptKitExample.wasm");
41+
const responseArrayBuffer = await response.arrayBuffer();
4342

44-
// Instantiate the WebAssembly file
45-
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
46-
let { instance } = await WebAssembly.instantiate(wasm_bytes, {
47-
wasi_snapshot_preview1: wasi.wasiImport,
48-
javascript_kit: swift.importObjects(),
49-
});
43+
// Instantiate the WebAssembly file
44+
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
45+
let { instance } = await WebAssembly.instantiate(wasm_bytes, {
46+
wasi_snapshot_preview1: wasi.wasiImport,
47+
javascript_kit: swift.importObjects(),
48+
});
5049

51-
swift.setInstance(instance);
52-
// Start the WebAssembly WASI instance!
53-
wasi.start(instance);
50+
swift.setInstance(instance);
51+
// Start the WebAssembly WASI instance!
52+
wasi.start(instance);
5453
};
5554
startWasiTask();

Example/webpack.config.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
const path = require('path');
2-
const outputPath = path.resolve(__dirname, 'dist');
1+
const path = require("path");
2+
const outputPath = path.resolve(__dirname, "dist");
33

44
module.exports = {
5-
entry: './src/index.js',
6-
mode: 'development',
7-
output: {
8-
filename: 'main.js',
9-
path: outputPath,
10-
},
11-
devServer: {
12-
inline: true,
13-
watchContentBase: true,
14-
contentBase: [
15-
path.join(__dirname, 'public'),
16-
path.join(__dirname, 'dist'),
17-
],
18-
},
5+
entry: "./src/index.js",
6+
mode: "development",
7+
output: {
8+
filename: "main.js",
9+
path: outputPath,
10+
},
11+
devServer: {
12+
inline: true,
13+
watchContentBase: true,
14+
contentBase: [
15+
path.join(__dirname, "public"),
16+
path.join(__dirname, "dist"),
17+
],
18+
},
1919
};

IntegrationTests/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ node_modules: package-lock.json
1616

1717
.PHONY: build_rt
1818
build_rt: node_modules
19-
cd ../Runtime && npm run build
19+
cd .. && npm run build
2020

2121
.PHONY: benchmark
2222
benchmark: build_rt dist/BenchmarkTests.wasm
+25-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
const { startWasiTask } = require("../lib")
1+
const { startWasiTask } = require("../lib");
22
const { performance } = require("perf_hooks");
33

4-
global.benchmarkRunner = function(name, body) {
5-
console.log(`Running '${name}' ...`)
6-
const startTime = performance.now();
7-
body(5000)
8-
const endTime = performance.now();
9-
console.log("done " + (endTime - startTime) + " ms");
10-
}
4+
global.benchmarkRunner = function (name, body) {
5+
console.log(`Running '${name}' ...`);
6+
const startTime = performance.now();
7+
body(5000);
8+
const endTime = performance.now();
9+
console.log("done " + (endTime - startTime) + " ms");
10+
};
1111

1212
class JSBenchmark {
13-
constructor(title) { this.title = title }
13+
constructor(title) {
14+
this.title = title;
15+
}
1416
testSuite(name, body) {
1517
benchmarkRunner(`${this.title}/${name}`, (iteration) => {
1618
for (let idx = 0; idx < iteration; idx++) {
17-
body()
19+
body();
1820
}
19-
})
21+
});
2022
}
2123
}
2224

23-
const serialization = new JSBenchmark("Serialization")
25+
const serialization = new JSBenchmark("Serialization");
2426
serialization.testSuite("Write JavaScript number directly", () => {
25-
const jsNumber = 42
26-
const object = global
27+
const jsNumber = 42;
28+
const object = global;
2729
for (let idx = 0; idx < 100; idx++) {
28-
object["numberValue" + idx] = jsNumber
30+
object["numberValue" + idx] = jsNumber;
2931
}
30-
})
32+
});
3133

3234
serialization.testSuite("Write JavaScript string directly", () => {
33-
const jsString = "Hello, world"
34-
const object = global
35+
const jsString = "Hello, world";
36+
const object = global;
3537
for (let idx = 0; idx < 100; idx++) {
36-
object["stringValue" + idx] = jsString
38+
object["stringValue" + idx] = jsString;
3739
}
38-
})
40+
});
3941

40-
startWasiTask("./dist/BenchmarkTests.wasm").catch(err => {
41-
console.log(err)
42-
});
42+
startWasiTask("./dist/BenchmarkTests.wasm").catch((err) => {
43+
console.log(err);
44+
});

IntegrationTests/bin/primary-tests.js

+52-40
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
global.globalObject1 = {
2-
"prop_1": {
3-
"nested_prop": 1,
4-
},
5-
"prop_2": 2,
6-
"prop_3": true,
7-
"prop_4": [
8-
3, 4, "str_elm_1", null, undefined, 5,
9-
],
10-
"prop_5": {
11-
"func1": function () { return },
12-
"func2": function () { return 1 },
13-
"func3": function (n) { return n * 2},
14-
"func4": function (a, b, c) { return a + b + c },
15-
"func5": function (x) { return "Hello, " + x },
16-
"func6": function (c, a, b) {
17-
if (c) { return a } else { return b }
2+
prop_1: {
3+
nested_prop: 1,
184
},
19-
},
20-
"prop_6": {
21-
"call_host_1": () => {
22-
return global.globalObject1.prop_6.host_func_1()
23-
}
24-
},
25-
"prop_7": 3.14,
26-
"prop_8": [0, , 2, 3, , , 6],
27-
}
5+
prop_2: 2,
6+
prop_3: true,
7+
prop_4: [3, 4, "str_elm_1", null, undefined, 5],
8+
prop_5: {
9+
func1: function () {
10+
return;
11+
},
12+
func2: function () {
13+
return 1;
14+
},
15+
func3: function (n) {
16+
return n * 2;
17+
},
18+
func4: function (a, b, c) {
19+
return a + b + c;
20+
},
21+
func5: function (x) {
22+
return "Hello, " + x;
23+
},
24+
func6: function (c, a, b) {
25+
if (c) {
26+
return a;
27+
} else {
28+
return b;
29+
}
30+
},
31+
},
32+
prop_6: {
33+
call_host_1: () => {
34+
return global.globalObject1.prop_6.host_func_1();
35+
},
36+
},
37+
prop_7: 3.14,
38+
prop_8: [0, , 2, 3, , , 6],
39+
};
2840

29-
global.Animal = function(name, age, isCat) {
30-
this.name = name
31-
this.age = age
32-
this.bark = () => {
33-
return isCat ? "nyan" : "wan"
34-
}
35-
this.isCat = isCat
36-
this.getIsCat = function() {
37-
return this.isCat
38-
}
39-
}
41+
global.Animal = function (name, age, isCat) {
42+
this.name = name;
43+
this.age = age;
44+
this.bark = () => {
45+
return isCat ? "nyan" : "wan";
46+
};
47+
this.isCat = isCat;
48+
this.getIsCat = function () {
49+
return this.isCat;
50+
};
51+
};
4052

41-
const { startWasiTask } = require("../lib")
53+
const { startWasiTask } = require("../lib");
4254

43-
startWasiTask("./dist/PrimaryTests.wasm").catch(err => {
44-
console.log(err)
45-
process.exit(1)
55+
startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
56+
console.log(err);
57+
process.exit(1);
4658
});

0 commit comments

Comments
 (0)