summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/acorn-jsx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/acorn-jsx')
-rw-r--r--tools/node_modules/eslint/node_modules/acorn-jsx/README.md10
-rw-r--r--tools/node_modules/eslint/node_modules/acorn-jsx/index.js111
-rw-r--r--tools/node_modules/eslint/node_modules/acorn-jsx/package.json10
3 files changed, 83 insertions, 48 deletions
diff --git a/tools/node_modules/eslint/node_modules/acorn-jsx/README.md b/tools/node_modules/eslint/node_modules/acorn-jsx/README.md
index 2bbb1d99fd..317c3ac4a5 100644
--- a/tools/node_modules/eslint/node_modules/acorn-jsx/README.md
+++ b/tools/node_modules/eslint/node_modules/acorn-jsx/README.md
@@ -1,19 +1,15 @@
# Acorn-JSX
-[![Build Status](https://travis-ci.org/RReverser/acorn-jsx.svg?branch=master)](https://travis-ci.org/RReverser/acorn-jsx)
+[![Build Status](https://travis-ci.org/acornjs/acorn-jsx.svg?branch=master)](https://travis-ci.org/acornjs/acorn-jsx)
[![NPM version](https://img.shields.io/npm/v/acorn-jsx.svg)](https://www.npmjs.org/package/acorn-jsx)
This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
-It was created as an experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser.
-
-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)).
-
-**UPDATE [14-Apr-2015]**: Facebook implementation started [deprecation process](https://github.com/facebook/esprima/issues/111) in favor of Acorn + Acorn-JSX + Babel for parsing and transpiling JSX syntax.
+It was created as an experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser. Later, it replaced the [official parser](https://github.com/facebookarchive/esprima) and these days is used by many prominent development tools.
## 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 the [babel transpiler](https://babeljs.io/) which uses `acorn-jsx` under the hood.
+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 [Babel](https://babeljs.io/) and [Buble](https://buble.surge.sh/) transpilers which use `acorn-jsx` under the hood.
## Usage
diff --git a/tools/node_modules/eslint/node_modules/acorn-jsx/index.js b/tools/node_modules/eslint/node_modules/acorn-jsx/index.js
index 460e793399..6df802bee9 100644
--- a/tools/node_modules/eslint/node_modules/acorn-jsx/index.js
+++ b/tools/node_modules/eslint/node_modules/acorn-jsx/index.js
@@ -5,40 +5,53 @@ const XHTMLEntities = require('./xhtml');
const hexNumber = /^[\da-fA-F]+$/;
const decimalNumber = /^\d+$/;
-const acorn = require("acorn");
-const tt = acorn.tokTypes;
-const TokContext = acorn.TokContext;
-const tokContexts = acorn.tokContexts;
-const TokenType = acorn.TokenType;
-const isNewLine = acorn.isNewLine;
-const isIdentifierStart = acorn.isIdentifierStart;
-const isIdentifierChar = acorn.isIdentifierChar;
-
-const tc_oTag = new TokContext('<tag', false);
-const tc_cTag = new TokContext('</tag', false);
-const tc_expr = new TokContext('<tag>...</tag>', true, true);
-
-const tok = {
- jsxName: new TokenType('jsxName'),
- jsxText: new TokenType('jsxText', {beforeExpr: true}),
- jsxTagStart: new TokenType('jsxTagStart'),
- jsxTagEnd: new TokenType('jsxTagEnd')
-}
+// The map to `acorn-jsx` tokens from `acorn` namespace objects.
+const acornJsxMap = new WeakMap();
+
+// Get the original tokens for the given `acorn` namespace object.
+function getJsxTokens(acorn) {
+ acorn = acorn.Parser.acorn || acorn;
+ let acornJsx = acornJsxMap.get(acorn);
+ if (!acornJsx) {
+ const tt = acorn.tokTypes;
+ const TokContext = acorn.TokContext;
+ const TokenType = acorn.TokenType;
+ const tc_oTag = new TokContext('<tag', false);
+ const tc_cTag = new TokContext('</tag', false);
+ const tc_expr = new TokContext('<tag>...</tag>', true, true);
+ const tokContexts = {
+ tc_oTag: tc_oTag,
+ tc_cTag: tc_cTag,
+ tc_expr: tc_expr
+ };
+ const tokTypes = {
+ jsxName: new TokenType('jsxName'),
+ jsxText: new TokenType('jsxText', {beforeExpr: true}),
+ jsxTagStart: new TokenType('jsxTagStart'),
+ jsxTagEnd: new TokenType('jsxTagEnd')
+ };
+
+ tokTypes.jsxTagStart.updateContext = function() {
+ this.context.push(tc_expr); // treat as beginning of JSX expression
+ this.context.push(tc_oTag); // start opening tag context
+ this.exprAllowed = false;
+ };
+ tokTypes.jsxTagEnd.updateContext = function(prevType) {
+ let out = this.context.pop();
+ if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
+ this.context.pop();
+ this.exprAllowed = this.curContext() === tc_expr;
+ } else {
+ this.exprAllowed = true;
+ }
+ };
-tok.jsxTagStart.updateContext = function() {
- this.context.push(tc_expr); // treat as beginning of JSX expression
- this.context.push(tc_oTag); // start opening tag context
- this.exprAllowed = false;
-};
-tok.jsxTagEnd.updateContext = function(prevType) {
- let out = this.context.pop();
- if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
- this.context.pop();
- this.exprAllowed = this.curContext() === tc_expr;
- } else {
- this.exprAllowed = true;
+ acornJsx = { tokContexts: tokContexts, tokTypes: tokTypes };
+ acornJsxMap.set(acorn, acornJsx);
}
-};
+
+ return acornJsx;
+}
// Transforms JSX element name to string.
@@ -64,12 +77,38 @@ module.exports = function(options) {
allowNamespaces: options.allowNamespaces !== false,
allowNamespacedObjects: !!options.allowNamespacedObjects
}, Parser);
- }
+ };
};
-module.exports.tokTypes = tok;
+
+// This is `tokTypes` of the peer dep.
+// This can be different instances from the actual `tokTypes` this plugin uses.
+Object.defineProperty(module.exports, "tokTypes", {
+ get: function get_tokTypes() {
+ return getJsxTokens(require("acorn")).tokTypes;
+ },
+ configurable: true,
+ enumerable: true
+});
function plugin(options, Parser) {
+ const acorn = Parser.acorn || require("acorn");
+ const acornJsx = getJsxTokens(acorn);
+ const tt = acorn.tokTypes;
+ const tok = acornJsx.tokTypes;
+ const tokContexts = acorn.tokContexts;
+ const tc_oTag = acornJsx.tokContexts.tc_oTag;
+ const tc_cTag = acornJsx.tokContexts.tc_cTag;
+ const tc_expr = acornJsx.tokContexts.tc_expr;
+ const isNewLine = acorn.isNewLine;
+ const isIdentifierStart = acorn.isIdentifierStart;
+ const isIdentifierChar = acorn.isIdentifierChar;
+
return class extends Parser {
+ // Expose actual `tokTypes` and `tokContexts` to other plugins.
+ static get acornJsx() {
+ return acornJsx;
+ }
+
// Reads inline JSX contents token.
jsx_readToken() {
let out = '', chunkStart = this.pos;
@@ -419,7 +458,7 @@ function plugin(options, Parser) {
++this.pos;
return this.finishToken(tok.jsxTagStart);
}
- return super.readToken(code)
+ return super.readToken(code);
}
updateContext(prevType) {
@@ -427,7 +466,7 @@ function plugin(options, Parser) {
var curContext = this.curContext();
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
- else super.updateContext(prevType)
+ else super.updateContext(prevType);
this.exprAllowed = true;
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
diff --git a/tools/node_modules/eslint/node_modules/acorn-jsx/package.json b/tools/node_modules/eslint/node_modules/acorn-jsx/package.json
index a8f903e4aa..55b6aadbce 100644
--- a/tools/node_modules/eslint/node_modules/acorn-jsx/package.json
+++ b/tools/node_modules/eslint/node_modules/acorn-jsx/package.json
@@ -1,14 +1,14 @@
{
"bugs": {
- "url": "https://github.com/RReverser/acorn-jsx/issues"
+ "url": "https://github.com/acornjs/acorn-jsx/issues"
},
"bundleDependencies": false,
"deprecated": false,
- "description": "Alternative, faster React.js JSX parser",
+ "description": "Modern, fast React.js JSX parser",
"devDependencies": {
"acorn": "^7.0.0"
},
- "homepage": "https://github.com/RReverser/acorn-jsx",
+ "homepage": "https://github.com/acornjs/acorn-jsx",
"license": "MIT",
"maintainers": [
{
@@ -23,10 +23,10 @@
},
"repository": {
"type": "git",
- "url": "git+https://github.com/RReverser/acorn-jsx.git"
+ "url": "git+https://github.com/acornjs/acorn-jsx.git"
},
"scripts": {
"test": "node test/run.js"
},
- "version": "5.0.2"
+ "version": "5.1.0"
} \ No newline at end of file