Skip to content

Commit 4020602

Browse files
authoredJul 12, 2024··
chore: format everything (#1020)
1 parent 092b91b commit 4020602

File tree

110 files changed

+2869
-2557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2869
-2557
lines changed
 

‎biome.json

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
33
"files": {
4-
"ignore": ["**/dist", "**/pnpm-lock.yaml"],
4+
"ignore": ["**/dist", "**/pnpm-lock.yaml", "wasm_exec.ts"],
55
"include": ["packages/**"]
66
},
77
"formatter": {
88
"enabled": true,
9-
"indentStyle": "space",
9+
"indentStyle": "tab",
1010
"indentWidth": 2,
11-
"lineWidth": 180
11+
"lineWidth": 100
1212
},
1313
"organizeImports": {
1414
"enabled": true
@@ -36,12 +36,24 @@
3636
},
3737
"javascript": {
3838
"formatter": {
39-
"quoteStyle": "single"
39+
"trailingCommas": "es5",
40+
"quoteStyle": "single",
41+
"semicolons": "always"
42+
}
43+
},
44+
"json": {
45+
"parser": {
46+
"allowComments": true,
47+
"allowTrailingCommas": true
48+
},
49+
"formatter": {
50+
"indentStyle": "space",
51+
"trailingCommas": "none"
4052
}
4153
},
4254
"overrides": [
4355
{
44-
"include": ["package.json", "biome.jsonc"],
56+
"include": ["package.json"],
4557
"json": {
4658
"formatter": {
4759
"lineWidth": 1

‎packages/compiler/src/browser/index.ts

+61-49
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,95 @@ import type * as types from '../shared/types';
22
import Go from './wasm_exec.js';
33

44
export const transform: typeof types.transform = (input, options) => {
5-
return ensureServiceIsRunning().transform(input, options);
5+
return ensureServiceIsRunning().transform(input, options);
66
};
77

88
export const parse: typeof types.parse = (input, options) => {
9-
return ensureServiceIsRunning().parse(input, options);
9+
return ensureServiceIsRunning().parse(input, options);
1010
};
1111

1212
export const convertToTSX: typeof types.convertToTSX = (input, options) => {
13-
return ensureServiceIsRunning().convertToTSX(input, options);
13+
return ensureServiceIsRunning().convertToTSX(input, options);
1414
};
1515

1616
interface Service {
17-
transform: typeof types.transform;
18-
parse: typeof types.parse;
19-
convertToTSX: typeof types.convertToTSX;
17+
transform: typeof types.transform;
18+
parse: typeof types.parse;
19+
convertToTSX: typeof types.convertToTSX;
2020
}
2121

2222
let initializePromise: Promise<Service> | undefined;
2323
let longLivedService: Service | undefined;
2424

2525
export const teardown: typeof types.teardown = () => {
26-
initializePromise = undefined;
27-
longLivedService = undefined;
28-
(globalThis as any)['@astrojs/compiler'] = undefined;
26+
initializePromise = undefined;
27+
longLivedService = undefined;
28+
(globalThis as any)['@astrojs/compiler'] = undefined;
2929
};
3030

3131
export const initialize: typeof types.initialize = async (options) => {
32-
let wasmURL = options.wasmURL;
33-
if (!wasmURL) throw new Error('Must provide the "wasmURL" option');
34-
wasmURL += '';
35-
if (!initializePromise) {
36-
initializePromise = startRunningService(wasmURL).catch((err) => {
37-
// Let the caller try again if this fails.
38-
initializePromise = void 0;
39-
// But still, throw the error back up the caller.
40-
throw err;
41-
});
42-
}
43-
longLivedService = longLivedService || (await initializePromise);
32+
let wasmURL = options.wasmURL;
33+
if (!wasmURL) throw new Error('Must provide the "wasmURL" option');
34+
wasmURL += '';
35+
if (!initializePromise) {
36+
initializePromise = startRunningService(wasmURL).catch((err) => {
37+
// Let the caller try again if this fails.
38+
initializePromise = void 0;
39+
// But still, throw the error back up the caller.
40+
throw err;
41+
});
42+
}
43+
longLivedService = longLivedService || (await initializePromise);
4444
};
4545

4646
const ensureServiceIsRunning = (): Service => {
47-
if (!initializePromise) throw new Error('You need to call "initialize" before calling this');
48-
if (!longLivedService) throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this');
49-
return longLivedService;
47+
if (!initializePromise) throw new Error('You need to call "initialize" before calling this');
48+
if (!longLivedService)
49+
throw new Error(
50+
'You need to wait for the promise returned from "initialize" to be resolved before calling this'
51+
);
52+
return longLivedService;
5053
};
5154

52-
const instantiateWASM = async (wasmURL: string, importObject: Record<string, any>): Promise<WebAssembly.WebAssemblyInstantiatedSource> => {
53-
let response = undefined;
55+
const instantiateWASM = async (
56+
wasmURL: string,
57+
importObject: Record<string, any>
58+
): Promise<WebAssembly.WebAssemblyInstantiatedSource> => {
59+
let response = undefined;
5460

55-
if (WebAssembly.instantiateStreaming) {
56-
response = await WebAssembly.instantiateStreaming(fetch(wasmURL), importObject);
57-
} else {
58-
const fetchAndInstantiateTask = async () => {
59-
const wasmArrayBuffer = await fetch(wasmURL).then((res) => res.arrayBuffer());
60-
return WebAssembly.instantiate(wasmArrayBuffer, importObject);
61-
};
62-
response = await fetchAndInstantiateTask();
63-
}
61+
if (WebAssembly.instantiateStreaming) {
62+
response = await WebAssembly.instantiateStreaming(fetch(wasmURL), importObject);
63+
} else {
64+
const fetchAndInstantiateTask = async () => {
65+
const wasmArrayBuffer = await fetch(wasmURL).then((res) => res.arrayBuffer());
66+
return WebAssembly.instantiate(wasmArrayBuffer, importObject);
67+
};
68+
response = await fetchAndInstantiateTask();
69+
}
6470

65-
return response;
71+
return response;
6672
};
6773

6874
const startRunningService = async (wasmURL: string): Promise<Service> => {
69-
const go = new Go();
70-
const wasm = await instantiateWASM(wasmURL, go.importObject);
71-
go.run(wasm.instance);
75+
const go = new Go();
76+
const wasm = await instantiateWASM(wasmURL, go.importObject);
77+
go.run(wasm.instance);
7278

73-
const service: any = (globalThis as any)['@astrojs/compiler'];
79+
const service: any = (globalThis as any)['@astrojs/compiler'];
7480

75-
return {
76-
transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
77-
convertToTSX: (input, options) =>
78-
new Promise((resolve) => resolve(service.convertToTSX(input, options || {}))).then((result: any) => ({
79-
...result,
80-
map: JSON.parse(result.map),
81-
})),
82-
parse: (input, options) => new Promise((resolve) => resolve(service.parse(input, options || {}))).then((result: any) => ({ ...result, ast: JSON.parse(result.ast) })),
83-
};
81+
return {
82+
transform: (input, options) =>
83+
new Promise((resolve) => resolve(service.transform(input, options || {}))),
84+
convertToTSX: (input, options) =>
85+
new Promise((resolve) => resolve(service.convertToTSX(input, options || {}))).then(
86+
(result: any) => ({
87+
...result,
88+
map: JSON.parse(result.map),
89+
})
90+
),
91+
parse: (input, options) =>
92+
new Promise((resolve) => resolve(service.parse(input, options || {}))).then(
93+
(result: any) => ({ ...result, ast: JSON.parse(result.ast) })
94+
),
95+
};
8496
};

0 commit comments

Comments
 (0)
Please sign in to comment.