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

Allow transpiled JS to be imported by external modules #662

Open
lavaleri opened this issue Jun 11, 2020 · 0 comments
Open

Allow transpiled JS to be imported by external modules #662

lavaleri opened this issue Jun 11, 2020 · 0 comments
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: js Dafny's JavaScript transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag

Comments

@lavaleri
Copy link
Contributor

Currently the Dafny to JS transpiler compiles JS that is very difficult to reference from an external module. As is, there are a couple of issues that block being able to use generated code in a meaningful way:

  • In an external module one is unable to either import or require objects defined in the generated JS. For my own work I have been getting around this by manually inserting module.exports = { ... } in the generated file to explicitly export any module/class/object that I need to reference in my external module.
  • The generated file, if imported as-is, fails to compile if it contains externs. This is because the generated file references things that must first be defined in extern files. In my own work, I get around this by manually adding const myExtern = require(./path/to/extern) to the generated javascript.
  • If your externs must refer to objects defined in the generated JS, there is no clean way to resolve circular dependencies. This is because the dafny to javascript transpiler compiles a set of dafny files into a single generated JS file. The generated JS contains a module that depends on definitions in extern files, which then prevents your extern files from depending on any other module in the generated JS.

Additionally, we need documentation to show how one can build a JS module using the dafny to JS transpiler, which looks like any other native module, and can be imported and used the same as any other native module.

@acioc acioc added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: js Dafny's JavaScript transpiler and its runtime labels Jun 22, 2020
@acioc acioc added this to the Dafny 3.0 milestone Jun 22, 2020
@acioc acioc added the area: ffi The {:extern} attribute and otherwise interfacing with code in other languages label Jun 22, 2020
@robin-aws robin-aws modified the milestones: Dafny 3.0, Post 3.0 Dec 2, 2020
@robin-aws robin-aws removed this from the Post 3.1 milestone Sep 22, 2021
@atomb atomb added the part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag label Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ffi The {:extern} attribute and otherwise interfacing with code in other languages kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny lang: js Dafny's JavaScript transpiler and its runtime part: code-generation Support for transpiling Dafny to another language. If relevant, add a `lang:` tag
Projects
None yet
Development

No branches or pull requests

4 participants