Compare commits

...

24 Commits

Author SHA1 Message Date
Sebastian McKenzie
4763b95a0d v3.3.2 2015-02-02 01:43:47 +11:00
Sebastian McKenzie
9fe1e37ca7 fix t.buildMatchMemberExpression 2015-02-02 01:41:39 +11:00
Sebastian McKenzie
8a9aac3e68 fix linting errors 2015-02-02 01:37:27 +11:00
Sebastian McKenzie
27138abd29 simplify member expression checking, flesh out react component optimiser #653 2015-02-02 01:30:06 +11:00
Sebastian McKenzie
dcf91db475 add react component optimisation base #653 2015-02-02 00:50:25 +11:00
Sebastian McKenzie
ab63345764 3.3.1 2015-02-01 18:44:46 +11:00
Sebastian McKenzie
a35e63fb29 v3.3.1 2015-02-01 18:44:07 +11:00
Sebastian McKenzie
3fe7df9a48 fix regenerator destructuring test 2015-02-01 18:42:15 +11:00
Sebastian McKenzie
5288f3afda add 3.3.1 changelog 2015-02-01 18:33:54 +11:00
Sebastian McKenzie
25566a24f6 block hoist assignment pattern destructuring - fixes #652 2015-02-01 18:33:36 +11:00
Sebastian McKenzie
2ff6dee0ec 3.3.0 2015-02-01 16:52:23 +11:00
Sebastian McKenzie
491d1238c2 fix buildHelpers function name 2015-02-01 16:51:57 +11:00
Sebastian McKenzie
234414c2f2 v3.3.0 2015-02-01 16:49:18 +11:00
Sebastian McKenzie
3ff544bbab fix indentation detection 2015-02-01 16:47:28 +11:00
Sebastian McKenzie
416c4cbb84 fix linting errors 2015-02-01 16:44:47 +11:00
Sebastian McKenzie
db5bf1749b fix linting errors 2015-02-01 16:43:42 +11:00
Sebastian McKenzie
41349afea3 add 3.3.0 changelog 2015-02-01 16:43:05 +11:00
Sebastian McKenzie
27da6de723 add back runtime - fixes #651 2015-02-01 16:38:13 +11:00
Sebastian McKenzie
2cdb4e3343 fix linting errors 2015-02-01 16:21:13 +11:00
Sebastian McKenzie
981d3e40f8 add canRun check for playground transformers 2015-02-01 16:20:32 +11:00
Sebastian McKenzie
c7a616730c add levenshtein suggestions to undeclared variable transformer 2015-02-01 16:20:18 +11:00
Sebastian McKenzie
5aa8ece242 don't run playground transformers at all if playground isn't enabled 2015-02-01 16:19:49 +11:00
Sebastian McKenzie
8c7ba20f86 fix regenerator transformer order - fixes #617 2015-02-01 16:19:35 +11:00
Sebastian McKenzie
1cc9027fcf 3.2.1 2015-02-01 16:19:09 +11:00
36 changed files with 469 additions and 77 deletions

View File

@@ -11,6 +11,18 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 3.3.1
* **Bug Fix**
* Block hoist assignment pattern destructuring.
## 3.3.0
* **Bug Fix**
* Do all transforms before the regenerator transform is ran.
* **New Feature**
* Added back the 2.x optional runtime.
## 3.2.1
* **Bug Fix**

View File

@@ -21,6 +21,9 @@ build:
node $(BROWSERIFY_CMD) lib/6to5/browser.js -s to5 >dist/6to5.js
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
node bin/6to5-runtime >dist/runtime.js
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
rm -rf templates.json
clean:
@@ -77,6 +80,7 @@ publish:
make build
cp dist/6to5.min.js browser.js
cp dist/polyfill.min.js browser-polyfill.js
cp dist/runtime.min.js runtime.js
node tools/cache-templates
test -f templates.json

4
bin/6to5-runtime Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
var runtime = require("../lib/6to5/build-runtime");
console.log(runtime());

View File

@@ -11,6 +11,7 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
commander.option("-w, --watch", "Recompile files on changes");
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
commander.option("-p, --playground", "Enable playground support");
@@ -108,6 +109,7 @@ exports.opts = {
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
optional: commander.optional,
comments: !commander.removeComments,
runtime: commander.runtime,
modules: commander.modules,
loose: commander.loose
};

13
lib/6to5/build-helpers.js Normal file
View File

@@ -0,0 +1,13 @@
var File = require("./file");
var util = require("./util");
var each = require("lodash/collection/each");
var t = require("./types");
module.exports = function (body, namespace) {
each(File.helpers, function (name) {
var key = t.identifier(t.toIdentifier(name));
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
));
});
};

25
lib/6to5/build-runtime.js Normal file
View File

@@ -0,0 +1,25 @@
"use strict";
var buildHelpers = require("./build-helpers");
var generator = require("./generation");
var util = require("./util");
var t = require("./types");
module.exports = function () {
var namespace = t.identifier("to5Runtime");
var body = [];
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
)
]));
buildHelpers(body, namespace);
return generator(tree).code;
};

View File

@@ -1,9 +1,7 @@
module.exports = detect;
//var useragent = require("useragent");
var traverse = require("../traverse");
var SYNTAX_KEYS = require("./syntax-keys");
var traverse = require("../traverse");
var visitors = traverse.explode(require("./visitors"));
function detect(ast) {

View File

@@ -24,7 +24,7 @@ function File(opts) {
this.data = {};
this.lastStatements = [];
this.opts = File.normaliseOptions(opts);
this.opts = this.normaliseOptions(opts);
this.ast = {};
this.buildTransformers();
@@ -76,6 +76,7 @@ File.validOptions = [
"playground",
"experimental",
"resolveModuleSource",
"runtime",
// these are used by plugins
"ignore",
@@ -84,7 +85,7 @@ File.validOptions = [
"accept"
];
File.normaliseOptions = function (opts) {
File.prototype.normaliseOptions = function (opts) {
opts = clone(opts);
for (var key in opts) {
@@ -108,6 +109,7 @@ File.normaliseOptions = function (opts) {
comments: true,
filename: "unknown",
modules: "common",
runtime: false,
loose: [],
code: true,
ast: true
@@ -146,6 +148,10 @@ File.normaliseOptions = function (opts) {
opts.experimental = true;
}
if (opts.runtime) {
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
}
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
opts.whitelist = transform._ensureTransformerNames("whitelist", opts.whitelist);
opts.optional = transform._ensureTransformerNames("optional", opts.optional);

View File

@@ -40,9 +40,11 @@ each(Buffer.prototype, function (fn, key) {
});
CodeGenerator.normaliseOptions = function (code, opts) {
var indent = detectIndent(code);
var style = indent.indent;
if (!style || style === " ") style = " ";
var style = " ";
if (code) {
var indent = detectIndent(code).indent;
if (indent && indent !== " ") style = indent;
}
return merge({
parentheses: true,

View File

@@ -0,0 +1,38 @@
// taken from stackoverflow, it's crap i know.
module.exports = function (a, b) {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
var matrix = [];
// increment along the first column of each row
var i;
for (i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
// increment each column in the first row
var j;
for (j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
// Fill in the rest of the matrix
for (i = 1; i <= b.length; i++) {
for (j = 1; j <= a.length; j++) {
if (b.charAt(i - 1) == a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1, // substitution
Math.min(
matrix[i][j - 1] + 1, // insertion
matrix[i - 1][j] + 1) // deletion
);
}
}
}
return matrix[b.length][a.length];
};

View File

@@ -7,6 +7,8 @@ var isFunction = require("lodash/lang/isFunction");
exports.version = require("../../package").version;
exports.runtime = require("./build-runtime");
exports.types = require("./types");
exports.register = function (opts) {

View File

@@ -0,0 +1,22 @@
var t = require("../../types");
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
exports.isCreateClass = function (node) {
if (!node || !t.isCallExpression(node)) return false;
// not React.createClass call member object
if (!isCreateClassCallExpression(node.callee)) return false;
// no call arguments
var args = node.arguments;
if (args.length !== 1) return false;
// first node arg is not an object
var first = args[0];
if (!t.isObjectExpression(first)) return false;
return true;
};
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");

View File

@@ -3,9 +3,9 @@
module.exports = CommonJSFormatter;
var DefaultFormatter = require("./_default");
var contains = require("lodash/collection/contains");
var util = require("../../util");
var t = require("../../types");
var contains = require("lodash/collection/contains");
function CommonJSFormatter() {
DefaultFormatter.apply(this, arguments);

View File

@@ -41,6 +41,8 @@ TransformerPass.prototype.canRun = function () {
if (transformer.experimental && !opts.experimental) return false;
if (transformer.playground && !opts.playground) return false;
return true;
};

View File

@@ -17,6 +17,7 @@ var each = require("lodash/collection/each");
function Transformer(key, transformer, opts) {
this.manipulateOptions = transformer.manipulateOptions;
this.experimental = !!transformer.experimental;
this.playground = !!transformer.playground;
this.secondPass = !!transformer.secondPass;
this.optional = !!transformer.optional;
this.handlers = this.normalise(transformer);

View File

@@ -31,7 +31,7 @@ var visitor = {
exports.Scope = function (node, parent, scope, context, file) {
traverse(node, visitor, scope, {
constants: scope.getAllOfKind("const"),
constants: scope.getAllDeclarationsOfKind("const"),
file: file
});
};

View File

@@ -46,9 +46,11 @@ var push = function (opts, nodes, elem, parentId) {
var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
nodes.push(t.variableDeclaration("var", [
var declar = t.variableDeclaration("var", [
t.variableDeclarator(tempParentId, parentId)
]));
]);
declar._blockHoist = opts.blockHoist;
nodes.push(declar);
nodes.push(buildVariableAssign(
opts,

View File

@@ -58,15 +58,15 @@ exports.Function = function (node, parent, scope) {
node.body.body.unshift(restDeclar);
}
node.body.body.unshift(
util.template("rest", {
ARGUMENTS: argsId,
ARRAY_KEY: arrKey,
ARRAY_LEN: arrLen,
START: start,
ARRAY: rest,
KEY: key,
LEN: len,
})
);
var loop = util.template("rest", {
ARGUMENTS: argsId,
ARRAY_KEY: arrKey,
ARRAY_LEN: arrLen,
START: start,
ARRAY: rest,
KEY: key,
LEN: len,
});
loop._blockHoist = node.params.length + 1;
node.body.body.unshift(loop);
};

View File

@@ -12,6 +12,7 @@ module.exports = {
"playground.objectGetterMemoization": require("./playground/object-getter-memoization"),
react: require("./other/react"),
"optimisation.react": require("./optimisation/react"),
_modules: require("./internal/modules"),
@@ -52,14 +53,13 @@ module.exports = {
// needs to be after `es6.blockScoping` due to needing `letReferences` set on blocks
"es6.blockScopingTDZ": require("./es6/block-scoping-tdz"),
// needs to be after block scoping since regenerator doesn't support it
regenerator: require("./other/regenerator"),
"es6.parameters.default": require("./es6/parameters.default"),
"es6.parameters.rest": require("./es6/parameters.rest"),
"es6.destructuring": require("./es6/destructuring"),
regenerator: require("./other/regenerator"),
// needs to be after `regenerator` due to needing `regeneratorRuntime` references
// needs to be after `es6.forOf` due to needing `Symbol.iterator` references
// needs to be before `es6.modules` due to dynamic imports

View File

@@ -0,0 +1,55 @@
module.exports = BaseOptimiser;
var object = require("../../../../helpers/object");
/**
* Description
*
* @param {Node} node
*/
function BaseOptimiser(node) {
this.methods = object();
this.types = object();
this.node = node;
}
/**
* Description
*/
BaseOptimiser.prototype.run = function () {
this.getMethods();
this.getTypes();
};
/**
* Add an `ObjectExpression` `node` that contains `propTypes`.
*
* Search it and match it against the types that we can optimise
* and register it for consumption later.
*
* @param {Node} node
*/
BaseOptimiser.prototype.addPropTypes = function (node) {
var props = node.properties;
for (var i = 0; i < props.length; i++) {
this.addPropType(props[i]);
}
};
/**
* Register a `Property` node as a prop type.
*
* We'll try and resolve it to a known type if we can and normalise
* it for consumption later.
*
* @param {Node} prop
*/
BaseOptimiser.prototype.addPropType = function () {
};

View File

@@ -0,0 +1,51 @@
module.exports = CreateClassOptimiser;
var BaseOptimiser = require("./base");
var util = require("../../../../util");
var t = require("../../../../types");
function CreateClassOptimiser() {
BaseOptimiser.apply(this, arguments);
}
util.inherits(CreateClassOptimiser, BaseOptimiser);
/**
* Get all function expressions.
*/
CreateClassOptimiser.prototype.getMethods = function () {
var props = this.node.properties;
for (var i = 0; i < props.length; i++) {
var prop = props[i];
// irrelevant
if (!t.isFunctionExpression(prop.value)) continue;
// deopt
if (prop.computed) continue;
this.methods[prop.key.name] = prop;
}
};
/**
* Find a `propTypes` property.
*/
CreateClassOptimiser.prototype.getTypes = function () {
var props = this.node.properties;
for (var i = 0; i < props.length; i++) {
var prop = props[i];
var key = t.toComputedKey(prop, prop.key);
if (t.isLiteral(key, { value: "propTypes" }) && t.isObjectExpression(prop.value)) {
this.addPropTypes(prop.value);
return;
}
}
// not found
};

View File

@@ -0,0 +1,17 @@
var CreateClassOptimiser = require("./create-class");
var NativeClassOptimiser = require("./native-class");
var react = require("../../../helpers/react");
exports.optional = true;
exports.CallExpression = function (node) {
if (react.isCreateClass(node)) {
new CreateClassOptimiser(node.arguments[0]).run();
}
};
exports.CallExpression = function (node) {
if (react.isReactComponent(node.superClass)) {
new NativeClassOptimiser(node).run();
}
};

View File

@@ -0,0 +1,42 @@
module.exports = NativeClassOptimiser;
var BaseOptimiser = require("./base");
var util = require("../../../../util");
var t = require("../../../../types");
function NativeClassOptimiser() {
BaseOptimiser.apply(this, arguments);
}
util.inherits(NativeClassOptimiser, BaseOptimiser);
/**
* Get all instance methods.
*/
NativeClassOptimiser.prototype.getMethods = function () {
var body = this.node.body;
for (var i = 0; i < body.length; i++) {
var node = body[i];
// PrivateDeclaration etc
if (!t.isMethodDefinition(node)) continue;
// deopt
if (node.computed) continue;
// irrelevant
if (node.static) continue;
this.methods[node.key.name] = node;
}
};
/**
* Description
*/
NativeClassOptimiser.prototype.getTypes = function () {
};

View File

@@ -6,6 +6,7 @@
// jsx
var esutils = require("esutils");
var react = require("../../helpers/react");
var t = require("../../../types");
exports.JSXIdentifier = function (node, parent) {
@@ -197,33 +198,8 @@ var cleanJSXElementLiteralChild = function (child, args) {
// display names
var isCreateClass = function (call) {
if (!call || !t.isCallExpression(call)) return false;
var callee = call.callee;
if (!t.isMemberExpression(callee)) return false;
// not React call member object
var obj = callee.object;
if (!t.isIdentifier(obj, { name: "React" })) return false;
// not createClass call member property
var prop = callee.property;
if (!t.isIdentifier(prop, { name: "createClass" })) return false;
// no call arguments
var args = call.arguments;
if (args.length !== 1) return false;
// first call arg is not an object
var first = args[0];
if (!t.isObjectExpression(first)) return;
return true;
};
var addDisplayName = function (id, call) {
if (!isCreateClass(call)) return;
if (!react.isCreateClass(call)) return;
var props = call.arguments[0].properties;
var safe = true;

View File

@@ -1,7 +1,9 @@
"use strict";
var build = require("../../helpers/build-conditional-assignment-operator-transformer");
var t = require("../../../types");
var t = require("../../../types");
exports.playground = true;
build(exports, {
is: function (node, file) {

View File

@@ -3,6 +3,8 @@
var build = require("../../helpers/build-conditional-assignment-operator-transformer");
var t = require("../../../types");
exports.playground = true;
build(exports, {
is: function (node) {
var is = t.isAssignmentExpression(node) && node.operator === "?=";

View File

@@ -2,6 +2,8 @@
var t = require("../../../types");
exports.playground = true;
exports.BindMemberExpression = function (node, parent, scope) {
var object = node.object;
var prop = node.property;

View File

@@ -3,6 +3,8 @@
var traverse = require("../../../traverse");
var t = require("../../../types");
exports.playground = true;
var visitor = {
enter: function (node, parent, scope, context, state) {
if (t.isFunction(node)) return;

View File

@@ -1,9 +1,38 @@
"use strict";
var levenshtein = require("../../../helpers/levenshtein");
var t = require("../../../types");
exports.optional = true;
exports.Identifier = function (node, parent, scope, context, file) {
if (!scope.has(node.name, true)) {
throw file.errorWithNode(node, "Reference to undeclared variable", ReferenceError);
if (!t.isReferenced(node, parent)) return;
if (scope.has(node.name, true)) return;
var msg = "Reference to undeclared variable";
// get the closest declaration to offer as a suggestion
// the variable name may have just been mistyped
var declarations = scope.getAllDeclarations();
var closest;
var shortest = -1;
for (var name in declarations) {
var distance = levenshtein(node.name, name);
if (distance <= 0 || distance > 3) continue;
if (distance <= shortest) continue;
closest = name;
shortest = distance;
}
if (closest) {
msg += " - Did you mean " + closest + "?";
}
//
throw file.errorWithNode(node, msg, ReferenceError);
};

View File

@@ -326,12 +326,31 @@ Scope.prototype.getFunctionParent = function () {
};
/**
* Walks the scope tree and gathers all declarations of `kind`.
* Walks the scope tree and gathers **all** declarations.
*
* @returns {Object}
*/
Scope.prototype.getAllOfKind = function (kind) {
Scope.prototype.getAllDeclarations = function () {
var ids = object();
var scope = this;
do {
defaults(ids, scope.declarations);
scope = scope.parent;
} while (scope);
return ids;
};
/**
* Walks the scope tree and gathers all declarations of `kind`.
*
* @param {String} kind
* @returns {Object}
*/
Scope.prototype.getAllDeclarationsOfKind = function (kind) {
var ids = object();
var scope = this;

View File

@@ -399,6 +399,60 @@ t.ensureBlock = function (node, key) {
node[key] = t.toBlock(node[key], node);
};
/**
* Build a function that when called will return whether or not the
* input `node` `MemberExpression` matches the input `match`.
*
* For example, given the match `React.createClass` it would match the
* parsed nodes of `React.createClass` and `React["createClass"]`.
*
* @param {String} match Dot delimetered string
* @returns {Function}
*/
t.buildMatchMemberExpression = function (match) {
var parts = match.split(".");
return function (member) {
// not a member expression
if (!t.isMemberExpression(member)) return false;
var search = [member];
var i = 0;
while (search.length) {
var node = search.shift();
if (t.isIdentifier(node)) {
// this part doesn't match
if (parts[i] !== node.name) return false;
} else if (t.isLiteral(node)) {
// this part doesn't match
if (parts[i] !== node.value) return false;
} else if (t.isMemberExpression(node)) {
if (node.computed && !t.isLiteral(node.property)) {
// we can't deal with this
return false;
} else {
search.push(node.object);
search.push(node.property);
continue;
}
} else {
// we can't deal with this
return false;
}
// too many parts
if (++i > parts.length) {
return false;
}
}
return true;
};
};
/**
* Description
*

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "3.2.1",
"version": "3.3.2",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://6to5.org/",
"repository": "6to5/6to5",
@@ -9,7 +9,8 @@
"main": "lib/6to5/index.js",
"bin": {
"6to5": "./bin/6to5/index.js",
"6to5-node": "./bin/6to5-node"
"6to5-node": "./bin/6to5-node",
"6to5-runtime": "./bin/6to5-runtime"
},
"browser": {
"./lib/6to5/index.js": "./lib/6to5/browser.js",
@@ -48,7 +49,7 @@
"lodash": "3.0.0",
"output-file-sync": "1.1.0",
"private": "0.1.6",
"regenerator-6to5": "0.8.9-7",
"regenerator-6to5": "0.8.9-8",
"regexpu": "1.1.0",
"roadrunner": "1.0.4",
"source-map": "0.1.43",

View File

@@ -1,7 +1,7 @@
{
"name": "6to5-runtime",
"description": "6to5 selfContained runtime",
"version": "3.2.0",
"version": "3.3.1",
"repository": "6to5/6to5",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}

View File

@@ -1,11 +1,10 @@
"use strict";
var transform = require("../lib/6to5/transformation");
var File = require("../lib/6to5/file");
var util = require("../lib/6to5/util");
var fs = require("fs");
var t = require("../lib/6to5/types");
var _ = require("lodash");
var buildHelpers = require("../lib/6to5/build-helpers");
var transform = require("../lib/6to5/transformation");
var fs = require("fs");
var t = require("../lib/6to5/types");
var _ = require("lodash");
var relative = function (filename) {
return __dirname + "/6to5-runtime/" + filename;
@@ -31,23 +30,18 @@ var updatePackage = function () {
writeFile("package.json", JSON.stringify(pkg, null, 2));
};
var buildHelpers = function () {
var buildHelpers2 = function () {
var body = [];
var tree = t.program(body);
_.each(File.helpers, function (name) {
var key = t.identifier(t.toIdentifier(name));
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(t.identifier("exports"), key), util.template(name))
));
});
buildHelpers(body, t.identifier("exports"));
return transform.fromAst(tree, null, {
optional: ["selfContained"]
}).code;
};
writeFile("helpers.js", buildHelpers());
writeFile("helpers.js", buildHelpers2());
writeFile("core-js.js", readFile("core-js/library"));
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module"));
writeFile("regenerator/runtime.js", readFile("regenerator-6to5/runtime"));

View File

@@ -0,0 +1,5 @@
function* foo({ bar }) {
return bar;
}
assert(foo({ bar: "bar" }).next().value, "bar");

View File

@@ -1,5 +1,13 @@
function* foo({ bar }) {
function* foo() {
var { bar } = { bar: "bar" };
return bar;
}
assert(foo({ bar: "bar" }).next().value, "bar");
assert.equal(foo().next().value, "bar");
function* foo2({ bar = 0 }) {
return bar;
}
assert.equal(foo2({ bar: undefined }).next().value, 0);
assert.equal(foo2({ bar: 3 }).next().value, 3);