Socket
Socket
Sign inDemoInstall

acorn-es7-plugin

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn-es7-plugin - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

25

acorn-es7-plugin.js
var NotAsync = {} ;
var asyncExit = /^async[\t ]+(return|throw)/ ;
var asyncFunction = /^async[\t ]+function/ ;
var atomOrPropertyOrLabel = /^\s*[:;]/ ;

@@ -124,2 +125,7 @@ /* Create a new parser derived from the specified parser, so that in the

// could not be an identifier with the name 'await'.
// Look-ahead to see if this is really a property or label called async or await
if (this.input.slice(r.end).match(atomOrPropertyOrLabel))
return r ; // This is a valid property name or label
if (typeof options==="object" && options.awaitAnywhere) {

@@ -149,10 +155,13 @@ var start = this.start ;

if (key.type === "Identifier" && key.name === "async") {
es7check(prop) ;
prop.async = true ;
key = base.apply(this,arguments) ;
if (key.type==='Identifier') {
if (key.name==='constructor')
this.raise(key.start,"'constructor()' cannot be be async") ;
else if (key.name==='set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
// Look-ahead to see if this is really a property or label called async or await
if (!this.input.slice(key.end).match(atomOrPropertyOrLabel)){
es7check(prop) ;
prop.async = true ;
key = base.apply(this,arguments) ;
if (key.type==='Identifier') {
if (key.name==='constructor')
this.raise(key.start,"'constructor()' cannot be be async") ;
else if (key.name==='set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
}
}

@@ -159,0 +168,0 @@ }

{
"name": "acorn-es7-plugin",
"version": "1.0.4",
"version": "1.0.5",
"description": "A plugin for the Acorn parser that understands the ES7 keywords async and await",

@@ -5,0 +5,0 @@ "main": "acorn-es7-plugin.js",

@@ -22,9 +22,7 @@ [![NPM](https://nodei.co/npm/acorn-es7-plugin.png?downloads=true&downloadRank=true)](https://nodei.co/npm/acorn-es7-plugin/)

var code = "async function x(){ return ; }\n";
code += "await x(1);" ;
var code = "async function x(){ if (x) return await(x-1) ; return 0 ; }\n";
var ast = acorn.parse(code,{
// Specify use of the plugin
// Specify use of the plugin
plugins:{asyncawait:true},
// Specify the ecmaVersion
// Specify the ecmaVersion
ecmaVersion:7

@@ -35,2 +33,63 @@ }) ;

Output:
{
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "x"
},
"generator": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "IfStatement",
"test": {
"type": "Identifier",
"name": "x"
},
"consequent": {
"type": "ReturnStatement",
"argument": {
"type": "AwaitExpression",
"operator": "await",
"argument": {
"type": "BinaryExpression",
"left": {
"type": "Identifier",
"name": "x"
},
"operator": "-",
"right": {
"type": "Literal",
"value": 1,
"raw": "1"
}
}
}
},
"alternate": null
},
{
"type": "ReturnStatement",
"argument": {
"type": "Literal",
"value": 0,
"raw": "0"
}
}
]
},
"async": true
}
],
"sourceType": "script"
}
Options & Compliance

@@ -45,2 +104,2 @@ ====================

| 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](https://github.com/MatAtBread/nodent). In each case, as with async functions, a standard ReturnStatement (or ThrowStatement) node is generated, with an additional member 'async' set to true.
| asyncExits | Allow the additional sequences `async return <optional-expression>` and `async throw <expression>`. These sequences are used with [nodent](https://github.com/MatAtBread/nodent). In each case, as with async functions, a standard ReturnStatement (or ThrowStatement) node is generated, with an additional member 'async' set to true.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc