This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special case template literal rendering
- Loading branch information
1 parent
4af8163
commit 1009af8
Showing
4 changed files
with
61 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function render() { | ||
return <div> | ||
{`${i}`} | ||
{`text ${i}`} | ||
{`${i} text`} | ||
{`text ${i} text`} | ||
{"text" - i} | ||
</div>; | ||
} |
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,33 @@ | ||
var _hasOwn = Object.prototype.hasOwnProperty; | ||
|
||
var _forOwn = function _forOwn(object, iterator) { | ||
for (var prop in object) { | ||
if (_hasOwn.call(object, prop)) iterator(object[prop], prop); | ||
} | ||
}; | ||
|
||
var _renderArbitrary = function _renderArbitrary(child) { | ||
var type = typeof child; | ||
|
||
if (type === "number" || type === "string" || type === "object" && child instanceof String) { | ||
text(child); | ||
} else if (type === "function" && child.__jsxDOMWrapper) { | ||
child(); | ||
} else if (Array.isArray(child)) { | ||
child.forEach(_renderArbitrary); | ||
} else if (type === "object" && String(child) === "[object Object]") { | ||
_forOwn(child, _renderArbitrary); | ||
} | ||
}; | ||
|
||
function render() { | ||
elementOpen("div"); | ||
text("" + i); | ||
text("text " + i); | ||
text(i + " text"); | ||
text("text " + i + " text"); | ||
|
||
_renderArbitrary("text" - i); | ||
|
||
return elementClose("div"); | ||
} |