Clean up vite build warnings (#1332)

* WIP Clean up vite build warnings
Fixes #1014

* Fix lint

* Fix React Hooks dependencies
Clean up, use void when await not straightforward

* Clean up

* Fix missing deconstruction
This commit is contained in:
Pierre Jacquier
2024-01-31 10:17:24 +01:00
committed by GitHub
parent 7d887a1497
commit c1f661ab52
16 changed files with 90 additions and 96 deletions

View File

@ -138,14 +138,14 @@ export function useCalc({
}, [kclManager.ast, kclManager.programMemory, selectionRange])
useEffect(() => {
try {
const execAstAndSetResult = async () => {
const code = `const __result__ = ${value}`
const ast = parse(code)
const _programMem: any = { root: {}, return: null }
availableVarInfo.variables.forEach(({ key, value }) => {
_programMem.root[key] = { type: 'userVal', value, __meta: [] }
})
executeAst({
const { programMemory } = await executeAst({
ast,
engineCommandManager,
defaultPlanes: kclManager.defaultPlanes,
@ -153,23 +153,23 @@ export function useCalc({
programMemoryOverride: JSON.parse(
JSON.stringify(kclManager.programMemory)
),
}).then(({ programMemory }) => {
const resultDeclaration = ast.body.find(
(a) =>
a.type === 'VariableDeclaration' &&
a.declarations?.[0]?.id?.name === '__result__'
)
const init =
resultDeclaration?.type === 'VariableDeclaration' &&
resultDeclaration?.declarations?.[0]?.init
const result = programMemory?.root?.__result__?.value
setCalcResult(typeof result === 'number' ? String(result) : 'NAN')
init && setValueNode(init)
})
} catch (e) {
const resultDeclaration = ast.body.find(
(a) =>
a.type === 'VariableDeclaration' &&
a.declarations?.[0]?.id?.name === '__result__'
)
const init =
resultDeclaration?.type === 'VariableDeclaration' &&
resultDeclaration?.declarations?.[0]?.init
const result = programMemory?.root?.__result__?.value
setCalcResult(typeof result === 'number' ? String(result) : 'NAN')
init && setValueNode(init)
}
execAstAndSetResult().catch(() => {
setCalcResult('NAN')
setValueNode(null)
}
})
}, [value, availableVarInfo])
return {