Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Handle JSX Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed May 4, 2019
1 parent 9b53e5b commit ce90ca5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "babel-plugin-jsx-dom-expressions",
"description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
"version": "0.7.2",
"version": "0.7.3",
"author": "Ryan Carniato",
"license": "MIT",
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export default (babel) => {
// reduce unnecessary refs
function detectExpressions(jsx, index) {
for (let i = index; i < jsx.children.length; i++) {
if (t.isJSXExpressionContainer(jsx.children[i])) return true;
if (t.isJSXElement(jsx.children[i])) {
if (t.isJSXExpressionContainer(jsx.children[i])) {
if (!t.isJSXEmptyExpression(jsx.children[i].expression)) return true;
}
else if (t.isJSXElement(jsx.children[i])) {
const tagName = getTagName(jsx.children[i]);
if (tagName.toLowerCase() !== tagName) return true;
if (jsx.children[i].openingElement.attributes.some(attr => t.isJSXSpreadAttribute(attr) || t.isJSXExpressionContainer(attr.value))) return true;
Expand Down Expand Up @@ -340,6 +342,7 @@ export default (babel) => {
if (!info.skipId) results.id = path.scope.generateUidIdentifier("el$")
return results;
} else if (t.isJSXExpressionContainer(jsx)) {
if (t.isJSXEmptyExpression(jsx.expression)) return null;
if (!checkParens(jsx, path)) return { exprs: [jsx.expression], template: '' }
return { exprs: [t.arrowFunctionExpression([], jsx.expression)], template: '' }
}
Expand Down
1 change: 1 addition & 0 deletions test/__fixtures__/simpleElements/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const template = (
<h1>Welcome</h1>
<label for={"entry"}>Edit:</label>
<input id="entry" type="text" />
{/* Comment Node */}
</div>
);
1 change: 1 addition & 0 deletions test/__fixtures__/subTemplates/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const template = props => {
<div>From Parent</div>
</Child>
<Child name='Jason' {...(props)} forwardRef={props.ref}>
{/* Comment Node */}
<div>{state.content}</div>
</Child>
<Context.Consumer>{ context =>
Expand Down

0 comments on commit ce90ca5

Please sign in to comment.