Socket
Socket
Sign inDemoInstall

acorn

Package Overview
Dependencies
Maintainers
2
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

20

CHANGELOG.md

@@ -1,3 +0,21 @@

## 3.1.0 (2015-04-18)
## 3.2.0 (2016-06-07)
## Bug fixes
Improve handling of lack of unicode regexp support in host
environment.
Properly reject shorthand properties whose name is a keyword.
Don't crash when the loose parser is called without options object.
### New features
Visitors created with `visit.make` now have their base as _prototype_,
rather than copying properties into a fresh object.
Make it possible to use `visit.ancestor` with a walk state.
## 3.1.0 (2016-04-18)
### Bug fixes

@@ -4,0 +22,0 @@

8

dist/acorn_loose.js

@@ -624,3 +624,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).loose = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

var LooseParser = (function () {
function LooseParser(input, options) {
function LooseParser(input) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
_classCallCheck(this, LooseParser);

@@ -1104,3 +1106,3 @@

if (this.eat(_.tokTypes.star)) {
node.source = this.eatContextual("from") ? this.parseExprAtom() : null;
node.source = this.eatContextual("from") ? this.parseExprAtom() : this.dummyString();
return this.finishNode(node, "ExportAllDeclaration");

@@ -1163,3 +1165,3 @@ }

this.next();
if (this.eatContextual("as")) elt.local = this.parseIdent();
elt.local = this.eatContextual("as") ? this.parseIdent() : this.dummyIdent();
elts.push(this.finishNode(elt, "ImportNamespaceSpecifier"));

@@ -1166,0 +1168,0 @@ } else {

@@ -43,16 +43,16 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).walk = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

// An ancestor walk builds up an array of ancestor nodes (including
// the current node) and passes them to the callback as the state parameter.
// An ancestor walk keeps an array of ancestor nodes (including the
// current node) and passes them to the callback as third parameter
// (and also as state parameter when no other state is present).
function ancestor(node, visitors, base, state) {
if (!base) base = exports.base;
if (!state) state = [];(function c(node, st, override) {
var ancestors = [];(function c(node, st, override) {
var type = override || node.type,
found = visitors[type];
if (node != st[st.length - 1]) {
st = st.slice();
st.push(node);
}
var isNew = node != ancestors[ancestors.length - 1];
if (isNew) ancestors.push(node);
base[type](node, st, c);
if (found) found(node, st);
if (found) found(node, st || ancestors, ancestors);
if (isNew) ancestors.pop();
})(node, state);

@@ -158,2 +158,9 @@ }

// Fallback to an Object.create polyfill for older environments.
var create = Object.create || function (proto) {
function Ctor() {}
Ctor.prototype = proto;
return new Ctor();
};
// Used to create a custom walker. Will fill in all missing node

@@ -164,4 +171,3 @@ // type properties with the defaults.

if (!base) base = exports.base;
var visitor = {};
for (var type in base) visitor[type] = base[type];
var visitor = create(base);
for (var type in funcs) visitor[type] = funcs[type];

@@ -168,0 +174,0 @@ return visitor;

@@ -6,3 +6,3 @@ {

"main": "dist/acorn.js",
"version": "3.1.0",
"version": "3.2.0",
"engines": {

@@ -9,0 +9,0 @@ "node": ">=0.4.0"

@@ -271,3 +271,3 @@ # Acorn

a tree, building up an array of ancestor nodes (including the current node)
and passing the array to callbacks in the `state` parameter.
and passing the array to the callbacks as a third parameter.

@@ -402,2 +402,8 @@ **recursive**`(node, state, functions, base)` does a 'recursive'

There is a proof-of-concept JSX plugin in the [`acorn-jsx`](https://github.com/RReverser/acorn-jsx) project.
### Existing plugins
- [`acorn-jsx`](https://github.com/RReverser/acorn-jsx): Parse [Facebook JSX syntax extensions](https://github.com/facebook/jsx)
- [`acorn-es7-plugin`](https://github.com/MatAtBread/acorn-es7-plugin/): Parse [async/await syntax proposal](https://github.com/tc39/ecmascript-asyncawait)
- [`acorn-object-spread`](https://github.com/UXtemple/acorn-object-spread): Parse [object spread syntax proposal](https://github.com/sebmarkbage/ecmascript-rest-spread)
- [`acorn-es7`](https://www.npmjs.com/package/acorn-es7): Parse [decorator syntax proposal](https://github.com/wycats/javascript-decorators)
- [`acorn-objj`](https://www.npmjs.com/package/acorn-objj): [Objective-J](http://www.cappuccino-project.org/learn/objective-j.html) language parser built as Acorn plugin

@@ -21,2 +21,3 @@ // A recursive descent parser operates by defining functions for all

import {Parser} from "./state"
import {DestructuringErrors} from "./parseutil"

@@ -96,6 +97,6 @@ const pp = Parser.prototype

let validateDestructuring = false
let ownDestructuringErrors = false
if (!refDestructuringErrors) {
refDestructuringErrors = {shorthandAssign: 0, trailingComma: 0}
validateDestructuring = true
refDestructuringErrors = new DestructuringErrors
ownDestructuringErrors = true
}

@@ -108,3 +109,4 @@ let startPos = this.start, startLoc = this.startLoc

if (this.type.isAssign) {
if (validateDestructuring) this.checkPatternErrors(refDestructuringErrors, true)
this.checkPatternErrors(refDestructuringErrors, true)
if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors)
let node = this.startNodeAt(startPos, startLoc)

@@ -119,3 +121,3 @@ node.operator = this.value

} else {
if (validateDestructuring) this.checkExpressionErrors(refDestructuringErrors, true)
if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true)
}

@@ -353,3 +355,3 @@ return left

let exprList = [], first = true
let refDestructuringErrors = {shorthandAssign: 0, trailingComma: 0}, spreadStart, innerParenStart
let refDestructuringErrors = new DestructuringErrors, spreadStart, innerParenStart
while (this.type !== tt.parenR) {

@@ -498,43 +500,43 @@ first ? first = false : this.expect(tt.comma)

if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors)
prop.kind = "init"
} else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
if (isPattern) this.unexpected()
prop.kind = "init"
prop.method = true
prop.value = this.parseMethod(isGenerator)
} else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type != tt.comma && this.type != tt.braceR)) {
if (isGenerator || isPattern) this.unexpected()
prop.kind = prop.key.name
this.parsePropertyName(prop)
prop.value = this.parseMethod(false)
let paramCount = prop.kind === "get" ? 0 : 1
if (prop.value.params.length !== paramCount) {
let start = prop.value.start
if (prop.kind === "get")
this.raiseRecoverable(start, "getter should have no params")
else
this.raiseRecoverable(start, "setter should have exactly one param")
}
if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params")
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
prop.kind = "init"
if (isPattern) {
if (this.keywords.test(prop.key.name) ||
(this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) ||
(this.inGenerator && prop.key.name == "yield"))
this.raiseRecoverable(prop.key.start, "Binding " + prop.key.name)
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
} else if (this.type === tt.eq && refDestructuringErrors) {
if (!refDestructuringErrors.shorthandAssign)
refDestructuringErrors.shorthandAssign = this.start
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
} else {
prop.value = prop.key
}
prop.shorthand = true
} else this.unexpected()
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors)
prop.kind = "init"
} else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
if (isPattern) this.unexpected()
prop.kind = "init"
prop.method = true
prop.value = this.parseMethod(isGenerator)
} else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type != tt.comma && this.type != tt.braceR)) {
if (isGenerator || isPattern) this.unexpected()
prop.kind = prop.key.name
this.parsePropertyName(prop)
prop.value = this.parseMethod(false)
let paramCount = prop.kind === "get" ? 0 : 1
if (prop.value.params.length !== paramCount) {
let start = prop.value.start
if (prop.kind === "get")
this.raiseRecoverable(start, "getter should have no params")
else
this.raiseRecoverable(start, "setter should have exactly one param")
}
if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params")
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
if (this.keywords.test(prop.key.name) ||
(this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) ||
(this.inGenerator && prop.key.name == "yield"))
this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property")
prop.kind = "init"
if (isPattern) {
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
} else if (this.type === tt.eq && refDestructuringErrors) {
if (!refDestructuringErrors.shorthandAssign)
refDestructuringErrors.shorthandAssign = this.start
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
} else {
prop.value = prop.key
}
prop.shorthand = true
} else this.unexpected()
}

@@ -553,3 +555,3 @@

}
return prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true)
return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true)
}

@@ -556,0 +558,0 @@

@@ -7,3 +7,3 @@ import {tokenizer, SourceLocation, tokTypes as tt, Node, lineBreak, isNewLine} from ".."

export class LooseParser {
constructor(input, options) {
constructor(input, options = {}) {
this.toks = tokenizer(input, options)

@@ -10,0 +10,0 @@ this.options = this.toks.options

@@ -322,3 +322,3 @@ import {LooseParser} from "./state"

if (this.eat(tt.star)) {
node.source = this.eatContextual("from") ? this.parseExprAtom() : null
node.source = this.eatContextual("from") ? this.parseExprAtom() : this.dummyString()
return this.finishNode(node, "ExportAllDeclaration")

@@ -379,3 +379,3 @@ }

this.next()
if (this.eatContextual("as")) elt.local = this.parseIdent()
elt.local = this.eatContextual("as") ? this.parseIdent() : this.dummyIdent()
elts.push(this.finishNode(elt, "ImportNamespaceSpecifier"))

@@ -382,0 +382,0 @@ } else {

@@ -92,6 +92,13 @@ import {types as tt} from "./tokentype"

export class DestructuringErrors {
constructor() {
this.shorthandAssign = 0
this.trailingComma = 0
}
}
pp.checkPatternErrors = function(refDestructuringErrors, andThrow) {
let pos = refDestructuringErrors && refDestructuringErrors.trailingComma
if (!andThrow) return !!pos
if (pos) this.raise(pos, "Comma is not permitted after the rest element")
let trailing = refDestructuringErrors && refDestructuringErrors.trailingComma
if (!andThrow) return !!trailing
if (trailing) this.raise(trailing, "Comma is not permitted after the rest element")
}

@@ -98,0 +105,0 @@

@@ -5,2 +5,3 @@ import {types as tt} from "./tokentype"

import {isIdentifierStart, isIdentifierChar} from "./identifier"
import {DestructuringErrors} from "./parseutil"

@@ -183,3 +184,3 @@ const pp = Parser.prototype

}
let refDestructuringErrors = {shorthandAssign: 0, trailingComma: 0}
let refDestructuringErrors = new DestructuringErrors
let init = this.parseExpression(true, refDestructuringErrors)

@@ -186,0 +187,0 @@ if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {

@@ -420,3 +420,3 @@ import {isIdentifierStart, isIdentifierChar} from "./identifier"

let mods = this.readWord1()
let tmp = content
let tmp = content, tmpFlags = ""
if (mods) {

@@ -426,17 +426,22 @@ let validFlags = /^[gim]*$/

if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag")
if (mods.indexOf('u') >= 0 && !regexpUnicodeSupport) {
// Replace each astral symbol and every Unicode escape sequence that
// possibly represents an astral symbol or a paired surrogate with a
// single ASCII symbol to avoid throwing on regular expressions that
// are only valid in combination with the `/u` flag.
// Note: replacing with the ASCII symbol `x` might cause false
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
// be replaced by `[x-b]` which throws an error.
tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, (_match, code, offset) => {
code = Number("0x" + code)
if (code > 0x10FFFF) this.raise(start + offset + 3, "Code point out of bounds")
return "x"
})
tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x")
if (mods.indexOf("u") >= 0) {
if (regexpUnicodeSupport) {
tmpFlags = "u"
} else {
// Replace each astral symbol and every Unicode escape sequence that
// possibly represents an astral symbol or a paired surrogate with a
// single ASCII symbol to avoid throwing on regular expressions that
// are only valid in combination with the `/u` flag.
// Note: replacing with the ASCII symbol `x` might cause false
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
// be replaced by `[x-b]` which throws an error.
tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, (_match, code, offset) => {
code = Number("0x" + code)
if (code > 0x10FFFF) this.raise(start + offset + 3, "Code point out of bounds")
return "x"
})
tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x")
tmpFlags = tmpFlags.replace("u", "")
}
}

@@ -449,3 +454,3 @@ }

if (!isRhino) {
tryCreateRegexp(tmp, undefined, start, this)
tryCreateRegexp(tmp, tmpFlags, start, this)
// Get a regular expression object for this pattern-flag pair, or `null` in

@@ -452,0 +457,0 @@ // case the current environment doesn't support the flags it uses.

@@ -28,15 +28,15 @@ // AST walker module for Mozilla Parser API compatible trees

// An ancestor walk builds up an array of ancestor nodes (including
// the current node) and passes them to the callback as the state parameter.
// An ancestor walk keeps an array of ancestor nodes (including the
// current node) and passes them to the callback as third parameter
// (and also as state parameter when no other state is present).
export function ancestor(node, visitors, base, state) {
if (!base) base = exports.base
if (!state) state = []
let ancestors = []
;(function c(node, st, override) {
let type = override || node.type, found = visitors[type]
if (node != st[st.length - 1]) {
st = st.slice()
st.push(node)
}
let isNew = node != ancestors[ancestors.length - 1]
if (isNew) ancestors.push(node)
base[type](node, st, c)
if (found) found(node, st)
if (found) found(node, st || ancestors, ancestors)
if (isNew) ancestors.pop()
})(node, state)

@@ -143,2 +143,9 @@ }

// Fallback to an Object.create polyfill for older environments.
const create = Object.create || function(proto) {
function Ctor() {}
Ctor.prototype = proto
return new Ctor
}
// Used to create a custom walker. Will fill in all missing node

@@ -148,4 +155,3 @@ // type properties with the defaults.

if (!base) base = exports.base
let visitor = {}
for (var type in base) visitor[type] = base[type]
let visitor = create(base)
for (var type in funcs) visitor[type] = funcs[type]

@@ -152,0 +158,0 @@ return visitor

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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