diff --git a/CHANGELOG.md b/CHANGELOG.md index f19d004..bba243e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project tries to adhere to [Semantic Versioning](http://semver.org/). - Python Support - Jade Support - Stylus Support +- JSX Support ### Changed - Use Espree to parse JavaScript to extract the outline diff --git a/README.md b/README.md index d94ad58..bc2975c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ * CoffeeScript * Haxe * Jade - * JavaScript (based on Espree AST) + * JavaScript, JSX (based on Espree AST) * Markdown, GitHub-Flavored-Markdown (atx-style headings only) * PHP * Python diff --git a/main.js b/main.js index 4f88e88..80d25a5 100644 --- a/main.js +++ b/main.js @@ -16,6 +16,7 @@ define(function (require, exports, module) { /* beautify preserve:start *//* eslint-disable key-spacing */ var languageMapping = { JavaScript: "JavaScript", + JSX: "JavaScript", Haxe: "Haxe", CoffeeScript: "CoffeeScript", CSS: "CSS", diff --git a/package.json b/package.json index 0fc341b..3179dbe 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "hirse.outline-list", "version": "0.7.0", "title": "Brackets Outline List", - "description": "Displays a list of the functions or definitions in the currently opened document. Works with CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, and XML.", + "description": "Displays a list of the functions or definitions in the currently opened document. Works with CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, JSX, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, and XML.", "engines": { "brackets": ">=1.8.0" }, @@ -18,6 +18,7 @@ "Haxe", "Jade", "JavaScript", + "JSX", "LESS", "Markdown", "PHP", @@ -37,16 +38,16 @@ ], "package-i18n": { "de": { - "description": "Zeigt eine Liste der Funktionen oder Definitionen im geöffneten Dokument. Unterstützt CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, und XML." + "description": "Zeigt eine Liste der Funktionen oder Definitionen im geöffneten Dokument. Unterstützt CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, JSX, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, und XML." }, "es": { - "description": "Muestra una lista con las funciones o definiciones del documento actualmente abierto. Funciona con CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, y XML." + "description": "Muestra una lista con las funciones o definiciones del documento actualmente abierto. Funciona con CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, JSX, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, y XML." }, "fr": { - "description": "Affiche une liste des fonctions ou définition du document ouvert actuellement. Fonctionne avec CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, et XML." + "description": "Affiche une liste des fonctions ou définition du document ouvert actuellement. Fonctionne avec CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, JSX, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, et XML." }, "ja": { - "description": "現在開いているドキュメントの関数または定義の一覧を表示する。CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, と XML に対応。" + "description": "現在開いているドキュメントの関数または定義の一覧を表示する。CSS, CoffeeScript, HTML, Haxe, Jade, JavaScript, JSX, LESS, Markdown, PHP, Python, Ruby, SCSS, SVG, Stylus, と XML に対応。" } }, "devDependencies": { diff --git a/src/lexers/JSParser.js b/src/lexers/JSParser.js index 074c2af..e25149a 100644 --- a/src/lexers/JSParser.js +++ b/src/lexers/JSParser.js @@ -128,7 +128,10 @@ define(function (require, exports, module) { try { ast = espree.parse(source, { loc: true, - ecmaVersion: 8 + ecmaVersion: 8, + ecmaFeatures: { + jsx: true + } }); } catch (error) { throw new Error("SyntaxError"); diff --git a/test/JSXSpec.js b/test/JSXSpec.js new file mode 100644 index 0000000..2852ebf --- /dev/null +++ b/test/JSXSpec.js @@ -0,0 +1,20 @@ +define(function JavaScriptSpec(require) { + "use strict"; + + var Parser = require("lexers/JSParser"); + + describe("JSX Parser", function () { + it("detects a function with JSX", function () { + var test = require("text!example/jsx/test.jsx"); + var result = Parser.parse(test); + + expect(result.length).toEqual(1); + + expect(result[0].args.length).toEqual(0); + expect(result[0].level).toEqual(0); + expect(result[0].line).toEqual(1); + expect(result[0].name).toEqual("a"); + expect(result[0].type).toEqual("public"); + }); + }); +}); diff --git a/test/example/jsx/test.jsx b/test/example/jsx/test.jsx new file mode 100644 index 0000000..af74aac --- /dev/null +++ b/test/example/jsx/test.jsx @@ -0,0 +1,3 @@ +function a() { + return ; +}