How to use await with traceur compiler on the fly?

69 views
Skip to first unread message

Danilo Araújo Silva

unread,
Jun 17, 2015, 1:48:31 PM6/17/15
to traceur-comp...@googlegroups.com
This is a clone of this question of mine in StackOverflow.

I'm needing help to configure my browser to work with trace compiler. I have tried of several ways to put a simple async code to work, but with no sucess yet. The code is the following:

    <!DOCTYPE html>
    <html>
    <body>
      <h1 id="message"></h1>
      <script type="module">
        $traceurRuntime.options = traceur.util.Options.experimental();
    console.log("t", traceur, "tr", $traceurRuntime, "tro", $traceurRuntime.options); 
    function changeTest(text) {
      return new Promise().resolve(text+text);
    }
    
    async function run(text) {
      var newText = await encrypt(text);
    }
    
    console.log(run("asdf"));
      </script>
    </body>
    </html>

The traceur compiler link show that it should work is here.

The following error appears:

> ["file:///.../traceur_inline_script_1.js:8:8: Semi-colon expected",
> "file:///.../traceur_inline_script_1.js:9:9: Semi-colon expected"]

The tracerRuntimeOptions looks ok:

    Options {
        arrowFunctions: true,
        blockBinding: true,
        classes: true,
        computedPropertyNames: true,
        defaultParameters: true…
    }
    annotations: true
    arrayComprehension: true
    arrowFunctions: true
    asyncFunctions: true
    asyncGenerators: true
    atscript: (...)
    blockBinding: true
    classes: true
    commentCallback: false
    computedPropertyNames: true
    debug: false
    debugNames: false
    defaultParameters: true
    destructuring: true
    experimental: (...)
    exponentiation: true
    exportFromExtended: true
    forOf: true
    forOn: true
    freeVariableChecker: false
    generatorComprehension: true
    generators: true
    inputSourceMap: false
    lowResolutionSourceMap: false
    memberVariables: true
    moduleName: "default"
    modules: (...)
    modules_: "bootstrap"
    numericLiterals: true
    outputLanguage: "es5"
    parseOptions: Object
    properTailCalls: true
    propertyMethods: true
    propertyNameShorthand: true
    referrer: ""
    require: true
    restParameters: true
    script: false
    sourceMaps: (...)
    sourceMaps_: false
    sourceRoot: false
    sourceRoot_: false
    spread: true
    symbols: true
    templateLiterals: true
    transformOptions: Object
    typeAssertionModule: null
    typeAssertions: false
    types: true
    unicodeEscapeSequences: true
    unicodeExpressions: true
    validate: false
    __proto__: Options


I tried several variations but no sucess yet. Someone can help me to write a working code?

Thanks in advance.

John J Barton

unread,
Jun 17, 2015, 6:51:55 PM6/17/15
to traceur-comp...@googlegroups.com
Sorry but at this time we don't have any way to pass options to the  <script type="module">.  Setting the options within the code won't work: it's too late we've already compiled with code and run it so the options have no affect.

Maybe we can implement something similar to the REPL options.

--
You received this message because you are subscribed to the Google Groups "traceur-compiler-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to traceur-compiler-d...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Danilo Araújo Silva

unread,
Jun 17, 2015, 11:25:13 PM6/17/15
to traceur-comp...@googlegroups.com
Hi John, thanks about the answer.

The truth is I'm interested in user async functions a ES5 browsers (await or yield). And I was trying with traceur.

Can you help me to write a first working code that I can move on? Maybe modifying this one.
I don't bother about the type module, I'm just interested in use await on a browser in a standalone way.

Thanks in advance.
To unsubscribe from this group and stop receiving emails from it, send an email to traceur-compiler-discuss+unsub...@googlegroups.com.

John J Barton

unread,
Jun 18, 2015, 11:03:07 AM6/18/15
to traceur-comp...@googlegroups.com
Two approaches more closely match practical web usage and work with Traceur:

  1) Transcode on the server. Apply Traceur's node-based command to compile the await call into an ES5 file and load that into the browser. This is pretty much the professional solution since most sites want to compress code anyway and they don't want the compiler in the browser.

  2) Dynamic loading. Use System.import() to load ES6 files into the browser. It will look something like this:
  var metadata = {
    traceurOptions: options,
    outputName: filename
  };

  System.import(moduleName, {metadata: metadata}).
    catch(function(err) {
      console.error(err.stack || err + '');
    });
This is the only officially proposed way to load ES6 modules currently, the <script type=module> is still wishful thinking.

To unsubscribe from this group and stop receiving emails from it, send an email to traceur-compiler-d...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "traceur-compiler-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to traceur-compiler-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages