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.9.1-8 to 0.11.1-1

docco.css

108

acorn_loose.js

@@ -48,3 +48,2 @@ // Acorn: Loose parser

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

@@ -71,2 +70,4 @@ options = fetchToken.options;

token = ahead.shift() || readToken(forceRegexp);
if (options.onToken)
options.onToken(token);

@@ -105,2 +106,8 @@ if (token.start >= nextLineStart) {

replace = {start: e.pos, end: pos, type: tt.regexp, value: re};
} else if (/template/.test(msg)) {
replace = {start: e.pos, end: pos,
type: tt.template,
value: input.slice(e.pos, pos)};
} else if (/comment/.test(msg)) {
replace = fetchToken.current();
} else {

@@ -299,2 +306,3 @@ replace = false;

case "SpreadElement":
case "AssignmentPattern":
return expr;

@@ -621,10 +629,3 @@

if (token.type.prefix) {
var node = startNode(), update = token.type.isUpdate, nodeType;
if (token.type === tt.ellipsis) {
nodeType = "SpreadElement";
} else {
nodeType = update ? "UpdateExpression" : "UnaryExpression";
node.operator = token.value;
node.prefix = true;
}
var node = startNode(), update = token.type.isUpdate;
node.operator = token.value;

@@ -635,3 +636,8 @@ node.prefix = true;

if (update) node.argument = checkLVal(node.argument);
return finishNode(node, nodeType);
return finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
} else if (token.type === tt.ellipsis) {
var node = startNode();
next();
node.argument = parseMaybeUnary(noIn);
return finishNode(node, "SpreadElement");
}

@@ -690,2 +696,7 @@ var start = storeCurrentPos();

base = finishNode(node, "CallExpression");
} else if (token.type == tt.backQuote) {
var node = startNodeAt(start);
node.tag = base;
node.quasi = parseTemplate();
base = finishNode(node, "TaggedTemplateExpression");
} else {

@@ -779,2 +790,5 @@ return base;

case tt.backQuote:
return parseTemplate();
default:

@@ -799,2 +813,35 @@ return dummyIdent();

function parseTemplateElement() {
var elem = startNode();
elem.value = {
raw: input.slice(token.start, token.end),
cooked: token.value
};
next();
elem.tail = token.type === tt.backQuote;
return finishNode(elem, "TemplateElement");
}
function parseTemplate() {
var node = startNode();
next();
node.expressions = [];
var curElt = parseTemplateElement();
node.quasis = [curElt];
while (!curElt.tail) {
next();
node.expressions.push(parseExpression());
if (expect(tt.braceR)) {
curElt = parseTemplateElement();
} else {
curElt = startNode();
curElt.value = {cooked: '', raw: ''};
curElt.tail = true;
}
node.quasis.push(curElt);
}
expect(tt.backQuote);
return finishNode(node, "TemplateLiteral");
}
function parseObj(isClass, isStatement) {

@@ -817,6 +864,7 @@ var node = startNode();

while (!closes(tt.braceR, indent, line)) {
if (isClass && semicolon()) continue;
var prop = startNode(), isGenerator;
if (options.ecmaVersion >= 6) {
if (isClass) {
if (prop['static'] = (token.type === tt.name && token.value === "static")) next();
prop['static'] = false;
} else {

@@ -830,2 +878,12 @@ prop.method = false;

if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
if (isClass) {
if (prop.key.type === "Identifier" && !prop.computed && prop.key.name === "static" &&
(token.type != tt.parenL && token.type != tt.braceL)) {
prop['static'] = true;
isGenerator = eat(tt.star);
parsePropertyName(prop);
} else {
prop['static'] = false;
}
}
if (!isClass && eat(tt.colon)) {

@@ -843,3 +901,4 @@ prop.kind = "init";

} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set")) {
!prop.computed && (prop.key.name === "get" || prop.key.name === "set") &&
(token.type != tt.comma && token.type != tt.braceR)) {
prop.kind = prop.key.name;

@@ -859,3 +918,2 @@ parsePropertyName(prop);

node.body.body.push(finishNode(prop, "MethodDefinition"));
semicolon();
} else {

@@ -867,3 +925,8 @@ node.properties.push(finishNode(prop, "Property"));

popCx();
eat(tt.braceR);
if (!eat(tt.braceR)) {
// If there is no closing brace, make the node span to the start
// of the next token (this is useful for Tern)
lastEnd = token.start;
if (options.locations) lastEndLoc = token.startLoc;
}
if (isClass) {

@@ -900,3 +963,2 @@ semicolon();

node.name = token.type === tt.name ? token.value : token.type.keyword;
fetchToken.noRegexp();
next();

@@ -942,2 +1004,6 @@ return finishNode(node, "Identifier");

break;
case "AssignmentExpression":
node.type = "AssignmentPattern";
break;
}

@@ -1100,6 +1166,5 @@ }

function parseExprList(close, allowEmpty) {
var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart;
var indent = curIndent, line = curLineStart, elts = [];
next(); // Opening bracket
if (curLineStart > continuedLine) continuedLine = curLineStart;
while (!closes(close, indent + (curLineStart <= continuedLine ? 1 : 0), line)) {
while (!closes(close, indent + 1, line)) {
if (eat(tt.comma)) {

@@ -1119,5 +1184,10 @@ elts.push(allowEmpty ? null : dummyIdent());

popCx();
eat(close);
if (!eat(close)) {
// If there is no closing brace, make the node span to the start
// of the next token (this is useful for Tern)
lastEnd = token.start;
if (options.locations) lastEndLoc = token.startLoc;
}
return elts;
}
});

37

package.json
{
"name": "acorn-jsx",
"description": "Alternative React JSX parser",
"description": "Alternative, faster React.js JSX parser",
"homepage": "https://github.com/RReverser/acorn-jsx",
"main": "acorn.js",
"version": "0.9.1-8",
"maintainers": [
{
"name": "Marijn Haverbeke",
"email": "marijnh@gmail.com",
"web": "http://marijnhaverbeke.nl"
},
{
"name": "Ingvar Stepanyan",
"email": "me@rreverser.com",
"web": "https://github.com/RReverser"
}
],
"repository": "RReverser/acorn-jsx",
"licenses": [{
"type": "MIT",
"url": "http://marijnhaverbeke.nl/acorn/LICENSE"
}],
"scripts": {"test": "node test/run.js"},
"bin": {"acorn-jsx": "./bin/acorn"},
"version": "0.11.1-1",
"engines": {"node": ">=0.4.0"},
"maintainers": [{"name": "Ingvar Stepanyan",
"email": "me@rreverser.com",
"web": "http://rreverser.com/"}],
"repository": {"type": "git",
"url": "https://github.com/RReverser/acorn-jsx"},
"licenses": [{"type": "MIT",
"url": "https://raw.githubusercontent.com/RReverser/acorn-jsx/master/LICENSE"}],
"scripts": {
"test": "node test/run.js",
"prepublish": "node bin/without_eval > acorn_csp.js"
},
"bin": {"acorn": "./bin/acorn"},
"devDependencies": {"regenerate": "~0.6.2",
"unicode-7.0.0": "~0.1.5"}
}

@@ -1,25 +0,14 @@

# Acorn-JSX
# Acorn
[![Build Status](https://travis-ci.org/RReverser/acorn.svg?branch=master)](https://travis-ci.org/RReverser/acorn)
[![Build Status](https://travis-ci.org/marijnh/acorn.svg?branch=master)](https://travis-ci.org/marijnh/acorn)
This is modification of [Acorn][acorn] - a tiny, fast JavaScript parser, written completely in JavaScript.
This is modification of [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
It was forked to create experimental alternative, faster [React.js JSX][jsx] parser by integrating pieces
of code from official parser, modified to match Acorn's parsing logic.
It was forked to create experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser by integrating pieces of code from official parser, modified to match Acorn's parsing logic.
According to [benchmarks](test/bench.html), Acorn-JSX is 2x faster than official [Esprima-based parser][esprima-fb]
when location tracking is turned on in both (call it "source maps enabled mode").
At the same time, it consumes all the ES6+JSX syntax that can be consumed by Esprima-FB
(this is proved by [official tests](test/tests-jsx.js)).
According to [benchmarks](https://github.com/RReverser/acorn-jsx/blob/master/test/bench.html), Acorn-JSX is 2x faster than official [Esprima-based parser](https://github.com/facebook/esprima) when location tracking is turned on in both (call it "source maps enabled mode"). At the same time, it consumes all the ES6+JSX syntax that can be consumed by Esprima-FB (this is proved by [official tests](https://github.com/RReverser/acorn-jsx/blob/master/test/tests-jsx.js)).
However, Esprima-FB is maintained by authors of React.js itself,
so it's recommended to be used in production code.
[acorn]: http://marijnhaverbeke.nl/acorn/
[esprima-fb]: https://github.com/facebook/esprima
[jsx]: http://facebook.github.io/react/docs/jsx-in-depth.html
## Transpiler
Please note that this tool only parses source code to JSX AST. If you want to convert result to JS AST or directly to JS code and source map, check out [jsx-transpiler](https://github.com/RReverser/jsx-transpiler).
Please note that this tool only parses source code to JSX AST, which is useful for various language tools and services. If you want to transpile your code to regular ES5-compliant JavaScript with source map, check out [6to5 transpiler](http://6to5.org/) which used `acorn-jsx` under the hood.

@@ -33,3 +22,3 @@ ## Installation

```sh
npm install acorn-jsx
npm install acorn
```

@@ -40,3 +29,3 @@

```sh
git clone https://github.com/RReverser/acorn-jsx.git
git clone https://github.com/marijnh/acorn.git
```

@@ -92,2 +81,10 @@

- **allowImportExportEverywhere**: By default, `import` and `export`
declarations can only appear at a program's top level. Setting this
option to `true` allows them anywhere where a statement is allowed.
- **allowHashBang**: When this is enabled (off by default), if the
code starts with the characters `#!` (as in a shellscript), the
first line will be treated as a comment.
- **locations**: When `true`, each node has a `loc` object attached

@@ -179,2 +176,13 @@ with `start` and `end` subobjects, each of which contains the

In ES6 environment, returned result can be used as any other protocol-compliant iterable:
```javascript
for (let token of acorn.tokenize(str)) {
// iterate over the tokens
}
// transform code to array of tokens:
var tokens = [...acorn.tokenize(str)];
```
**tokTypes** holds an object mapping names to the token type objects

@@ -237,3 +245,3 @@ that end up in the `type` properties of tokens.

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

@@ -240,0 +248,0 @@ ### util/walk.js ###

@@ -53,3 +53,3 @@ (function() {

}
}/*,
},
Loose: {

@@ -60,3 +60,2 @@ config: {

filter: function (test) {
if (/`/.test(test.code)) return false; // FIXME remove this when the loose parse supports template strings
var opts = test.options || {};

@@ -67,9 +66,9 @@ if (opts.loose === false) return false;

}
}*/
}
};
function report(state, code, message) {
function report(state, code, message) {
if (state != "ok") {++stats.failed; log(code, message);}
++stats.testsRun;
}
}

@@ -82,3 +81,3 @@ group("Errors");

stats = mode.stats = {testsRun: 0, failed: 0};
var t0 = +new Date;
var t0 = +new Date;
driver.runTests(mode.config, report);

@@ -111,6 +110,6 @@ mode.stats.duration = +new Date - t0;

if (total.failed && typeof process === "object") {
process.stdout.write("", function() {
process.exit(1);
});
process.stdout.write("", function() {
process.exit(1);
});
}
})();

@@ -288,3 +288,11 @@ // AST walker module for Mozilla Parser API compatible trees

};
base.Identifier = base.Literal = base.ExportDeclaration = base.ImportDeclaration = ignore;
base.ExportDeclaration = function (node, st, c) {
c(node.declaration, st);
};
base.ImportDeclaration = function (node, st, c) {
node.specifiers.forEach(function (specifier) {
c(specifier, st);
});
};
base.ImportSpecifier = base.ImportBatchSpecifier = base.Identifier = base.Literal = ignore;

@@ -291,0 +299,0 @@ base.TaggedTemplateExpression = function(node, st, c) {

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 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 not supported yet

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 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 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