Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for arrow function inside generator #5595

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/babel-generator/src/index.js
Expand Up @@ -99,7 +99,7 @@ function findCommonStringDelimiter(code, tokens) {
return DEFAULT_STRING_DELIMITER;
}

const occurences = {
const occurrences = {
single: 0,
double: 0
};
Expand All @@ -112,15 +112,15 @@ function findCommonStringDelimiter(code, tokens) {

const raw = code.slice(token.start, token.end);
if (raw[0] === "'") {
occurences.single++;
occurrences.single++;
} else {
occurences.double++;
occurrences.double++;
}

checked++;
if (checked >= 3) break;
}
if (occurences.single > occurences.double) {
if (occurrences.single > occurrences.double) {
return "single";
} else {
return "double";
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-regenerator/package.json
Expand Up @@ -7,7 +7,7 @@
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-regenerator",
"main": "lib/index.js",
"dependencies": {
"regenerator-transform": "0.9.8"
"regenerator-transform": "0.9.11"
},
"license": "MIT",
"devDependencies": {
Expand Down
@@ -0,0 +1,19 @@
const assert = require("assert");
const babel = require("babel-core");

test("Doesn't throw with arrow function inside generator", function () {
const code = "function* gen () {const a = () => {return 1;}}";

const transform = function () {
babel.transform(code, {
"plugins": [
require("../")
]
});
};

assert.doesNotThrow(
transform,
Error
);
});
@@ -0,0 +1,5 @@
var o = {
*foo() {
return "foo";
}
};
@@ -0,0 +1,14 @@
var o = {
foo: regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", "foo");

case 1:
case "end":
return _context.stop();
}
}, _callee, this);
})
};
@@ -0,0 +1,3 @@
{
"plugins": ["transform-regenerator"]
}
@@ -0,0 +1,5 @@
function test(fn) {
return async (...args) => {
return fn(...args);
};
}
@@ -0,0 +1,21 @@
"use strict";

function test(fn) {
var _this = this;

return function _callee() {
var _args = arguments;
return regeneratorRuntime.async(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", fn.apply(undefined, _args));

case 1:
case "end":
return _context.stop();
}
}
}, null, _this);
};
}
@@ -0,0 +1,7 @@
{
"plugins": [
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-regenerator"
]
}