bqn.js: JavaScript import module support #99
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I want to do
What I get instead
What I expect to happen
The single function relevant for my
main.jsto get loaded.Why this change
While working on WASM-based tree-sitter support for BQN code highlighting for my blog (demo here), I ran into the convoluted world of modern JavaScript imports.
In my
main.jsfile, when I run thetsserverLSP, I get these errors saying thatbqnfunction does not exist, because my editor is not running in a browser context. In the browser the function is defined when the file is imported via the script tag and everything works.To make the LSP happy, what can be done instead is to use the
importfeature to load the functions from some URI to "lift" the context of the LSP to the similar situation as the browser. However, this requires the variable to be prefixed withexportin the source file. Once done, thescripttag in HTML must be updated to includetype="module"if using animportstatement in any other JS file.Even with the
exportchange, a user does not need to update their JS import unless some other file is trying to read it using JS module features. In other words, introducing this change should not cause any apparent regressions, but only add features to those wanting to use modern JS.