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 5 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,5 @@
function* gen () {
const a = () => {
return 1;
};
}
@@ -0,0 +1,17 @@
var _marked = [gen].map(regeneratorRuntime.mark);

function gen() {
var a;
return regeneratorRuntime.wrap(function gen$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
a = () => {
return 1;
};

case 1:
case "end":
return _context.stop();
}
}, _marked[0], this);
}
@@ -0,0 +1,5 @@
{
"plugins": [
"transform-regenerator"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to add a ES2015 presets (like here), currently not working for me

Copy link
Member Author

@yavorsky yavorsky Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es2015 will transform arrow function, so there is no sense in this test. The goal is test for generator with arrow function inside 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we should do a simple string comparaison here to avoid Node parsing it.

]
}
@@ -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"
]
}