Re: Re: Inline ES Modules
I actually quite like the idea. - Extend the import syntax to allow an identifier instead of a string. Such identifier must be match the name of a module declaration the same file (they are hoisted and a syntax error if not present/something else). - Module declaration names are abstracts since they are "exposed" in the scope through an import. - Module declarations only allowed on the global level (like import/export declarations) - Maybe in the future modules could refer to their name identifier to access meta data. - Module bodies are for all intentions and purposes treated as if they were independent js module files - Module identifiers are hoisted Bonus points for making the end token easier to scan for (realistically speaking I'm pretty sure a regular block is preferred). This could help browsers parse large bundle files by fast scanning past module blocks. ``` import foo from bar; module bar {# log('I'm a module!'); #} ``` The downside to inline modules is that I'm not sure whether this has more real use beyond webpack/metro/rollup/etc bundlers that put all modules in one bundle file. However, that might still help js envs in some way. This kind of thing wouldn't need to be a huge tax on the spec by reusing existing semantics. - peter On Mon, Jun 18, 2018 at 11:10 PM, Darien Valentine wrote: > ``` > import getPersonType from 'data:text/javascript,\ > export default function getPersonType(person) {\ > switch (person) {\ > case \'Teacher\': return \'A teacher\';\ > case \'Director\': return \'A director\';\ > }\ > }'; > ``` > > okay, not a serious suggestion, but it does technically work :) > > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Re: Inline ES Modules
``` import getPersonType from 'data:text/javascript,\ export default function getPersonType(person) {\ switch (person) {\ case \'Teacher\': return \'A teacher\';\ case \'Director\': return \'A director\';\ }\ }'; ``` okay, not a serious suggestion, but it does technically work :) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Inline ES Modules
How would an inline module be imported? Module descriptors are roughly relative URLs so can refer to a JavaScript source file, but it sounds like you'd need something more fine-grained to refer to an inline module. Using fragments to refer to a passage within a document instead of a location might have unintended effects. Also, assuming that problem is solved, does the below mean anything if (Math.random() < 0.5) { module School { export function getPersonType() {} } } If not, if inline modules are defined eagerly, what advantages, besides making life easier for transpiler writers, would inline modules have over exporting frozen namespaces? On Sun, Jun 17, 2018 at 10:34 AM Sultan wrote: > Are there any open proposals/discussions related to creating ES modules > inline? For example: > > ``` > import getPersonType from School > > module School { > export function getPersonType (person) { > switch (person) { > case 'Teacher': return 'A teacher' > case 'Director': return 'A director' > } > } > } > ``` > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss