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

why load statement must import at least 1 symbol #417

Closed
vanishs opened this issue Aug 26, 2022 · 6 comments
Closed

why load statement must import at least 1 symbol #417

vanishs opened this issue Aug 26, 2022 · 6 comments

Comments

@vanishs
Copy link
Contributor

vanishs commented Aug 26, 2022

I made a packager tool:
https://github.com/vanishs/starc2one
This tool packages the relevant dependent modules through the ”load“ reference
I want to package them into a file by referencing them by "load". like this:

load("mod1")
load("mod2")
load("mod3")

but i got an error: "load statement must import at least 1 symbol"

Why is there such a limit?

@laurentlb
Copy link
Contributor

The point of a load statement is to import a symbol in the environment. So a load with no symbol would be a no-op.

If you need to do a side-effect, you could define your own function, e.g. import("mod1").

@vanishs
Copy link
Contributor Author

vanishs commented Aug 26, 2022

could you add a parameter AllowLoadNothing to give "load" the ability to run a module?

@adonovan
Copy link
Collaborator

adonovan commented Aug 26, 2022

A Starlark load statement must specify both the name of a module to load, and a list of 1 or more symbols to import from it. Anything else is a syntax error. There is no way to say "import all the symbols from a module into this file", because it would make it very hard to tell where a symbol was defined.

However, there is an open spec proposal for a way to say "import an entire module to the local name foo", so that you could then access members using the syntax foo.x, but this has not been accepted. Personally I like it but it would be a fair amount of work to implement. Feel free to comment on that issue (and see also #302).

@vanishs
Copy link
Contributor Author

vanishs commented Aug 26, 2022

@adonovan I mean allow the load statement not to import any symbols. like @laurentlb understands.

@adonovan
Copy link
Collaborator

What would be the value of a load statement that doesn't load anything?

@vanishs
Copy link
Contributor Author

vanishs commented Aug 26, 2022

Nothing at all.
like typescript. you can write like this code:
import {} from "path/mymodule1"

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

3 participants