diff --git a/src/runner/fullJSRunner.ts b/src/runner/fullJSRunner.ts index ea9ad0d16..97f8c3b79 100644 --- a/src/runner/fullJSRunner.ts +++ b/src/runner/fullJSRunner.ts @@ -9,10 +9,15 @@ import { RuntimeSourceError } from '../errors/runtimeSourceError' import { hoistAndMergeImports } from '../localImports/transformers/hoistAndMergeImports' import { getRequireProvider, RequireProvider } from '../modules/requireProvider' import { parse } from '../parser/parser' -import { evallerReplacer, getBuiltins, transpile } from '../transpiler/transpiler' +import { + evallerReplacer, + getBuiltins, + getGloballyDeclaredIdentifiers, + transpile +} from '../transpiler/transpiler' import type { Context, NativeStorage } from '../types' import * as create from '../utils/astCreator' -import { getIdentifiersInProgram } from '../utils/uniqueIds' +import { getFunctionDeclarationNamesInProgram } from '../utils/uniqueIds' import { toSourceError } from './errors' import { appendModulesToContext, resolvedErrorPromise } from './utils' @@ -70,7 +75,10 @@ export async function fullJSRunner( ...preludeAndBuiltins, evallerReplacer(create.identifier(NATIVE_STORAGE_ID), new Set()) ]) - getIdentifiersInProgram(preEvalProgram).forEach(id => + getFunctionDeclarationNamesInProgram(preEvalProgram).forEach(id => + context.nativeStorage.previousProgramsIdentifiers.add(id) + ) + getGloballyDeclaredIdentifiers(preEvalProgram).forEach(id => context.nativeStorage.previousProgramsIdentifiers.add(id) ) const preEvalCode: string = generate(preEvalProgram) diff --git a/src/transpiler/transpiler.ts b/src/transpiler/transpiler.ts index b33bb6b66..9cb8b0796 100644 --- a/src/transpiler/transpiler.ts +++ b/src/transpiler/transpiler.ts @@ -12,6 +12,7 @@ import { ModuleDocumentation } from '../modules/moduleTypes' import { AllowedDeclarations, Chapter, Context, NativeStorage, Variant } from '../types' import * as create from '../utils/astCreator' import { + getFunctionDeclarationNamesInProgram, getIdentifiersInNativeStorage, getIdentifiersInProgram, getUniqueId @@ -678,6 +679,9 @@ function transpileToFullJS( globalIds.native ) + getFunctionDeclarationNamesInProgram(program).forEach(id => + context.nativeStorage.previousProgramsIdentifiers.add(id) + ) getGloballyDeclaredIdentifiers(program).forEach(id => context.nativeStorage.previousProgramsIdentifiers.add(id) )