Convert Figma logo to code with AI

google logotraceur-compiler

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

8,181
580
8,181
293

Top Related Projects

43,160

🐠 Babel is a compiler for writing next generation JavaScript.

100,112

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

37,921

An extremely fast bundler for the web

31,086

Rust-based platform for the Web

43,380

The zero configuration build tool for the web. 📦🚀

25,227

Next-generation ES module bundler

Quick Overview

Traceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to use features from the future of JavaScript today. It is developed by Google and supports many ECMAScript 6 (ES6) features, translating them into equivalent ES5 code that can run in current JavaScript environments.

Pros

  • Enables developers to use future JavaScript features in current projects
  • Provides a smooth transition path for adopting new ECMAScript standards
  • Includes a built-in module system for better code organization
  • Offers both command-line and browser-based compilation options

Cons

  • Some compiled code may be less efficient than hand-written ES5 equivalents
  • Debugging can be challenging as errors may occur in the compiled code
  • Not all ES6+ features are fully supported or implemented
  • Project is no longer actively maintained (last commit was in 2018)

Code Examples

  1. Using arrow functions and template literals:
// ES6 code
const greet = name => `Hello, ${name}!`;
console.log(greet('World'));
  1. Utilizing destructuring and default parameters:
// ES6 code
function printPerson({name, age = 30}) {
  console.log(`${name} is ${age} years old.`);
}
printPerson({name: 'Alice'});
  1. Implementing a class with inheritance:
// ES6 code
class Animal {
  constructor(name) {
    this.name = name;
  }
  speak() {
    console.log(`${this.name} makes a sound.`);
  }
}

class Dog extends Animal {
  speak() {
    console.log(`${this.name} barks.`);
  }
}

const dog = new Dog('Rex');
dog.speak();

Getting Started

To use Traceur in your project:

  1. Install Traceur via npm:

    npm install --save-dev traceur
    
  2. Create a simple ES6 file (e.g., example.js):

    let message = 'Hello, Traceur!';
    console.log(`The message is: ${message}`);
    
  3. Compile the file using Traceur:

    npx traceur --out compiled.js example.js
    
  4. Run the compiled file:

    node compiled.js
    

This will output: "The message is: Hello, Traceur!"

Competitor Comparisons

43,160

🐠 Babel is a compiler for writing next generation JavaScript.

Pros of Babel

  • Wider community support and more frequent updates
  • More extensive plugin ecosystem for customization
  • Better integration with modern build tools and frameworks

Cons of Babel

  • Slightly more complex configuration process
  • Larger bundle size due to polyfills and helpers

Code Comparison

Traceur:

// Traceur compiler options
traceur.options.experimental = true;
traceur.options.jsx = true;

// Compile ES6+ code
var compiled = traceur.compile(source);

Babel:

// Babel configuration
const babelConfig = {
  presets: ['@babel/preset-env'],
  plugins: ['@babel/plugin-transform-react-jsx']
};

// Compile ES6+ code
const compiled = babel.transform(source, babelConfig);

Summary

Both Traceur and Babel are JavaScript compilers that allow developers to use next-generation JavaScript features. Babel has gained more popularity due to its extensive ecosystem and better integration with modern development workflows. However, Traceur may be simpler to set up for basic use cases. The choice between the two depends on project requirements and the desired level of customization.

100,112

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Pros of TypeScript

  • Stronger type system with interfaces, generics, and advanced type inference
  • Better tooling support, including IDE integration and refactoring capabilities
  • Larger community and ecosystem, with more third-party libraries and resources

Cons of TypeScript

  • Steeper learning curve, especially for developers new to static typing
  • Compilation step required, which can slow down development workflow
  • Potential for overuse of types, leading to unnecessarily complex code

Code Comparison

TypeScript:

interface User {
  name: string;
  age: number;
}

function greet(user: User): string {
  return `Hello, ${user.name}! You are ${user.age} years old.`;
}

Traceur:

function greet(user) {
  return `Hello, ${user.name}! You are ${user.age} years old.`;
}

TypeScript provides static typing and interfaces, offering better type checking and documentation. Traceur focuses on transpiling newer JavaScript features to older versions, without adding type annotations.

Both TypeScript and Traceur aim to improve JavaScript development, but TypeScript offers a more comprehensive solution with its type system and tooling support. Traceur is lighter-weight and focuses primarily on enabling the use of newer JavaScript features in older environments.

37,921

An extremely fast bundler for the web

Pros of esbuild

  • Significantly faster build times due to its Go-based implementation
  • Supports modern JavaScript features and TypeScript out of the box
  • Smaller bundle sizes with built-in minification and tree shaking

Cons of esbuild

  • Less mature and may have fewer plugins available compared to Traceur
  • Limited configuration options, which can be restrictive for complex setups
  • Lacks some advanced features like polyfilling and certain code transformations

Code Comparison

esbuild:

import * as esbuild from 'esbuild'

await esbuild.build({
  entryPoints: ['app.js'],
  bundle: true,
  outfile: 'out.js',
})

Traceur:

var traceur = require('traceur');
var compiler = new traceur.Compiler();

var source = 'class Example { method() {} }';
var result = compiler.compile(source);

esbuild focuses on simplicity and speed, offering a straightforward API for bundling and transforming JavaScript. Traceur, on the other hand, provides more granular control over the compilation process and supports a wider range of ECMAScript features.

While esbuild excels in performance and modern language support, Traceur offers more flexibility for complex transformations and polyfilling. The choice between the two depends on project requirements, build performance needs, and the desired level of control over the compilation process.

31,086

Rust-based platform for the Web

Pros of swc

  • Significantly faster compilation speeds due to Rust implementation
  • Broader language support, including TypeScript and JSX
  • More actively maintained with frequent updates

Cons of swc

  • Less mature and potentially less stable than Traceur
  • Smaller community and ecosystem compared to Traceur
  • May have fewer advanced features for experimental JavaScript proposals

Code Comparison

swc:

use swc_ecma_parser::Syntax;
use swc_ecma_transforms_base::resolver;

let output = swc::transform_file(
    "input.js",
    &swc::config::Options::default()
)?;

Traceur:

var traceur = require('traceur');
var compiler = new traceur.Compiler();

var result = compiler.compile(content);

Summary

swc is a newer, faster JavaScript/TypeScript compiler written in Rust, offering broader language support and active development. However, it may be less mature and have a smaller ecosystem compared to Traceur. Traceur, developed by Google, has been around longer and may be more stable, but it's less actively maintained and slower in compilation speed. The choice between the two depends on specific project requirements, performance needs, and desired language features.

43,380

The zero configuration build tool for the web. 📦🚀

Pros of Parcel

  • Zero configuration bundling, making it easier to set up and use
  • Faster build times due to multicore processing and caching
  • Built-in support for various file types and assets without additional plugins

Cons of Parcel

  • Less flexibility and customization options compared to Traceur
  • Larger bundle sizes in some cases
  • Relatively newer project with potentially fewer community resources

Code Comparison

Traceur (ES6 to ES5 compilation):

// Input
let x = 1;
const y = 2;
console.log(`${x} + ${y} = ${x + y}`);

// Output
var x = 1;
var y = 2;
console.log(x + " + " + y + " = " + (x + y));

Parcel (bundling and transformation):

// Input (index.js)
import { sum } from './math.js';
console.log(sum(1, 2));

// Output (bundled)
(function() {
  function sum(a, b) { return a + b; }
  console.log(sum(1, 2));
})();

Summary

Traceur is primarily a JavaScript compiler focused on transforming newer ECMAScript features to older versions, while Parcel is a more comprehensive bundler that handles various asset types and provides an all-in-one solution for web projects. Traceur offers more granular control over JavaScript transformations, whereas Parcel aims for simplicity and ease of use with its zero-configuration approach.

25,227

Next-generation ES module bundler

Pros of Rollup

  • Focuses on ES modules and tree-shaking, resulting in smaller bundle sizes
  • Simpler configuration and faster build times
  • Better suited for library authors and modern JavaScript projects

Cons of Rollup

  • Less comprehensive language feature support compared to Traceur
  • May require additional plugins for certain transformations
  • Not as well-suited for complex application builds with many dependencies

Code Comparison

Traceur:

// Traceur compilation
traceur.compile(content, {
  modules: 'commonjs',
  experimental: true,
  sourceMaps: 'inline'
});

Rollup:

// Rollup configuration
export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  }
};

Traceur is a more comprehensive JavaScript-to-JavaScript compiler that supports a wide range of ECMAScript features, including experimental ones. It's designed to allow developers to use future JavaScript features in current environments.

Rollup, on the other hand, is primarily a module bundler that excels at creating efficient bundles for libraries and applications using ES modules. It focuses on tree-shaking and producing smaller, more optimized output.

While Traceur offers broader language feature support, Rollup provides a more streamlined experience for modern JavaScript development, particularly when working with ES modules and aiming for smaller bundle sizes.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.

NPM DownloadsLast 30 Days