Merge branch 'development'

This commit is contained in:
Sebastian McKenzie 2015-11-10 14:26:48 -08:00
commit 482e4229db
7 changed files with 47 additions and 18 deletions

View File

@ -0,0 +1,5 @@
var buildCodeFrame = require("..");
suite("babel-code-frame", function () {
});

View File

@ -73,8 +73,26 @@ function buildVar(namespace, builder) {
}
function buildHelpers(body, namespace, whitelist) {
function shouldIgnore(name) {
if (!whitelist) {
return false;
}
// check for the raw name
if (whitelist.indexOf(name) >= 0) {
return false;
}
// typeof -> _typeof
if (name[0] === "_" && whitelist.indexOf(name.slice(1)) >= 0) {
return false;
}
return true;
}
each(helpers.list, function (name) {
if (whitelist && whitelist.indexOf(name) === -1) return;
if (shouldIgnore(name)) return;
let key = t.identifier(t.toIdentifier(name));
body.push(t.expressionStatement(

View File

@ -3,10 +3,6 @@
import slash from "slash";
import * as util from "../../../util";
export function number(val: any): number {
return +val;
}
export let filename = slash;
export function boolean(val: any): boolean {

View File

@ -1,7 +1,5 @@
require("../lib/api/node");
var babel = require("../lib/api/node");
var buildExternalHelpers = require("../lib/tools/build-external-helpers");
var transform = require("../lib/api/node").transform;
var Pipeline = require("../lib/transformation/pipeline");
var sourceMap = require("source-map");
var assert = require("assert");
@ -19,12 +17,24 @@ function assertNotIgnored(result) {
function transformAsync(code, opts) {
return {
then: function (resolve) {
resolve(transform(code, opts));
resolve(babel.transform(code, opts));
}
};
}
suite("api", function () {
test("transformFile", function (done) {
babel.transformFile(__dirname + "/fixtures/api/file.js", {}, function (err, res) {
if (err) return done(err);
assert.equal(res.code, "foo();");
done();
});
});
test("transformFileSync", function () {
assert.equal(babel.transformFileSync(__dirname + "/fixtures/api/file.js", {}).code, "foo();");
});
test("options merge backwards", function () {
return transformAsync("", {
presets: [__dirname + "/../../babel-preset-es2015"],
@ -35,7 +45,7 @@ suite("api", function () {
});
test("source map merging", function () {
var result = transform([
var result = babel.transform([
'function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }',
'',
'let Foo = function Foo() {',
@ -387,5 +397,10 @@ suite("api", function () {
assert.ok(script.indexOf("classCallCheck") === -1);
assert.ok(script.indexOf("inherits") === -1);
});
test("underscored", function () {
var script = buildExternalHelpers(["typeof"]);
assert.ok(script.indexOf("typeof") >= 0);
});
});
});

View File

@ -0,0 +1 @@
foo();

View File

@ -1,7 +1,7 @@
{
"name": "babel-plugin-transform-regenerator",
"author": "Ben Newman <bn@cs.stanford.edu>",
"description": "",
"description": "Explode async and generator functions into a state machine.",
"version": "6.0.18",
"homepage": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-regenerator",
"main": "lib/index.js",

View File

@ -37,13 +37,7 @@ exports.visitor = {
return;
}
if (node.expression) {
// Transform expression lambdas into normal functions.
node.expression = false;
node.body = t.blockStatement([
t.returnStatement(node.body)
]);
}
path.ensureBlock();
if (node.async) {
path.get("body").traverse(awaitVisitor);