Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now it just transforms class= to className= and for= to htmlFor=
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Changes `class=` to `className=` and 'for=' to `htmlFor=` | ||
* for the sake of 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=' | ||
}; | ||
|
||
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); | ||
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
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