include
Why not:
import {} from 'foo';
or
import * as f from 'foo';
This is assuming that there are no other desired exports -- if there are, then the case is even easier.
Why not: import {} from 'foo'; or import * as f from 'foo'; This is assuming that there are no other desired exports -- if there are, then the case is even easier. Sam On Mon, Jul 14, 2014 at 8:37 PM, John Barton <johnjbarton at google.com> wrote: > In the module system we issue > import {foo} from 'foo'; > and the Loader computes an address, say foo.js, fetches the resource and > compiles it. If the content of foo.js has no dependencies, it is evaluated, > then the importer is evaluated. Yay! > > Now suppose that foo.js defines a global value. Oh bad sure, but sometimes > you have to play cards you are dealt. We still depend upon foo.js, bad or > not bad. > > In the current module system we have to abandon ship. In our importer we > need to: > // WARNING pre-load foo.js somehow! > > Now imagine if we could issue > include 'foo'; > and the Loader computes an address, say foo.js,fetches the resource and > compiles it. Since the content has no dependencies, it is evaluated, then > the importer is evaluated. Yay! > > On now back to preloading somehow, > jjb > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
There is also:
import "foo";
There is also: import "foo"; Yehuda Katz (ph) 718.877.1325 On Mon, Jul 14, 2014 at 6:24 PM, Sam Tobin-Hochstadt <samth at cs.indiana.edu> wrote: > Why not: > > import {} from 'foo'; > > or > > import * as f from 'foo'; > > This is assuming that there are no other desired exports -- if there > are, then the case is even easier. > > Sam > > On Mon, Jul 14, 2014 at 8:37 PM, John Barton <johnjbarton at google.com> > wrote: > > In the module system we issue > > import {foo} from 'foo'; > > and the Loader computes an address, say foo.js, fetches the resource and > > compiles it. If the content of foo.js has no dependencies, it is > evaluated, > > then the importer is evaluated. Yay! > > > > Now suppose that foo.js defines a global value. Oh bad sure, but > sometimes > > you have to play cards you are dealt. We still depend upon foo.js, bad or > > not bad. > > > > In the current module system we have to abandon ship. In our importer we > > need to: > > // WARNING pre-load foo.js somehow! > > > > Now imagine if we could issue > > include 'foo'; > > and the Loader computes an address, say foo.js,fetches the resource and > > compiles it. Since the content has no dependencies, it is evaluated, then > > the importer is evaluated. Yay! > > > > On now back to preloading somehow, > > jjb > > > > _______________________________________________ > > es-discuss mailing list > > es-discuss at mozilla.org > > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140714/1e3b4733/attachment-0001.html>
Sorry, I was imagining a specific scenario without giving the specifics: include 'foo'; // foo is conventional JS, not a module
I have written on global in a module, it works ok, but the goal was specifically to mutate global with code written in a module.
Here I have given code, designed to be loaded with a <script> tag or
included with require() in node. When I try to use say import "foo"; I get things like
SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function.
You could say, "oh this is just legacy code", but boy we've burnt a lot of energy on legacy modules maybe a small bit can be invested in legacy scripts.
jjb
Sorry, I was imagining a specific scenario without giving the specifics: include 'foo'; // foo is conventional JS, not a module I have written on global in a module, it works ok, but the goal was specifically to mutate global with code written in a module. Here I have given code, designed to be loaded with a <script> tag or included with require() in node. When I try to use say import "foo"; I get things like SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function. You could say, "oh this is just legacy code", but boy we've burnt a lot of energy on legacy modules maybe a small bit can be invested in legacy scripts. jjb On Mon, Jul 14, 2014 at 6:39 PM, Yehuda Katz <wycats at gmail.com> wrote: > There is also: > > import "foo"; > > Yehuda Katz > (ph) 718.877.1325 > > > On Mon, Jul 14, 2014 at 6:24 PM, Sam Tobin-Hochstadt <samth at cs.indiana.edu > > wrote: > >> Why not: >> >> import {} from 'foo'; >> >> or >> >> import * as f from 'foo'; >> >> This is assuming that there are no other desired exports -- if there >> are, then the case is even easier. >> >> Sam >> >> On Mon, Jul 14, 2014 at 8:37 PM, John Barton <johnjbarton at google.com> >> wrote: >> > In the module system we issue >> > import {foo} from 'foo'; >> > and the Loader computes an address, say foo.js, fetches the resource and >> > compiles it. If the content of foo.js has no dependencies, it is >> evaluated, >> > then the importer is evaluated. Yay! >> > >> > Now suppose that foo.js defines a global value. Oh bad sure, but >> sometimes >> > you have to play cards you are dealt. We still depend upon foo.js, bad >> or >> > not bad. >> > >> > In the current module system we have to abandon ship. In our importer we >> > need to: >> > // WARNING pre-load foo.js somehow! >> > >> > Now imagine if we could issue >> > include 'foo'; >> > and the Loader computes an address, say foo.js,fetches the resource and >> > compiles it. Since the content has no dependencies, it is evaluated, >> then >> > the importer is evaluated. Yay! >> > >> > On now back to preloading somehow, >> > jjb >> > >> > _______________________________________________ >> > es-discuss mailing list >> > es-discuss at mozilla.org >> > https://mail.mozilla.org/listinfo/es-discuss >> > >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140714/736c9f10/attachment.html>
You could imagine a loader plugin that enabled:
import "legacy:foo";
Which would evaluate the module in a script context.
You could imagine a loader plugin that enabled: import "legacy:foo"; Which would evaluate the module in a script context. Yehuda Katz (ph) 718.877.1325 On Mon, Jul 14, 2014 at 9:20 PM, John Barton <johnjbarton at google.com> wrote: > Sorry, I was imagining a specific scenario without giving the specifics: > include 'foo'; // foo is conventional JS, not a module > > I have written on global in a module, it works ok, but the goal was > specifically to mutate global with code written in a module. > > Here I have given code, designed to be loaded with a <script> tag or > included with require() in node. When I try to use say > import "foo"; > I get things like > > SyntaxError: In strict mode code, functions can only be declared at top > level or immediately within another function. > > You could say, "oh this is just legacy code", but boy we've burnt a lot of > energy on legacy modules maybe a small bit can be invested in legacy > scripts. > > jjb > > > > > On Mon, Jul 14, 2014 at 6:39 PM, Yehuda Katz <wycats at gmail.com> wrote: > >> There is also: >> >> import "foo"; >> >> Yehuda Katz >> (ph) 718.877.1325 >> >> >> On Mon, Jul 14, 2014 at 6:24 PM, Sam Tobin-Hochstadt < >> samth at cs.indiana.edu> wrote: >> >>> Why not: >>> >>> import {} from 'foo'; >>> >>> or >>> >>> import * as f from 'foo'; >>> >>> This is assuming that there are no other desired exports -- if there >>> are, then the case is even easier. >>> >>> Sam >>> >>> On Mon, Jul 14, 2014 at 8:37 PM, John Barton <johnjbarton at google.com> >>> wrote: >>> > In the module system we issue >>> > import {foo} from 'foo'; >>> > and the Loader computes an address, say foo.js, fetches the resource >>> and >>> > compiles it. If the content of foo.js has no dependencies, it is >>> evaluated, >>> > then the importer is evaluated. Yay! >>> > >>> > Now suppose that foo.js defines a global value. Oh bad sure, but >>> sometimes >>> > you have to play cards you are dealt. We still depend upon foo.js, bad >>> or >>> > not bad. >>> > >>> > In the current module system we have to abandon ship. In our importer >>> we >>> > need to: >>> > // WARNING pre-load foo.js somehow! >>> > >>> > Now imagine if we could issue >>> > include 'foo'; >>> > and the Loader computes an address, say foo.js,fetches the resource and >>> > compiles it. Since the content has no dependencies, it is evaluated, >>> then >>> > the importer is evaluated. Yay! >>> > >>> > On now back to preloading somehow, >>> > jjb >>> > >>> > _______________________________________________ >>> > es-discuss mailing list >>> > es-discuss at mozilla.org >>> > https://mail.mozilla.org/listinfo/es-discuss >>> > >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140714/dac8c6d1/attachment-0001.html>
In the module system we issue import {foo} from 'foo'; and the Loader computes an address, say foo.js, fetches the resource and compiles it. If the content of foo.js has no dependencies, it is evaluated, then the importer is evaluated. Yay!
Now suppose that foo.js defines a global value. Oh bad sure, but sometimes you have to play cards you are dealt. We still depend upon foo.js, bad or not bad.
In the current module system we have to abandon ship. In our importer we need to: // WARNING pre-load foo.js somehow!
Now imagine if we could issue include 'foo'; and the Loader computes an address, say foo.js,fetches the resource and compiles it. Since the content has no dependencies, it is evaluated, then the importer is evaluated. Yay!
On now back to preloading somehow, jjb