Giter Site home page Giter Site logo

inside-babel-stages's Introduction

The aim of this page is to provide information (at least the ES proposal) around babel plugins, all in one page to avoid going back and forth in Babel documentation and ES propoals and specs. It's grouped by stages so you know what you have when you use babel stages.

I usually don't use Babel stages as I don't use all the features of all stages, I include the plugins of the features I want, it makes my npm install quicker and small and it helps tracking which feature I have.

It's interesting as I think that most people don't need stage 0 and there are some stage 0 proposals like function bind that I've never heard of and I've never seen a tutorial about them.

If you have useful links about each feature, open a PR or an issue.

// from https://gist.github.com/DmitrySoshnikov/de4727f57c5acc17e9469d1a91743125

let x = 10;

let a = do {
  if (x == 10) {
    100;
  } else if (x > 10) {
    200;
  } else {
    300;
  }
};

console.log(a); // Prints '100'
// from https://babeljs.io/blog/2015/05/14/function-bind

import { map, takeWhile, forEach } from "iterlib";

getPlayers()
::map(x => x.character())
::takeWhile(x => x.strength > 100)
::forEach(x => console.log(x));

// equivalent

import { map, takeWhile, forEach } from "iterlib";

let _val;
_val = getPlayers();
_val = map.call(_val, x => x.character());
_val = takeWhile.call(_val, x => x.strength > 100);
_val = forEach.call(_val, x => console.log(x));
// from http://www.2ality.com/2015/10/call-constructor-esprop.html

class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
  call constructor(x, y) {
    return new Point(x, y);
  }
}

let p1 = new Point(1, 2); // OK
let p2 = Point(3, 4); // OK
// from https://github.com/jeffmo/es-class-fields-and-static-properties

class MyClass {
  myProp = 42;
  static myStaticProp = 21;

  constructor() {
    console.log(this.myProp); // Prints '42'
    console.log(MyClass.myStaticProp); // Prints '21'
  }
}
// from https://github.com/wycats/javascript-decorators/blob/master/README.md

// Simple class decorator
@annotation
class MyClass { }

function annotation(target) {
   target.annotated = true;
}

// Class decorator
@isTestable(true)
class MyClass { }

function isTestable(value) {
   return function decorator(target) {
      target.isTestable = value;
   }
}

// Function decorator
class C {
  @enumerable(false)
  method() { }
}

function enumerable(value) {
  return function (target, key, descriptor) {
     descriptor.enumerable = value;
     return descriptor;
  }
}
// from https://github.com/leebyron/ecmascript-more-export-from

export * as ns from "mod";
export v from "mod";
// from https://github.com/jeffmo/es-trailing-function-commas

function clownPuppiesEverywhere(
  param1,
  param2, // Next parameter that's added only has to add a new line, not modify this line
) { /* ... */ }
 
clownPuppiesEverywhere(
  'foo',
  'bar',
);
// from https://github.com/sebmarkbage/ecmascript-rest-spread

// Rest properties
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }

// Spread properties
let n = { x, y, ...z };
n; // { x: 1, y: 2, a: 3, b: 4 }
// from http://babeljs.io/docs/plugins/transform-async-to-generator/

async function foo() {
  await bar();
}

// equivalent
var _asyncToGenerator = function (fn) {
  ...
};
var foo = _asyncToGenerator(function* () {
  yield bar();
});
// from https://github.com/rwaldron/exponentiation-operator

// x ** y

let squared = 2 ** 2;
// same as: 2 * 2

let cubed = 2 ** 3;
// same as: 2 * 2 * 2


// x **= y

let a = 2;
a **= 2;
// same as: a = a * a;

let b = 3;
b **= 3;
// same as: b = b * b * b;

inside-babel-stages's People

Contributors

adriantoine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

inside-babel-stages's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.