Skip to content

Instantly share code, notes, and snippets.

@leo60228
Last active August 29, 2015 14:22
Show Gist options
  • Save leo60228/71c3a9f2cd20dc258765 to your computer and use it in GitHub Desktop.
Save leo60228/71c3a9f2cd20dc258765 to your computer and use it in GitHub Desktop.
ESPath Asyncify Syntax XPath

What is this?

This is a XPath, to be parsed with DefiantJS, that can be used to parse the current Asyncify syntax when supplied with a ESPath generator.

What is Asyncify?

Asyncify is intended to be an upcoming JS extension allowing to make async code sync and sync code async through special operators modifing the code structure.

How do I use this?

Currently there is no implementation, but that will soon be implemented with the upcoming repo snuggles08/asyncify-js. To make your own implementation, use the following mini-specs:

Specs

Use an ESPath generator to generate the sample ESPath. Use the XPath on the ESPath with DefiantJS. If there are any matches, use the output to create the output described in the sample input and output. Note that only one XPath has been created at this time, look for updates for more features.

{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "test"
},
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "setTimeout"
},
"arguments": [
{
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": "hi",
"raw": "'hi'"
},
"right": {
"type": "Identifier",
"name": "asyncify"
}
}
}
]
},
"generator": false,
"expression": false
},
{
"type": "Literal",
"value": 1000,
"raw": "1000"
}
]
}
}
]
},
"generator": false,
"expression": false
},
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "result"
},
"init": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "test"
},
"arguments": []
}
}
],
"kind": "var"
},
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "console"
},
"property": {
"type": "Identifier",
"name": "log"
}
},
"arguments": [
{
"type": "Identifier",
"name": "result"
}
]
}
}
]
}
function test(hello, lPkPbdIJyZK5PzIZNDGG) { // Generated argument should be a unique random string.
setTimeout(function() {
lPkPbdIJyZK5PzIZNDGG(hello);
}, 1000);
}
test('hi', function(result) {
console.log(result);
});
function test() {
setTimeout(function() {
return 'hi' + asyncify;
}, 1000);
}
var result = test();
console.log(result);
//*[contains(type, "FunctionExpression")]/body[contains(type, "BlockStatement")]/*[contains(type, "ReturnStatement")]/argument[contains(type, "BinaryExpression")][contains(operator, "+")]/right[contains(type, "Identifier")][contains(name, "asyncify")]/../../../..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment