Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
acorn-es7-plugin
Advanced tools
A plugin for the Acorn parser that understands the ES7 keywords async and await
acorn-es7-plugin is a plugin for the Acorn parser that generates ESTrees following the 'experimental' specification for asynchronous functions.
npm install --save acorn-es7-plugin
Adding the plugin
// Require acorn as usual
var acorn = require("acorn");
// Add the es7-plugin
require('./acorn-es7-plugin')(acorn) ;
Using the plugin
var code = "async function x(){ return ; }\n";
code += "await x(1);" ;
var ast = acorn.parse(code,{
// Specify use of the plugin
plugins:{asyncawait:true},
// Specify the ecmaVersion
ecmaVersion:7
}) ;
// Show the AST
console.log(JSON.stringify(ast,null,2)) ;
The parser attempts to enforce strict contextualisation of async
and await
. Specifically, async
is only a keyword if it precedes a function declaration, function expression or arrow function. await
is only a keyword inside an async
function. Outside of these contexts, both tokens are treated as identifiers (as they were in ES6 and earlier).
When using the plugin, you can supply an object in place of the 'true' flag with the following options.
flag | meaning |
---|---|
awaitAnywhere | If await is used outside of an async function and could not be an identifier, generate an AwaitExpression node. This typically means you can use await anywhere except when its argument would require parentheses, as this parses to a call to 'await(....)'. |
asyncExits | Allow the additional sequences async return <optional-expression> and async throw <optional-expression> . These sequences are used with nodent. In each case, as with async functions, a standard ReturnStatement (or ThrowStatement) node is generated, with an additional member 'async' set to true. |
FAQs
A plugin for the Acorn parser that understands the ES7 keywords async and await
The npm package acorn-es7-plugin receives a total of 135,732 weekly downloads. As such, acorn-es7-plugin popularity was classified as popular.
We found that acorn-es7-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.