npm babel-traverse 6.19.0
v6.19.0

latest releases: 7.0.0-beta.3, 7.0.0-beta.2, 7.0.0-beta.1...
8 years ago

v6.19.0 (2016-11-16)

🚀 New Feature

  • babel-plugin-transform-object-rest-spread
    • #4755 Make the plugin work standalone with parameters/destructuring plugins. (@hzoo)

This rewrite fixes a long standing issue where the object-rest-spread plugin was depending on 2 other plugins to compile RestProperty. This is important given the assumption that plugins should be independent and is vital for the use of babel-preset-env since new environments support destructuring natively.

RestProperty

  • Parameters
function a({ b, ...c }) {}
  • VariableDeclaration
const { a, ...b } = c;
  • ExportNamedDeclaration
export var { a, ...b } = c;
  • CatchClause
try {} catch ({a, ...b}) {}
  • AssignmentExpression
({a, ...b} = c);
  • ForXStatement
for ({a, ...b} of []) {}

SpreadProperty

  • ObjectExpression
var a = { ...b, ...c }
  • babel-plugin-transform-class-properties
    • #4544 Greater spec compliance for class properties with the new spec option. (@motiz88)

Usage

{
  "plugins": [
    ["transform-class-properties", {
      "spec": true
    }]
  ]
}
  • Class properties are compiled to use Object.defineProperty
  • Static fields are now defined even if they are not initialized

In

class Foo {
  static bar;
}

Out

var Foo = function Foo() {
  babelHelpers.classCallCheck(this, Foo);
};

Object.defineProperty(Foo, "bar", {
  enumerable: true,
  writable: true,
  value: undefined
});
  • babel-traverse

We've added 2 similar "ancestry" path methods to path.findParent:

path.isAncestor/path.isDescenant

Usage:

let programPath, numberPath;
traverse(ast, {
  Program(path) { programPath = path; },
  NumberPath(path) { numberPath = path; },
});

programPath.isAncestor(numberPath); // true
numberPath.isDescendant(programPath); // true
  • #4835 Add clearCache and clearPath as separate APIs under traverse. (@boopathi)

Usage:

traverse.clearCache(); // clears both path's and scope cache
traverse.clearCache.clearPath();
traverse.clearCache.clearScope();
  • babel-generator
    • #4827 Add jsonCompatibleStrings option to generator. (@kangax)

Usage:

{
  "generatorOpts": {
    "jsonCompatibleStrings": true // defaults to false
  }
}

Set to true for the generator to use jsesc with "json": true. This will make it print "\u00A9" vs. "©";

Usage:

{
  "generatorOpts": {
    "flowCommaSeparator": true // defaults to false
  }
}

Currently there are 2 supported syntaxes (, and ;) in Flow Object Types. The use of commas is in line with the more popular style and matches how objects are defined in Javascript, making it a bit more natural to write.

var a: { param1: number; param2: string }
var a: { param1: number, param2: string }
  • babel-types
    • #3553 Start babel-types tests, add isNodesEquivalent. (@hzoo)

t.isNodesEquivalent

Usage:

assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+1")) === true);
  • babel-plugin-transform-es2015-modules-systemjs
    • #4789 Support import() as contextual import in system module format. (@guybedford)

Support stage-2 import() in systemjs.

It does not compile by default; you'll want to add the stage-2 preset or explicitly include babel-plugin-syntax-dynamic-import.

export function lazyLoadOperation () {
  return import('./x')
  .then(function (x) {
    x.y();
  });
}

🐛 Bug Fix

  • babel-generator

Will print the shorter of the NumericLiterals if using the minified option.

Input

5e1;
5e4;

Output

50;
5e4;
  • babel-plugin-transform-es2015-modules-systemjs
    • #4832 Fix system transformer to ensure consistent modules iteration. (@guybedford)

Fixes inconsistent modules iteration for numeric imports

import "2"; // should be imported first
import "1"; // second
  • babel-plugin-transform-es2015-destructuring, babel-plugin-transform-react-constant-elements
    • #4813 Fix binding kind of destructured variables.. (@STRML)

Fixes an issue with destructuring parameters being hoisted incorrectly.

Input

function render({ text }) {
  return () => (<Component text={text} />);
}

Output

function render(_ref) {
  let text = _ref.text;
  var _ref2 = <Component text={text} />;
  return () => _ref2;
}

📝 Documentation

🏠 Internal

  • babel-plugin-transform-async-to-generator
  • Other
    • #4807 Chore: FLOW command in makefile and logic in .travis.yml(issue#4710).. (@sstern6)

Committers: 10

Don't miss a new babel-traverse release

NewReleases is sending notifications on new releases.