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.6 to 1.0.7

67

acorn-es7-plugin.js

@@ -7,5 +7,18 @@ var NotAsync = {} ;

/* Return the object holding the parser's 'State'. This is different between acorn ('this')
* and babylon ('this.state') */
function state(p) {
if (('state' in p) && p.state.constructor && p.state.constructor.name==='State')
return p.state ; // Probably babylon
return p ; // Probably acorn
}
/* Create a new parser derived from the specified parser, so that in the
* event of an error we can back out and try again */
function subParse(parser, pos, extensions) {
// NB: The Babylon constructor does NOT expect 'pos' as an argument, and so
// the input needs truncation at the start position, however at present
// this doesn't work nicely as all the node location/start/end values
// are therefore offset. Consequently, this plug-in is NOT currently working
// with the (undocumented) Babylon plug-in interface.
var p = new parser.constructor(parser.options, parser.input, pos);

@@ -16,6 +29,8 @@ if (extensions)

p.inFunction = parser.inFunction ;
p.inAsyncFunction = parser.inAsyncFunction ;
p.inGenerator = parser.inGenerator ;
p.inModule = parser.inModule ;
var src = state(parser) ;
var dest = state(p) ;
['inFunction','inAsyncFunction','inAsync','inGenerator','inModule'].forEach(function(k){
if (k in src)
dest[k] = src[k] ;
}) ;
p.nextToken();

@@ -41,7 +56,8 @@ return p;

return function (declaration, topLevel) {
if (this.type.label==='name') {
if (asyncFunction.test(this.input.slice(this.start))) {
var wasAsync = this.inAsyncFunction ;
var st = state(this) ;
if (st.type.label==='name') {
if (asyncFunction.test(st.input.slice(st.start))) {
var wasAsync = st.inAsyncFunction ;
try {
this.inAsyncFunction = true ;
st.inAsyncFunction = true ;
this.next() ;

@@ -52,5 +68,5 @@ var r = this.parseStatement(declaration, topLevel) ;

} finally {
this.inAsyncFunction = wasAsync ;
st.inAsyncFunction = wasAsync ;
}
} else if ((typeof options==="object" && options.asyncExits) && asyncExit.test(this.input.slice(this.start))) {
} else if ((typeof options==="object" && options.asyncExits) && asyncExit.test(st.input.slice(st.start))) {
// NON-STANDARD EXTENSION iff. options.asyncExits is set, the

@@ -72,10 +88,11 @@ // extensions 'async return <expr>?' and 'async throw <expr>?'

return function(refShorthandDefaultPos){
var start = this.start ;
var st = state(this) ;
var start = st.start ;
var rhs,r = base.apply(this,arguments);
if (r.type==='Identifier') {
if (r.name==='async' && !asyncAtEndOfLine.test(this.input.slice(start))) {
if (r.name==='async' && !asyncAtEndOfLine.test(st.input.slice(start))) {
// Is this really an async function?
var isAsync = this.inAsyncFunction ;
var isAsync = st.inAsyncFunction ;
try {
this.inAsyncFunction = true ;
st.inAsyncFunction = true ;
var pp = this ;

@@ -103,3 +120,4 @@ var inBody = false ;

rhs = subParse(this,this.start,parseHooks).parseExpression() ;
start = st.start ;
rhs = subParse(this,start,parseHooks).parseExpression() ;
if (rhs.type==='SequenceExpression')

@@ -109,3 +127,3 @@ rhs = rhs.expressions[0] ;

rhs.async = true ;
this.pos = rhs.end ;
st.pos = rhs.end;
this.next();

@@ -120,3 +138,3 @@ es7check(rhs) ;

finally {
this.inAsyncFunction = isAsync ;
st.inAsyncFunction = isAsync ;
}

@@ -126,3 +144,3 @@ }

var n = this.startNode() ;
if (this.inAsyncFunction) {
if (st.inAsyncFunction) {
rhs = this.parseExprSubscripts() ;

@@ -140,14 +158,14 @@ n.operator = '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))
if (st.input.slice(r.end).match(atomOrPropertyOrLabel))
return r ; // This is a valid property name or label
if (typeof options==="object" && options.awaitAnywhere) {
var start = this.start ;
rhs = subParse(this,this.start-4).parseExprSubscripts() ;
start = st.start ;
rhs = subParse(this,start-4).parseExprSubscripts() ;
if (rhs.end<=start) {
rhs = subParse(this,this.start).parseExprSubscripts() ;
rhs = subParse(this,start).parseExprSubscripts() ;
n.operator = 'await' ;
n.argument = rhs ;
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc) ;
this.pos = rhs.end ;
st.pos = rhs.end;
this.next();

@@ -166,6 +184,7 @@ es7check(n) ;

return function (prop) {
var st = state(this) ;
var key = base.apply(this,arguments) ;
if (key.type === "Identifier" && key.name === "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)){
if (!st.input.slice(key.end).match(atomOrPropertyOrLabel)){
es7check(prop) ;

@@ -172,0 +191,0 @@ prop.async = true ;

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

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

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