Skip to content

Commit

Permalink
fix: keep track of declared identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyih0ng committed Jul 1, 2023
1 parent 569e080 commit 8e940cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/runner/fullJSRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { parse } from '../parser/parser'
import { evallerReplacer, getBuiltins, transpile } from '../transpiler/transpiler'
import type { Context, NativeStorage } from '../types'
import * as create from '../utils/astCreator'
import { getIdentifiersInProgram } from '../utils/uniqueIds'
import { toSourceError } from './errors'
import { appendModulesToContext, resolvedErrorPromise } from './utils'

Expand Down Expand Up @@ -69,6 +70,9 @@ export async function fullJSRunner(
...preludeAndBuiltins,
evallerReplacer(create.identifier(NATIVE_STORAGE_ID), new Set())
])
getIdentifiersInProgram(preEvalProgram).forEach(id =>
context.nativeStorage.previousProgramsIdentifiers.add(id)
)
const preEvalCode: string = generate(preEvalProgram)
const requireProvider = getRequireProvider(context)
await fullJSEval(preEvalCode, requireProvider, context.nativeStorage)
Expand Down
3 changes: 3 additions & 0 deletions src/transpiler/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ function transpileToFullJS(
globalIds.native
)

getGloballyDeclaredIdentifiers(program).forEach(id =>
context.nativeStorage.previousProgramsIdentifiers.add(id)
)
const transpiledProgram: es.Program = create.program([
evallerReplacer(create.identifier(NATIVE_STORAGE_ID), new Set()),
create.expressionStatement(create.identifier('undefined')),
Expand Down

0 comments on commit 8e940cd

Please sign in to comment.