Skip to content

Commit

Permalink
[[FEAT]] Implement support for async iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Jan 29, 2019
1 parent 70ab03d commit 1af5930
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 709 deletions.
16 changes: 16 additions & 0 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4898,6 +4898,7 @@ var JSHINT = (function() {
blockstmt("for", function(context) {
var s, t = state.tokens.next;
var letscope = false;
var isAsync = false;
var foreachtok = null;

if (t.value === "each") {
Expand All @@ -4908,6 +4909,17 @@ var JSHINT = (function() {
}
}

if (state.tokens.next.identifier && state.tokens.next.value === "await") {
advance("await");
isAsync = true;

if (!(context & prodParams.async)) {
error("E024", state.tokens.curr, "await");
} else if (!state.inES9()) {
warning("W119", state.tokens.curr, "asynchronous iteration", "9");
}
}

increaseComplexityCount();
advance("(");

Expand Down Expand Up @@ -4996,6 +5008,10 @@ var JSHINT = (function() {

nextop = state.tokens.next;

if (isAsync && nextop.value !== "of") {
error("E066", nextop);
}

// if we're in a for (… in|of …) statement
if (_.includes(["in", "of"], nextop.value)) {
if (nextop.value === "of") {
Expand Down
3 changes: 2 additions & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ var errors = {
E063: "Super property may only be used within method bodies.",
E064: "Super call may only be used within class method bodies.",
E065: "Functions defined outside of strict mode with non-simple parameter lists may not " +
"enable strict mode."
"enable strict mode.",
E066: "Asynchronous iteration is only available with for-of loops."
};

var warnings = {
Expand Down
Loading

0 comments on commit 1af5930

Please sign in to comment.