Skip to content

Commit

Permalink
fix: not declared errors in source native variant REPL (#1479)
Browse files Browse the repository at this point in the history
* fix: only add func and var identifiers instead of all identifiers

* fix: add function declarations into `previousProgramIdentifiers`

---------

Co-authored-by: Martin Henz <[email protected]>
  • Loading branch information
shenyih0ng and martin-henz authored Sep 3, 2023
1 parent 563bc0d commit 0107752
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/runner/fullJSRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/transpiler/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
Expand Down

0 comments on commit 0107752

Please sign in to comment.