-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
15 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
/** | ||
* 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); | ||
}; | ||
} | ||
|
||
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; | ||
}; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters