-
Notifications
You must be signed in to change notification settings - Fork 196
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
rfc: import syntax #3352
Comments
We should find a way to designate a module first before selecting specific parts of it to import. e.g. instead of: bring Baz from "./file2.w"; // import only Baz we should have something like: bring "./file2.w" with Baz
// or
bring "./file2.w" with { Baz }
// or (with aliasing)
bring "./file2.w" with { Baz as Foo } This allows the language server to offer real suggestions when typing |
// file1.w
bring cloud;
pub class Foo {
store: cloud.Bucket;
pub key: str;
init() {
this.store = new cloud.Bucket();
this.key = "data.json";
}
}
class Bar {}
pub class UsesBar {
pub bar: Bar; // ERROR: private type `Bar` in public field
init() {
this.bar = new Bar();
}
} In the code above, I found the error strange since, despite the To me, the I find it counterintuitive for the visibility of a variable to be defined by the type assigned to it. |
I liked that suggestion. Whenever I do an import in TypeScript, I usually write:
and then go back to the If the library is defined first, it's better for using auto-complete. |
What should the export syntax look like? I don't think it's mentioned in the issue. pub let COOL = 2; If so, does pub let COOL_STUFF = MutJson {}; |
+1 on having {} at the end. Though something doesnt feel right to me with maybe just trying to think of what is the most intuitive. |
This is more or less what I felt. Having |
why not use something like Feels like python |
We had an earlier discussion about imports (video). It seems like we've converged on at least two directions for import syntaxes. Direction 1: Use the Direction 2: Use the Ultimately we might be able to support both (as @MarkMcCulloh suggested) but I thought I'd try at least to steelman both sides to get a feel for both sides, and get folks' opinions on it. EDIT: the options have now been added to the first post as "Approach 1" and "Approach 2" |
I think a deep import syntax shouldn't force you to re-alias types if it's not needed. e.g. for a deep import I think it would be interesting to allow this: bring "./lib.w" {
foo.inner.MyInnerFoo,
};
new MyInnerFoo(); Basically a combination of a |
Console point of view: Currently to support multiple files (external files) the console is watching the main file parent directory excluding A better solution would be to get the list of files to watch from the compiler. |
@ainvoner Makes sense to me. 👍 Off the top of my head it sounds like information the compiler should be able to produce. (Maybe it would also be useful for the LSP? @MarkMcCulloh) |
@ainvoner Is it possible you can use a simple heuristic like simply watching all |
@Chriscbr we allow users to load external files into their Currently, in order to support the above use case we watch all files in the In a real life use case (even in our small dogfooding project for winglang.io reverse proxy), watching the parent directory of the |
@ainvoner Got it. If I understand you correctly this means the list of files to watch needs to include .w files as well as external JS files (referenced from I don't think there is a fool-proof approach with our current language design since it's possible the extern JS file will reference other JS files on the file system, or npm modules, etc. Example 1: // hello.w
class Util {
extern "./helpers.js" inflight foo();
}
// helpers.js
exports.foo = function() {
require("./other.js").bar();
}
// other.js
exports.bar = function() {
console.log("hello");
} Currently the compiler doesn't analyze the source code of extern files (like Example 2: // hello.w
class Util {
extern "./helpers.js" inflight foo();
}
// helpers.js
exports.foo = function() {
const { minimatch } = require('minimatch')
minimatch('bar.foo', '*.foo');
} In this example, if the version of I think it still makes sense for the compiler to give a "best-effort" attempt at providing a list of files to watch. But my guess is that we will also need a reload/refresh button in the Wing Console. |
Our team had another discussion about the merits of the syntax options. We didn't finalize any syntax decisions, but a third new syntax proposal was brought to the table (I've added it as "Approach 3" in the first issue), and we had a few takeaways:
|
I like that avoiding |
Hi, This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
Hi, This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
Use cases
Design goals:
In the set of examples that follows,
lib.w
is a Wing module / JSII type system that contains roughly:Use case 1: Import a few types/submodules from a module, giving them new names
Approach 1:
Approach 2:
Approach 3:
Use case 2: Import an entire module, assigning it a name
Approach 1:
Approach 2:
Approach 3:
(no difference)
Use case 3: Deep-import types from a module
Approach 1:
Approach 2:
Approach 3:
Use case 4: Re-export imported modules or types
Approach 0:
Avoid adding a re-export syntax, and instead favor explicitly defining modules using
pub module
syntax and type aliases.Approach 1:
Approach 2:
Approach 3:
N/A
The text was updated successfully, but these errors were encountered: