Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jscript: Fix parsing async functions and methods
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add1 input.js /^async function add1(x) {$/;" f | ||
add2 input.js /^async function add2(x) {$/;" f | ||
resolveAfter2Seconds input.js /^function resolveAfter2Seconds(x) {$/;" f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#Simple_example */ | ||
|
||
function resolveAfter2Seconds(x) { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(x); | ||
}, 2000); | ||
}); | ||
} | ||
|
||
async function add1(x) { | ||
var a = resolveAfter2Seconds(20); | ||
var b = resolveAfter2Seconds(30); | ||
return x + await a + await b; | ||
} | ||
|
||
add1(10).then(v => { | ||
console.log(v); // prints 60 after 2 seconds. | ||
}); | ||
|
||
async function add2(x) { | ||
var a = await resolveAfter2Seconds(20); | ||
var b = await resolveAfter2Seconds(30); | ||
return x + a + b; | ||
} | ||
|
||
add2(10).then(v => { | ||
console.log(v); // prints 60 after 4 seconds. | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Class input.js /^var Class = {$/;" c | ||
ES6Class input.js /^class ES6Class {$/;" c | ||
asyncAnonymousFunc input.js /^var asyncAnonymousFunc = async function() {$/;" f | ||
es6AsyncMethod input.js /^ async es6AsyncMethod() {}$/;" m class:ES6Class | ||
es6Method input.js /^ es6Method() {}$/;" m class:ES6Class | ||
method1 input.js /^ method1 : function() {$/;" m class:Class | ||
method2 input.js /^ method2 : async function() {$/;" m class:Class | ||
method3 input.js /^ method3() {$/;" m class:Class | ||
method4 input.js /^ async method4() {$/;" m class:Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var Class = { | ||
method1 : function() { | ||
return 0; | ||
}, | ||
method2 : async function() { | ||
return await resolveAfter2Seconds(42); | ||
}, | ||
// ES6 shorthand methods | ||
method3() { | ||
}, | ||
async method4() { | ||
}, | ||
}; | ||
|
||
var asyncAnonymousFunc = async function() { | ||
} | ||
|
||
class ES6Class { | ||
async es6AsyncMethod() {} | ||
es6Method() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters