-
Notifications
You must be signed in to change notification settings - Fork 35
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 literal "module"#export
hoists import { export } from "module"
#1652
base: main
Are you sure you want to change the base?
Conversation
I think the original syntax of a snug prefix ^ could work pretty well. Similar to how symbols fit in despite object properties and labels. I’m not as big a fan of overloading the length syntax since it requires the quotes which reduces some of the benefits. ^ ModuleSpecifier seems like it handles everything except spaces and in that case it could be explicitly wrapped with quotes. The main open questions are:
Sorry I can’t experiment more myself but I’m away from PC for the rest of the week. (Mobile interface is also why I accidentally untoggled draft on this PR 😵💫) |
Thanks for the feedback; I agree. So I think we need some kind of character after the module name. This is what led me down the I had forgot about I always had in mind that |
Maybe : for named export, ^. for property? And plain . is always part of the file name. We’ll need to play around to see what we prefer to be most common. |
Unfortunately, we can't use I wish we could use the same symbols from an Similar to |
Here's a weird idea: if ^module // import ref1 from 'module'
^module* // import * as ref2 from 'module'
^module*foo // import {foo as ref3} from 'module'
// or just use ref2.foo Update: Vendethiel points out that Weirder (bad) idea: ^module // import ref1 from 'module'
*module // import * as ref2 from 'module'
*module.foo // import {foo as ref3} from 'module'
// or just use ref2.foo Update: Sorry, what am I thinking? |
I think
import ref from "lodash/add"
import { add as ref1 } from "lodash" The advantage is it allows single / to remain the regular path separator. We could also consider defaulting . to being property access and require it being escaped or the whole path to be quoted for it to appear in the path since it seems uncommon there. *. as a suffix seems pretty good for property access after a star import. I think star import is generally rare except for common JS compatibility. Favoring default export and paths may help with code splitting. |
Cool, I forgot that
So including an extension in the filename would require quotes? Hmm, also an interesting idea. I guess we could still allow for leading
My point was that |
On Discord, @vendethiel reminds us that the original PR's string-based approach would work well with "module"^ // import ref from "module"
"module"^export // import { export as ref } from "module"
"module"^* // import * as ref from "module" Can dereference the default export via We're overloading binary XOR (for named exports) but that seems fine for string literal LHS. If we wanted an unquoted version, we could use |
I went ahead and implemented the following: ^module^ // import ref from "module"
^module^export // import { export as ref } from "module"
^module^* // import * as ref from "module"
"module"^ // import ref from "module"
"module"^export // import { export as ref } from "module"
"module"^* // import * as ref from "module" Mostly I wanted to implement the We don't need to use this syntax, but I wanted to nudge a bit in this direction. I like that |
If the quoted strings exist as a fallback we could do a more concise prefix caret for common cases:
I generally prefer the prefix caret since it limits backtracking but a postfix caret could also work. |
If we're going to require quotes for extensions and give Combining with your suggestion of prefix caret (less backtracking is maybe also a good argument for human readers):
Or is conflict with comments too weird? (I didn't add syntax highlighting because it looks terrible.) At this point we could also consider ^underscore/modules/map // import ref from "underscore/modules/map"
^underscore.map // import ref from "underscore"; ref.map
^underscore#map // import { map as ref } from "underscore"
^underscore#* // import * as ref from "underscore"
^"./module.js" // import ref from "./module.js"
^"./module.js"#export // import { export as ref } from "./module.js"
^"./module.js"#* // import * as ref from "./module.js" Or we could follow the " ^underscore/modules/map // import ref from "underscore/modules/map"
^underscore.map // import ref from "underscore"; ref.map
^underscore^map // import { map as ref } from "underscore"
^underscore^* // import * as ref from "underscore"
^"./module.js" // import ref from "./module.js"
^"./module.js"^export // import { export as ref } from "./module.js"
^"./module.js"^* // import * as ref from "./module.js" I'm still not sure I like any of these better than the currently implemented ^module^ // import ref from "module"
^module^.map // import ref from "module"; ref.map
^module^export // import { export as ref } from "module"
^module^* // import * as ref from "module"
^./module.js^ // import ref from "./module.js"
^./module.js^.map // import ref from "./module.js"; ref.map
^./module.js^export // import { export as ref } from "./module.js"
^./module.js^* // import * as ref from "./module.js" |
We could also consider snug Edit: forgot about |
I don't think
|
Fixes #113 (auto imports) by introducing syntax
"module"#export
that turns into aref
resulting fromimport { export as ref } from "module"
.But I'd like some feedback (here or in #113) on whether we have the right syntax here. (It should be easy to change.)
One thing I don't like about this notation is that the default export is rather verbose:
"module"#default
. We can't use"module"#
because that refers tolength
.