Skip to content

Commit

Permalink
Merge branch 'master' into fix-version-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 31, 2016
2 parents 62c89ec + 9badd0e commit aed548b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ Parser.prototype.walkExpression = function walkExpression(expression) {
return this["walk" + expression.type](expression);
};

Parser.prototype.walkAwaitExpression = function walkAwaitExpression(expression) {
var argument = expression.argument
if(this["walk" + argument.type])
return this["walk" + argument.type](argument);
}

Parser.prototype.walkArrayExpression = function walkArrayExpression(expression) {
if(expression.elements)
this.walkExpressions(expression.elements);
Expand Down Expand Up @@ -1035,12 +1041,12 @@ Parser.prototype.parseCalculatedString = function parseCalculatedString(expressi
var POSSIBLE_AST_OPTIONS = [{
ranges: true,
locations: true,
ecmaVersion: 6,
ecmaVersion: 2017,
sourceType: "module"
}, {
ranges: true,
locations: true,
ecmaVersion: 6,
ecmaVersion: 2017,
sourceType: "script"
}]

Expand All @@ -1062,7 +1068,7 @@ Parser.prototype.parse = function parse(source, initialState) {
ast = acorn.parse(source, {
ranges: true,
locations: true,
ecmaVersion: 6,
ecmaVersion: 2017,
sourceType: "module",
onComment: comments
});
Expand All @@ -1088,7 +1094,7 @@ Parser.prototype.evaluate = function evaluate(source) {
var ast = acorn.parse("(" + source + ")", {
ranges: true,
locations: true,
ecmaVersion: 6,
ecmaVersion: 2017,
sourceType: "module"
});
if(!ast || typeof ast !== "object" || ast.type !== "Program")
Expand Down
49 changes: 49 additions & 0 deletions test/Parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,53 @@ describe("Parser", function() {
});
});
});

describe("async/await support", function() {
describe("should accept", function() {
var cases = {
"async function": "async function x() {}",
"async arrow function": "async () => {}",
"await expression": "async function x(y) { await y }"
};
var parser = new Parser();
Object.keys(cases).forEach(function(name) {
var expr = cases[name];
it(name, function() {
var actual = parser.parse(expr);
should.strictEqual(typeof actual, "object");
});
});
});
describe("should parse await", function() {
var cases = {
"require": [
"async function x() { await require('y'); }", {
param: "y"
}
],
"System.import": [
"async function x() { var y = await System.import('z'); }", {
param: "z"
}
]
};

var parser = new Parser();
parser.plugin("call require", function(expr) {
var param = this.evaluateExpression(expr.arguments[0]);
this.state.param = param.string;
});
parser.plugin("call System.import", function(expr) {
var param = this.evaluateExpression(expr.arguments[0]);
this.state.param = param.string;
});

Object.keys(cases).forEach(function(name) {
it(name, function() {
var actual = parser.parse(cases[name][0]);
actual.should.be.eql(cases[name][1]);
});
});
});
})
});

0 comments on commit aed548b

Please sign in to comment.