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

JS export #17296

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
88cda6a
Add Debug breakpoints support
juancarlospaco Mar 8, 2021
55f9110
Add Debug breakpoints support
juancarlospaco Mar 8, 2021
04969e7
Merge branch 'devel' of https://github.com/nim-lang/Nim into debugjs
juancarlospaco Mar 8, 2021
fd12f82
Add JS export
juancarlospaco Mar 8, 2021
5795c8e
Add JS export
juancarlospaco Mar 8, 2021
88a3716
https://github.com/nim-lang/Nim/pull/17296#discussion_r589372905
juancarlospaco Mar 8, 2021
7a78c60
Update changelog.md
juancarlospaco Mar 8, 2021
67ea007
Update lib/js/jscore.nim
juancarlospaco Mar 8, 2021
864b5e5
Pear review
juancarlospaco Mar 8, 2021
4af3487
Pear review
juancarlospaco Mar 8, 2021
96b60a4
Merge branch 'devel' of https://github.com/nim-lang/Nim into js2
juancarlospaco Mar 8, 2021
edda464
Sync
juancarlospaco Mar 8, 2021
895aa31
Sync
juancarlospaco Mar 8, 2021
344af44
Workaround https://github.com/nim-lang/Nim/issues/16993
juancarlospaco Mar 8, 2021
c9b3257
export default is not special in Nim but it is in JS
juancarlospaco Mar 8, 2021
d12b235
Fix a lot
juancarlospaco Mar 8, 2021
267bf9c
Update lib/js/jscore.nim
juancarlospaco Mar 9, 2021
6f3f574
Update lib/js/jscore.nim
juancarlospaco Mar 9, 2021
b0ad202
improve doc
juancarlospaco Mar 9, 2021
591e3a6
Merge branch 'devel' of https://github.com/nim-lang/Nim into js2
juancarlospaco Mar 9, 2021
c0857f0
improve runnableExamples
juancarlospaco Mar 9, 2021
fd36a70
improve doc
juancarlospaco Mar 9, 2021
9a9783b
Merge branch 'devel' of https://github.com/nim-lang/Nim into js2
juancarlospaco Mar 9, 2021
ae7bddc
Merge branch 'devel' of https://github.com/nim-lang/Nim into js2
juancarlospaco Mar 9, 2021
0da91f1
Merge branch 'devel' of https://github.com/nim-lang/Nim into js2
juancarlospaco Mar 12, 2021
a7c267f
The famous way to restart the CI
juancarlospaco Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ provided by the operating system.

- Added `jscore.debugger` to [call any available debugging functionality, such as breakpoints.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger)

- Added `jscore.jsexport` to [generate JavaScript `export` statements, including aliased exports and default export.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)

juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved

## Language changes

Expand Down
12 changes: 12 additions & 0 deletions lib/js/jscore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ proc parse*(l: JsonLib, s: cstring): JsRoot {.importcpp.}
since (1, 5):
func debugger*() {.importjs: "debugger@".}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is "debugger@" documented and what does it mean?

manual mentions "createDevice(@)" but not "createDevice@"

Copy link
Collaborator Author

@juancarlospaco juancarlospaco Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cat example.nim
func debugger*() {.importjs: "debugger".}
debugger()

$ nim js example.nim
Error: `importjs` for routines requires a pattern

$

https://github.com/nim-lang/Nim/wiki/Nim-for-TypeScript-Programmers#JavaScript-Interoperability

🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • but shouldn't it be "debugger(@)" ? "debugger@"` seems wrong and may (in future) turn into a CT error
  • in future work we should support importjs: "debugger" though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"debugger(@)" emits debugger() but must be debugger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document this in a followup PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you use importc: "debugger"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a small bug on importjs tho. 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a note in nim-lang/RFCs#315 so we don't lose track

## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger

template jsexport*(symbol: untyped; alias = "") =
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
runnableExamples("-b:js -r:off"):
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
proc example = echo "This is exported as 'default' in JavaScript"
let example2 = "This is exported as 'another' in JavaScript"
const example3 = "This is exported as 'example3' in JavaScript"
jsexport(example, alias = "default") ## Alias for `export { symbol as default };`
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved
jsexport(example2, alias = "another") ## Alias for `export { symbol as another };`
jsexport(example3) ## Alias for `export { symbol };`
var _ {.codegenDecl: "const $2", exportc: astToStr(symbol).} = symbol
{.emit: "export { " & astToStr(symbol) & (if alias.len > 0: " as " & alias else: "") & " };" .}
juancarlospaco marked this conversation as resolved.
Show resolved Hide resolved