Modules vs Scripts

John Barton johnjbarton at google.com
Fri Nov 15 10:32:14 PST 2013


Could someone help me understand why two goals for parsing JS is a good
thing?


On Mon, Nov 11, 2013 at 3:30 PM, John Barton <johnjbarton at google.com> wrote:

> Just a user-experience report with traceur: the following code fails to
> compile in the repl.html and command line compiler:
> -----
> import {WrapNewObjectTransformer} from './WrapNewObjectTransformer';
>
> export function transcode(src, url) {
>     var file = new SourceFile(url, src);
>     var reporter = new ErrorReporter();
>     var tree = new Parser(reporter, file).parseProgram(true);
>     return (new WrapNewObjectTransformer()).transformAny(tree);
> }
> ----
>
> It fails on 'unexpected token export'. This was unexpected by me ;-)
>
> However it does seem consistent with the grammar in
> http://wiki.ecmascript.org/doku.php?id=harmony:modules.  The |export|
> keyword is part of an ExportDeclaration which appears in a ModuleElement
> but not in a ScriptElement. The parser believes it is parsing a Script. So
> the only way to legally parse JS as a Module is as a side-effect of module
> loading?
>
> I suppose that a Script is intended to be the root of the dependency tree,
> so the error message is trying to tell me "You are compiling an interior
> node of the dependency tree silly". But both Script and Module are things
> that JS devs will want to compile. Concretely I will want to be able to
> copy the contents of a JS file and paste it into a repl window to analyze
> it without having it die on syntax errors because it is a module.
>
> hth,
> jjb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131115/a24fb8f3/attachment.html>


More information about the es-discuss mailing list