Socket
Socket
Sign inDemoInstall

acorn-jsx

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn-jsx - npm Package Compare versions

Comparing version 0.7.1-3 to 0.9.1-1

bin/without_eval

102

acorn_loose.js

@@ -46,5 +46,7 @@ // Acorn: Loose parser

input = String(inpt);
if (/^#!.*/.test(input)) input = "//" + input.slice(2);
options = opts;
if (!opts.tabSize) opts.tabSize = 4;
fetchToken = acorn.tokenize(inpt, opts);
fetchToken = acorn.tokenize(input, opts);
sourceFile = options.sourceFile || null;

@@ -213,9 +215,23 @@ context = [];

node.sourceFile = options.directSourceFile;
if (options.ranges)
node.range = [token.start, 0];
return node;
}
function startNodeFrom(other) {
var node = new Node(other.start);
if (options.locations)
node.loc = new SourceLocation(other.loc.start);
function storeCurrentPos() {
return options.locations ? [token.start, token.startLoc] : token.start;
}
function startNodeAt(pos) {
var node;
if (options.locations) {
node = new Node(pos[0]);
node.loc = new SourceLocation(pos[1]);
} else {
node = new Node(pos);
}
if (options.directSourceFile)
node.sourceFile = options.directSourceFile;
if (options.ranges)
node.range = [pos[0], 0];
return node;

@@ -229,20 +245,11 @@ }

node.loc.end = lastEndLoc;
if (options.ranges)
node.range[1] = lastEnd;
return node;
}
function getDummyLoc() {
if (options.locations) {
var loc = new SourceLocation();
loc.end = loc.start;
return loc;
}
};
function dummyIdent() {
var dummy = new Node(token.start);
dummy.type = "Identifier";
dummy.end = token.start;
var dummy = startNode();
dummy.name = "✖";
dummy.loc = getDummyLoc();
return dummy;
return finishNode(dummy, "Identifier");
}

@@ -405,3 +412,2 @@ function isDummy(node) { return node.name == "✖"; }

node = parseVar(node);
semicolon();
return node;

@@ -494,2 +500,3 @@

}
if (!noIn) semicolon();
return finishNode(node, "VariableDeclaration");

@@ -499,5 +506,6 @@ }

function parseExpression(noComma, noIn) {
var start = storeCurrentPos();
var expr = parseMaybeAssign(noIn);
if (!noComma && token.type === tt.comma) {
var node = startNodeFrom(expr);
var node = startNodeAt(start);
node.expressions = [expr];

@@ -520,5 +528,6 @@ while (eat(tt.comma)) node.expressions.push(parseMaybeAssign(noIn));

function parseMaybeAssign(noIn) {
var start = storeCurrentPos();
var left = parseMaybeConditional(noIn);
if (token.type.isAssign) {
var node = startNodeFrom(left);
var node = startNodeAt(start);
node.operator = token.value;

@@ -534,5 +543,6 @@ node.left = checkLVal(left);

function parseMaybeConditional(noIn) {
var start = storeCurrentPos();
var expr = parseExprOps(noIn);
if (eat(tt.question)) {
var node = startNodeFrom(expr);
var node = startNodeAt(start);
node.test = expr;

@@ -547,7 +557,8 @@ node.consequent = parseExpression(true);

function parseExprOps(noIn) {
var start = storeCurrentPos();
var indent = curIndent, line = curLineStart;
return parseExprOp(parseMaybeUnary(noIn), -1, noIn, indent, line);
return parseExprOp(parseMaybeUnary(noIn), start, -1, noIn, indent, line);
}
function parseExprOp(left, minPrec, noIn, indent, line) {
function parseExprOp(left, start, minPrec, noIn, indent, line) {
if (curLineStart != line && curIndent < indent && tokenStartsLine()) return left;

@@ -557,12 +568,14 @@ var prec = token.type.binop;

if (prec > minPrec) {
var node = startNodeFrom(left);
var node = startNodeAt(start);
node.left = left;
node.operator = token.value;
next();
if (curLineStart != line && curIndent < indent && tokenStartsLine())
if (curLineStart != line && curIndent < indent && tokenStartsLine()) {
node.right = dummyIdent();
else
node.right = parseExprOp(parseMaybeUnary(noIn), prec, noIn, indent, line);
var node = finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression");
return parseExprOp(node, minPrec, noIn, indent, line);
} else {
var rightStart = storeCurrentPos();
node.right = parseExprOp(parseMaybeUnary(noIn), rightStart, prec, noIn, indent, line);
}
finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression");
return parseExprOp(node, start, minPrec, noIn, indent, line);
}

@@ -583,5 +596,6 @@ }

}
var start = storeCurrentPos();
var expr = parseExprSubscripts();
while (token.type.postfix && !canInsertSemicolon()) {
var node = startNodeFrom(expr);
var node = startNodeAt(start);
node.operator = token.value;

@@ -597,6 +611,7 @@ node.prefix = false;

function parseExprSubscripts() {
return parseSubscripts(parseExprAtom(), false, curIndent, curLineStart);
var start = storeCurrentPos();
return parseSubscripts(parseExprAtom(), start, false, curIndent, curLineStart);
}
function parseSubscripts(base, noCalls, startIndent, line) {
function parseSubscripts(base, start, noCalls, startIndent, line) {
for (;;) {

@@ -611,3 +626,3 @@ if (curLineStart != line && curIndent <= startIndent && tokenStartsLine()) {

if (eat(tt.dot)) {
var node = startNodeFrom(base);
var node = startNodeAt(start);
node.object = base;

@@ -623,3 +638,3 @@ if (curLineStart != line && curIndent <= startIndent && tokenStartsLine())

next();
var node = startNodeFrom(base);
var node = startNodeAt(start);
node.object = base;

@@ -633,3 +648,3 @@ node.property = parseExpression();

pushCx();
var node = startNodeFrom(base);
var node = startNodeAt(start);
node.callee = base;

@@ -667,7 +682,4 @@ node.arguments = parseExprList(tt.parenR);

case tt.parenL:
var tokStart1 = token.start;
next();
var val = parseExpression();
val.start = tokStart1;
val.end = token.end;
expect(tt.parenR);

@@ -701,3 +713,4 @@ return val;

next();
node.callee = parseSubscripts(parseExprAtom(), true, startIndent, line);
var start = storeCurrentPos();
node.callee = parseSubscripts(parseExprAtom(), start, true, startIndent, line);
if (token.type == tt.parenL) {

@@ -716,5 +729,6 @@ pushCx();

pushCx();
var indent = curIndent + 1, line = curLineStart;
next();
var propIndent = curIndent, line = curLineStart;
while (!closes(tt.braceR, propIndent, line)) {
if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; }
while (!closes(tt.braceR, indent, line)) {
var name = parsePropertyName();

@@ -733,5 +747,3 @@ if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }

} else {
next();
eat(tt.comma);
continue;
prop.value = dummyIdent();
}

@@ -738,0 +750,0 @@

@@ -5,3 +5,3 @@ {

"main": "acorn.js",
"version": "0.7.1-3",
"version": "0.9.1-1",
"maintainers": [

@@ -8,0 +8,0 @@ {

@@ -154,4 +154,13 @@ # Acorn-JSX

- **preserveParens**: If this option is `true`, parenthesized expressions
are represented by (non-standard) `ParenthesizedExpression` nodes
that have a single `expression` property containing the expression
inside parentheses.
[range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
**parseExpressionAt**`(input, offset, options)` will parse a single
expression in a string, and return its AST. It will not complain if
there is more of the string left after the expression.
**getLineInfo**`(input, offset)` can be used to get a `{line,

@@ -199,2 +208,17 @@ column}` object for a given program string and character offset.

#### Using Acorn in an environment with a Content Security Policy
Some contexts, such as Chrome Web Apps, disallow run-time code evaluation.
Acorn uses `new Function` to generate fast functions that test whether
a word is in a given set, and will trigger a security error when used
in a context with such a
[Content Security Policy](http://www.html5rocks.com/en/tutorials/security/content-security-policy/#eval-too)
(see [#90](https://github.com/marijnh/acorn/issues/90) and
[#123](https://github.com/marijnh/acorn/issues/123)).
The `bin/without_eval` script can be used to generate a version of
`acorn.js` that has the generated code inlined, and can thus run
without evaluating anything. In versions of this library downloaded
from NPM, this script will be available as `acorn_csp.js`.
### acorn_loose.js ###

@@ -211,3 +235,3 @@

sense of the input. Depends on `acorn.js`, because it uses the same
tokenizer.
tokenizer. The loose parser does not support ECMAScript 6 syntax yet.

@@ -214,0 +238,0 @@ ### util/walk.js ###

@@ -46,6 +46,5 @@ (function(exports) {

var mis = misMatch(test.ast, ast);
if (!mis && test.comments) mis = misMatch(test.comments, comments);
if (mis) callback("fail", test.code, mis);
if (test.comments) mis = misMatch(test.comments, comments);
if (!mis) callback("ok", test.code);
else callback("fail", test.code, mis);
else callback("ok", test.code);
}

@@ -71,3 +70,3 @@ } catch(e) {

function misMatch(exp, act) {
var misMatch = exports.misMatch = function(exp, act) {
if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {

@@ -88,3 +87,3 @@ if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act);

}
}
};

@@ -91,0 +90,0 @@ function mangle(ast) {

@@ -309,2 +309,4 @@ // AST walker module for Mozilla Parser API compatible trees

// NOTE: the stuff below is deprecated, and will be removed when 1.0 is released
// A custom walker that keeps track of the scope chain and the

@@ -311,0 +313,0 @@ // variables defined in it.

@@ -1,23 +0,4 @@

var acorn = require('./');
var escodegen = require('escodegen');
var comments = [], tokens = [];
var ast = acorn.parse('var x = 42; // answer', {
// collect ranges for each node
ranges: true,
locations: true,
// collect comments in Esprima's format
onComment: comments,
// collect token ranges
onToken: tokens
});
console.log(comments, tokens);
// attach comments using collected information
escodegen.attachComments(ast, comments, tokens);
// generate code
console.log(escodegen.generate(ast, {comment: true}));
// > 'var x = 42; // answer'
template = `<widget foo="{{foo}}">
{{#if foo}}foo!{{/if}}
{{#if foo}}foo!{{/if}}
</widget>`;

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

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

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

Sorry, the diff of this file is not supported yet

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