Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 2ce594d

Browse files
committed
fix regenerator bug
1 parent 7219594 commit 2ce594d

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

build-babel/jspm_packages_override/npm/babel-plugin-transform-regenerator@6.16.1/lib/util.js renamed to build-babel/jspm_packages/npm/regenerator-transform@0.9.8/lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ function runtimeProperty(name, regeneratorIdentifier) {
2424

2525
function isReference(path) {
2626
return path.isReferenced() || path.parentPath.isAssignmentExpression({ left: path.node });
27-
}
27+
}

build-babel/jspm_packages_override/npm/babel-plugin-transform-regenerator@6.16.1/lib/visit.js renamed to build-babel/jspm_packages/npm/regenerator-transform@0.9.8/lib/visit.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ exports.visitor = {
7070

7171
bodyBlockPath.get("body").forEach(function (childPath) {
7272
var node = childPath.node;
73-
if (node && node._blockHoist != null) {
73+
if (t.isExpressionStatement(node) && t.isStringLiteral(node.expression)) {
74+
// Babylon represents directives like "use strict" as elements
75+
// of a bodyBlockPath.node.directives array, but they could just
76+
// as easily be represented (by other parsers) as traditional
77+
// string-literal-valued expression statements, so we need to
78+
// handle that here. (#248)
79+
outerBody.push(node);
80+
} else if (node && node._blockHoist != null) {
7481
outerBody.push(node);
7582
} else {
7683
innerBody.push(node);
@@ -123,6 +130,13 @@ exports.visitor = {
123130
outerBody.push(t.returnStatement(wrapCall));
124131
node.body = t.blockStatement(outerBody);
125132

133+
var oldDirectives = bodyBlockPath.node.directives;
134+
if (oldDirectives) {
135+
// Babylon represents directives like "use strict" as elements of
136+
// a bodyBlockPath.node.directives array. (#248)
137+
node.body.directives = oldDirectives;
138+
}
139+
126140
var wasGeneratorFunction = node.generator;
127141
if (wasGeneratorFunction) {
128142
node.generator = false;
@@ -251,4 +265,4 @@ var awaitVisitor = {
251265
// can distinguish between awaited and merely yielded values.
252266
path.replaceWith(t.yieldExpression(t.callExpression(util.runtimeProperty("awrap", state.file.get("regeneratorIdentifier")), [argument]), false));
253267
}
254-
};
268+
};

test/testing-code.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
export async function p() {
22
return (await import('./testing-dep.js')).p;
33
}
4+
5+
function * responseTime (next) {
6+
let start = new Date()
7+
yield next
8+
var ms = new Date() - start
9+
this.set('X-Response-Time', ms + 'ms')
10+
}
11+
12+
export default function init (app) {
13+
app.use(responseTime)
14+
}

0 commit comments

Comments
 (0)