-
Notifications
You must be signed in to change notification settings - Fork 51
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
Import syntax #103
base: master
Are you sure you want to change the base?
Import syntax #103
Conversation
My previous message sounded a lot harsher than intended and I would like to apologize, but my two main questions were:
|
@Almost89 There are plenty of languages that have auto-complete for the suggested syntax implementation which always ends up being better than the explicit "from this import these". When using the latter approach you only start getting auto-complete suggestions once the path has been defined for it to draw these suggestions from. In the former approach we can get auto-complete suggestions based on the indices being typed and then can choose the desired path based off that. The former approach will always be better because of this. It goes from having to remember the path your desired value is in to just simply having to remember the import index for that value (which is typically just the name of the Value itself) and then having intellisense/auto-complete present to you the import options for that value. Also for the module name being implicitly imported, it most likely wouldn't be and is simply a misleading formatting issue. Realistically it would be equivalent to just the below indexing. |
@Almost89 I did not consider a default import, but I do think it is viable. I think the syntax |
This comment was marked as resolved.
This comment was marked as resolved.
@Wunder-Wulfe I find using hot comments to be horrific, and a function would not be meaningfully different from None of the example code you provided is at all similar or representative of any example code in the RFC, which leads me to believe you did not read it. Please do so before making more comments. |
I previously had a similar idea a while ago in the old repo; at the time I thought it would be a reasonable alternative to more general destructuring syntax like you do here. As I understand it, this syntax:
Would basically mean you could never have anything that could be interpreted as a function call in that list of identifiers, which is unpalatable (but nonetheless, theoretically workable...) However, over time I've thought about it a lot more and it really seems like whatever syntax we would choose for an import syntax should align with destructuring syntax anyway, in case the call is made to allow destructuring for local variable declarations too, thus not really sidestepping the problem at all. This would rule out the use of a contextual keyword at the start of the statement.
At that point, you may as well just use destructuring with the normal import system, unless you're particularly motivated to have a nice syntax for this.
So I don't think this is the right path to go down. |
I somewhat agree, though I am unsure if destructuring syntax will be added. I also feel that this syntax more closely aligns with Luau's export syntax. Consider this an alternative for when destructuring fails to be accepted once again. |
Worth noting the similarity with #97 too, fwiw. |
Would be nice if this rfc allowed for import all from "./react" And this for all types import types from "./react" Also perhaps worth considering having file paths as first class? |
Could this be transformed into the killer destructuring syntax we're all looking for, actually? The local t = { a = 1, b = 2 }
local function f()
local a, b from t
print(a, b)
end Then you can have the module-like import syntax like this: -- Import specific fields.
local useState, useEffect from require("react")
-- Import everything.
local react = require("react")
-- Also import from a ModuleScript!
local coolMethod, coolFunction from require(game:GetService("ReplicatedStorage").CoolModule) This would introduce two features for a new keyword instead of a single one. It can also be extended to globals if anyone wants to by also accounting for -- Import variables into the global environment.
table, string from require("./my-cool-env-extensions.lua") IMO this version's ability to declare imported variables as either local or global makes it a better fit for the language than the current RFC since the syntax introduced by the RFC doesn't explicitly specify the locality of the imported variables (you have to assume that they will only be available within the current file). |
@loukamb |
Syntactical minimalism aside, I don't see an issue with adding a contextual keyword, but if one is to be added, it would be nice to give it additional functionality. A separate RFC can written but it would make this RFC redundant (it provides the same user-facing advantages as a built-in import statement), code processors/bundlers notwithstanding. I do understand that a very predictable import statement form eases parsing module imports, and my suggestion would make that parsing a tiny bit less predictable as it involves an expression. The global import assignment is for parity with standard assignments. |
The mutable global environment should not be remembered except by embedders. |
This RFC proposes import syntax like the following:
Rendered.