diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..fbbbb71463 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "vendor/traceur"] + path = vendor/traceur + url = https://github.com/google/traceur-compiler +[submodule "vendor/regenerator"] + path = vendor/regenerator + url = https://github.com/facebook/regenerator diff --git a/Makefile b/Makefile index ee5cbe0098..a220f5e5f5 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ MOCHA_CMD = node_modules/mocha/bin/_mocha export NODE_ENV = test -.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build +.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build bootstrap build: mkdir -p dist @@ -23,7 +23,7 @@ build: node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js rm -rf templates.json - + clean: rm -rf coverage templates.json test/tmp dist @@ -81,3 +81,7 @@ publish: git push --follow-tags rm -rf templates.json browser.js runtime.js browser-polyfill.js + +bootstrap: + git submodule update --init + cd vendor/regenerator; npm install diff --git a/doc/differences.md b/doc/differences.md index ff27c62378..e90b2ea907 100644 --- a/doc/differences.md +++ b/doc/differences.md @@ -78,43 +78,43 @@ that when you turn it off and use your code in a full ES6 environment ### Features -| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform | -| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- | -| Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ | -| No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ | -| Optional runtime | ✓ | | ✓ | | | ✓ | -| Browser compiler | ✓ | ✓ | | ✓ | | | +| | 6to5 | Traceur | es6-transpiler | es6now | jstransform | +| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- | +| Source maps | ✓ | ✓ | ✓ | | ✓ | +| No compiler global pollution | ✓ | | ✓ | | ✓ | +| Optional runtime | ✓ | | ✓ | | ✓ | +| Browser compiler | ✓ | ✓ | | | | ### Language Support -| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform | -| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- | -| Abstract references | ✓ | | | | | | -| Array comprehension | ✓ | ✓ | ✓ | | | | -| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Async functions | ✓ | ✓ | | ✓ | | | -| Async generator functions | ✓ | ✓ | | | | | -| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Constants | ✓ | ✓ | ✓ | | | | -| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Exponentiation operator | ✓ | ✓ | | | | | -| Flow types | ✓ | | | | | ✓ | -| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Generators | ✓ | ✓ | | ✓ | | | -| Generator comprehension | ✓ | ✓ | | | | | -| JSX | ✓ | | | | | | -| Let scoping | ✓ | ✓ | ✓ | | | | -| Modules | ✓ | ✓ | | | ✓ | | -| Object rest/spread | ✓ | | | | | ✓ | -| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| React | ✓ | | | | | | -| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | | -| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | -| Unicode regex | ✓ | ✓ | ✓ | | | | +| | 6to5 | Traceur | es6-transpiler | es6now | jstransform | +| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- | +| Abstract references | ✓ | | | | | +| Array comprehension | ✓ | ✓ | ✓ | | | +| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | +| Async functions | ✓ | ✓ | | | | +| Async generator functions | ✓ | ✓ | | | | +| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | +| Computed property names | ✓ | ✓ | ✓ | ✓ | | +| Constants | ✓ | ✓ | ✓ | | | +| Default parameters | ✓ | ✓ | ✓ | ✓ | | +| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | +| Exponentiation operator | ✓ | ✓ | | | | +| Flow types | ✓ | | | | ✓ | +| For-of | ✓ | ✓ | ✓ | ✓ | | +| Generators | ✓ | ✓ | | | | +| Generator comprehension | ✓ | ✓ | | | | +| JSX | ✓ | | | | | +| Let scoping | ✓ | ✓ | ✓ | | | +| Modules | ✓ | ✓ | | ✓ | | +| Object rest/spread | ✓ | | | | ✓ | +| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | +| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | +| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | +| React | ✓ | | | | | +| Spread | ✓ | ✓ | ✓ | ✓ | | +| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | +| Unicode regex | ✓ | ✓ | ✓ | | | ### [Traceur](https://github.com/google/traceur-compiler) diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 73c10aef1f..be2f61a613 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -10,11 +10,12 @@ var t = require("./types"); var _ = require("lodash"); function File(opts) { - this.dynamicImports = []; - this.opts = File.normaliseOptions(opts); - this.transformers = this.getTransformers(); - this.uids = {}; - this.ast = {}; + this.dynamicImports = []; + this.dynamicImportIds = {}; + this.opts = File.normaliseOptions(opts); + this.transformers = this.getTransformers(); + this.uids = {}; + this.ast = {}; } File.helpers = [ @@ -29,12 +30,16 @@ File.helpers = [ "object-without-properties", "has-own", "slice", + "bind", "define-property", - "async-to-generator" + "async-to-generator", + "interop-require-wildcard", + "typeof" ]; File.excludeHelpersFromRuntime = [ - "async-to-generator" + "async-to-generator", + "typeof" ]; File.normaliseOptions = function (opts) { @@ -160,11 +165,20 @@ File.prototype.parseShebang = function (code) { return code; }; -File.prototype.addImport = function (id, source) { - var specifiers = [t.importSpecifier(t.identifier("default"), id)]; - var declar = t.importDeclaration(specifiers, t.literal(source)); - declar._blockHoist = 3; - this.dynamicImports.push(declar); +File.prototype.addImport = function (source, name) { + name = name || source; + var id = this.dynamicImportIds[name]; + + if (!id) { + id = this.dynamicImportIds[name] = this.generateUidIdentifier(name); + + var specifiers = [t.importSpecifier(t.identifier("default"), id)]; + var declar = t.importDeclaration(specifiers, t.literal(source)); + declar._blockHoist = 3; + this.dynamicImports.push(declar); + } + + return id; }; File.prototype.addHelper = function (name) { @@ -273,7 +287,7 @@ File.prototype.generate = function () { }; File.prototype.generateUid = function (name, scope) { - name = t.toIdentifier(name); + name = t.toIdentifier(name).replace(/^_+/, ""); scope = scope || this.scope; diff --git a/lib/6to5/generation/generators/expressions.js b/lib/6to5/generation/generators/expressions.js index 17f5dbda68..b246abf27f 100644 --- a/lib/6to5/generation/generators/expressions.js +++ b/lib/6to5/generation/generators/expressions.js @@ -1,5 +1,6 @@ var util = require("../../util"); var t = require("../../types"); +var _ = require("lodash"); exports.UnaryExpression = function (node, print) { var hasSpace = /[a-z]$/.test(node.operator); @@ -86,6 +87,7 @@ exports.ExpressionStatement = function (node, print) { exports.BinaryExpression = exports.LogicalExpression = +exports.AssignmentPattern = exports.AssignmentExpression = function (node, print) { print(node.left); this.push(" " + node.operator + " "); @@ -102,7 +104,12 @@ exports.MemberExpression = function (node, print) { throw new TypeError("Got a MemberExpression for MemberExpression property"); } - if (node.computed) { + var computed = node.computed; + if (t.isLiteral(node.property) && _.isNumber(node.property.value)) { + computed = true; + } + + if (computed) { this.push("["); print(node.property); this.push("]"); diff --git a/lib/6to5/generation/node/index.js b/lib/6to5/generation/node/index.js index b0b283d853..8828ba9030 100644 --- a/lib/6to5/generation/node/index.js +++ b/lib/6to5/generation/node/index.js @@ -61,9 +61,12 @@ Node.prototype.needsParens = function () { if (!parent) return false; if (t.isNewExpression(parent) && parent.callee === node) { - return t.isCallExpression(node) || _.some(node, function (val) { + if (t.isCallExpression(node)) return true; + + var hasCall = _.some(node, function (val) { return t.isCallExpression(val); }); + if (hasCall) return true; } return find(parens, node, parent); diff --git a/lib/6to5/generation/node/parentheses.js b/lib/6to5/generation/node/parentheses.js index 6d96d78675..8415b0c9a5 100644 --- a/lib/6to5/generation/node/parentheses.js +++ b/lib/6to5/generation/node/parentheses.js @@ -13,7 +13,8 @@ _.each([ ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], - ["*", "/", "%"] + ["*", "/", "%"], + ["**"] ], function (tier, i) { _.each(tier, function (op) { PRECEDENCE[op] = i; @@ -35,7 +36,7 @@ exports.ObjectExpression = function (node, parent) { }; exports.Binary = function (node, parent) { - if (t.isCallExpression(parent) && parent.callee === node) { + if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) { return true; } diff --git a/lib/6to5/patch.js b/lib/6to5/patch.js index 836538b2f8..76e65bd38f 100644 --- a/lib/6to5/patch.js +++ b/lib/6to5/patch.js @@ -12,6 +12,12 @@ var types = require("ast-types"); var def = types.Type.def; var or = types.Type.or; +def("AssignmentPattern") + .bases("Pattern") + .build("left", "right") + .field("left", def("Pattern")) + .field("right", def("Expression")); + // Acorn - Same as ImportNamespaceSpecifier but `id` is `name` def("ImportBatchSpecifier") .bases("Specifier") diff --git a/lib/6to5/transformation/modules/_default.js b/lib/6to5/transformation/modules/_default.js index 95b7a97b85..7713fff73c 100644 --- a/lib/6to5/transformation/modules/_default.js +++ b/lib/6to5/transformation/modules/_default.js @@ -141,10 +141,17 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node, // export * from "foo"; nodes.push(this._exportsWildcard(getRef(), node)); } else { + var ref; + if (t.isSpecifierDefault(specifier.id) || this.noInteropRequire) { + ref = t.memberExpression(getRef(), specifier.id); + } else { + ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]); + } + // export { foo } from "test"; nodes.push(this._exportsAssign( t.getSpecifierName(specifier), - t.memberExpression(getRef(), specifier.id), + ref, node )); } diff --git a/lib/6to5/transformation/modules/common.js b/lib/6to5/transformation/modules/common.js index d527e49e73..77224cd148 100644 --- a/lib/6to5/transformation/modules/common.js +++ b/lib/6to5/transformation/modules/common.js @@ -32,18 +32,24 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) ) ])); } else { - // import foo from "foo"; - - var templateName = "require-assign"; - - // import * as bar from "foo"; - if (specifier.type !== "ImportBatchSpecifier") templateName += "-key"; - - nodes.push(util.template(templateName, { - VARIABLE_NAME: variableName, - MODULE_NAME: node.source, - KEY: specifier.id - })); + if (specifier.type === "ImportBatchSpecifier") { + // import * as bar from "foo"; + nodes.push(t.variableDeclaration("var", [ + t.variableDeclarator( + variableName, + t.callExpression(this.file.addHelper("interop-require-wildcard"), [ + t.callExpression(t.identifier("require"), [node.source]) + ]) + ) + ])); + } else { + // import foo from "foo"; + nodes.push(util.template("require-assign-key", { + VARIABLE_NAME: variableName, + MODULE_NAME: node.source, + KEY: specifier.id + })); + } } }; @@ -65,7 +71,7 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) { // exports = module.exports = VALUE; if (this.hasNonDefaultExports) templateName = "exports-default-module-override"; - if (t.isFunction(declar) || !this.hasNonDefaultExports) { + if (t.isFunctionDeclaration(declar) || !this.hasNonDefaultExports) { assign = util.template(templateName, { VALUE: this._pushStatement(declar, nodes) }, true); diff --git a/lib/6to5/transformation/templates/bind.js b/lib/6to5/transformation/templates/bind.js new file mode 100644 index 0000000000..abe1c0668a --- /dev/null +++ b/lib/6to5/transformation/templates/bind.js @@ -0,0 +1 @@ +Function.prototype.bind diff --git a/lib/6to5/transformation/templates/inherits.js b/lib/6to5/transformation/templates/inherits.js index 1e8f6b5e8f..8822bbea7e 100644 --- a/lib/6to5/transformation/templates/inherits.js +++ b/lib/6to5/transformation/templates/inherits.js @@ -1,4 +1,7 @@ (function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/lib/6to5/transformation/templates/interop-require-wildcard.js b/lib/6to5/transformation/templates/interop-require-wildcard.js new file mode 100644 index 0000000000..89287917c8 --- /dev/null +++ b/lib/6to5/transformation/templates/interop-require-wildcard.js @@ -0,0 +1,3 @@ +(function (obj) { + return obj && obj.constructor === Object ? obj : { default: obj }; +}) diff --git a/lib/6to5/transformation/templates/require-assign.js b/lib/6to5/transformation/templates/require-assign.js deleted file mode 100644 index 2b389fbfdf..0000000000 --- a/lib/6to5/transformation/templates/require-assign.js +++ /dev/null @@ -1 +0,0 @@ -var VARIABLE_NAME = require(MODULE_NAME); diff --git a/lib/6to5/transformation/templates/typeof.js b/lib/6to5/transformation/templates/typeof.js new file mode 100644 index 0000000000..8efdeefe3d --- /dev/null +++ b/lib/6to5/transformation/templates/typeof.js @@ -0,0 +1,3 @@ +(function (obj) { + return obj && obj.constructor === Symbol ? "symbol" : typeof obj; +}); diff --git a/lib/6to5/transformation/transform.js b/lib/6to5/transformation/transform.js index bf647e1f69..e1ad5833d1 100644 --- a/lib/6to5/transformation/transform.js +++ b/lib/6to5/transformation/transform.js @@ -89,6 +89,7 @@ _.each({ _moduleFormatter: require("./transformers/_module-formatter"), useStrict: require("./transformers/use-strict"), + typeofSymbol: require("./transformers/optional-typeof-symbol"), coreAliasing: require("./transformers/optional-core-aliasing"), undefinedToVoid: require("./transformers/optional-undefined-to-void"), diff --git a/lib/6to5/transformation/transformer.js b/lib/6to5/transformation/transformer.js index 7239e5e976..d9587a38c0 100644 --- a/lib/6to5/transformation/transformer.js +++ b/lib/6to5/transformation/transformer.js @@ -8,20 +8,25 @@ function Transformer(key, transformer, opts) { this.manipulateOptions = transformer.manipulateOptions; this.experimental = !!transformer.experimental; this.secondPass = !!transformer.secondPass; - this.transformer = Transformer.normalise(transformer); + this.transformer = this.normalise(transformer); this.optional = !!transformer.optional; this.opts = opts || {}; this.key = key; } -Transformer.normalise = function (transformer) { +Transformer.prototype.normalise = function (transformer) { + var self = this; + if (_.isFunction(transformer)) { transformer = { ast: transformer }; } _.each(transformer, function (fns, type) { // hidden property - if (type[0] === "_") return; + if (type[0] === "_") { + self[type] = fns; + return; + } if (_.isFunction(fns)) fns = { enter: fns }; diff --git a/lib/6to5/transformation/transformers/_block-hoist.js b/lib/6to5/transformation/transformers/_block-hoist.js index b6fff4a860..e024a8a193 100644 --- a/lib/6to5/transformation/transformers/_block-hoist.js +++ b/lib/6to5/transformation/transformers/_block-hoist.js @@ -1,4 +1,5 @@ -var _ = require("lodash"); +var useStrict = require("./use-strict"); +var _ = require("lodash"); // Priority: // @@ -17,13 +18,15 @@ exports.Program = { } if (!hasChange) return; - var nodePriorities = _.groupBy(node.body, function (bodyNode) { - var priority = bodyNode._blockHoist; - if (priority == null) priority = 1; - if (priority === true) priority = 2; - return priority; - }); + useStrict._wrap(node, function () { + var nodePriorities = _.groupBy(node.body, function (bodyNode) { + var priority = bodyNode._blockHoist; + if (priority == null) priority = 1; + if (priority === true) priority = 2; + return priority; + }); - node.body = _.flatten(_.values(nodePriorities).reverse()); + node.body = _.flatten(_.values(nodePriorities).reverse()); + }); } }; diff --git a/lib/6to5/transformation/transformers/_declarations.js b/lib/6to5/transformation/transformers/_declarations.js index ae0f355b08..20fbfadb6e 100644 --- a/lib/6to5/transformation/transformers/_declarations.js +++ b/lib/6to5/transformation/transformers/_declarations.js @@ -1,4 +1,5 @@ -var t = require("../../types"); +var useStrict = require("./use-strict"); +var t = require("../../types"); exports.secondPass = true; @@ -7,23 +8,25 @@ exports.Program = function (node) { var kinds = {}; var kind; - for (var i in node._declarations) { - var declar = node._declarations[i]; + useStrict._wrap(node, function () { + for (var i in node._declarations) { + var declar = node._declarations[i]; - kind = declar.kind || "var"; - var declarNode = t.variableDeclarator(declar.id, declar.init); + kind = declar.kind || "var"; + var declarNode = t.variableDeclarator(declar.id, declar.init); - if (!declar.init) { - kinds[kind] = kinds[kind] || []; - kinds[kind].push(declarNode); - } else { - node.body.unshift(t.variableDeclaration(kind, [declarNode])); + if (!declar.init) { + kinds[kind] = kinds[kind] || []; + kinds[kind].push(declarNode); + } else { + node.body.unshift(t.variableDeclaration(kind, [declarNode])); + } } - } - for (kind in kinds) { - node.body.unshift(t.variableDeclaration(kind, kinds[kind])); - } + for (kind in kinds) { + node.body.unshift(t.variableDeclaration(kind, kinds[kind])); + } + }); node._declarations = null; }; diff --git a/lib/6to5/transformation/transformers/es6-destructuring.js b/lib/6to5/transformation/transformers/es6-destructuring.js index c8b7bffb36..489d2de53c 100644 --- a/lib/6to5/transformation/transformers/es6-destructuring.js +++ b/lib/6to5/transformation/transformers/es6-destructuring.js @@ -20,11 +20,31 @@ var push = function (opts, nodes, elem, parentId) { pushObjectPattern(opts, nodes, elem, parentId); } else if (t.isArrayPattern(elem)) { pushArrayPattern(opts, nodes, elem, parentId); + } else if (t.isAssignmentPattern(elem)) { + pushAssignmentPattern(opts, nodes, elem, parentId); } else { nodes.push(buildVariableAssign(opts, elem, parentId)); } }; +var pushAssignmentPattern = function (opts, nodes, pattern, parentId) { + var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file); + + nodes.push(t.variableDeclaration("var", [ + t.variableDeclarator(tempParentId, parentId) + ])); + + nodes.push(buildVariableAssign( + opts, + pattern.left, + t.conditionalExpression( + t.binaryExpression("===", tempParentId, t.identifier("undefined")), + pattern.right, + tempParentId + ) + )); +}; + var pushObjectPattern = function (opts, nodes, pattern, parentId) { for (var i in pattern.properties) { var prop = pattern.properties[i]; @@ -48,6 +68,8 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) { var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]); nodes.push(buildVariableAssign(opts, prop.argument, value)); } else { + if (t.isLiteral(prop.key)) prop.computed = true; + var pattern2 = prop.value; var patternId2 = t.memberExpression(parentId, prop.key, prop.computed); @@ -183,6 +205,24 @@ exports.Function = function (node, parent, file, scope) { block.body = nodes.concat(block.body); }; +exports.CatchClause = function (node, parent, file, scope) { + var pattern = node.param; + if (!t.isPattern(pattern)) return; + + var ref = file.generateUidIdentifier("ref", scope); + node.param = ref; + + var nodes = []; + + push({ + kind: "var", + file: file, + scope: scope + }, nodes, pattern, ref); + + node.body.body = nodes.concat(node.body.body); +}; + exports.ExpressionStatement = function (node, parent, file, scope) { var expr = node.expression; if (expr.type !== "AssignmentExpression") return; diff --git a/lib/6to5/transformation/transformers/es6-let-scoping.js b/lib/6to5/transformation/transformers/es6-let-scoping.js index 3da1800688..44151d58b8 100644 --- a/lib/6to5/transformation/transformers/es6-let-scoping.js +++ b/lib/6to5/transformation/transformers/es6-let-scoping.js @@ -376,7 +376,7 @@ LetScoping.prototype.getLetReferences = function () { // this scope has a variable with the same name so it couldn't belong // to our let scope - if (scope.hasOwn(node.name)) return; + if (scope.hasOwn(node.name, true)) return; closurify = true; @@ -388,8 +388,6 @@ LetScoping.prototype.getLetReferences = function () { } }); - return this.skip(); - } else if (t.isLoop(node)) { return this.skip(); } } diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index 214a765f03..2f544fe989 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -1,4 +1,5 @@ var t = require("../../types"); +var _ = require("lodash"); var getSpreadLiteral = function (spread, file) { return file.toArray(spread.argument); @@ -98,7 +99,14 @@ exports.NewExpression = function (node, parent, file) { var args = node.arguments; if (!hasSpread(args)) return; + var nativeType = t.isIdentifier(node.callee) && _.contains(t.NATIVE_TYPES_NAMES, node.callee.name); + var nodes = build(args, file); + + if (nativeType) { + nodes.unshift(t.arrayExpression([t.literal(null)])); + } + var first = nodes.shift(); if (nodes.length) { @@ -107,5 +115,15 @@ exports.NewExpression = function (node, parent, file) { args = first; } - return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]); + if (nativeType) { + return t.newExpression( + t.callExpression( + t.memberExpression(file.addHelper("bind"), t.identifier("apply")), + [node.callee, args] + ), + [] + ); + } else { + return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]); + } }; diff --git a/lib/6to5/transformation/transformers/optional-bluebird-coroutines.js b/lib/6to5/transformation/transformers/optional-bluebird-coroutines.js index beb19dad7a..cda714330c 100644 --- a/lib/6to5/transformation/transformers/optional-bluebird-coroutines.js +++ b/lib/6to5/transformation/transformers/optional-bluebird-coroutines.js @@ -38,8 +38,6 @@ exports._Function = function (node, callId) { exports.Function = function (node, parent, file) { if (!node.async || node.generator) return; - var id = t.identifier("Bluebird"); - file.addImport(id, "bluebird"); - + var id = file.addImport("bluebird"); return exports._Function(node, t.memberExpression(id, t.identifier("coroutine"))); }; diff --git a/lib/6to5/transformation/transformers/optional-core-aliasing.js b/lib/6to5/transformation/transformers/optional-core-aliasing.js index bd2fb2f572..a67bf045ec 100644 --- a/lib/6to5/transformation/transformers/optional-core-aliasing.js +++ b/lib/6to5/transformation/transformers/optional-core-aliasing.js @@ -12,8 +12,7 @@ exports.optional = true; exports.ast = { enter: function (ast, file) { - file._coreId = file.generateUidIdentifier("core"); - file.addImport(file._coreId, "core-js/library"); + file._coreId = file.addImport("core-js/library", "core"); }, exit: function (ast, file) { diff --git a/lib/6to5/transformation/transformers/optional-typeof-symbol.js b/lib/6to5/transformation/transformers/optional-typeof-symbol.js new file mode 100644 index 0000000000..55be121b08 --- /dev/null +++ b/lib/6to5/transformation/transformers/optional-typeof-symbol.js @@ -0,0 +1,9 @@ +var t = require("../../types"); + +exports.optional = true; + +exports.UnaryExpression = function (node, parent, file) { + if (node.operator === "typeof") { + return t.callExpression(file.addHelper("typeof"), [node.argument]); + } +}; diff --git a/lib/6to5/transformation/transformers/use-strict.js b/lib/6to5/transformation/transformers/use-strict.js index 02d4dbc264..bd9fd9c651 100644 --- a/lib/6to5/transformation/transformers/use-strict.js +++ b/lib/6to5/transformation/transformers/use-strict.js @@ -1,14 +1,27 @@ var t = require("../../types"); +exports._has = function (node) { + var first = node.body[0]; + return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" }); +}; + +exports._wrap = function (node, callback) { + var useStrictNode; + if (exports._has(node)) { + useStrictNode = node.body.shift(); + } + + callback(); + + if (useStrictNode) { + node.body.unshift(useStrictNode); + } +}; + exports.ast = { exit: function (ast) { - var body = ast.program.body; - var first = body[0]; - - var noStrict = !first || !t.isExpressionStatement(first) || !t.isLiteral(first.expression) || first.expression.value !== "use strict"; - - if (noStrict) { - body.unshift(t.expressionStatement(t.literal("use strict"))); + if (!exports._has(ast.program)) { + ast.program.body.unshift(t.expressionStatement(t.literal("use strict"))); } } }; diff --git a/lib/6to5/types/alias-keys.json b/lib/6to5/types/alias-keys.json index 56ad154225..e07ecc429d 100644 --- a/lib/6to5/types/alias-keys.json +++ b/lib/6to5/types/alias-keys.json @@ -39,8 +39,9 @@ "ForInStatement": ["Statement", "For", "Scope", "Loop"], "ForStatement": ["Statement", "For", "Scope", "Loop"], - "ObjectPattern": ["Pattern"], - "ArrayPattern": ["Pattern"], + "ObjectPattern": ["Pattern"], + "ArrayPattern": ["Pattern"], + "AssignmentPattern": ["Pattern"], "Property": ["UserWhitespacable"], "XJSElement": ["UserWhitespacable", "Expression"], diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 284fb7eb12..efe141328f 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -3,6 +3,10 @@ var _ = require("lodash"); var t = exports; +t.NATIVE_TYPES_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"]; + +// + var addAssert = function (type, is) { t["assert" + type] = function (node, opts) { opts = opts || {}; @@ -214,7 +218,7 @@ t.isReferenced = function (node, parent) { */ t.isValidIdentifier = function (name) { - return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true); + return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isReservedWordES6(name, true); }; /* @@ -227,6 +231,8 @@ t.isValidIdentifier = function (name) { t.toIdentifier = function (name) { if (t.isIdentifier(name)) return name.name; + name = name + ""; + // replace all non-valid identifiers with dashes name = name.replace(/[^a-zA-Z0-9$_]/g, "-"); @@ -241,6 +247,10 @@ t.toIdentifier = function (name) { // remove underscores from start of name name = name.replace(/^\_/, ""); + if (!t.isValidIdentifier(name)) { + name = "_" + name; + } + return name || '_'; }; diff --git a/lib/6to5/types/visitor-keys.json b/lib/6to5/types/visitor-keys.json index 32292aa669..aac62dd391 100644 --- a/lib/6to5/types/visitor-keys.json +++ b/lib/6to5/types/visitor-keys.json @@ -3,6 +3,7 @@ "ArrayPattern": ["elements"], "ArrowFunctionExpression": ["params", "defaults", "rest", "body"], "AssignmentExpression": ["left", "right"], + "AssignmentPattern": ["left", "right"], "AwaitExpression": ["argument"], "BinaryExpression": ["left", "right"], "BindFunctionExpression": ["callee", "arguments"], diff --git a/package.json b/package.json index 390149491c..b7fe304c6f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "ast-types": "~0.6.1", "chokidar": "0.11.1", "commander": "2.5.0", - "core-js": "^0.3.3", + "core-js": "^0.4.0", "estraverse": "1.8.0", "esutils": "1.1.6", "fs-readdir-recursive": "0.1.0", @@ -51,7 +51,7 @@ "lodash": "2.4.1", "mkdirp": "0.5.0", "private": "0.1.6", - "regenerator": "^0.8.2", + "regenerator": "^0.8.3", "regexpu": "0.3.0", "roadrunner": "^1.0.4", "source-map": "0.1.40", diff --git a/test/_helper.js b/test/_helper.js index 6f5afdd93b..60371d0e2f 100644 --- a/test/_helper.js +++ b/test/_helper.js @@ -3,7 +3,7 @@ var fs = require("fs"); var _ = require("lodash"); var humanise = function (val) { - return val.replace(/-/g, " "); + return path.basename(val, path.extname(val)).replace(/-/g, " "); }; var readFile = exports.readFile = function (filename) { @@ -16,11 +16,11 @@ var readFile = exports.readFile = function (filename) { } }; -exports.get = function (entryName) { +exports.get = function (entryName, entryLoc) { if (exports.cache[entryName]) return exports.cache[entryName]; var suites = []; - var entryLoc = __dirname + "/fixtures/" + entryName; + var entryLoc = entryLoc || __dirname + "/fixtures/" + entryName; _.each(fs.readdirSync(entryLoc), function (suiteName) { if (suiteName[0] === ".") return; @@ -36,8 +36,18 @@ exports.get = function (entryName) { var suiteOptsLoc = suite.filename + "/options.json"; if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc); - _.each(fs.readdirSync(suite.filename), function (taskName) { - var taskDir = suite.filename + "/" + taskName; + if (fs.statSync(suite.filename).isFile()) { + push(suiteName, suite.filename); + } else { + _.each(fs.readdirSync(suite.filename), function (taskName) { + var taskDir = suite.filename + "/" + taskName; + push(taskName, taskDir); + }); + } + + function push(taskName, taskDir) { + // tracuer error tests + if (taskName.indexOf("Error_") >= 0) return; var actualLocAlias = suiteName + "/" + taskName + "/actual.js"; var expectLocAlias = suiteName + "/" + taskName + "/expected.js"; @@ -49,7 +59,7 @@ exports.get = function (entryName) { if (fs.statSync(taskDir).isFile()) { var ext = path.extname(taskDir); - if (ext !== ".js") return; + if (ext !== ".js" && ext !== ".module.js") return; execLoc = taskDir; } @@ -84,6 +94,18 @@ exports.get = function (entryName) { } }; + // traceur checks + + var shouldSkip = function (code) { + return code.indexOf("// Error:") >= 0 || code.indexOf("// Skip.") >= 0; + }; + + if (shouldSkip(test.actual.code) || shouldSkip(test.exec.code)) { + return; + } else if (test.exec.code.indexOf("// Async.") >= 0) { + //test.options.asyncExec = true; + } + suite.tests.push(test); var sourceMappingsLoc = taskDir + "/source-mappings.json"; @@ -97,7 +119,7 @@ exports.get = function (entryName) { test.options.sourceMap = true; test.sourceMap = require(sourceMap); } - }); + } }); return exports.cache[entryName] = suites; @@ -111,4 +133,5 @@ try { var cache = exports.cache = {}; cache.transformation = exports.get("transformation"); cache.generation = exports.get("generation"); + cache.esnext = exports.get("esnext"); } diff --git a/test/_transformation-helper.js b/test/_transformation-helper.js new file mode 100644 index 0000000000..882d0e85c1 --- /dev/null +++ b/test/_transformation-helper.js @@ -0,0 +1,152 @@ +var genHelpers = require("./_generator-helpers"); +var transform = require("../lib/6to5/transformation/transform"); +var sourceMap = require("source-map"); +var Module = require("module"); +var helper = require("./_helper"); +var assert = require("assert"); +var chai = require("chai"); +var path = require("path"); +var util = require("../lib/6to5/util"); +var _ = require("lodash"); + +require("../lib/6to5/polyfill"); + +global.assertNoOwnProperties = function (obj) { + assert.equal(Object.getOwnPropertyNames(obj).length, 0); +}; + +global.assertArrayEquals = assert.deepEqual; +global.assert = chai.assert; +global.chai = chai; +global.genHelpers = genHelpers; + +// Different Traceur generator message +chai.assert._throw = chai.assert.throw; +chai.assert.throw = function (fn, msg) { + if (msg === '"throw" on executing generator' || + msg === '"next" on executing generator') { + msg = "Generator is already running"; + } else if (msg === "Sent value to newborn generator") { + msg = /^attempt to send (.*?) to newborn generator$/; + } + + return chai.assert._throw(fn, msg); +}; + +var run = function (task, done) { + var actual = task.actual; + var expect = task.expect; + var exec = task.exec; + var opts = task.options; + + var getOpts = function (self) { + return _.merge({ + filename: self.loc + }, opts); + }; + + var execCode = exec.code; + var result; + + if (execCode) { + result = transform(execCode, getOpts(exec)); + execCode = result.code; + + try { + var fakeRequire = function (loc) { + if (loc === "../../../src/runtime/polyfills/Number.js") { + return Number; + } else if (loc === "../../../src/runtime/polyfills/Math.js") { + return Math; + } else { + return require(path.resolve(exec.loc, "..", loc)); + } + }; + + var fn = new Function("require", "done", execCode); + fn.call(global, fakeRequire, chai.assert, done); + } catch (err) { + err.message = exec.loc + ": " + err.message; + err.message += util.codeFrame(execCode); + throw err; + } + } + + var actualCode = actual.code; + var expectCode = expect.code; + if (!execCode || actualCode) { + result = transform(actualCode, getOpts(actual)); + actualCode = result.code; + + chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc); + } + + if (task.sourceMap) { + chai.expect(result.map).to.deep.equal(task.sourceMap); + } + + if (task.sourceMappings) { + var consumer = new sourceMap.SourceMapConsumer(result.map); + + _.each(task.sourceMappings, function (mapping, i) { + var expect = mapping.original; + + var actual = consumer.originalPositionFor(mapping.generated); + chai.expect({ line: actual.line, column: actual.column }).to.deep.equal(expect); + }); + } +}; + +module.exports = function (suiteOpts, taskOpts, dynamicOpts) { + taskOpts = taskOpts || {}; + + require("6to5/register")(taskOpts); + + _.each(helper.get(suiteOpts.name, suiteOpts.loc), function (testSuite) { + if (_.contains(suiteOpts.ignoreSuites, testSuite.title)) return; + + suite(suiteOpts.name + "/" + testSuite.title, function () { + _.each(testSuite.tests, function (task) { + if (_.contains(suiteOpts.ignoreTasks, task.title) || _.contains(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) return; + + var runTest = function (done) { + var runTask = function () { + try { + run(task, done); + } catch (err) { + if (task.options.after) task.options.after(); + throw err; + } + }; + + _.extend(task.options, taskOpts); + if (dynamicOpts) dynamicOpts(task.options, task); + + var throwMsg = task.options.throws; + if (throwMsg) { + // internal api doesn't have this option but it's best not to pollute + // the options object with useless options + delete task.options.throws; + + assert.throws(runTask, function (err) { + return throwMsg === true || err.message.indexOf(throwMsg) >= 0; + }); + } else { + runTask(); + } + }; + + var callback; + if (task.options.asyncExec) { + callback = runTest; + } else { + callback = function () { + return runTest(); + }; + } + + test(task.title, !task.disabled && callback); + }); + }); + }); +}; diff --git a/test/esnext.js b/test/esnext.js new file mode 100644 index 0000000000..86558a55c6 --- /dev/null +++ b/test/esnext.js @@ -0,0 +1,5 @@ +if (!process.env.ALL_6TO5_TESTS) return; + +require("./_transformation-helper")({ + name: "esnext" +}); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js b/test/fixtures/esnext/es6-arrow-functions/arguments-refers-to-parent-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js rename to test/fixtures/esnext/es6-arrow-functions/arguments-refers-to-parent-function.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js b/test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js rename to test/fixtures/esnext/es6-arrow-functions/does-not-bind-this-from-standard-function.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js b/test/fixtures/esnext/es6-arrow-functions/empty-arrow-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js rename to test/fixtures/esnext/es6-arrow-functions/empty-arrow-function.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js b/test/fixtures/esnext/es6-arrow-functions/handles-nested-context-bindings.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js rename to test/fixtures/esnext/es6-arrow-functions/handles-nested-context-bindings.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js b/test/fixtures/esnext/es6-arrow-functions/no-parens-for-low-precedence-expression-body.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js rename to test/fixtures/esnext/es6-arrow-functions/no-parens-for-low-precedence-expression-body.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js b/test/fixtures/esnext/es6-arrow-functions/object-literal-needs-parens.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js rename to test/fixtures/esnext/es6-arrow-functions/object-literal-needs-parens.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js b/test/fixtures/esnext/es6-arrow-functions/only-lexical-this-not-dynamic-this.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js rename to test/fixtures/esnext/es6-arrow-functions/only-lexical-this-not-dynamic-this.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js b/test/fixtures/esnext/es6-arrow-functions/passed-to-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js rename to test/fixtures/esnext/es6-arrow-functions/passed-to-function.js diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js b/test/fixtures/esnext/es6-arrow-functions/single-param-does-not-need-parens.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js rename to test/fixtures/esnext/es6-arrow-functions/single-param-does-not-need-parens.js diff --git a/test/fixtures/transformation/esnext-es6-classes/anonymous-class.js b/test/fixtures/esnext/es6-classes/anonymous-class.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/anonymous-class.js rename to test/fixtures/esnext/es6-classes/anonymous-class.js diff --git a/test/fixtures/transformation/esnext-es6-classes/call-super-function.js b/test/fixtures/esnext/es6-classes/call-super-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/call-super-function.js rename to test/fixtures/esnext/es6-classes/call-super-function.js diff --git a/test/fixtures/transformation/esnext-es6-classes/class-expressions.js b/test/fixtures/esnext/es6-classes/class-expressions.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/class-expressions.js rename to test/fixtures/esnext/es6-classes/class-expressions.js diff --git a/test/fixtures/transformation/esnext-es6-classes/class-extend.js b/test/fixtures/esnext/es6-classes/class-extend.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/class-extend.js rename to test/fixtures/esnext/es6-classes/class-extend.js diff --git a/test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js b/test/fixtures/esnext/es6-classes/class-with-constructor.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js rename to test/fixtures/esnext/es6-classes/class-with-constructor.js diff --git a/test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js b/test/fixtures/esnext/es6-classes/class-with-method-declaration.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js rename to test/fixtures/esnext/es6-classes/class-with-method-declaration.js diff --git a/test/fixtures/transformation/esnext-es6-classes/empty-named-class.js b/test/fixtures/esnext/es6-classes/empty-named-class.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/empty-named-class.js rename to test/fixtures/esnext/es6-classes/empty-named-class.js diff --git a/test/fixtures/transformation/esnext-es6-classes/enumerable.js b/test/fixtures/esnext/es6-classes/enumerable.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/enumerable.js rename to test/fixtures/esnext/es6-classes/enumerable.js diff --git a/test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js b/test/fixtures/esnext/es6-classes/explicit-super-in-constructor.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js rename to test/fixtures/esnext/es6-classes/explicit-super-in-constructor.js diff --git a/test/fixtures/transformation/esnext-es6-classes/extends-null.js b/test/fixtures/esnext/es6-classes/extends-null.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/extends-null.js rename to test/fixtures/esnext/es6-classes/extends-null.js diff --git a/test/fixtures/transformation/esnext-es6-classes/.getter-setter-super.js b/test/fixtures/esnext/es6-classes/getter-setter-super.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/.getter-setter-super.js rename to test/fixtures/esnext/es6-classes/getter-setter-super.js diff --git a/test/fixtures/transformation/esnext-es6-classes/getter-setter.js b/test/fixtures/esnext/es6-classes/getter-setter.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/getter-setter.js rename to test/fixtures/esnext/es6-classes/getter-setter.js diff --git a/test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js b/test/fixtures/esnext/es6-classes/implicit-superclass.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js rename to test/fixtures/esnext/es6-classes/implicit-superclass.js diff --git a/test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js b/test/fixtures/esnext/es6-classes/method-declaration-with-arguments.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js rename to test/fixtures/esnext/es6-classes/method-declaration-with-arguments.js diff --git a/test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js b/test/fixtures/esnext/es6-classes/methods-are-writable.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js rename to test/fixtures/esnext/es6-classes/methods-are-writable.js diff --git a/test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js b/test/fixtures/esnext/es6-classes/methods-with-rest-params.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js rename to test/fixtures/esnext/es6-classes/methods-with-rest-params.js diff --git a/test/fixtures/transformation/esnext-es6-classes/static-getter.js b/test/fixtures/esnext/es6-classes/static-getter.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/static-getter.js rename to test/fixtures/esnext/es6-classes/static-getter.js diff --git a/test/fixtures/transformation/esnext-es6-classes/static-method.js b/test/fixtures/esnext/es6-classes/static-method.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/static-method.js rename to test/fixtures/esnext/es6-classes/static-method.js diff --git a/test/fixtures/transformation/esnext-es6-classes/static-setter.js b/test/fixtures/esnext/es6-classes/static-setter.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/static-setter.js rename to test/fixtures/esnext/es6-classes/static-setter.js diff --git a/test/fixtures/transformation/esnext-es6-classes/.super-change-proto.js b/test/fixtures/esnext/es6-classes/super-change-proto.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-classes/.super-change-proto.js rename to test/fixtures/esnext/es6-classes/super-change-proto.js diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/accessor.js b/test/fixtures/esnext/es6-computed-properties/accessor.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-computed-properties/accessor.js rename to test/fixtures/esnext/es6-computed-properties/accessor.js diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/method.js b/test/fixtures/esnext/es6-computed-properties/method.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-computed-properties/method.js rename to test/fixtures/esnext/es6-computed-properties/method.js diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/nested.js b/test/fixtures/esnext/es6-computed-properties/nested.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-computed-properties/nested.js rename to test/fixtures/esnext/es6-computed-properties/nested.js diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/simple.js b/test/fixtures/esnext/es6-computed-properties/simple.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-computed-properties/simple.js rename to test/fixtures/esnext/es6-computed-properties/simple.js diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/arity.js b/test/fixtures/esnext/es6-default-parameters/arity.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-default-parameters/arity.js rename to test/fixtures/esnext/es6-default-parameters/arity.js diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js b/test/fixtures/esnext/es6-default-parameters/arrow-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js rename to test/fixtures/esnext/es6-default-parameters/arrow-function.js diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js b/test/fixtures/esnext/es6-default-parameters/null-vs-undefined.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js rename to test/fixtures/esnext/es6-default-parameters/null-vs-undefined.js diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/scope.js b/test/fixtures/esnext/es6-default-parameters/scope.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-default-parameters/scope.js rename to test/fixtures/esnext/es6-default-parameters/scope.js diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js b/test/fixtures/esnext/es6-default-parameters/simple-function.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js rename to test/fixtures/esnext/es6-default-parameters/simple-function.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js b/test/fixtures/esnext/es6-object-concise/method-arguments.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js rename to test/fixtures/esnext/es6-object-concise/method-arguments.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-context.js b/test/fixtures/esnext/es6-object-concise/method-context.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method-context.js rename to test/fixtures/esnext/es6-object-concise/method-context.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js b/test/fixtures/esnext/es6-object-concise/method-has-name.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js rename to test/fixtures/esnext/es6-object-concise/method-has-name.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js b/test/fixtures/esnext/es6-object-concise/method-is-not-in-scope-inside.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js rename to test/fixtures/esnext/es6-object-concise/method-is-not-in-scope-inside.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js b/test/fixtures/esnext/es6-object-concise/method-to-string.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js rename to test/fixtures/esnext/es6-object-concise/method-to-string.js diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method.js b/test/fixtures/esnext/es6-object-concise/method.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-object-concise/method.js rename to test/fixtures/esnext/es6-object-concise/method.js diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js b/test/fixtures/esnext/es6-rest-parameters/arrow-fn.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js rename to test/fixtures/esnext/es6-rest-parameters/arrow-fn.js diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js b/test/fixtures/esnext/es6-rest-parameters/declaration.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js rename to test/fixtures/esnext/es6-rest-parameters/declaration.js diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js b/test/fixtures/esnext/es6-rest-parameters/rest.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-rest-parameters/rest.js rename to test/fixtures/esnext/es6-rest-parameters/rest.js diff --git a/test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js b/test/fixtures/esnext/es6-spread/arguments-as-array.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js rename to test/fixtures/esnext/es6-spread/arguments-as-array.js diff --git a/test/fixtures/transformation/esnext-es6-spread/array-literal.js b/test/fixtures/esnext/es6-spread/array-literal.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/array-literal.js rename to test/fixtures/esnext/es6-spread/array-literal.js diff --git a/test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js b/test/fixtures/esnext/es6-spread/call-with-array-literal.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js rename to test/fixtures/esnext/es6-spread/call-with-array-literal.js diff --git a/test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js b/test/fixtures/esnext/es6-spread/inside-function-expression.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js rename to test/fixtures/esnext/es6-spread/inside-function-expression.js diff --git a/test/fixtures/transformation/esnext-es6-spread/iterator.js b/test/fixtures/esnext/es6-spread/iterator.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/iterator.js rename to test/fixtures/esnext/es6-spread/iterator.js diff --git a/test/fixtures/transformation/esnext-es6-spread/new-object.js b/test/fixtures/esnext/es6-spread/new-object.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/new-object.js rename to test/fixtures/esnext/es6-spread/new-object.js diff --git a/test/fixtures/transformation/esnext-es6-spread/preserve-context.js b/test/fixtures/esnext/es6-spread/preserve-context.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/preserve-context.js rename to test/fixtures/esnext/es6-spread/preserve-context.js diff --git a/test/fixtures/transformation/esnext-es6-spread/simple-function-call.js b/test/fixtures/esnext/es6-spread/simple-function-call.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-spread/simple-function-call.js rename to test/fixtures/esnext/es6-spread/simple-function-call.js diff --git a/test/fixtures/transformation/esnext-es6-templates/multi-line.js b/test/fixtures/esnext/es6-templates/multi-line.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/multi-line.js rename to test/fixtures/esnext/es6-templates/multi-line.js diff --git a/test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js b/test/fixtures/esnext/es6-templates/nested-interpolation.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js rename to test/fixtures/esnext/es6-templates/nested-interpolation.js diff --git a/test/fixtures/transformation/esnext-es6-templates/no-interpolation.js b/test/fixtures/esnext/es6-templates/no-interpolation.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/no-interpolation.js rename to test/fixtures/esnext/es6-templates/no-interpolation.js diff --git a/test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js b/test/fixtures/esnext/es6-templates/raw-tagged-template-expression.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js rename to test/fixtures/esnext/es6-templates/raw-tagged-template-expression.js diff --git a/test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js b/test/fixtures/esnext/es6-templates/simple-interpolation.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js rename to test/fixtures/esnext/es6-templates/simple-interpolation.js diff --git a/test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js b/test/fixtures/esnext/es6-templates/tagged-template-expression.js similarity index 100% rename from test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js rename to test/fixtures/esnext/es6-templates/tagged-template-expression.js diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index 14f12f07e2..1600d655fb 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -2,6 +2,9 @@ var _slice = Array.prototype.slice; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js index 95ba3c53f4..29526be129 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-properties/expected.js @@ -1,6 +1,9 @@ "use strict"; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js index 1b2b38ce31..7e8f2bfd43 100644 --- a/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes/calling-super-properties/expected.js @@ -1,6 +1,9 @@ "use strict"; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-classes/constructor/expected.js b/test/fixtures/transformation/es6-classes/constructor/expected.js index d43c12f6e7..cc5264d5b6 100644 --- a/test/fixtures/transformation/es6-classes/constructor/expected.js +++ b/test/fixtures/transformation/es6-classes/constructor/expected.js @@ -1,6 +1,9 @@ "use strict"; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js index a3dc10057d..d9a40e4753 100644 --- a/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class-id-member-expression/expected.js @@ -1,6 +1,9 @@ "use strict"; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-classes/super-class/expected.js b/test/fixtures/transformation/es6-classes/super-class/expected.js index 50b689e121..01534a385f 100644 --- a/test/fixtures/transformation/es6-classes/super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/super-class/expected.js @@ -1,6 +1,9 @@ "use strict"; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/es6-generators/LICENSE b/test/fixtures/transformation/es6-generators/LICENSE deleted file mode 100644 index eba1d817f5..0000000000 --- a/test/fixtures/transformation/es6-generators/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2014, Facebook, Inc. -All rights reserved. - -This source code is licensed under the BSD-style license found in the -https://raw.github.com/facebook/regenerator/master/LICENSE file. An -additional grant of patent rights can be found in the PATENTS file in -the same directory. diff --git a/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-correctly/exec.js b/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-correctly/exec.js deleted file mode 100644 index 140f327a37..0000000000 --- a/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-correctly/exec.js +++ /dev/null @@ -1,24 +0,0 @@ -function *gen() { - var a$0 = 0, a$1 = 1; - - let a = 3; - - { - let a = 1; - yield a + a$0; - } - - { - let a = 2; - yield a - 1 + a$1; - } - - yield a; -} - -var g = gen(); - -assert.deepEqual(g.next(), { value: 1, done: false }); -assert.deepEqual(g.next(), { value: 2, done: false }); -assert.deepEqual(g.next(), { value: 3, done: false }); -assert.deepEqual(g.next(), { value: void 0, done: true }); diff --git a/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-with-iife-correctly/exec.js b/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-with-iife-correctly/exec.js deleted file mode 100644 index 3edc3451b3..0000000000 --- a/test/fixtures/transformation/es6-generators/block-binding-should-translate-block-binding-with-iife-correctly/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -function *gen() { - let arr = []; - - for (let x = 0; x < 3; x++) { - let y = x; - arr.push(function() { return y; }); - } - - { - let x; - while( x = arr.pop() ) { - yield x; - } - } -} - -var g = gen(); - -assert.equal(g.next().value(), 2); -assert.equal(g.next().value(), 1); -assert.equal(g.next().value(), 0); -assert.deepEqual(g.next(), { value: void 0, done: true }); diff --git a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-allow-nested-catch-parameters-of-the-same-name/exec.js b/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-allow-nested-catch-parameters-of-the-same-name/exec.js deleted file mode 100644 index bfa31390c1..0000000000 --- a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-allow-nested-catch-parameters-of-the-same-name/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -function *gen() { - try { - genHelpers.raise("e1"); - } catch (e) { - yield e; - try { - genHelpers.raise("e2"); - } catch (e) { - yield e; - } - yield e; - } -} - -genHelpers.check(gen(), ["e1", "e2", "e1"]); diff --git a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-leave-outer-variables-unmodified/exec.js b/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-leave-outer-variables-unmodified/exec.js deleted file mode 100644 index cedc2ee2d7..0000000000 --- a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-leave-outer-variables-unmodified/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -function *gen(x) { - var y = x + 1; - try { - throw x + 2; - } catch (x) { - yield x; - x += 1; - yield x; - } - yield x; - try { - throw x + 3; - } catch (y) { - yield y; - y *= 2; - yield y; - } - yield y; -} - -genHelpers.check(gen(1), [3, 4, 1, 4, 8, 2]); -genHelpers.check(gen(2), [4, 5, 2, 5, 10, 3]); diff --git a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-not-replace-variables-defined-in-inner-scopes/exec.js b/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-not-replace-variables-defined-in-inner-scopes/exec.js deleted file mode 100644 index e5e527e3c3..0000000000 --- a/test/fixtures/transformation/es6-generators/catch-parameter-shadowing-should-not-replace-variables-defined-in-inner-scopes/exec.js +++ /dev/null @@ -1,32 +0,0 @@ -function *gen(x) { - try { - throw x; - } catch (x) { - yield x; - - yield (function(x) { - return x += 1; - }(x + 1)); - - yield (function() { - var x = arguments[0]; - return x * 2; - }(x + 2)); - - yield (function() { - function notCalled(x) { - throw x; - } - - x >>= 1; - return x; - }()); - - yield x -= 1; - } - - yield x; -} - -genHelpers.check(gen(10), [10, 12, 24, 5, 4, 10]); -genHelpers.check(gen(11), [11, 13, 26, 5, 4, 11]); diff --git a/test/fixtures/transformation/es6-generators/collatz-generator/exec.js b/test/fixtures/transformation/es6-generators/collatz-generator/exec.js deleted file mode 100644 index 9bc63db1e9..0000000000 --- a/test/fixtures/transformation/es6-generators/collatz-generator/exec.js +++ /dev/null @@ -1,42 +0,0 @@ -function *gen(n) { - var count = 0; - - yield n; - - while (n !== 1) { - count += 1; - - if (n % 2) { - yield n = n * 3 + 1; - } else { - yield n >>= 1; - } - } - - return count; -} - -function collatz(n) { - var result = [n]; - - while (n !== 1) { - if (n % 2) { - n *= 3; - n += 1; - } else { - n >>= 1; - } - - result.push(n); - } - - return result; -} - -var seven = collatz(7); -var fiftyTwo = seven.slice(seven.indexOf(52)); -var eightyTwo = collatz(82); - -genHelpers.check(gen(7), seven, 16); -genHelpers.check(gen(52), fiftyTwo, 11); -genHelpers.check(gen(82), eightyTwo, 110); diff --git a/test/fixtures/transformation/es6-generators/completed-generator/exec.js b/test/fixtures/transformation/es6-generators/completed-generator/exec.js deleted file mode 100644 index 540636d9d3..0000000000 --- a/test/fixtures/transformation/es6-generators/completed-generator/exec.js +++ /dev/null @@ -1,11 +0,0 @@ -function *gen() { - return "ALL DONE"; -} - -var g = gen(); - -assert.deepEqual(g.next(), { - value: "ALL DONE", done: true -}); - -genHelpers.assertAlreadyFinished(g); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-be-governed-by-enclosing-try-statements/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-be-governed-by-enclosing-try-statements/exec.js deleted file mode 100644 index a4f36ea34b..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-be-governed-by-enclosing-try-statements/exec.js +++ /dev/null @@ -1,27 +0,0 @@ -var error = new Error("thrown"); - -function *outer(n) { - try { - yield 0; - yield* inner(n); - yield 1; - } catch (err) { - yield err.message; - } - yield 4; -} - -function *inner(n) { - while (n --> 0) { - try { - if (n === 3) { - genHelpers.raise(error); - } - } finally { - yield n; - } - } -} - -genHelpers.check(outer(3), [0, 2, 1, 0, 1, 4]); -genHelpers.check(outer(5), [0, 4, 3, "thrown", 4]); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-cope-with-empty-delegatees/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-cope-with-empty-delegatees/exec.js deleted file mode 100644 index bf51aa9c8f..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-cope-with-empty-delegatees/exec.js +++ /dev/null @@ -1,10 +0,0 @@ -function *gen(condition) { - if (condition) { - yield 0; - yield* gen(false); - yield 1; - } -} - -genHelpers.check(gen(true), [0, 1]); -genHelpers.check(gen(false), []); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-delegate-correctly/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-delegate-correctly/exec.js deleted file mode 100644 index 2db0a32fd5..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-delegate-correctly/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -function *gen(condition) { - yield 0; - if (condition) { - yield 1; - yield* gen(false); - yield 2; - } - yield 3; -} - -genHelpers.check(gen(true), [0, 1, 0, 3, 2, 3]); -genHelpers.check(gen(false), [0, 3]); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-dispatch-thrown-exceptions-correctly/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-dispatch-thrown-exceptions-correctly/exec.js deleted file mode 100644 index 1dff85c4ab..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-dispatch-thrown-exceptions-correctly/exec.js +++ /dev/null @@ -1,37 +0,0 @@ -var count = 0; - -function *gen() { - yield* inner(); - try { - yield* inner(); - } catch (err) { - // pass - } - return yield* inner(); -} - -function *inner() { - return yield count++; -} - -var g = gen(); - -assert.deepEqual(g.next(), { - value: 0, - done: false -}); - -assert.deepEqual(g.next(), { - value: 1, - done: false -}); - -assert.deepEqual(g.throw(new Error("lol")), { - value: 2, - done: false, -}); - -assert.deepEqual(g.next("sent"), { - value: "sent", - done: true -}); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-pass-sent-values-through/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-pass-sent-values-through/exec.js deleted file mode 100644 index 1abc3a015a..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-pass-sent-values-through/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -function *outer(n) { - yield* inner(n << 1); - yield "zxcv"; -} - -function *inner(n) { - return yield yield yield n; -} - -var g = outer(3); -assert.deepEqual(g.next(), { value: 6, done: false }); -assert.deepEqual(g.next(1), { value: 1, done: false }); -assert.deepEqual(g.next(2), { value: 2, done: false }); -assert.deepEqual(g.next(4), { value: "zxcv", done: false }); -assert.deepEqual(g.next(5), { value: void 0, done: true }); diff --git a/test/fixtures/transformation/es6-generators/delegated-yield-should-support-deeper-nesting/exec.js b/test/fixtures/transformation/es6-generators/delegated-yield-should-support-deeper-nesting/exec.js deleted file mode 100644 index f3b8d0f438..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yield-should-support-deeper-nesting/exec.js +++ /dev/null @@ -1,18 +0,0 @@ -function *outer(n) { - yield n; - yield* middle(n - 1, inner(n + 10)); - yield n + 1; -} - -function *middle(n, plusTen) { - yield n; - yield* inner(n - 1); - yield n + 1; - yield* plusTen; -} - -function *inner(n) { - yield n; -} - -genHelpers.check(outer(5), [5, 4, 3, 5, 15, 6]); diff --git a/test/fixtures/transformation/es6-generators/delegated-yieldshould-support-any-iterable-argument/exec.js b/test/fixtures/transformation/es6-generators/delegated-yieldshould-support-any-iterable-argument/exec.js deleted file mode 100644 index de52f46776..0000000000 --- a/test/fixtures/transformation/es6-generators/delegated-yieldshould-support-any-iterable-argument/exec.js +++ /dev/null @@ -1,11 +0,0 @@ -function *gen() { - yield 0; - yield* [ - yield "one", - yield "two", - yield "three" - ]; - yield 5; -} - -genHelpers.check(gen(), [0, "one", "two", "three", 2, 3, 4, 5]); diff --git a/test/fixtures/transformation/es6-generators/dynamic-exception-should-be-dispatched-correctly/exec.js b/test/fixtures/transformation/es6-generators/dynamic-exception-should-be-dispatched-correctly/exec.js deleted file mode 100644 index 27a64b3356..0000000000 --- a/test/fixtures/transformation/es6-generators/dynamic-exception-should-be-dispatched-correctly/exec.js +++ /dev/null @@ -1,20 +0,0 @@ -function *gen(x, fname) { - try { - return fns[fname](x); - } catch (thrown) { - yield thrown; - } - } - - var fns = { - f: function(x) { - throw x; - }, - - g: function(x) { - return x; - } - }; - - genHelpers.check(gen("asdf", "f"), ["asdf"]); - genHelpers.check(gen("asdf", "g"), [], "asdf"); diff --git a/test/fixtures/transformation/es6-generators/empty-while-loops-should-be-preserved-in-generated-code/exec.js b/test/fixtures/transformation/es6-generators/empty-while-loops-should-be-preserved-in-generated-code/exec.js deleted file mode 100644 index e762ed9881..0000000000 --- a/test/fixtures/transformation/es6-generators/empty-while-loops-should-be-preserved-in-generated-code/exec.js +++ /dev/null @@ -1,16 +0,0 @@ -function *gen(x) { - while (x) { - // empty while loop - } - - do { - // empty do-while loop - } while (x); - - return gen.toString(); -} - -var info = gen(false).next(); -assert.strictEqual(info.done, true); -assert.ok(/do \{/.test(info.value)); -assert.ok(/while \(/.test(info.value)); diff --git a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-break-in-loop/exec.js b/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-break-in-loop/exec.js deleted file mode 100644 index e5a2225e7b..0000000000 --- a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-break-in-loop/exec.js +++ /dev/null @@ -1,19 +0,0 @@ -function *gen(obj) { - var count = 0; - for (var key in (yield "why not", obj)) { - if (obj.hasOwnProperty(key)) { - if (key === "skip") { - break; - } - count += 1; - yield [key, obj[key]]; - } - } - return count; -} - -genHelpers.check( - gen({ a: 1, b: 2, skip: 3, c: 4 }), - ["why not", ["a", 1], ["b", 2]], - 2 -); diff --git a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-property-deletion-in-loop/exec.js b/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-property-deletion-in-loop/exec.js deleted file mode 100644 index e0b9313bd7..0000000000 --- a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-property-deletion-in-loop/exec.js +++ /dev/null @@ -1,13 +0,0 @@ -function *gen() { - var count = 0; - var obj = {foo: 1, bar: 2}; - for (var key in obj) { - assert(obj.hasOwnProperty(key), key + " must be own property"); - yield [key, obj[key]]; - delete obj.bar; - count += 1; - } - return count; -} - -genHelpers.check(gen(), [["foo", 1]], 1); diff --git a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-risky-object-expressions/exec.js b/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-risky-object-expressions/exec.js deleted file mode 100644 index 9fa63ef689..0000000000 --- a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-risky-object-expressions/exec.js +++ /dev/null @@ -1,26 +0,0 @@ -function a(sent) { - assert.strictEqual(sent, 1); - a.called = true; -} - -function b(sent) { - assert.strictEqual(sent, 2); - b.called = true; - return { callee: b }; -} - -function *gen() { - assert.ok(!a.called); - assert.ok(!b.called); - for (var key in a(yield 0), b(yield 1)) { - assert.ok(a.called); - assert.ok(b.called); - assert.strictEqual(yield key, 3); - } - - for (var key in a(1), { foo: "foo", bar: "bar" }) { - yield key; - } -} - -genHelpers.check(gen(), [0, 1, "callee", "foo", "bar"]); diff --git a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-the-simple-case/exec.js b/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-the-simple-case/exec.js deleted file mode 100644 index 740041c23f..0000000000 --- a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-handle-the-simple-case/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -function *gen() { - var count = 0; - var obj = {foo: 1, bar: 2}; - for (var key in obj) { - assert(obj.hasOwnProperty(key), key + " must be own property"); - yield [key, obj[key]]; - count += 1; - } - return count; -} - -genHelpers.check(gen(), [["foo", 1], ["bar", 2]], 2); diff --git a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-loop-over-inherited-properties/exec.js b/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-loop-over-inherited-properties/exec.js deleted file mode 100644 index 1248131d9b..0000000000 --- a/test/fixtures/transformation/es6-generators/for-in-loop-generator-should-loop-over-inherited-properties/exec.js +++ /dev/null @@ -1,16 +0,0 @@ -function *gen() { - var count = 0; - function Foo() { - this.baz = 1 - } - Foo.prototype.bar = 2; - - var foo = new Foo(); - for (var key in foo) { - yield [key, foo[key]]; - count += 1; - } - return count; -} - -genHelpers.check(gen(), [["baz", 1], ["bar", 2]], 2); diff --git a/test/fixtures/transformation/es6-generators/for-loop-with-var-decl-and-no-update-expression-should-compile-and-run/exec.js b/test/fixtures/transformation/es6-generators/for-loop-with-var-decl-and-no-update-expression-should-compile-and-run/exec.js deleted file mode 100644 index 933b61aa3c..0000000000 --- a/test/fixtures/transformation/es6-generators/for-loop-with-var-decl-and-no-update-expression-should-compile-and-run/exec.js +++ /dev/null @@ -1,7 +0,0 @@ -// https://github.com/facebook/regenerator/issues/103 -function *range() { - for (var i = 0; false; ) { - } -} - -genHelpers.check(range(), []); diff --git a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-Arrays/exec.js b/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-Arrays/exec.js deleted file mode 100644 index 30b287a0b1..0000000000 --- a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-Arrays/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -var sum = 0; -for (var x of [1, 2].concat(3)) { - sum += x; -} -assert.strictEqual(sum, 6); diff --git a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-generators/exec.js b/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-generators/exec.js deleted file mode 100644 index 667e1b67bf..0000000000 --- a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-for-generators/exec.js +++ /dev/null @@ -1,10 +0,0 @@ -function *range(n) { - for (var i = 0; i < n; ++i) { - yield i; - } -} - -var value, values = []; -for (value of range(3)) - values.push(value); -assert.deepEqual(values, [0, 1, 2]); diff --git a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-inside-of-generators/exec.js b/test/fixtures/transformation/es6-generators/for-of-loops-should-work-inside-of-generators/exec.js deleted file mode 100644 index fda5afe451..0000000000 --- a/test/fixtures/transformation/es6-generators/for-of-loops-should-work-inside-of-generators/exec.js +++ /dev/null @@ -1,45 +0,0 @@ -function *yieldPermutations(list) { - if (list.length < 2) { - yield list; - return 1; - } - - var count = 0; - var first = list.slice(0, 1); - var genRest = yieldPermutations(list.slice(1)); - - for (var perm of genRest) { - for (var i = 0; i < list.length; ++i) { - var prefix = perm.slice(0, i); - var suffix = perm.slice(i); - yield prefix.concat(first, suffix); - } - - count += i; - } - - return count; -} - -var count = 0; -for (var perm of yieldPermutations([])) { - assert.deepEqual(perm, []); - ++count; -} -assert.strictEqual(count, 1); - -genHelpers.check(yieldPermutations([1]), [[1]], 1); - -genHelpers.check(yieldPermutations([2, 1]), [ - [2, 1], - [1, 2] -], 2); - -genHelpers.check(yieldPermutations([1,3,2]), [ - [1, 3, 2], - [3, 1, 2], - [3, 2, 1], - [1, 2, 3], - [2, 1, 3], - [2, 3, 1] -], 6); diff --git a/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-even-if-the-declarations-are-out-of-order/exec.js b/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-even-if-the-declarations-are-out-of-order/exec.js deleted file mode 100644 index 1b1de7c33b..0000000000 --- a/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-even-if-the-declarations-are-out-of-order/exec.js +++ /dev/null @@ -1,24 +0,0 @@ -function *gen(n) { - yield increment(n); - - function increment(x) { - return x + 1; - } - - if (n % 2) { - yield halve(decrement(n)); - - function halve(x) { - return x >> 1; - } - - function decrement(x) { - return x - 1; - } - } - - yield increment(increment(n)); -} - -genHelpers.check(gen(3), [4, 1, 5]); -genHelpers.check(gen(4), [5, 6]); diff --git a/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-for-nested-generator-function-declarations/exec.js b/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-for-nested-generator-function-declarations/exec.js deleted file mode 100644 index 62337159e3..0000000000 --- a/test/fixtures/transformation/es6-generators/function-declaration-hoisting-should-work-for-nested-generator-function-declarations/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -function *outer(n) { - yield 0; - assert.ok(regeneratorRuntime.isGeneratorFunction(inner)); - return yield* inner(n); - - // Note that this function declaration comes after everything else - // in the outer function, but needs to be fully available above. - function *inner(n) { - yield n - 1; - yield n; - return yield n + 1; - } -} - -genHelpers.check(outer(2), [0, 1, 2, 3], 4); diff --git a/test/fixtures/transformation/es6-generators/generator-function-expression-should-behave-just-like-a-declared-generator/exec.js b/test/fixtures/transformation/es6-generators/generator-function-expression-should-behave-just-like-a-declared-generator/exec.js deleted file mode 100644 index 6dd8796cb4..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-function-expression-should-behave-just-like-a-declared-generator/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -genHelpers.check(function *(x, y) { - yield x; - yield y; - yield x + y; - return x * y; -}(3, 7), [3, 7, 10], 21); diff --git a/test/fixtures/transformation/es6-generators/generator-function-prototype-should-follow-the-expected-object-model/exec.js b/test/fixtures/transformation/es6-generators/generator-function-prototype-should-follow-the-expected-object-model/exec.js deleted file mode 100644 index db35e057a7..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-function-prototype-should-follow-the-expected-object-model/exec.js +++ /dev/null @@ -1,60 +0,0 @@ - -var GeneratorFunctionPrototype = f.__proto__; -var GeneratorFunction = GeneratorFunctionPrototype.constructor; - -assert.strictEqual(GeneratorFunction.name, 'GeneratorFunction'); -assert.strictEqual(GeneratorFunction.prototype, - GeneratorFunctionPrototype); -assert.strictEqual(GeneratorFunctionPrototype.prototype.constructor, - GeneratorFunctionPrototype); -assert.strictEqual(GeneratorFunctionPrototype.prototype, - f.prototype.__proto__); -assert.strictEqual(GeneratorFunctionPrototype.__proto__, - Function.prototype); -assert.strictEqual(GeneratorFunctionPrototype.name, - "GeneratorFunctionPrototype"); - -assert.strictEqual(typeof f2, "function"); -assert.strictEqual(f2.constructor, GeneratorFunction); -assert.ok(f2 instanceof GeneratorFunction); -assert.strictEqual(f2.name, "f2"); - -var g = f(); -assert.ok(g instanceof f); -assert.strictEqual(g.__proto__, f.prototype); - -assert.deepEqual([], Object.getOwnPropertyNames(f.prototype)); -// assert.deepEqual([], Object.getOwnPropertyNames(g)); - -f.prototype.x = 42; - -var g2 = f(); -assert.strictEqual(g2.x, 42); - -var g3 = new f(); -assert.strictEqual(g3.x, 42); - -function* f2() { - yield 1; -} - -assert.strictEqual(f.__proto__, f2.__proto__); -assert.strictEqual(f.hasOwnProperty('constructor'), false); -assert.strictEqual(f.__proto__.constructor.name, 'GeneratorFunction'); - -// Intentionally at the end to test hoisting. -function* f() { - yield this; -} - -function* f() { - yield 1; -} - -var f2 = f; -f = 42; -var g = f2(); - -assert.deepEqual(g.next(), { value: 1, done: false }); -assert.deepEqual(g.next(), { value: void 0, done: true }); -assert.ok(g instanceof f2); diff --git a/test/fixtures/transformation/es6-generators/generator-reentry-attempt-should-complain-with-a-TypeError/exec.js b/test/fixtures/transformation/es6-generators/generator-reentry-attempt-should-complain-with-a-TypeError/exec.js deleted file mode 100644 index ce41e9851e..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-reentry-attempt-should-complain-with-a-TypeError/exec.js +++ /dev/null @@ -1,18 +0,0 @@ -function *gen(x) { - try { - (yield x).next(x); - } catch (err) { - yield err; - } - return x + 1; -} - -var g = gen(3); -assert.deepEqual(g.next(), { value: 3, done: false }); -var complaint = g.next(g); // Sending the generator to itself. -assert.ok(complaint.value instanceof Error); -assert.strictEqual( - complaint.value.message, - "Generator is already running" -); -assert.deepEqual(g.next(), { value: 4, done: true }); diff --git a/test/fixtures/transformation/es6-generators/generator-return-method-should-behave-as-if-generator-actually-returned/exec.js b/test/fixtures/transformation/es6-generators/generator-return-method-should-behave-as-if-generator-actually-returned/exec.js deleted file mode 100644 index 089deed534..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-return-method-should-behave-as-if-generator-actually-returned/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -var executedFinally = false; - -function *gen() { - try { - yield 0; - } catch (err) { - assert.ok(false, "should not have executed the catch handler"); - } finally { - executedFinally = true; - } -} - -var g = gen(); -assert.deepEqual(g.next(), { value: 0, done: false }); - -assert.deepEqual(g.return("argument"), { - value: "argument", - done: true -}); - -assert.strictEqual(executedFinally, true); -genHelpers.assertAlreadyFinished(g); diff --git a/test/fixtures/transformation/es6-generators/generator-return-method-should-work-with-newborn-generators/exec.js b/test/fixtures/transformation/es6-generators/generator-return-method-should-work-with-newborn-generators/exec.js deleted file mode 100644 index 84f60dbf8f..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-return-method-should-work-with-newborn-generators/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -function *gen() { - yield 0; -} - -var g = gen(); - -assert.deepEqual(g.return("argument"), { - value: "argument", - done: true -}); - -genHelpers.assertAlreadyFinished(g); diff --git a/test/fixtures/transformation/es6-generators/generator-throw-method-should-complete-generator/exec.js b/test/fixtures/transformation/es6-generators/generator-throw-method-should-complete-generator/exec.js deleted file mode 100644 index c41c82c2dd..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-throw-method-should-complete-generator/exec.js +++ /dev/null @@ -1,16 +0,0 @@ -function *gen(x) { - yield 2; - throw 1; -} - -var u = gen(); - -u.next(); - -try { - u.throw(2); -} catch (err) { - assert.strictEqual(err, 2); -} - -genHelpers.assertAlreadyFinished(u); diff --git a/test/fixtures/transformation/es6-generators/generator-throw-method-should-immediately-complete-a-new-born-generator/exec.js b/test/fixtures/transformation/es6-generators/generator-throw-method-should-immediately-complete-a-new-born-generator/exec.js deleted file mode 100644 index 175435b562..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-throw-method-should-immediately-complete-a-new-born-generator/exec.js +++ /dev/null @@ -1,16 +0,0 @@ -var began = false; - -function *gen() { - began = true; - yield 1; -} - -var g = gen(); -var exception = new Error("unhandled exception"); -try { - g.throw(exception); - assert.ok(false, "should have thrown an exception"); -} catch (err) { - assert.strictEqual(err, exception); - assert.strictEqual(began, false); -} diff --git a/test/fixtures/transformation/es6-generators/generator-throw-method-should-not-propagate-errors-handled-inside-a-delegate/exec.js b/test/fixtures/transformation/es6-generators/generator-throw-method-should-not-propagate-errors-handled-inside-a-delegate/exec.js deleted file mode 100644 index dcdce48792..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-throw-method-should-not-propagate-errors-handled-inside-a-delegate/exec.js +++ /dev/null @@ -1,20 +0,0 @@ -function *outer() { - try { - yield* inner(); - } catch (err) { - return -1; - } - return 1; -} - -function *inner() { - try { - yield void 0; - } catch (e) { - return; - } -} - -var g = outer(); -g.next(); -assert.equal(g.throw(new Error('foo')).value, 1); diff --git a/test/fixtures/transformation/es6-generators/generator-throw-method-should-propagate-errors-unhandled-inside-a-delegate/exec.js b/test/fixtures/transformation/es6-generators/generator-throw-method-should-propagate-errors-unhandled-inside-a-delegate/exec.js deleted file mode 100644 index 295a4c8aeb..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-throw-method-should-propagate-errors-unhandled-inside-a-delegate/exec.js +++ /dev/null @@ -1,16 +0,0 @@ -function *outer() { - try { - yield* inner(); - } catch (err) { - return -1; - } - return 1; -} - -function *inner() { - yield void 0; -} - -var g = outer(); -g.next(); -assert.equal(g.throw(new Error('foo')).value, -1); diff --git a/test/fixtures/transformation/es6-generators/generator-throw-method-should-work-after-the-final-call-to-next/exec.js b/test/fixtures/transformation/es6-generators/generator-throw-method-should-work-after-the-final-call-to-next/exec.js deleted file mode 100644 index 7017683f5e..0000000000 --- a/test/fixtures/transformation/es6-generators/generator-throw-method-should-work-after-the-final-call-to-next/exec.js +++ /dev/null @@ -1,14 +0,0 @@ -function *gen() { - yield 1; -} - -var g = gen(); -assert.deepEqual(g.next(), { value: 1, done: false }); - -var exception = new Error("unhandled exception"); -try { - g.throw(exception); - assert.ok(false, "should have thrown an exception"); -} catch (err) { - assert.strictEqual(err, exception); -} diff --git a/test/fixtures/transformation/es6-generators/infinite-sequence-generator/exec.js b/test/fixtures/transformation/es6-generators/infinite-sequence-generator/exec.js deleted file mode 100644 index 7c74586b83..0000000000 --- a/test/fixtures/transformation/es6-generators/infinite-sequence-generator/exec.js +++ /dev/null @@ -1,41 +0,0 @@ -function *gen(start, step) { - step = step || 1; - while (true) { - yield start; - start += step; - } -} - -function *limit(g, stop) { - while (true) { - var info = g.next(); - if (info.done) { - return; - } else if (info.value < stop) { - yield info.value; - } else { - return; - } - } -} - -// should generate a lot of plausible values -var g = gen(10, 2); - -assert.deepEqual(g.next(), { value: 10, done: false }); -assert.deepEqual(g.next(), { value: 12, done: false }); -assert.deepEqual(g.next(), { value: 14, done: false }); -assert.deepEqual(g.next(), { value: 16, done: false }); - -var sum = 10 + 12 + 14 + 16; - -for (var n = 0; n < 1000; ++n) { - var info = g.next(); - sum += info.value; - assert.strictEqual(info.done, false); -} - -assert.strictEqual(sum, 1017052); - -// should allow limiting -genHelpers.check(limit(gen(10, 3), 20), [10, 13, 16, 19]); diff --git a/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-declarations/exec.js b/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-declarations/exec.js deleted file mode 100644 index daebbf16da..0000000000 --- a/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-declarations/exec.js +++ /dev/null @@ -1,19 +0,0 @@ -// Do the assertions up here to make sure the generator function is -// marked at the beginning of the block the function is declared in. -assert.strictEqual( - regeneratorRuntime.isGeneratorFunction(genFun), - true -); - -assert.strictEqual( - regeneratorRuntime.isGeneratorFunction(normalFun), - false -); - -function normalFun() { - return 0; -} - -function *genFun() { - yield 0; -} diff --git a/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-expressions/exec.js b/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-expressions/exec.js deleted file mode 100644 index a7649e0737..0000000000 --- a/test/fixtures/transformation/es6-generators/isGeneratorFunction-should-work-for-function-expressions/exec.js +++ /dev/null @@ -1,13 +0,0 @@ -assert.strictEqual( - regeneratorRuntime.isGeneratorFunction(function *genFun() { - yield 0; - }), - true -); - -assert.strictEqual( - regeneratorRuntime.isGeneratorFunction(function normalFun() { - return 0; - }), - false -); diff --git a/test/fixtures/transformation/es6-generators/labeled-break-and-continue-statements-should-be-able-to-exit-multiple-try-statements/exec.js b/test/fixtures/transformation/es6-generators/labeled-break-and-continue-statements-should-be-able-to-exit-multiple-try-statements/exec.js deleted file mode 100644 index 3bf4008ebe..0000000000 --- a/test/fixtures/transformation/es6-generators/labeled-break-and-continue-statements-should-be-able-to-exit-multiple-try-statements/exec.js +++ /dev/null @@ -1,82 +0,0 @@ - - var e1 = "first"; - var e2 = "second"; - var e3 = "third"; - var e4 = "fourth"; - - function *gen(n, which) { - try { - yield 0; - genHelpers.raise(e1); - - } finally { - yield 1; - - loop: - for (var i = 0; i < n; ++i) { - yield i; - - try { - genHelpers.raise(e2); - } finally { - yield 2; - - try { - genHelpers.raise(e3); - } finally { - yield 3; - - try { - genHelpers.raise(e4); - } finally { - yield 4; - - if (which === "break") { - yield "breaking"; - break loop; - } - - if (which === "continue") { - yield "continuing"; - continue loop; - } - - yield 5; - } - } - } - } - - yield 6; - } - } - - try { - genHelpers.check(gen(1, "break"), [ - 0, 1, 0, 2, 3, 4, "breaking", 6 - ]); - assert.ok(false, "should have thrown an exception"); - } catch (err) { - assert.strictEqual(err, e1); - } - - try { - genHelpers.check(gen(3, "continue"), [ - 0, 1, 0, 2, 3, 4, "continuing", - 1, 2, 3, 4, "continuing", - 2, 2, 3, 4, "continuing", - 6 // Loop finished naturally. - ]); - assert.ok(false, "should have thrown an exception"); - } catch (err) { - assert.strictEqual(err, e1); - } - - try { - genHelpers.check(gen(3, "neither"), [ - 0, 1, 0, 2, 3, 4, 5 - ]); - assert.ok(false, "should have thrown an exception"); - } catch (err) { - assert.strictEqual(err, e4); - } diff --git a/test/fixtures/transformation/es6-generators/nested-finally-blocks/exec.js b/test/fixtures/transformation/es6-generators/nested-finally-blocks/exec.js deleted file mode 100644 index 1bcdee5b49..0000000000 --- a/test/fixtures/transformation/es6-generators/nested-finally-blocks/exec.js +++ /dev/null @@ -1,41 +0,0 @@ -function *usingThrow() { - try { - try { - try { - throw "thrown"; - } finally { - yield 1; - } - } catch (thrown) { - yield thrown; - } finally { - yield 2; - } - } finally { - yield 3; - } -} - -function *usingRaise() { - try { - try { - try { - genHelpers.raise("thrown"); - } finally { - yield 1; - } - } catch (thrown) { - yield thrown; - } finally { - yield 2; - } - } finally { - yield 3; - } -} - -// should statically execute in order -genHelpers.check(usingThrow(), [1, "thrown", 2, 3]); - -// should dynamically execute in order -genHelpers.check(usingRaise(), [1, "thrown", 2, 3]); diff --git a/test/fixtures/transformation/es6-generators/nested-generators-in-try-catch-should-get-a-reference-to-the-caught-error/exec.js b/test/fixtures/transformation/es6-generators/nested-generators-in-try-catch-should-get-a-reference-to-the-caught-error/exec.js deleted file mode 100644 index f585b20cba..0000000000 --- a/test/fixtures/transformation/es6-generators/nested-generators-in-try-catch-should-get-a-reference-to-the-caught-error/exec.js +++ /dev/null @@ -1,18 +0,0 @@ -function *gen() { - try { - nonExistent; - } catch (e) { - yield function* () { - yield e; - } - } -} - -var genFun2 = gen().next().value; -assert.ok(regeneratorRuntime.isGeneratorFunction(genFun2)); -var gen2 = genFun2(); -var res = gen2.next(); -assert.ok(res.value instanceof ReferenceError); -// Note that we don't do strict equality over the message because it varies -// across browsers (if we ever want to run tests in browsers). -assert.ok(res.value.message.match(/nonExistent/)); diff --git a/test/fixtures/transformation/es6-generators/new-expressions-should-be-able-to-contain-yield-sub-expressions/exec.js b/test/fixtures/transformation/es6-generators/new-expressions-should-be-able-to-contain-yield-sub-expressions/exec.js deleted file mode 100644 index 6435d69531..0000000000 --- a/test/fixtures/transformation/es6-generators/new-expressions-should-be-able-to-contain-yield-sub-expressions/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -function A(first, second) { - this.first = first; - this.second = second; -} - -function *gen() { - return yield new (yield 0)(yield 1, yield 2); -} - -var g = gen(); - -assert.deepEqual(g.next(), { value: 0, done: false }); -assert.deepEqual(g.next(A), { value: 1, done: false }); -assert.deepEqual(g.next("asdf"), { value: 2, done: false }); - -var info = g.next("zxcv"); -assert.strictEqual(info.done, false); -assert.ok(info.value instanceof A); -assert.strictEqual(info.value.first, "asdf"); -assert.strictEqual(info.value.second, "zxcv"); - -assert.deepEqual(g.next("qwer"), { value: "qwer", done: true }); diff --git a/test/fixtures/transformation/es6-generators/newborn-generators-should-allow-chaining-newborn-and-non-newborn-generators/exec.js b/test/fixtures/transformation/es6-generators/newborn-generators-should-allow-chaining-newborn-and-non-newborn-generators/exec.js deleted file mode 100644 index 630120638b..0000000000 --- a/test/fixtures/transformation/es6-generators/newborn-generators-should-allow-chaining-newborn-and-non-newborn-generators/exec.js +++ /dev/null @@ -1,40 +0,0 @@ -function *range(n) { - for (var i = 0; i < n; ++i) { - yield i; - } -} - -function *chain(a, b) { - yield* a; - yield* b; -} - -genHelpers.check(chain(range(3), range(5)), [0, 1, 2, 0, 1, 2, 3, 4]); - -function *y3(x) { - return yield yield yield x; -} - -function *y5(x) { - return yield yield yield yield yield x; -} - -genHelpers.check( - chain(y3("foo"), y5("bar")), - ["foo", 1, 2, "bar", 4, 5, 6, 7] -); - -var g3 = y3("three"); -assert.deepEqual(g3.next(), { - value: "three", - done: false -}); - -var g5 = y5("five"); -assert.deepEqual(g5.next(), { - value: "five", - done: false -}); - -var undef; // A little easier to read than void 0. -genHelpers.check(chain(g3, g5), [undef, 1, undef, 3, 4, 5]); diff --git a/test/fixtures/transformation/es6-generators/newborn-generators-should-be-able-to-yield-star-non-newborn-generators/exec.js b/test/fixtures/transformation/es6-generators/newborn-generators-should-be-able-to-yield-star-non-newborn-generators/exec.js deleted file mode 100644 index 9d8d186519..0000000000 --- a/test/fixtures/transformation/es6-generators/newborn-generators-should-be-able-to-yield-star-non-newborn-generators/exec.js +++ /dev/null @@ -1,29 +0,0 @@ -function *inner() { - return [yield 1, yield 2]; -} - -function *outer(delegate) { - return yield* delegate; -} - -var n = inner(); - -assert.deepEqual(n.next(), { - value: 1, - done: false -}); - -var g = outer(n); - -// I would really like to be able to pass 3 to g.next here, but V8 -// ignores values sent to newborn generators, and SpiderMonkey throws -// a TypeError. -assert.deepEqual(g.next(), { - value: 2, - done: false -}); - -assert.deepEqual(g.next(4), { - value: [void 0, 4], - done: true -}); diff --git a/test/fixtures/transformation/es6-generators/newborn-generators-should-support-the-ignore-initial-yield-wrapper-idiom/exec.js b/test/fixtures/transformation/es6-generators/newborn-generators-should-support-the-ignore-initial-yield-wrapper-idiom/exec.js deleted file mode 100644 index 2eb492c895..0000000000 --- a/test/fixtures/transformation/es6-generators/newborn-generators-should-support-the-ignore-initial-yield-wrapper-idiom/exec.js +++ /dev/null @@ -1,58 +0,0 @@ -var markers = []; - -function *inner() { - markers.push(0); - var sent1 = yield 1; - markers.push(2); - var sent2 = yield 2; - markers.push(3); - return [sent1, sent2]; -} - -function wrapper(delegate) { - var gen = (function*() { - // This yield is the "initial yield" whose argument we ignore. - var sent = yield "ignored", info; - - markers.push(1); - - while (!(info = delegate.next(sent)).done) { - sent = yield info.value; - } - - markers.push(4); - - return info.value; - })(); - - // Ensure that gen is not newborn and that the next invocation of - // gen.next(value) can send value to the initial yield expression. - gen.next(); - - return gen; -} - -var n = inner(); - -assert.deepEqual(n.next(), { - value: 1, - done: false -}); - -var g = wrapper(n); - -// Unlike in the previous spec, it's fine to pass 3 to g.next here, -// because g is not newborn, because g.next was already called once -// before g was returned from the wrapper function. -assert.deepEqual(g.next(3), { - value: 2, - done: false -}); - -assert.deepEqual(g.next(4), { - value: [3, 4], - done: true -}); - -// Ensure we encountered the marker points in the expected order. -assert.deepEqual(markers, [0, 1, 2, 3, 4]); diff --git a/test/fixtures/transformation/es6-generators/object-literal-generator-should-yield-the-correct-object/exec.js b/test/fixtures/transformation/es6-generators/object-literal-generator-should-yield-the-correct-object/exec.js deleted file mode 100644 index a45a519ba8..0000000000 --- a/test/fixtures/transformation/es6-generators/object-literal-generator-should-yield-the-correct-object/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -function *gen(a, b) { - yield { - a: a - (yield a), - b: yield b - }; -} - -genHelpers.check(gen(1, 2), [1, 2, { a: 0, b: 2 }]); -genHelpers.check(gen(4, 2), [4, 2, { a: 3, b: 2 }]); diff --git a/test/fixtures/transformation/es6-generators/object-literals-with-multiple-yields-should-receive-different-sent-values/exec.js b/test/fixtures/transformation/es6-generators/object-literals-with-multiple-yields-should-receive-different-sent-values/exec.js deleted file mode 100644 index e18ec96410..0000000000 --- a/test/fixtures/transformation/es6-generators/object-literals-with-multiple-yields-should-receive-different-sent-values/exec.js +++ /dev/null @@ -1,17 +0,0 @@ -function *gen(fn) { - return { - a: yield "a", - b: yield "b", - c: fn(yield "c", yield "d"), - d: [yield "e", yield "f"] - }; -} - -genHelpers.check(gen(function sum(x, y) { - return x + y; -}), ["a", "b", "c", "d", "e", "f"], { - a: 1, - b: 2, - c: 3 + 4, - d: [5, 6] -}); diff --git a/test/fixtures/transformation/es6-generators/range-generator/exec.js b/test/fixtures/transformation/es6-generators/range-generator/exec.js deleted file mode 100644 index eef007c261..0000000000 --- a/test/fixtures/transformation/es6-generators/range-generator/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -function *range(n) { - for (var i = 0; i < n; ++i) { - yield i; - } -} - -genHelpers.check(range(0), []); - -genHelpers.check(range(5), [0, 1, 2, 3, 4]); diff --git a/test/fixtures/transformation/es6-generators/should-support-multiple-yields-in-expression/exec.js b/test/fixtures/transformation/es6-generators/should-support-multiple-yields-in-expression/exec.js deleted file mode 100644 index 07ea21e280..0000000000 --- a/test/fixtures/transformation/es6-generators/should-support-multiple-yields-in-expression/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -function *gen() { return (yield 0) + (yield 0); } -var itr = gen(); -itr.next(); -itr.next(1); -assert.equal(itr.next(2).value, 3); diff --git a/test/fixtures/transformation/es6-generators/should-yield-only-its-first-argument/exec.js b/test/fixtures/transformation/es6-generators/should-yield-only-its-first-argument/exec.js deleted file mode 100644 index d872a6c160..0000000000 --- a/test/fixtures/transformation/es6-generators/should-yield-only-its-first-argument/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -function *gen(x) { - yield x; -} - -genHelpers.check(gen("oyez"), ["oyez"]); -genHelpers.check(gen("foo", "bar"), ["foo"]); diff --git a/test/fixtures/transformation/es6-generators/switch-statement-generator-should-jump-to-the-correct-cases/exec.js b/test/fixtures/transformation/es6-generators/switch-statement-generator-should-jump-to-the-correct-cases/exec.js deleted file mode 100644 index f506e3dc92..0000000000 --- a/test/fixtures/transformation/es6-generators/switch-statement-generator-should-jump-to-the-correct-cases/exec.js +++ /dev/null @@ -1,11 +0,0 @@ -function *gen(a) { - switch (yield a) { - case (yield "x") - a: - return "first case"; - case (yield "y") - a: - return "second case"; - } -} - -genHelpers.check(gen(1), [1, "x"], "first case"); -genHelpers.check(gen(2), [2, "x", "y"], "second case"); diff --git a/test/fixtures/transformation/es6-generators/the-arguments-object-should-not-get-confused-by-properties/exec.js b/test/fixtures/transformation/es6-generators/the-arguments-object-should-not-get-confused-by-properties/exec.js deleted file mode 100644 index 0193713567..0000000000 --- a/test/fixtures/transformation/es6-generators/the-arguments-object-should-not-get-confused-by-properties/exec.js +++ /dev/null @@ -1,7 +0,0 @@ -function *gen(obj) { - yield obj.arguments; - obj.arguments = "oyez"; - yield obj; -} - -genHelpers.check(gen({ arguments: 42 }), [42, { arguments: "oyez" }]); diff --git a/test/fixtures/transformation/es6-generators/the-arguments-object-should-work-in-simple-variadic-functions/exec.js b/test/fixtures/transformation/es6-generators/the-arguments-object-should-work-in-simple-variadic-functions/exec.js deleted file mode 100644 index 2082baecd9..0000000000 --- a/test/fixtures/transformation/es6-generators/the-arguments-object-should-work-in-simple-variadic-functions/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -function *sum() { - var result = 0; - - for (var i = 0; i < arguments.length; ++i) { - yield result += arguments[i]; - } - - return result; -} - -genHelpers.check(sum(1, 2, 3), [1, 3, 6], 6); -genHelpers.check(sum(9, -5, 3, 0, 2), [9, 4, 7, 7, 9], 9); diff --git a/test/fixtures/transformation/es6-generators/throw-should-complete-generator/exec.js b/test/fixtures/transformation/es6-generators/throw-should-complete-generator/exec.js deleted file mode 100644 index aeba49f47d..0000000000 --- a/test/fixtures/transformation/es6-generators/throw-should-complete-generator/exec.js +++ /dev/null @@ -1,13 +0,0 @@ -function *gen(x) { - throw 1; -} - -var u = gen(); - -try { - u.next(); -} catch (err) { - assert.strictEqual(err, 1); -} - -genHelpers.assertAlreadyFinished(u); diff --git a/test/fixtures/transformation/es6-generators/try-catch-finally-generator/exec.js b/test/fixtures/transformation/es6-generators/try-catch-finally-generator/exec.js deleted file mode 100644 index 5c25e461bd..0000000000 --- a/test/fixtures/transformation/es6-generators/try-catch-finally-generator/exec.js +++ /dev/null @@ -1,42 +0,0 @@ - - function *usingThrow() { - yield 0; - try { - try { - yield 1; - throw 2; - yield 3; - } catch (x) { - throw yield x; - } finally { - yield 5; - } - } catch (thrown) { - yield thrown; - } - yield 6; - } - - function *usingRaise() { - yield 0; - try { - try { - yield 1; - genHelpers.raise(2); - yield 3; - } catch (x) { - throw yield x; - } finally { - yield 5; - } - } catch (thrown) { - yield thrown; - } - yield 6; - } - - // should statically catch and then finalize - genHelpers.check(usingThrow(), [0, 1, 2, 5, 3, 6]); - - // should dynamically catch and then finalize - genHelpers.check(usingRaise(), [0, 1, 2, 5, 3, 6]); diff --git a/test/fixtures/transformation/es6-generators/try-catch-generator/exec.js b/test/fixtures/transformation/es6-generators/try-catch-generator/exec.js deleted file mode 100644 index 67ce947eab..0000000000 --- a/test/fixtures/transformation/es6-generators/try-catch-generator/exec.js +++ /dev/null @@ -1,33 +0,0 @@ -function *usingThrow(x) { - yield 0; - try { - yield 1; - if (x % 2 === 0) - throw 2; - yield x; - } catch (x) { - yield x; - } - yield 3; -} - -function *usingRaise(x) { - yield 0; - try { - yield 1; - if (x % 2 === 0) - genHelpers.raise(2); - yield x; - } catch (x) { - yield x; - } - yield 3; -} - -// should catch static exceptions properly -genHelpers.check(usingThrow(4), [0, 1, 2, 3]); -genHelpers.check(usingThrow(5), [0, 1, 5, 3]); - -// should catch dynamic exceptions properly -genHelpers.check(usingRaise(4), [0, 1, 2, 3]); -genHelpers.check(usingRaise(5), [0, 1, 5, 3]); diff --git a/test/fixtures/transformation/es6-generators/try-finally-generator/exec.js b/test/fixtures/transformation/es6-generators/try-finally-generator/exec.js deleted file mode 100644 index 889aa259cc..0000000000 --- a/test/fixtures/transformation/es6-generators/try-finally-generator/exec.js +++ /dev/null @@ -1,114 +0,0 @@ -function *usingThrow(condition) { - yield 0; - try { - yield 1; - throw 2; - yield 3; - } finally { - if (condition) { - yield 4; - return 5; - } - yield 6; - return 7; - } -} - -function *usingRaise(condition) { - yield 0; - try { - yield 1; - genHelpers.raise(2); - yield 3; - } finally { - if (condition) { - yield 4; - return 5; - } - yield 6; - return 7; - } -} - -// should execute finally blocks statically -genHelpers.check(usingThrow(true), [0, 1, 4], 5); -genHelpers.check(usingThrow(false), [0, 1, 6], 7); - -// should execute finally blocks dynamically -genHelpers.check(usingRaise(true), [0, 1, 4], 5); -genHelpers.check(usingRaise(false), [0, 1, 6], 7); - -// should execute finally blocks before throwing -var uncaughtError = new Error("uncaught"); - -function *uncaught(condition) { - try { - yield 0; - if (condition) { - yield 1; - genHelpers.raise(uncaughtError); - } - yield 2; - } finally { - yield 3; - } - yield 4; -} - -genHelpers.check(uncaught(false), [0, 2, 3, 4]); - -var u = uncaught(true); - -assert.deepEqual(u.next(), { value: 0, done: false }); -assert.deepEqual(u.next(), { value: 1, done: false }); -assert.deepEqual(u.next(), { value: 3, done: false }); - -try { - u.next(); - assert.ok(false, "should have thrown an exception"); -} catch (err) { - assert.strictEqual(err, uncaughtError); -} - -// should throw correct error when finally contains catch -var right = new Error("right"); -var wrong = new Error("wrong"); - -function *gen() { - try { - yield 0; - genHelpers.raise(right); - } finally { - yield 1; - try { - genHelpers.raise(wrong); - } catch (err) { - assert.strictEqual(err, wrong); - yield 2; - } - } -} - -var g = gen(); - -assert.deepEqual(g.next(), { - value: 0, - done: false -}); - -assert.deepEqual(g.next(), { - value: 1, - done: false -}); - -assert.deepEqual(g.next(), { - value: 2, - done: false -}); - -try { - g.next(); - assert.ok(false, "should have thrown an exception"); -} catch (err) { - assert.strictEqual(err, right); -} diff --git a/test/fixtures/transformation/es6-generators/unqualified-function-calls-should-have-a-global-`this`-object/exec.js b/test/fixtures/transformation/es6-generators/unqualified-function-calls-should-have-a-global-`this`-object/exec.js deleted file mode 100644 index 35f5677b77..0000000000 --- a/test/fixtures/transformation/es6-generators/unqualified-function-calls-should-have-a-global-`this`-object/exec.js +++ /dev/null @@ -1,26 +0,0 @@ -function getThis() { - return this; -} - -// This is almost certainly the global object, but there's a chance it -// might be null or undefined (in strict mode). -var unqualifiedThis = getThis(); - -function *invoke() { - // It seems like a bug in the ES6 spec that we have to yield an - // argument instead of just calling (yield)(). - return (yield "dummy")(); -} - -var g = invoke(); -var info = g.next(); - -assert.deepEqual(info, { value: "dummy", done: false }); - -info = g.next(getThis); - -// Avoid using assert.strictEqual when the arguments might equal the -// global object, since JSON.stringify chokes on circular structures. -assert.ok(info.value === unqualifiedThis); - -assert.strictEqual(info.done, true); diff --git a/test/fixtures/transformation/es6-generators/yield-chain-should-have-correct-associativity/exec.js b/test/fixtures/transformation/es6-generators/yield-chain-should-have-correct-associativity/exec.js deleted file mode 100644 index 5918d1c894..0000000000 --- a/test/fixtures/transformation/es6-generators/yield-chain-should-have-correct-associativity/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -function *gen(n) { - return yield yield yield yield n; -} - -genHelpers.check(gen(5), [5, 1, 2, 3], 4); -genHelpers.check(gen("asdf"), ["asdf", 1, 2, 3], 4); diff --git a/test/fixtures/transformation/es6-generators/yield-star-expression-results-can-be-used-in-complex-expressions/exec.js b/test/fixtures/transformation/es6-generators/yield-star-expression-results-can-be-used-in-complex-expressions/exec.js deleted file mode 100644 index ffe646947a..0000000000 --- a/test/fixtures/transformation/es6-generators/yield-star-expression-results-can-be-used-in-complex-expressions/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -function pumpNumber(gen) { - var n = 0; - - while (true) { - var res = n > 0 ? gen.next(n) : gen.next(); - n = res.value; - if (res.done) { - return n; - } - } -} - -function* foo() { - return (yield* bar()) + (yield* bar()); -} - -function* bar() { - return (yield 2) + (yield 3); -} - -assert.strictEqual(pumpNumber(bar()), 5); -assert.strictEqual(pumpNumber(foo()), 10); diff --git a/test/fixtures/transformation/es6-generators/yield-star-expression-results-have-correct-values/exec.js b/test/fixtures/transformation/es6-generators/yield-star-expression-results-have-correct-values/exec.js deleted file mode 100644 index 8622122707..0000000000 --- a/test/fixtures/transformation/es6-generators/yield-star-expression-results-have-correct-values/exec.js +++ /dev/null @@ -1,11 +0,0 @@ -function* foo() { - yield 0; - return yield* bar(); -} - -function* bar() { - yield 1; - return 2; -} - -genHelpers.check(foo(), [0, 1], 2); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/closure/actual.js b/test/fixtures/transformation/es6-let-scoping-traceur/closure/actual.js deleted file mode 100644 index e443b2633f..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/closure/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -(function() { - let foo = 'bar'; - - [true].forEach(function() { - foo = 'baz'; - }); - - console.log(foo); -}); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/closure/expected.js b/test/fixtures/transformation/es6-let-scoping-traceur/closure/expected.js deleted file mode 100644 index ae5ea97d75..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/closure/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; - -(function () { - var foo = "bar"; - - [true].forEach(function () { - foo = "baz"; - }); - - console.log(foo); -}); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/deep-nested/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/deep-nested/exec.js deleted file mode 100644 index 6880f64525..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/deep-nested/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -var a = 'var a'; -{ - var b = 'var b'; - { - var c = 'var c'; - let d = 'let d'; - assert.equal(d, 'let d'); - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/for-in-initializers/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/for-in-initializers/exec.js deleted file mode 100644 index 3228d3680e..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/for-in-initializers/exec.js +++ /dev/null @@ -1,17 +0,0 @@ -var result; -{ - let let_result = []; - let let_array = ['one', 'two', 'three']; - for (var index in let_array) { - let let_index = index; - let let_value = let_array[let_index]; - let_result.push(function () { - return [let_index, let_value]; - }); - } - result = let_result; -} - -assert.deepEqual(['0', 'one'], result[0]()); -assert.deepEqual(['1', 'two'], result[1]()); -assert.deepEqual(['2', 'three'], result[2]()); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/for-initializers/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/for-initializers/exec.js deleted file mode 100644 index 89892cb5c3..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/for-initializers/exec.js +++ /dev/null @@ -1,26 +0,0 @@ -var result; -{ - let let_x = 'let x'; - let let_l = []; - for (var var_x = 1, var_y = 2, var_z = 3; var_x < 10; var_x ++) { - let l_x = var_x, l_y = var_y, l_z = var_z; - let_l.push(function () { - return [l_x, l_y, l_z]; - }); - } - result = let_l; -} - -assert.deepEqual(result.map(function (fn) { - return fn(); -}), [ - [ 1, 2, 3 ], - [ 2, 2, 3 ], - [ 3, 2, 3 ], - [ 4, 2, 3 ], - [ 5, 2, 3 ], - [ 6, 2, 3 ], - [ 7, 2, 3 ], - [ 8, 2, 3 ], - [ 9, 2, 3 ] -]); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/actual.js b/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/actual.js deleted file mode 100644 index fdd92c1221..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -domready(function () { - let a = 1; - const b = 1; - runIt(); - - function runIt() { - console.log(a + b); - } -}); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/expected.js b/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/expected.js deleted file mode 100644 index 3e681cb35b..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/function-declaration/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; - -domready(function () { - var a = 1; - var b = 1; - runIt(); - - function runIt() { - console.log(a + b); - } -}); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-class/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-class/exec.js deleted file mode 100644 index d410cf0ccb..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-class/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -class LetInClass { - get z() { - let let_z = 10; - return let_z; - } - - set z(v) { - let let_zv = v; - } - - distance() { - let dist = this.y - this.x; - return dist; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-closure/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-closure/exec.js deleted file mode 100644 index e01538c804..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-closure/exec.js +++ /dev/null @@ -1,21 +0,0 @@ -function letInClosure(n) { - var l = []; - for (var i = 0; i < n; i ++) { - let let_i = i; - if (i % 3 == 0) { - continue; - } - l.push(function () { - return let_i; - }); - } - return l; -} - -var result = letInClosure(10); -assert.equal(1, result[0]()); -assert.equal(2, result[1]()); -assert.equal(4, result[2]()); -assert.equal(5, result[3]()); -assert.equal(7, result[4]()); -assert.equal(8, result[5]()); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-inner/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-inner/exec.js deleted file mode 100644 index 802fed4059..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-inner/exec.js +++ /dev/null @@ -1,8 +0,0 @@ -for (var x = 0; x < 10; x ++) { - for (var y = 0; y < 10; y ++) { - let z = 'let z'; - if (x == 7) { - break; - } - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-named/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-named/exec.js deleted file mode 100644 index 973ea8e35f..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break-named/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -outer: -for (var x = 0; x < 10; x ++) { - for (var y = 0; y < 10; y ++) { - let z = 'let z'; - if (x == 7) { - break outer; - } - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break/exec.js deleted file mode 100644 index 1fbe54486d..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-break/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -for (var x = 0; x < 10; x ++) { - let y = 'let y'; - if (x % 2 == 0) { - break; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-inner/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-inner/exec.js deleted file mode 100644 index 539d540e3a..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-inner/exec.js +++ /dev/null @@ -1,8 +0,0 @@ -for (var x = 0; x < 10; x ++) { - for (var y = 0; y < 10; y ++) { - let z = 'let z'; - if (x == 7) { - continue; - } - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-named/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-named/exec.js deleted file mode 100644 index 85efb6541d..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue-named/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -outer: -for (var x = 0; x < 10; x ++) { - for (var y = 0; y < 10; y ++) { - let z = 'let z'; - if (x == 7) { - continue outer; - } - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue/exec.js deleted file mode 100644 index 4458457d71..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for-continue/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -for (var x = 0; x < 10; x ++) { - let y = 'let y'; - if (x % 2 == 0) { - continue; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-for/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-for/exec.js deleted file mode 100644 index de1630e09e..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-for/exec.js +++ /dev/null @@ -1,3 +0,0 @@ -for (var x = 0; x < 10; x ++) { - let y = 'let y'; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/in-properties/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/in-properties/exec.js deleted file mode 100644 index 9cba2236c1..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/in-properties/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -var object = { - get x() { - while (true) { - let let_x = 'let x'; - return let_x; - } - }, - - set x(v) { - do { - let let_v = v; - this.v = let_v; - } while (false); - } -}; diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-1/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-1/exec.js deleted file mode 100644 index dd2909dea2..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-1/exec.js +++ /dev/null @@ -1,3 +0,0 @@ -for (let x = 1; x < 10; x++) { - x; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-2/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-2/exec.js deleted file mode 100644 index a2bd89dbac..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-2/exec.js +++ /dev/null @@ -1,4 +0,0 @@ -for (let x = 1, y = 2, z = 3; x < 10; x ++) { - y++; - z++; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-3/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-3/exec.js deleted file mode 100644 index 73f4794698..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-3/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -for (let x = 1, y = x + 1; x < 10 && y != 0; x ++, y *= 2) { - if (y > 300) { - continue; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-in/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-in/exec.js deleted file mode 100644 index b80574713d..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/initializer-for-in/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -let sum = 0; -let a = [1,2,3]; -for (let x in a) { - sum = sum + a[x]; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/nested-conflict/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/nested-conflict/exec.js deleted file mode 100644 index 4243019c5f..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/nested-conflict/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -(function () { - var x = 1; - function f() { - assert.equal(x, 1); - { - let x = 2; - assert.equal(x, 2); - } - assert.equal(x, 1); - } - f(); -})(); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-1/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-1/exec.js deleted file mode 100644 index 617db23c44..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-1/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -function nestedFunction1() { - return function () { - let let_x = 'let x'; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-2/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-2/exec.js deleted file mode 100644 index f993f344c2..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-2/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -function nestedFunction2() { - let let_func = function () { - let let_x = 'let x'; - } - return let_func; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-3/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-3/exec.js deleted file mode 100644 index 3e45d93ff5..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/nested-function-3/exec.js +++ /dev/null @@ -1,4 +0,0 @@ -function nestedFunction3() { - let let_x = 'let x'; - function function_foo() { } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/nested/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/nested/exec.js deleted file mode 100644 index bf9b8f57d0..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/nested/exec.js +++ /dev/null @@ -1,7 +0,0 @@ -var x = 'var'; -{ - let y = 'let 1'; -} -{ - let y = 'let 2'; -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer-global/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer-global/exec.js deleted file mode 100644 index f01f21783d..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer-global/exec.js +++ /dev/null @@ -1,4 +0,0 @@ -let x2; -assert.equal(undefined, x2); -x2 = 2; -assert.equal(2, x2); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer/exec.js deleted file mode 100644 index f9d28fb681..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/no-initializer/exec.js +++ /dev/null @@ -1,8 +0,0 @@ -var x = 1; -{ - let x; - assert.equal(undefined, x); - x = 2; - assert.equal(2, x); -} -assert.equal(1, x); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/actual.js b/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/actual.js deleted file mode 100644 index c26fd3ff99..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -function foo (n) { - let bar = n; - eval('console.log(bar)'); -} - -foo(42); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/expected.js b/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/expected.js deleted file mode 100644 index 5499842172..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/no-renaming/expected.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; - -function foo(n) { - var bar = n; - eval("console.log(bar)"); -} - -foo(42); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/regress-1381/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/regress-1381/exec.js deleted file mode 100644 index 26c224809a..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/regress-1381/exec.js +++ /dev/null @@ -1,8 +0,0 @@ -function test() { - let ret = true; - while (false) - for (let i = 0; i < 1; i++) - ret = () => i; - return ret -} -assert.ok(test()); diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/with-for-in/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/with-for-in/exec.js deleted file mode 100644 index 7f6fbf1740..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/with-for-in/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -for (var x in [1,2,3]) { - let let_y = x; - for (var for_in_z in [4,5,6]) { - continue; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/with-for/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/with-for/exec.js deleted file mode 100644 index 07912563f8..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/with-for/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -for (var x = 0; x < 10; x++) { - let let_y = 'let y'; - for (var for_z = 0; for_z < 2; for_z ++) { - break; - } -} diff --git a/test/fixtures/transformation/es6-let-scoping-traceur/with-switch/exec.js b/test/fixtures/transformation/es6-let-scoping-traceur/with-switch/exec.js deleted file mode 100644 index 5100a8032e..0000000000 --- a/test/fixtures/transformation/es6-let-scoping-traceur/with-switch/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -for (var i = 0; i < 5; i ++) { - let let_x = 'let x'; - - switch (i) { - case 0: - break; - case 2: - break; - default: - break; - } -} diff --git a/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js index 8e2d46f06e..7483137265 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js @@ -1,17 +1,21 @@ "use strict"; define(["exports", "foo"], function (exports, _foo) { + var _interopRequire = function (obj) { + return obj && (obj["default"] || obj); + }; + (function (obj) { for (var i in obj) { exports[i] = obj[i]; } })(_foo); - exports.foo = _foo.foo; - exports.foo = _foo.foo; - exports.bar = _foo.bar; - exports.bar = _foo.foo; - exports["default"] = _foo.foo; - exports["default"] = _foo.foo; - exports.bar = _foo.bar; + exports.foo = _interopRequire(_foo); + exports.foo = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); + exports["default"] = _interopRequire(_foo); + exports["default"] = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); }); diff --git a/test/fixtures/transformation/es6-modules-common/exports-from/expected.js b/test/fixtures/transformation/es6-modules-common/exports-from/expected.js index feaeac94ee..23274cc873 100644 --- a/test/fixtures/transformation/es6-modules-common/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-common/exports-from/expected.js @@ -1,15 +1,19 @@ "use strict"; +var _interopRequire = function (obj) { + return obj && (obj["default"] || obj); +}; + (function (obj) { for (var i in obj) { exports[i] = obj[i]; } })(require("foo")); -exports.foo = require("foo").foo; -exports.foo = require("foo").foo; -exports.bar = require("foo").bar; -exports.bar = require("foo").foo; -exports["default"] = require("foo").foo; -exports["default"] = require("foo").foo; -exports.bar = require("foo").bar; +exports.foo = _interopRequire(require("foo")); +exports.foo = _interopRequire(require("foo")); +exports.bar = _interopRequire(require("foo")); +exports.bar = _interopRequire(require("foo")); +exports["default"] = _interopRequire(require("foo")); +exports["default"] = _interopRequire(require("foo")); +exports.bar = _interopRequire(require("foo")); diff --git a/test/fixtures/transformation/es6-modules-common/imports-glob/expected.js b/test/fixtures/transformation/es6-modules-common/imports-glob/expected.js index 3293bd0ebd..d885f06222 100644 --- a/test/fixtures/transformation/es6-modules-common/imports-glob/expected.js +++ b/test/fixtures/transformation/es6-modules-common/imports-glob/expected.js @@ -1,3 +1,9 @@ "use strict"; -var foo = require("foo"); +var _interopRequireWildcard = function (obj) { + return obj && obj.constructor === Object ? obj : { + "default": obj + }; +}; + +var foo = _interopRequireWildcard(require("foo")); diff --git a/test/fixtures/transformation/es6-modules-common/overview/expected.js b/test/fixtures/transformation/es6-modules-common/overview/expected.js index ed9175cbfb..9ce11f0b0d 100644 --- a/test/fixtures/transformation/es6-modules-common/overview/expected.js +++ b/test/fixtures/transformation/es6-modules-common/overview/expected.js @@ -1,5 +1,11 @@ "use strict"; +var _interopRequireWildcard = function (obj) { + return obj && obj.constructor === Object ? obj : { + "default": obj + }; +}; + var _interopRequire = function (obj) { return obj && (obj["default"] || obj); }; @@ -12,7 +18,7 @@ require("./directory/foo-bar"); var foo = _interopRequire(require("foo")); -var foo = require("foo"); +var foo = _interopRequireWildcard(require("foo")); var bar = require("foo").bar; var bar = require("foo").foo; diff --git a/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js index 522d97be92..70af3ecb6f 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js @@ -7,17 +7,21 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + var _interopRequire = function (obj) { + return obj && (obj["default"] || obj); + }; + (function (obj) { for (var i in obj) { exports[i] = obj[i]; } })(_foo); - exports.foo = _foo.foo; - exports.foo = _foo.foo; - exports.bar = _foo.bar; - exports.bar = _foo.foo; - exports["default"] = _foo.foo; - exports["default"] = _foo.foo; - exports.bar = _foo.bar; + exports.foo = _interopRequire(_foo); + exports.foo = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); + exports["default"] = _interopRequire(_foo); + exports["default"] = _interopRequire(_foo); + exports.bar = _interopRequire(_foo); }); diff --git a/test/fixtures/transformation/es7-async-functions/LICENSE b/test/fixtures/transformation/es7-async-functions/LICENSE deleted file mode 100644 index eba1d817f5..0000000000 --- a/test/fixtures/transformation/es7-async-functions/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2014, Facebook, Inc. -All rights reserved. - -This source code is licensed under the BSD-style license found in the -https://raw.github.com/facebook/regenerator/master/LICENSE file. An -additional grant of patent rights can be found in the PATENTS file in -the same directory. diff --git a/test/fixtures/transformation/es7-async-functions/dependent-promises-should-be-awaitable-out-of-order/exec.js b/test/fixtures/transformation/es7-async-functions/dependent-promises-should-be-awaitable-out-of-order/exec.js deleted file mode 100644 index ef8e93ddcd..0000000000 --- a/test/fixtures/transformation/es7-async-functions/dependent-promises-should-be-awaitable-out-of-order/exec.js +++ /dev/null @@ -1,26 +0,0 @@ -async function outer(value) { - var resolved = false; - var p1 = new Promise(function(resolve) { - setTimeout(function() { - resolve(value + 1); - resolved = true; - }, 0); - }); - - assert.strictEqual(resolved, false); - - var v2 = await p1.then(function(value) { - return value + 1; - }); - - assert.strictEqual(resolved, true); - - var v1 = await p1; - - return [v1, v2]; -} - -outer(1).then(function(pair) { - assert.deepEqual(pair, [2, 3]); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/es7-async-functions/nested-async-function-calls-should-evaluate-in-the-right-order/exec.js b/test/fixtures/transformation/es7-async-functions/nested-async-function-calls-should-evaluate-in-the-right-order/exec.js deleted file mode 100644 index 2e9ac0094f..0000000000 --- a/test/fixtures/transformation/es7-async-functions/nested-async-function-calls-should-evaluate-in-the-right-order/exec.js +++ /dev/null @@ -1,40 +0,0 @@ -var markers = []; - -async function innerMost(marker) { - markers.push(marker); - return await marker; -} - -async function inner(marker) { - markers.push(marker); - - assert.strictEqual( - await innerMost(marker + 1), - marker + 1 - ); - - markers.push(marker + 2); - - assert.strictEqual( - await innerMost(marker + 3), - marker + 3 - ); - - markers.push(marker + 4); -} - -async function outer() { - markers.push(0); - await inner(1); - markers.push(6); - await inner(7); - markers.push(12); -} - -outer().then(function() { - var expected = []; - for (var i = 0; i <= 12; ++i) - expected.push(i); - assert.deepEqual(markers, expected); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/es7-async-functions/no-await-async-function-should-return-a-Promise/exec.js b/test/fixtures/transformation/es7-async-functions/no-await-async-function-should-return-a-Promise/exec.js deleted file mode 100644 index e4c0a55454..0000000000 --- a/test/fixtures/transformation/es7-async-functions/no-await-async-function-should-return-a-Promise/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -var called = false; - -async function noAwait(value) { - called = true; - return value; -} - -var promise = noAwait("asdf"); -assert.strictEqual(called, true); - -promise.then(function(value) { - assert.strictEqual(called, true); - assert.strictEqual(value, "asdf"); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/es7-async-functions/one-await-async-function-should-finish-asynchronously/exec.js b/test/fixtures/transformation/es7-async-functions/one-await-async-function-should-finish-asynchronously/exec.js deleted file mode 100644 index fae186c318..0000000000 --- a/test/fixtures/transformation/es7-async-functions/one-await-async-function-should-finish-asynchronously/exec.js +++ /dev/null @@ -1,19 +0,0 @@ -var flag1 = false; -var flag2 = false; - -async function oneAwait(value) { - flag1 = true; - var result = await value; - flag2 = true; - return result; -} - -var promise = oneAwait("asdf"); -assert.strictEqual(flag1, true); -assert.strictEqual(flag2, false); - -promise.then(function(value) { - assert.strictEqual(flag2, true); - assert.strictEqual(value, "asdf"); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/es7-async-functions/options.json b/test/fixtures/transformation/es7-async-functions/options.json deleted file mode 100644 index 8a6dc3a088..0000000000 --- a/test/fixtures/transformation/es7-async-functions/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "asyncExec": true, - "experimental": true -} diff --git a/test/fixtures/transformation/es7-async-functions/rejected-promises-should-be-returned-by-exceptional-async-functions/exec.js b/test/fixtures/transformation/es7-async-functions/rejected-promises-should-be-returned-by-exceptional-async-functions/exec.js deleted file mode 100644 index 8eb9f6ce33..0000000000 --- a/test/fixtures/transformation/es7-async-functions/rejected-promises-should-be-returned-by-exceptional-async-functions/exec.js +++ /dev/null @@ -1,42 +0,0 @@ -var error = new Error("rejected"); - -async function e(arg) { - if (arg) { - throw arg; - } - return "did not throw"; -} - -async function f(arg) { - return await e(arg); -} - -async function g(arg) { - return await f(arg); -} - -async function h(arg) { - return await Promise.all([ - g(arg), - Promise.resolve("dummy") - ]); -} - -Promise.all([ - h(error).then(function() { - done(new Error("should not have resolved")); - }, function(e) { - assert.strictEqual(e, error); - return "ok1"; - }), - h(null).then(function(result) { - assert.deepEqual(result, [ - "did not throw", - "dummy" - ]); - return "ok2"; - }) -]).then(function(results) { - assert.deepEqual(results, ["ok1", "ok2"]); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/es7-async-functions/rejected-promises-should-cause-await-expressions-to-throw/exec.js b/test/fixtures/transformation/es7-async-functions/rejected-promises-should-cause-await-expressions-to-throw/exec.js deleted file mode 100644 index 3abf9e0f9d..0000000000 --- a/test/fixtures/transformation/es7-async-functions/rejected-promises-should-cause-await-expressions-to-throw/exec.js +++ /dev/null @@ -1,21 +0,0 @@ -var error = new Error("rejected"); - -async function f(arg) { - try { - return await arg; - } catch (e) { - assert.strictEqual(e, error); - return "did throw"; - } -} - -Promise.all([ - f(Promise.reject(error)), - f(Promise.resolve("did not throw")) -]).then(function(results) { - assert.deepEqual(results, [ - "did throw", - "did not throw" - ]); - done(); -}).catch(done); diff --git a/test/fixtures/transformation/optional-bluebird-coroutines/expression/expected.js b/test/fixtures/transformation/optional-bluebird-coroutines/expression/expected.js index a672903731..13943a98de 100644 --- a/test/fixtures/transformation/optional-bluebird-coroutines/expression/expected.js +++ b/test/fixtures/transformation/optional-bluebird-coroutines/expression/expected.js @@ -4,8 +4,8 @@ var _interopRequire = function (obj) { return obj && (obj["default"] || obj); }; -var Bluebird = _interopRequire(require("bluebird")); +var _bluebird = _interopRequire(require("bluebird")); -var foo = Bluebird.coroutine(function* () { +var foo = _bluebird.coroutine(function* () { var wat = yield bar(); }); diff --git a/test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js b/test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js index 65d8cff6ef..9b200b29f0 100644 --- a/test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js +++ b/test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js @@ -4,8 +4,8 @@ var _interopRequire = function (obj) { return obj && (obj["default"] || obj); }; -var Bluebird = _interopRequire(require("bluebird")); +var _bluebird = _interopRequire(require("bluebird")); -var foo = Bluebird.coroutine(function* foo() { +var foo = _bluebird.coroutine(function* foo() { var wat = yield bar(); }); diff --git a/test/fixtures/transformation/optional-proto-to-assign/class/expected.js b/test/fixtures/transformation/optional-proto-to-assign/class/expected.js index 2af2a9b699..2d7d562265 100644 --- a/test/fixtures/transformation/optional-proto-to-assign/class/expected.js +++ b/test/fixtures/transformation/optional-proto-to-assign/class/expected.js @@ -11,6 +11,9 @@ var _defaults = function (obj, defaults) { }; var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, diff --git a/test/fixtures/transformation/optional-typeof-symbol/basic/actual.js b/test/fixtures/transformation/optional-typeof-symbol/basic/actual.js new file mode 100644 index 0000000000..20422ebc64 --- /dev/null +++ b/test/fixtures/transformation/optional-typeof-symbol/basic/actual.js @@ -0,0 +1,2 @@ +var s = Symbol("s"); +assert.equal(typeof s, "symbol"); diff --git a/test/fixtures/transformation/optional-typeof-symbol/basic/exec.js b/test/fixtures/transformation/optional-typeof-symbol/basic/exec.js new file mode 100644 index 0000000000..20422ebc64 --- /dev/null +++ b/test/fixtures/transformation/optional-typeof-symbol/basic/exec.js @@ -0,0 +1,2 @@ +var s = Symbol("s"); +assert.equal(typeof s, "symbol"); diff --git a/test/fixtures/transformation/optional-typeof-symbol/basic/expected.js b/test/fixtures/transformation/optional-typeof-symbol/basic/expected.js new file mode 100644 index 0000000000..c33ed64571 --- /dev/null +++ b/test/fixtures/transformation/optional-typeof-symbol/basic/expected.js @@ -0,0 +1,8 @@ +"use strict"; + +var _typeof = function (obj) { + return obj && obj.constructor === Symbol ? "symbol" : typeof obj; +}; + +var s = Symbol("s"); +assert.equal(_typeof(s), "symbol"); diff --git a/test/fixtures/transformation/optional-typeof-symbol/options.json b/test/fixtures/transformation/optional-typeof-symbol/options.json new file mode 100644 index 0000000000..6e208aa132 --- /dev/null +++ b/test/fixtures/transformation/optional-typeof-symbol/options.json @@ -0,0 +1,3 @@ +{ + "optional": ["typeofSymbol"] +} diff --git a/test/mocha.opts b/test/mocha.opts index 51c30180df..850a6c2f64 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,2 @@ --reporter dot --ui tdd ---check-leaks ---globals regeneratorRuntime diff --git a/test/regenerator.js b/test/regenerator.js new file mode 100644 index 0000000000..2a2481cba7 --- /dev/null +++ b/test/regenerator.js @@ -0,0 +1,23 @@ +if (!process.env.ALL_6TO5_TESTS) return; + +require("../register")({ + blacklist: ["useStrict"], + experimental: true +}); + +var transform = require("../lib/6to5/transformation/transform"); +var fs = require("fs"); +var _ = require("lodash"); + +var regeneratorLoc = __dirname + "/../vendor/regenerator"; + +if (!fs.existsSync(regeneratorLoc)) { + console.error("No vendor/regenerator - run `git submodule update --init && cd vendor/regenerator && npm install`"); + process.exit(1); +} + +_.each(["tests", "async"], function (filename) { + var loc = regeneratorLoc + "/test/" + filename + ".es6.js"; + var code = fs.readFileSync(loc, "utf8"); + require(loc); +}); diff --git a/test/traceur.js b/test/traceur.js new file mode 100644 index 0000000000..a52e2deaad --- /dev/null +++ b/test/traceur.js @@ -0,0 +1,59 @@ +if (!process.env.ALL_6TO5_TESTS) return; + +var fs = require("fs"); +var _ = require("lodash"); + +var traceurLoc = __dirname + "/../vendor/traceur"; +if (!fs.existsSync(traceurLoc)) { + console.error("No vendor/traceur - run `git submodule update --init`"); + process.exit(1); +} + +require("./_transformation-helper")({ + name: "traceur", + loc: traceurLoc + "/test/feature", + + ignoreSuites: [ + "ObjectMixin", + "Annotations", + "TestRunner", + "Tools", + "TempVarTransformer", + "AtScript", + "FreeVariableChecker", + "TypeAssertions", + "MemberVariables", + "Types" + ], + + ignoreTasks: [ + // core.js doesn't support due to a perf hit and having to override a lot + // of native methods + "Symbol/GetOwnPropertySymbols", + + // traceur doesn't name methods and has an incorrect test asserting that + // they have no names + "PropertyMethodAssignment/PropertyMethodAssignment", + + // 6to5 assumes that all code transformed is a module + "Strict", + "Syntax/UseStrictEscapeSequence", + "Syntax/UseStrictLineContinuation", + + // the spec for these doesn't define syntax (as far as i could tell) + // these both fail because of filter between blocks + "ArrayComprehension/Simple", + "GeneratorComprehension/Simple" + ] +}, { + optional: ["typeofSymbol"], + experimental: true, + after: function () { + // StringExtras/StarsWith + delete Object.prototype[1]; + } +}, function (opts, task) { + if (!_.contains(task.exec.loc, "module.js")) { + opts.blacklist = ["useStrict"]; + } +}); diff --git a/test/transformation.js b/test/transformation.js index 8bed3f56c1..642604401e 100644 --- a/test/transformation.js +++ b/test/transformation.js @@ -1,100 +1,3 @@ -var genHelpers = require("./_generator-helpers"); -var transform = require("../lib/6to5/transformation/transform"); -var sourceMap = require("source-map"); -var helper = require("./_helper"); -var assert = require("assert"); -var chai = require("chai"); -var util = require("../lib/6to5/util"); -var _ = require("lodash"); - -require("../lib/6to5/polyfill"); - -var run = function (task, done) { - var actual = task.actual; - var expect = task.expect; - var exec = task.exec; - var opts = task.options; - - var getOpts = function (self) { - return _.merge({ - filename: self.loc - }, opts); - }; - - var execCode = exec.code; - var result; - - if (execCode) { - result = transform(execCode, getOpts(exec)); - execCode = result.code; - - try { - var fn = new Function("assert", "done", "genHelpers", execCode); - fn(assert, done, genHelpers); - } catch (err) { - err.message = exec.loc + ": " + err.message; - err.message += util.codeFrame(execCode); - throw err; - } - } - - var actualCode = actual.code; - var expectCode = expect.code; - if (!execCode || actualCode) { - result = transform(actualCode, getOpts(actual)); - actualCode = result.code; - - chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc); - } - - if (task.sourceMap) { - chai.expect(result.map).to.deep.equal(task.sourceMap); - } - - if (task.sourceMappings) { - var consumer = new sourceMap.SourceMapConsumer(result.map); - - _.each(task.sourceMappings, function (mapping, i) { - var expect = mapping.original; - - var actual = consumer.originalPositionFor(mapping.generated); - chai.expect({ line: actual.line, column: actual.column }).to.deep.equal(expect); - }); - } -}; - -_.each(helper.get("transformation"), function (testSuite) { - suite("transformation/" + testSuite.title, function () { - _.each(testSuite.tests, function (task) { - var runTest = function (done) { - var runTask = function () { - run(task, done); - }; - - var throwMsg = task.options.throws; - if (throwMsg) { - // internal api doesn't have this option but it's best not to pollute - // the options object with useless options - delete task.options.throws; - - assert.throws(runTask, function (err) { - return err.message.indexOf(throwMsg) >= 0; - }); - } else { - runTask(); - } - }; - - var callback; - if (task.options.asyncExec) { - callback = runTest; - } else { - callback = function () { - return runTest(); - }; - } - - test(task.title, !task.disabled && callback); - }); - }); +require("./_transformation-helper")({ + name: "transformation" }); diff --git a/vendor/regenerator b/vendor/regenerator new file mode 160000 index 0000000000..45829598be --- /dev/null +++ b/vendor/regenerator @@ -0,0 +1 @@ +Subproject commit 45829598be68fa4cb10f86b5ca13aa7284aa6bc8 diff --git a/vendor/traceur b/vendor/traceur new file mode 160000 index 0000000000..0c3dad3ae2 --- /dev/null +++ b/vendor/traceur @@ -0,0 +1 @@ +Subproject commit 0c3dad3ae217139b1a6b4b986cef57669e7b49c6