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.1.0 to 1.1.1

36

acorn-v3.js
var NotAsync = {} ;
var asyncExit = /^async[\t ]+(return|throw)/ ;
var asyncFunction = /^async[\t ]+function/ ;
var atomOrPropertyOrLabel = /^\s*[):;]/ ;
var atomOrPropertyOrLabel = /^\s*[():;]/ ;
var removeComments = /([^\n])\/\*(\*(?!\/)|[^\n*])*\*\/([^\n])/g ;

@@ -210,4 +210,7 @@

// Look-ahead to see if this is really a property or label called async or await
if (st.input.slice(r.end).match(atomOrPropertyOrLabel))
if (st.input.slice(r.end).match(atomOrPropertyOrLabel)) {
if (!options.awaitAnywhere && this.options.sourceType === 'module')
return this.raise(r.start,"'await' is reserved within modules") ;
return r ; // This is a valid property name or label
}

@@ -259,2 +262,8 @@ if (typeof options==="object" && options.awaitAnywhere) {

var allowedPropSpecifiers = {
get:true,
set:true,
async:true
};
parser.extend("parsePropertyName",function(base){

@@ -267,11 +276,18 @@ return function (prop) {

if (!st.input.slice(key.end).match(atomOrPropertyOrLabel)){
es7check(prop) ;
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')
// Cheese - eliminate the cases 'async get(){}' and async set(){}'
if (st.input.slice(key.end).match(/\s*(get|set)\s*\(/)) {
key = base.apply(this,arguments) ;
prop.__asyncValue = true ;
} else {
es7check(prop) ;
if (prop.kind === 'set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
key = base.apply(this,arguments) ;
if (key.type==='Identifier') {
if (key.name==='set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
}
prop.__asyncValue = true ;
}
prop.__asyncValue = true ;
}

@@ -287,2 +303,4 @@ }

if (method.__asyncValue) {
if (method.kind==='constructor')
this.raise(method.start,"class constructor() cannot be be async") ;
st = state(this) ;

@@ -289,0 +307,0 @@ wasAsync = st.inAsyncFunction ;

@@ -146,2 +146,10 @@ var asyncExit = /^async[\t ]+(return|throw)/ ;

var allowedPropValues = {
undefined:true,
get:true,
set:true,
static:true,
async:true,
constructor:true
};
parser.extend("parsePropertyName",function(base){

@@ -151,12 +159,18 @@ return function (prop) {

var key = base.apply(this,arguments) ;
if (key.type === "Identifier" && key.name === "async" && !hasLineTerminatorBeforeNext(st, key.end)) {
if (allowedPropValues[this.value])
return key ;
if (key.type === "Identifier" && (key.name === "async" || key.name === "get") && !hasLineTerminatorBeforeNext(st, key.end)) {
// Look-ahead to see if this is really a property or label called async or await
if (!st.input.slice(key.end).match(atomOrPropertyOrLabel)){
st.__isAsyncProp = 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") ;
if (prop.kind === 'set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
else {
st.__isAsyncProp = true ;
key = base.apply(this,arguments) ;
if (key.type==='Identifier') {
if (key.name==='set')
this.raise(key.start,"'set <member>(value)' cannot be be async") ;
}
}

@@ -163,0 +177,0 @@ }

@@ -28,3 +28,3 @@ {

},
"version": "1.1.0"
"version": "1.1.1"
}

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

07-Oct-16: v1.1.1
- Fix disambiguation of async, get and set tokens (and add tests) when defining object properties:
| Code | Interpretation
|-----------------------|-------------------------|
| `get async(){}` | Is a standard ES6 getter called 'async'
| `set async(v){}` | Is a standard ES6 setter called 'async'
| `async get(...){}` | Is a standard ES7 async method called 'get'
| `async set(...){}` | Is a standard ES7 async method called 'set'
| `async get x(){}` | Is an extension that defines an async getter called 'x'
| `get async x(){}` | Is an extension that defines an async getter called 'x', but is deprecated (`async` should proceed `get`)
In previous version of the plugin, the standard ES7 constructs were hidden by the plugin extensions and a SyntaxError was incorrectly thrown
25-Sep-16: v1.1.0

@@ -112,0 +127,0 @@

@@ -60,3 +60,3 @@ 'use strict';

},{
desc: "Async method",
desc: "Async method {code}",
code: "var a = {async x(){}}",

@@ -135,2 +135,43 @@ pass: function (ast) {

},{
desc: "Async method 'constructor' is valid",
code: "var a = {async constructor(){}}",
pass: function (ast) {
var props = ast.body[0].declarations[0].init.properties ;
return (props[0].kind === 'init' && props[0].key.name==='constructor' && props[0].value.async)
}
},{
desc: "Async class constructor fails",
code: "class a {async constructor(){}}",
pass: function (ex) {
return !!ex.match(/class constructor\(\) cannot be be async \(1:(15|9)\)/) || ex === "Constructor can't be an async method (1:15)";
}
},{
desc: "Async setter fails",
code: "var a = {async set x(y){}}",
pass: function (ex) {
return ex === "'set <member>(value)' cannot be be async (1:15)" || ex === "Unexpected token (1:19)";
}
},{
desc: "Deprecated async setter fails (use 'async set x')",
code: "var a = {set async x(y){}}",
pass: function (ex) {
return ex === "'set <member>(value)' cannot be be async (1:13)" || ex === "Unexpected token (1:19)";
}
},{
desc: "{code} are methods, not getters/setters",
code: "var a = {async get(){},async set(){}}",
pass: function (ast) {
var props = ast.body[0].declarations[0].init.properties ;
return (props[0].kind === 'init' && props[0].key.name==='get' && props[0].value.async)
&& (props[1].kind === 'init' && props[1].key.name==='set' && props[1].value.async);
}
},{
desc: "{code} [deprecated - use async get/set] are a getters/setters, not methods",
code: "var a = {get async(){},set async(x){}}",
pass: function (ast) {
var props = ast.body[0].declarations[0].init.properties ;
return (props[0].kind === 'get' && props[0].key.name==='async' && !props[0].value.async)
&& (props[1].kind === 'set' && props[1].key.name==='async' && !props[1].value.async);
}
},{
desc: "{code} is a SyntaxError when inAsyncFunction and awaitAnywhere option are false",

@@ -144,20 +185,16 @@ code: "await x",

{
desc: "Nodent:".grey+" Async get method",
code: "var a = {async get x(){}}",
desc: "Nodent:".grey+" In {code}, x is an async getter",
code: "var a = {async get x(){ await 0 }}",
pass: function (ast) {
return ast.body[0].declarations[0].init.properties[0].value.async;
return ast.body[0].declarations[0].init.properties[0].value.async
&& ast.body[0].declarations[0].init.properties[0].value.body.body[0].expression.type==='AwaitExpression';
}
},{
desc: "Nodent:".grey+" Async set method fails",
code: "var a = {async set x(){}}",
pass: function (ex) {
return ex === "'set <member>(value)' cannot be be async (1:15)";
desc: "Nodent:".grey+" In {code}, x is an async getter",
code: "var a = {async get x(){ await(0) }}",
pass: function (ast) {
return ast.body[0].declarations[0].init.properties[0].value.async
&& ast.body[0].declarations[0].init.properties[0].value.body.body[0].expression.type==='AwaitExpression';
}
},{
desc: "Nodent:".grey+" Async constructor fails",
code: "var a = {async constructor(){}}",
pass: function (ex) {
return ex === "'constructor()' cannot be be async (1:15)";
}
},{
desc: "Nodent:".grey+" {code} is an AwaitExpression when inAsyncFunction option is true",

@@ -223,2 +260,3 @@ code: "await(x)",

console.log(prefix, desc, ex.message.magenta, out[false]);
results.false += 1;
}

@@ -225,0 +263,0 @@ }

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