mirror of
https://github.com/enso-org/enso.git
synced 2024-12-24 03:02:30 +03:00
4bf79776c5
Fixes #6250 With this change, I've also slightly refactored the graph editor component by grouping related functionality into neat block and moving already loosely coupled groups to separate files. Further work will be needed to simplify it, but it is a good first step. https://github.com/enso-org/enso/assets/919491/fedce111-ea79-463f-a543-da3ecce28bf5
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { createXXHash128 } from 'hash-wasm'
|
|
import type { IDataType } from 'hash-wasm/dist/lib/util'
|
|
import init, { is_ident_or_operator, parse, parse_doc_to_json } from '../../rust-ffi/pkg/rust_ffi'
|
|
import { assertDefined } from '../util/assert'
|
|
import { isNode } from '../util/detect'
|
|
|
|
let xxHasher128: Awaited<ReturnType<typeof createXXHash128>> | undefined
|
|
export function xxHash128(input: IDataType) {
|
|
assertDefined(xxHasher128, 'Module should have been loaded with `initializeFFI`.')
|
|
xxHasher128.init()
|
|
xxHasher128.update(input)
|
|
return xxHasher128.digest()
|
|
}
|
|
|
|
export async function initializeFFI(path?: string | undefined) {
|
|
if (isNode) {
|
|
const fs = await import('node:fs/promises')
|
|
const { fileURLToPath, URL: nodeURL } = await import('node:url')
|
|
const buffer = fs.readFile(
|
|
path ?? fileURLToPath(new nodeURL('../../rust-ffi/pkg/rust_ffi_bg.wasm', import.meta.url)),
|
|
)
|
|
await init(buffer)
|
|
} else {
|
|
await init()
|
|
}
|
|
xxHasher128 = await createXXHash128()
|
|
}
|
|
|
|
// TODO[ao]: We cannot to that, because the ffi is used by cjs modules.
|
|
// await initializeFFI()
|
|
|
|
/* eslint-disable-next-line camelcase */
|
|
export { is_ident_or_operator, parse_doc_to_json, parse as parse_tree }
|