fix tests and add exec test
This commit is contained in:
@@ -414,7 +414,7 @@ export default class File extends Store {
|
||||
|
||||
parse(code: string) {
|
||||
let parseCode = parse;
|
||||
let parserOpts = this.opts.parserOpts || this.parserOpts;
|
||||
let parserOpts = this.opts.parserOpts;
|
||||
|
||||
if (parserOpts) {
|
||||
parserOpts = Object.assign({}, this.parserOpts, parserOpts);
|
||||
@@ -441,7 +441,7 @@ export default class File extends Store {
|
||||
}
|
||||
|
||||
this.log.debug("Parse start");
|
||||
let ast = parseCode(code, parserOpts);
|
||||
let ast = parseCode(code, parserOpts || this.parserOpts);
|
||||
this.log.debug("Parse stop");
|
||||
return ast;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ function findCommonStringDelimiter(code, tokens) {
|
||||
if (occurences.single > occurences.double) {
|
||||
return "single";
|
||||
} else {
|
||||
return DEFAULT_STRING_DELIMITER;
|
||||
return "double";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ function run(task) {
|
||||
|
||||
let execCode = exec.code;
|
||||
let result;
|
||||
let resultExec;
|
||||
|
||||
if (execCode) {
|
||||
let execOpts = getOpts(exec);
|
||||
@@ -54,7 +55,7 @@ function run(task) {
|
||||
execCode = result.code;
|
||||
|
||||
try {
|
||||
runExec(execOpts, execCode);
|
||||
resultExec = runExec(execOpts, execCode);
|
||||
} catch (err) {
|
||||
err.message = exec.loc + ": " + err.message;
|
||||
err.message += codeFrame(execCode);
|
||||
@@ -90,6 +91,10 @@ function run(task) {
|
||||
chai.expect({ line: expect.line, column: expect.column }).to.deep.equal(actual);
|
||||
});
|
||||
}
|
||||
|
||||
if (execCode && resultExec) {
|
||||
return resultExec;
|
||||
}
|
||||
}
|
||||
|
||||
function runExec(opts, execCode) {
|
||||
@@ -151,7 +156,14 @@ export default function (
|
||||
return throwMsg === true || err.message.indexOf(throwMsg) >= 0;
|
||||
});
|
||||
} else {
|
||||
runTask();
|
||||
if (task.exec.code) {
|
||||
let result = run(task);
|
||||
if (result && typeof result.then === "function") {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
runTask();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
let agf = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
this;
|
||||
yield babelHelpers.asyncGenerator.await(1);
|
||||
yield 2;
|
||||
return 3;
|
||||
});
|
||||
|
||||
return function agf() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
this;
|
||||
yield babelHelpers.asyncGenerator.await(1);
|
||||
yield 2;
|
||||
@@ -7,7 +7,7 @@
|
||||
});
|
||||
|
||||
function agf() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
}
|
||||
|
||||
return agf;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
let g = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
yield* babelHelpers.asyncGeneratorDelegate(babelHelpers.asyncIterator([1, 2, 3]), babelHelpers.asyncGenerator.await);
|
||||
yield* babelHelpers.asyncGeneratorDelegate(babelHelpers.asyncIterator(iterable), babelHelpers.asyncGenerator.await);
|
||||
});
|
||||
|
||||
return function g() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let f = (() => {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var _ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
@@ -25,7 +25,8 @@ let f = (() => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return function f() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
async function* genAnswers() {
|
||||
var stream = [ Promise.resolve(4), Promise.resolve(9), Promise.resolve(12) ];
|
||||
var total = 0;
|
||||
for await (let val of stream) {
|
||||
total += await val;
|
||||
yield total;
|
||||
}
|
||||
}
|
||||
|
||||
function forEach(ai, fn) {
|
||||
return ai.next().then(function (r) {
|
||||
if (!r.done) {
|
||||
fn(r);
|
||||
return forEach(ai, fn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var output = 0;
|
||||
return forEach(genAnswers(), function(val) { output += val.value })
|
||||
.then(function () {
|
||||
assert.equal(output, 42);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
"transform-async-to-generator",
|
||||
"transform-async-generator-functions"
|
||||
],
|
||||
"presets": ["es2015"],
|
||||
"parserOpts": {
|
||||
"allowReturnOutsideFunction": true
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
let g = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
@@ -25,7 +25,8 @@ let g = (() => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return function g() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let f = (() => {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var _ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
@@ -25,7 +25,8 @@ let f = (() => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return function f() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
"transform-async-to-generator",
|
||||
"transform-async-to-generator",
|
||||
"transform-async-generator-functions"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
let g = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _this = this;
|
||||
|
||||
(function () {
|
||||
@@ -14,7 +14,8 @@ let g = (() => {
|
||||
});
|
||||
yield babelHelpers.asyncGenerator.await(1);
|
||||
});
|
||||
|
||||
return function g() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
let g = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* (x = babelHelpers.asyncToGenerator(function* () {
|
||||
var _ref = babelHelpers.asyncGenerator.wrap(function* (x = babelHelpers.asyncToGenerator(function* () {
|
||||
yield 1;
|
||||
})) {
|
||||
yield babelHelpers.asyncGenerator.await(2);
|
||||
yield 3;
|
||||
});
|
||||
|
||||
return function g(_x) {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
let f = (() => {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var _ref = babelHelpers.asyncToGenerator(function* () {
|
||||
let g = (() => {
|
||||
var ref = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
var _ref2 = babelHelpers.asyncGenerator.wrap(function* () {
|
||||
yield babelHelpers.asyncGenerator.await(2);
|
||||
yield 3;
|
||||
});
|
||||
|
||||
return function g() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref2.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
yield 1;
|
||||
});
|
||||
|
||||
return function f() {
|
||||
return ref.apply(this, arguments);
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user