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

JS export #17296

wants to merge 26 commits into from

Conversation

juancarlospaco
Copy link
Collaborator

@juancarlospaco juancarlospaco commented Mar 8, 2021

  • Added jscore.jsexport.
const example = example_603979787;
export { example as default };

var example2_603979788 = "This is exported as another in JS";
const example2 = example2_603979788
export { example2 as another };

const example3 = "This is exported as example3 in JS";
export { example3 };

lib/js/jscore.nim Outdated Show resolved Hide resolved
changelog.md Outdated Show resolved Hide resolved
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
@@ -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

lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
lib/js/jscore.nim Outdated Show resolved Hide resolved
@juancarlospaco
Copy link
Collaborator Author

Gitlab is 500'ing in the CI. 😐

@juancarlospaco juancarlospaco requested review from timotheecour and a user March 9, 2021 13:20
Copy link
Member

@timotheecour timotheecour left a comment

Choose a reason for hiding this comment

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

LGTM

I guess we also need jsImport in future work then?
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)

docs look a bit funny with the runnableExamples at the top, but that'll be fixed when this regression is fixed: #16993

@ghost
Copy link

ghost commented Mar 12, 2021

https://github.com/nepeckman/jsExport.nim might be worth looking into for some ideas btw

1 similar comment
@ghost
Copy link

ghost commented Mar 12, 2021

https://github.com/nepeckman/jsExport.nim might be worth looking into for some ideas btw

@timotheecour timotheecour self-requested a review March 12, 2021 23:47
@timotheecour
Copy link
Member

@Yardanico has a good point, if we're offering it in stdlib, might as well make it as good as can be; but then it should be it's own module IMO; please check with @Araq first whether he'd accept a well designed std/jsexports (that'd contain jsImport, jsExport macros similar to https://github.com/nepeckman/jsExport.nim)

@juancarlospaco juancarlospaco marked this pull request as draft March 13, 2021 05:24
@Araq
Copy link
Member

Araq commented Mar 15, 2021

We still have Fusion as the staging area...

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.

5 participants