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

std.loadscript() equivalent #449

Open
ClosetGeek-Git opened this issue Jan 16, 2024 · 6 comments
Open

std.loadscript() equivalent #449

ClosetGeek-Git opened this issue Jan 16, 2024 · 6 comments

Comments

@ClosetGeek-Git
Copy link

Does txiki.js have the equivalent of quickjs's std.loadscript()?

@saghul
Copy link
Owner

saghul commented Jan 16, 2024

What do you need it for? Why not import a module directly? Or are you using the REPL?

@ClosetGeek-Git
Copy link
Author

I’m currently experimenting with tjs run. Std.loadscript() is able to load scripts that would typically be in a html <script> tag, for example babel-standalone.

@saghul
Copy link
Owner

saghul commented Jan 16, 2024

Sorry I might be a bit obtuse but I still don't get the use case.

There is no HTML here, so you can write a script that imports another.

Perhaps an example would help.

@ClosetGeek-Git
Copy link
Author

ClosetGeek-Git commented Jan 17, 2024

One example would be existing shims and pollyfills that can't be resolved using import. Not all useful javascript is distributed as a module. My reference to html is more a matter of a browsers javascript enfornment and how javascript is loaded into browser environments. This is the closest environment to quickjs as opposed to the standard server environments. "Browser" scripts which are not modules are loaded into the browser using <script src="baz"> which interprets everything at the global level. Such files can only be loaded into quickjs using std.loadscript().

@ClosetGeek-Git
Copy link
Author

It's basically the equivalent of dynamically creating a script tag in the dom in order to load a script from within a script.

@saghul
Copy link
Owner

saghul commented Jan 17, 2024

Gotcha.

I think you could have a helper that uses tjs.readFile and then uses indirect eval() to evaluate it.

That's how loadFile is implemented in qjs.

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

No branches or pull requests

2 participants