Traceur is a JavaScript.next-to-JavaScript-of-today compiler

Related tags

ES6 traceur-compiler
Overview

Join the chat at https://gitter.im/google/traceur-compiler Build Status

Traceur logo

What is Traceur?

Traceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to use features from the future today. Traceur supports ES6 as well as some experimental ES.next features.

Traceur's goal is to inform the design of new JavaScript features which are only valuable if they allow you to write better code. Traceur allows you to try out new and proposed language features today, helping you say what you mean in your code while informing the standards process.

JavaScript's evolution needs your input. Try out the new language features. Tell us how they work for you and what's still causing you to use more boilerplate and "design patterns" than you prefer.

What now? What can Traceur do for me?

Read the Getting Started page to get up and running. You can use some language features right now and even try it out in your browser here. Just type in some code and see what Traceur produces. For an idea of what is available and what we have in the pipeline, see the Language Features page.

The JSConf 2011 presentation of Traceur describes the goals of the project and what it can do today. Some documentation is on the wiki on this site. Extra demos are in the source repository.

We also presented Traceur at NodeConf 2011. The video is available on YouTube.

Questions, suggestions, and comments can be directed to the discussion group.

Comments
  • Proposal for a more performant module output

    Proposal for a more performant module output

    https://gist.github.com/matthewrobb/98bac8c935e606e1a7a5

    The simple idea is that if we can optimize the performance around get access to imports (which should be overwhelmingly the more common case) then we can sacrifice a little on initialization/memory and accept that setting is going to be slower.

    opened by matthewrobb 64
  • A new bundling target

    A new bundling target

    Writing a bundling system for SystemJS (https://github.com/systemjs/systemjs/blob/master/lib/system-bundles.js), the workflow I converged on was to define modules within bundles the following way:

      import { p } from 'q';
      export var s = 't';
    

    ->

      System.defined['module-name'] = {
        deps: ['q'],
        execute: function() {
          var q = System.get(arguments[0]);
          return Module({
            s: 't'
          });
        }
      };
    

    This was the simplest possible bundling mechanism, because then the instantiate function looks like:

      System.instantiate = function(load) {
        if (System.defined[load.name]) {
          var instantiateResult = System.defined[load.name];
          delete System.defined[load.name];
          return instantiateResult;
        }
      }
    

    I was wondering if Traceur would consider an output like this? For now, I'm trying to support the current $traceurRuntime.ModuleStore.registerModule and $traceurRuntime.getModuleImpl functions within ESML to avoid a custom transformer, hence this suggestion.

    opened by guybedford 49
  • Creating a Transformer

    Creating a Transformer

    I'm looking to create a transformer as part of converting module syntax to being parsed by Traceur for the ES6 Module Loader.

    The transformations are:

    Import Syntax

      import { a as b, c } from 'jquery';
    

    ->

      var b = __Loader.get('jquery')['a'];
      var c = __Loader.get('jquery')['c'];
    

    Export Syntax

      export { a as b, c };
    

    ->

      __exports['b'] = a;
      __exports['c'] = c;
    

    Export Variables / Functions

      export var p = 5;
    

    ->

      var p = 5;
      __exports['p'] = p;
    

    Can I directly modify the syntax tree after Traceur transformations to do further transformation?

    I also have no idea how to start constructing a modified syntax tree for the above.

    The code branch I've been working on is here: https://github.com/ModuleLoader/es6-module-loader/blob/traceur/lib/es6-module-loader.js#L689

    That exact line is where I would want to start doing transformations instead of getting the source directly.

    This way I could remove the code that has been based on string-based transforms up until now.

    Any tips would be really appreciated.

    opened by guybedford 48
  • Node API: add options parameter to require.makeDefault()

    Node API: add options parameter to require.makeDefault()

    Closes #1162.

    I've signed the CLA using my email ( ultcombo [\at] gmail {!dot!} com )

    I'm unsure how to properly add a test for require.makeDefault(), as there is no way to "resetDefault()". Should we create a method for that as well?

    opened by UltCombo 40
  • A for-of loop that exits prematurely should close its iterator

    A for-of loop that exits prematurely should close its iterator

    By https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-forin-div-ofbodyevaluation, a for-of-loop's iterator shall be closed when execution control breaks out of the for-of-loop.

    The test proves that traceur currently does not handle this problem properly.

    I'll see whether I can come up with a solution in the next days.

    opened by mnieper 33
  • Support circular dependency in System.register() under modules='instantiate' option

    Support circular dependency in System.register() under modules='instantiate' option

    Uses two-phase declaration / execution process to separate dependency binding from execution.

    Includes https://github.com/ModuleLoader/es6-module-loader.git as third-party/, License MIT, for testing circular references. Adds tests for loading with circular references.

    Closes #971, #953, #424, #107

    opened by guybedford 33
  • AMD and ES6 interop support

    AMD and ES6 interop support

    Under modules=amd, mark modules with property '__esModule', and treat all other modules as default exports to allow mixing ES6 and AMD modules under both ES6 and AMD loaders.

    opened by guybedford 33
  • Need relative paths in source map

    Need relative paths in source map

    Hi, is there anyway to generate source map without the aboslute path in the file field and without the sourceRoot field?

    $ traceur --source-maps file --out project.js main.js 
    $ cat project.map | jq .
    {
      "sourcesContent": [
        "System.registerModule($__placeholder__0, [], $__placeholder__1);",
        "function() {\n        $__placeholder__0\n      }",
        "var __moduleName = $__placeholder__0;",
        "var $__placeholder__0 = $__placeholder__1",
        "class Foo {\n  static hello() {\n    return 'Oh, hi!';\n  }\n}\n\nexport default Foo;\n",
        "($traceurRuntime.createClass)($__placeholder__0, $__placeholder__1, $__placeholder__2)",
        "var $__default = $__placeholder__0",
        "return $__placeholder__0",
        "get $__placeholder__0() { return $__placeholder__1; }",
        "import Foo from 'lib/foo';\n\nconsole.log(Foo.hello());\n",
        "System.get($__placeholder__0)",
        "System.get($__placeholder__0 +'')"
      ],
      "sourceRoot": "/tmp/project/",
      "file": "/tmp/project/project.js",
      "mappings": "AAAA,KAAK,eAAe,AAAC,WAAoB,GAAC,CCA1C,UAAS,AAAD;;ACAR,AAAI,IAAA,CAAA,YAAW,YAAoB,CAAC;ACApC,AAAI,IAAA,MCAJ,SAAM,IAAE,KAIR,ADJwC,CAAA;AEAxC,EAAC,eAAc,YAAY,CAAC,AAAC,WDCpB,KAAI,CAAX,UAAa,AAAD,CAAG;AACb,WAAO,UAAQ,CAAC;IAClB,ECHmF;ACArF,AAAI,IAAA,CAAA,UAAS,EFME,IAAE,AENgB,CAAA;ACAjC,SCAA,aAAwB;AAAE,uBAAwB;IAAE,EDA7B;ANEjB,CDFwD,CAAC;AAA/D,KAAK,eAAe,AAAC,WAAoB,GAAC,CCA1C,UAAS,AAAD;;ACAR,AAAI,IAAA,CAAA,YAAW,YAAoB,CAAC;IOA7B,IAAE,ECAT,CAAA,MAAK,IAAI,AAAC,WAAkB;ADE5B,QAAM,IAAI,AAAC,CAAC,GAAE,MAAM,AAAC,EAAC,CAAC,CAAC;AFFxB,WAAuB;ANEjB,CDFwD,CAAC;AWA/D,KAAK,IAAI,AAAC,CAAC,WAAmB,GAAC,CAAC,CAAA",
      "names": [],
      "sources": [
        "@traceur/generated/TemplateParser/6",
        "@traceur/generated/TemplateParser/5",
        "@traceur/generated/TemplateParser/4",
        "@traceur/generated/TemplateParser/7",
        "lib/foo.js",
        "@traceur/generated/TemplateParser/8",
        "@traceur/generated/TemplateParser/1",
        "@traceur/generated/TemplateParser/3",
        "@traceur/generated/TemplateParser/2",
        "main.js",
        "@traceur/generated/TemplateParser/9",
        "@traceur/generated/TemplateParser/10"
      ],
      "version": 3
    }
    

    Are there any cases when full path to project's directory is needed inside sourceRoot?

    I've tried some hacking, but no luck so far except breaking tests and sourcesContent field :)

    opened by mk0x9 32
  • Is the language features doc up to date?

    Is the language features doc up to date?

    https://github.com/google/traceur-compiler/wiki/LanguageFeatures

    E.g. it uses a non-standard iterator protocol.

    Mostly I am looking for a list of what Traceur flags are enabled by default and, if possible, how up-to-spec those flags are.

    opened by domenic 32
  • Uncaught ReferenceError: require is not defined

    Uncaught ReferenceError: require is not defined

    I'm trying to get ES6 modules working with pre-compiled files in the browser, and I'm getting this error:

    Uncaught ReferenceError: require is not defined
    

    On this line (generated by traceur):

    var Star = $traceurRuntime.assertObject(require('star')).Star;
    

    I'm compiling all my modules with modules='register', and my main script (the one I'm getting this error on) with modules='commonjs' (because using register means it never gets executed).

    Is this a bug? Or am I just doing something wrong?

    opened by Ajedi32 31
  • Implement proper tail calls.

    Implement proper tail calls.

    The following PR implements proper tail calls as demanded by ES6. The are behind the new experimental flag --proper-tail-calls. (Experimental because it necessarily reduces performance of the generated code.)

    This probably makes Traceur the first transpiler properly supporting tail calls!

    Each function that contains calls in tail position is rewritten. All tests pass with proper tail calls enabled by default. Traceur itself compiled with --proper-tail-calls true also works as expected.

    At the moment, the transformer does not touch arrow functions, class declarations and class expressions (so they should be transpiled if their are supposed to be properly tail recursive). Likewise, template literals in tail position are currently not touched, so the corresponding transpilation should be enabled as well.

    The changes to runtime.js are far less worse than what the diff shows. I had to wrap most of that code into an extra IIFE and the additional two spaces at the beginning of each line cause the diffs.

    It is left as a TODO to check all other transformers that they do not convert tail calls in non tail calls.

    Please review this PR; it's hopefully ready to merge.

    opened by mnieper 30
  • Failed to construct classes with 'HTMLElement' as super

    Failed to construct classes with 'HTMLElement' as super

    Traceur transpiled code is looking like this:

    var e,r=customElements,n=(e=HTMLElement,$traceurRuntime.createClass((function e(){$traceurRuntime.superConstructor(e).call(this),this.style="color: red;"}),{},{},e));
    

    From:

    class Foo extends HTMLElement {
      constructor() { super();
        this.style = 'color: red;';
      }
    };
    

    And results:

    Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
    

    Where this statement fails (the this object is a HTMLElement instance):

    $traceurRuntime.superConstructor(e).call(this)
    
    opened by duzy 0
  • Code review contributions in Github

    Code review contributions in Github

    This is a basic question, but... what counts as "code review" in the contribution graph in Github? Is it making comments on code or committing to code? I don't really understand the concept.

    opened by AtomicNess123 0
  • Path Manipulation in writeFile

    Path Manipulation in writeFile

    The filename argument passed to the writeFile() function in file-util.js may be manipulated to write arbitrary directories on the filesystem. The writeFile() function attempts to sanitize the untrusted filename, but calls the mkdirRecursive() function on the untrusted filename before the filename is sanitized (https://github.com/google/traceur-compiler/blob/master/src/node/file-util.js#L56)

    For example, passing the filename "../test/target.txt" on a *nix system will create the directory "test" in the parent directory. An attacker can use the dot-dot-slash path manipulation technique to create directories anywhere on the filesystem.

    function writeFile(filename, contents) {
      // Compute the output path
      var outputdir = fs.realpathSync(process.cwd());
      mkdirRecursive(path.dirname(filename));
      var filedir = fs.realpathSync(path.dirname(filename));
      filedir = removeCommonPrefix(outputdir, filedir);
      outputdir = path.join(outputdir, filedir);
    
      mkdirRecursive(outputdir);
      var outputfile = path.join(outputdir, path.basename(filename));
      fs.writeFileSync(outputfile, contents, 'utf8');
    }
    
    opened by dbohannon 3
  • Rihno version 1_7R2 - getting error Object.defineProperty

    Rihno version 1_7R2 - getting error Object.defineProperty

    Hi All

    we are upgrading to jQuery version 3.2.1 We have Rihno version 1_7R2 and we are getting error Object.defineProperty is not a function. I tried other new version of Rihno but nothing worked.

    The reason may be Object.defineProperty is defined in JS 1.8 and rihno is in JS 1.7

    can anyone of you help me to solve this ?

    opened by techhounds2015 3
  • Chrome 61 now supports ES6 Modules by default

    Chrome 61 now supports ES6 Modules by default

    When Chrome 61 sees a <script type="module"...> tag, it will interpret is as an ES6 module. Is there any way to detect this at run-time to prevent Traceur doing transpilation when we don't need it to?

    opened by codedread 2
Releases(0.0.111)
  • 0.0.111(Jun 9, 2016)

  • 0.0.110(May 24, 2016)

  • 0.0.109(May 24, 2016)

    • CJS: Module exports should be enumerable
    • Top level this in modules should be undefined
    • Allow the runtime to be imported as modules using --import-runtime
    Source code(tar.gz)
    Source code(zip)
  • 0.0.108(Apr 23, 2016)

  • 0.0.107(Apr 23, 2016)

    • bin/BrowserSystem.js includes compiler, polyfills, System, and WebPageTranscoder. Read traceurOptions attribute from <script type=module traceurOptions="--asyncFunctions">.
    Source code(tar.gz)
    Source code(zip)
  • 0.0.106(Apr 7, 2016)

  • 0.0.105(Apr 2, 2016)

    • Fix issue where we did not allow declarations to shadow the function expression name.
    • Implement Spread Properties. This add support for ... in object literals which is currently at stage 2.
    var x = {a: 1};
    var y = {...a, b: 2};  // {a: 1, b: 2}
    
    • JSX: Fix assignment expression parsing in place holders.
    • JSX: Fix whitespace and escaping of attribute values.
    Source code(tar.gz)
    Source code(zip)
  • 0.0.104(Apr 2, 2016)

  • 0.0.103(Apr 2, 2016)

    • Move runtime into modules. This is in preparation for allowing importing the runtime as modules in the future.
    • JSX: Tag name starting with an uppercase should use identifier. <Abc/> should generate React.createElement(Abc, null) and not React.createElement('Abc', null).
    • JSX: Support boolean shorthand attributes. <a b/> is short for <a b={true}/>.
    • JSX: Add support for JSXSpreadAttribute. This allows spreading an object into props/attributes:
    <p a='a' {...{b: 1, c: 2}}/>
    // same as (except the expansion happens at runtime)
    <p a='a' b={1} c={2}/>
    
    • Update commander and glob dependencies.
    Source code(tar.gz)
    Source code(zip)
  • 0.0.102(Apr 2, 2016)

  • 0.0.101(Apr 2, 2016)

    • Make sure we do not clobber a pre existing System object.
    • Use a context argument in System.register
    • Add commonjs versions of the src in dist/commonjs/. This making reusing core Traceur modules easier from projects such as es module loader:
    require('traceur/bin/traceur-runtime.js');
    var Parser = require('traceur/dist/commonjs/syntax/Parser.js').Parser;
    ...
    
    Source code(tar.gz)
    Source code(zip)
  • 0.0.94(Apr 2, 2016)

    • Lots of refactoring related to traceur runtime.
    • Add support for import type and make sure the import/export validation works.
    • Implement __moduleName second argument to System.register.
    Source code(tar.gz)
    Source code(zip)
  • 0.0.93(Apr 2, 2016)

    • Add support for TypeAliasDeclaration. This adds support for TypeScript/Flow's type alias declaration:
    type NumberArray = Array<number>;
    
    • Basic JSX parsing support. The option to turn this on is called jsx. You can provide your own function to call by setting this option to a string. --jsx=my.func. If not set it defaults to React.createElement.
    • Remove type-assertions option. It was never fully implemented...
    • Add --modules=parse output option. This allows outputting ES6 module syntax.
    • Basic polyfill for WeakMap/WeakSet.
    • Support IdentifierName in extended export. The following is now valid:
    // Options: --export-from-extended
    export new from './file.js';
    
    • Fix issue where we added initializers to for in vars.
    • Only conditionally override Object.keys and Object.getOwnPropertyNames if there is no native support for Symbol.
    Source code(tar.gz)
    Source code(zip)
  • 0.0.92(Apr 2, 2016)

    • Fix issue with regular expressions. Regular expressions starting with /=* was not parsed correctly.
    • Fix arrow functions in derived class constructors
    Source code(tar.gz)
    Source code(zip)
  • 0.0.91(Jul 19, 2015)

    • Add tool for printing dependencies
    • Improve performance for bulk exports when using --modules=instantiate
    • Add super support to object literals
    • Fix issue with parens and arrow functions (#1962)
    • Fix issue with let/const in while/do-while (#1970)
    • Remove extra use strict directive from modules (#1973)
    • Renamed some AST class names. See commits for details.
    Source code(tar.gz)
    Source code(zip)
Owner
Google
Google ❤️ Open Source
Google
Basic Javascript Cheat Sheet

Comments Examples // This is an in-line comment. /* This is a multi-line comment */ Data types Basics JavaScript provides seven different data types:

wilfredinni 370 Dec 26, 2022
JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

Rajkumar Dusad 36 Jan 5, 2023
🐠 Babel is a compiler for writing next generation JavaScript.

The compiler for writing next generation JavaScript. Supporting Babel Babel (pronounced "babble") is a community-driven project used by many companies

Babel 41.8k Jan 9, 2023
🐠 Babel is a compiler for writing next generation JavaScript.

The compiler for writing next generation JavaScript. Supporting Babel Babel (pronounced "babble") is a community-driven project used by many companies

Babel 41.8k Jan 8, 2023
Tiny JavaScript library (1kB) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Zero dependency tiny JavaScript library (1kB bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Yurii De 11 Nov 8, 2022
Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement track in new Skill.

NodeJs Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement t

Rahul Bhati 4 Oct 14, 2022
A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

A free and open source resume builder. Go to App What is this app all about? Reactive Resume is a free and open source resume builder that’s built to

Reactive Resume 9.7k Jan 3, 2023
The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day today activies. Check out the live demo.

Todo List App The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day toda

Atugonza ( Billions ) Joel 14 Apr 22, 2022
Easily open daily notes for today in new tab, and much more!

Obsidian daily notes new tab This plugin adds a command for opening daily notes in a new tab (so that a keyboard shortcut could be used!) and gives ex

Xiao Meng 16 Dec 26, 2022
A slack bot that tell's if you and your team should deploy today

Deploy-bot-slack A slack bot developed with node.js that tell's if you and your team should deploy today in your #general slack channel. Setup Install

Eusébio Silva 1 Jul 5, 2022
Migrate unfinished tasks to today, Logseq plugin

Unfinished-business Unfinished Business Because the day may be over, but your business isn't View Demo · Report Bug · Request Feature This plugin migr

Alex 23 Nov 16, 2022
A minimalistic card for Home Assistant Lovelace UI which shows how many days it has been between any input_datetime and today.

Datetime Card A minimalistic card for Home Assistant Lovelace UI which shows how many days it has been between any input_datetime and today. Useful to

Antonino Piazza 12 Aug 12, 2022
The best book finder app you'll see on the internet today😉

Updating Booksy's Docs...please be patient. yarn build Builds the app for production to the build folder. It correctly bundles React in production mod

Temidayo Falomo 3 Jul 7, 2022
Create or open note of today or selected date.

Joplin Plugin - Journal Create or open note of today or selected date. This plugin will create hierarchy folder for you. Manual Click menu Tools -> Jo

leen 11 Jan 2, 2023
An esbuild plugin to inject your application's version number or today's date into your files

esbuild-plugin-version-injector An esbuild plugin to inject your application's version number or today's date into your files This plugin was inspired

Favware 6 Dec 6, 2022
Javascript version of the Move language compiler, supports compiling Move code into Move bytecode in the browser.

move-js Javascript version of the move language compiler, supports compiling Move code into move bytecode in the browser. Features Compiling move pack

Starcoin 13 Dec 20, 2022
Frontend compiler, inspired by Svelte

Malina.js Malina.js builds your web-application to use it without framework on frontend side. Therefore your web-app becomes thinner and faster, and t

Malina.js 1.1k Dec 29, 2022
A compiler that converts React-compatible codes to VanillaJS with no Virtual DOM

Vidact Vidact compiles your React source codes to VanillaJS code with No Virtual DOM ™️ . It is similar to Svelte, but unlike Svelte, Vidact does not

Mohamad Mohebifar 753 Dec 22, 2022
A Web Component compiler for building fast, reusable UI components and static site generated Progressive Web Apps

Stencil: A Compiler for Web Components and PWAs npm init stencil Stencil is a simple compiler for generating Web Components and static site generated

Ionic 11.3k Jan 4, 2023
A compiler for the Mustache templating language

Hogan.js - A mustache compiler. Hogan.js is a compiler for the Mustache templating language. For information on Mustache, see the manpage and the spec

Twitter 5.1k Jan 2, 2023