mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 02:21:54 +03:00
a01aeab3a4
Fixes #9357 The main issue was the spread operator using at the wrong place in functions overriding spacing of nodes. The bug, to be visible, required copying AST node before, because during copying `whitespace` field was explicitly set to undefined (in opposite to being unset), what in turns make spread overriding the value set by those functions. # Important Notes * To enable VSCode debugging, added a workspace for vitest and fix any relative path to be working-dir independent.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { createXXHash128 } from 'hash-wasm'
|
|
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: string) {
|
|
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 }
|