diff --git a/lib/filter/jsx.js b/lib/filter/jsx.js index ee569d34..5a815de3 100644 --- a/lib/filter/jsx.js +++ b/lib/filter/jsx.js @@ -1,7 +1,8 @@ /** -* Changes `class=` to `className=` and 'for=' to `htmlFor=` -* for the sake of JSX! -*/ + * A filter for React.js (JSX): + * ranames attributes like `class` and `for` + * for proper representation in JSX + */ if (typeof module === 'object' && typeof define !== 'function') { var define = function (factory) { module.exports = factory(require, exports, module); @@ -9,26 +10,21 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var tokenMap = { - 'class=': 'className=', - 'for=': 'htmlFor=' + var attrMap = { + 'class': 'className', + 'for': 'htmlFor' }; - function replaceTokens(str) { - Object.keys(tokenMap).forEach(function(k){ - str = str.replace(k, tokenMap[k]); - }) - return str - } - return function process(tree) { tree.children.forEach(function(item) { - item.start = replaceTokens(item.start); - item.end = replaceTokens(item.end); - item.content = replaceTokens(item.content); + item._attributes.forEach(function(attr) { + if (attr.name in attrMap) { + attr.name = attrMap[attr.name] + } + }); process(item); }); return tree; }; -}); +}); \ No newline at end of file diff --git a/lib/snippets.json b/lib/snippets.json index 2f0df1ff..7cc05c0e 100644 --- a/lib/snippets.json +++ b/lib/snippets.json @@ -921,7 +921,7 @@ }, "jsx": { - "filters": "html, jsx", + "filters": "jsx, html", "extends": "html", "profile": "xml" }, diff --git a/package.json b/package.json index 6315201f..d349e0f6 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "gulp-rename": "^1.2.0", "gulp-streamify": "0.0.5", "gulp-uglify": "^1.0.1", - "mocha": "~1.13.0", + "mocha": "^2.2.1", "through2": "^0.6.3", "vinyl-source-stream": "^1.0.0" }