Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Enhancements of Module System #1427

Closed
wants to merge 98 commits into from
Closed

Further Enhancements of Module System #1427

wants to merge 98 commits into from

Conversation

leeyi45
Copy link
Contributor

@leeyi45 leeyi45 commented Jun 21, 2023

Notable Changes

export from resolution

When using export from declarations, the system will now resolve the symbol through the directives to where the symbol was defined:

// a.js
export const a = "a";

// b.js
export { a as b } from './a.js';

// c.js
import { b as c } from './c.js'
// gets translated to
import { a as c } from './a.js'

This change may cause snapshots that use import directives to produce different import statements when preprocessed.
Should fix #1416 by introducing support for such export declarations

Asynchronous Imports

Addresses #1348 partially by introducing a new set of functions that use fetch to retrieve module files. However, the interpreter does not support asynchronous operation, so the original synchronous module loading code has been left in.

Import Preprocessor

The import preprocessor has been changed to treat local and source imports more uniformly:

  • The preprocessor now supports resolving and checking for undefined symbols for local modules as well
  • Though export * statements are not currently supported by other language features, the preprocessor has the ability to detect reexported symbols should such statements become available in the future
  • Options for module resolution have been added, allowing specifications like import a from './a' to be resolved to import a from './a/index.js', similar to how Node and browsers resolve modules. This should help work toward the js-slang repl being able to execute multiple files

Assertions

Introduce a newAssertionError type that derives from RuntimeSourceError to gracefully handle unexpected conditions that arise during program execution, along side an assert function. Using a custom function allows us to modify the errors assertions throw, and removes the need for polyfills for the code to work with the browser.

Minor Changes

Execution Options

  • As part of an effort to make debugging js-slang easier, several options to display debugging information have been added to execution such as logTranspilerOutput have been added
  • Options controlling how imports are resolved have also been added. For example, js-slang can be configured to avoid loading tabs, which would come in handy especially for execution contexts that can't display tabs

Refactoring of AST utils

  • Code relating to manipulating an AST have been collected under src/utils/ast. Where possible, type guards that were spread out across different parts of js-slang have been consolidated.
  • import * as es from './utils/ast/types' can be used to replace import * as es from 'estree'. This will provide extra AST node types and reduce the amount of type checking needed when dealing with an AST. All types are compatible with estree.

@leeyi45 leeyi45 closed this Jun 22, 2023
@leeyi45 leeyi45 deleted the async-imports3 branch November 9, 2023 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect Error for ExportNamedDeclarations with sources
1 participant