acorn-es7-plugin
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -10,3 +10,3 @@ var NotAsync = {} ; | ||
function state(p) { | ||
if (('state' in p) && p.state.constructor && p.state.constructor.name==='State') | ||
if (('state' in p) && p.state.constructor && p.state.constructor.name==='State') | ||
return p.state ; // Probably babylon | ||
@@ -19,7 +19,7 @@ return p ; // Probably acorn | ||
function subParse(parser, pos, extensions) { | ||
// NB: The Babylon constructor does NOT expect 'pos' as an argument, and so | ||
// 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. | ||
// 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); | ||
@@ -57,2 +57,4 @@ if (extensions) | ||
var st = state(this) ; | ||
var start = st.start; | ||
var startLoc = st.startLoc; | ||
if (st.type.label==='name') { | ||
@@ -66,2 +68,4 @@ if (asyncFunction.test(st.input.slice(st.start))) { | ||
r.async = true ; | ||
r.start = start; | ||
r.loc && (r.loc.start = startLoc); | ||
return r ; | ||
@@ -72,3 +76,3 @@ } finally { | ||
} else if ((typeof options==="object" && options.asyncExits) && asyncExit.test(st.input.slice(st.start))) { | ||
// NON-STANDARD EXTENSION iff. options.asyncExits is set, the | ||
// NON-STANDARD EXTENSION iff. options.asyncExits is set, the | ||
// extensions 'async return <expr>?' and 'async throw <expr>?' | ||
@@ -80,2 +84,4 @@ // are enabled. In each case they are the standard ESTree nodes | ||
r.async = true ; | ||
r.start = start; | ||
r.loc && (r.loc.start = startLoc); | ||
return r ; | ||
@@ -85,3 +91,3 @@ } | ||
return base.apply(this,arguments); | ||
} | ||
} | ||
}) ; | ||
@@ -93,2 +99,3 @@ | ||
var start = st.start ; | ||
var startLoc = st.startLoc; | ||
var rhs,r = base.apply(this,arguments); | ||
@@ -103,3 +110,3 @@ if (r.type==='Identifier') { | ||
var inBody = false ; | ||
var parseHooks = { | ||
@@ -123,5 +130,4 @@ parseFunctionBody:function(){ | ||
} ; | ||
start = st.start ; | ||
rhs = subParse(this,start,parseHooks).parseExpression() ; | ||
rhs = subParse(this,st.start,parseHooks).parseExpression() ; | ||
if (rhs.type==='SequenceExpression') | ||
@@ -131,2 +137,4 @@ rhs = rhs.expressions[0] ; | ||
rhs.async = true ; | ||
rhs.start = start; | ||
rhs.loc && (rhs.loc.start = startLoc); | ||
st.pos = rhs.end; | ||
@@ -146,3 +154,3 @@ this.next(); | ||
else if (r.name==='await') { | ||
var n = this.startNode() ; | ||
var n = this.startNodeAt(r.start, r.loc && r.loc.start); | ||
if (st.inAsyncFunction) { | ||
@@ -152,6 +160,6 @@ rhs = this.parseExprSubscripts() ; | ||
n.argument = rhs ; | ||
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc) ; | ||
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ; | ||
es7check(n) ; | ||
return n ; | ||
} else | ||
} else | ||
// NON-STANDARD EXTENSION iff. options.awaitAnywhere is true, | ||
@@ -172,3 +180,3 @@ // an 'AwaitExpression' is allowed anywhere the token 'await' | ||
n.argument = rhs ; | ||
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc) ; | ||
n = this.finishNodeAt(n,'AwaitExpression', rhs.end, rhs.loc && rhs.loc.end) ; | ||
st.pos = rhs.end; | ||
@@ -186,2 +194,22 @@ this.next(); | ||
parser.extend('finishNodeAt',function(base){ | ||
return function(node,type,pos,loc) { | ||
if (node.__asyncValue) { | ||
delete node.__asyncValue ; | ||
node.value.async = true ; | ||
} | ||
return base.apply(this,arguments) ; | ||
} | ||
}) ; | ||
parser.extend('finishNode',function(base){ | ||
return function(node,type) { | ||
if (node.__asyncValue) { | ||
delete node.__asyncValue ; | ||
node.value.async = true ; | ||
} | ||
return base.apply(this,arguments) ; | ||
} | ||
}) ; | ||
parser.extend("parsePropertyName",function(base){ | ||
@@ -195,3 +223,2 @@ return function (prop) { | ||
es7check(prop) ; | ||
prop.async = true ; | ||
key = base.apply(this,arguments) ; | ||
@@ -204,2 +231,3 @@ if (key.type==='Identifier') { | ||
} | ||
prop.__asyncValue = true ; | ||
} | ||
@@ -206,0 +234,0 @@ } |
{ | ||
"name": "acorn-es7-plugin", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "A plugin for the Acorn parser that understands the ES7 keywords async and await", | ||
"main": "acorn-es7-plugin.js", | ||
"scripts": { | ||
"test": "echo \"### No tests here - 'npm install nodent' and test there\"" | ||
"test": "cd test ; npm i ; npm test" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
18253
8
470
0
2