Skip to content

Commit

Permalink
Add JSX support
Browse files Browse the repository at this point in the history
See #65
  • Loading branch information
Hirse committed Nov 13, 2016
1 parent 5002018 commit f4a141a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -18,6 +18,7 @@
"Haxe",
"Jade",
"JavaScript",
"JSX",
"LESS",
"Markdown",
"PHP",
Expand All @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/lexers/JSParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 20 additions & 0 deletions test/JSXSpec.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
});
3 changes: 3 additions & 0 deletions test/example/jsx/test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function a() {
return <A color="blue" />;
}

0 comments on commit f4a141a

Please sign in to comment.