Skip to content

Commit

Permalink
🐛 Added support for attributes that are not assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
deamme committed Oct 13, 2017
1 parent 038cf81 commit 7323a76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-transform-inferno",
"version": "0.3.0",
"version": "0.4.0",
"description": "A typescript transformer for InfernoJS",
"bugs": {
"url": "https://github.com/deamme/ts-transform-inferno/issues"
Expand Down
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default function (CONFIG?: Config) {
let assignArgs = [];
for (let i = 0; i < astProps.length; i++) {
let astProp = astProps[i];
const initializer = astProp.initializer

if (astProp.kind === ts.SyntaxKind.JsxSpreadAttribute) {
assignArgs = [
Expand All @@ -239,12 +240,12 @@ export default function (CONFIG?: Config) {
!isComponent &&
(propName === "className" || propName === "class")
) {
className = getValue(astProp.initializer);
className = getValue(initializer);
} else if (!isComponent && propName === "htmlFor") {
props.push(
ts.createPropertyAssignment(
getName("for"),
getValue(astProp.initializer)
getValue(initializer)
)
);
} else if (propName.substr(0, 11) === "onComponent" && isComponent) {
Expand All @@ -256,15 +257,15 @@ export default function (CONFIG?: Config) {
ref.properties.push(
ts.createObjectLiteral(
getName(propName),
getValue(astProp.initializer)
getValue(initializer)
)
);
} else if (!isComponent && propName in svgAttributes) {
// React compatibility for SVG Attributes
props.push(
ts.createPropertyAssignment(
getName(svgAttributes[propName]),
getValue(astProp.initializer)
getValue(initializer)
)
);
} else {
Expand All @@ -279,16 +280,16 @@ export default function (CONFIG?: Config) {
hasKeyedChildren = true;
break;
case "ref":
ref = getValue(astProp.initializer);
ref = getValue(initializer);
break;
case "key":
key = getValue(astProp.initializer);
key = getValue(initializer);
break;
default:
props.push(
ts.createPropertyAssignment(
getName(propName),
getValue(astProp.initializer)
initializer ? getValue(initializer) : ts.createTrue()
)
);
}
Expand Down
1 change: 1 addition & 0 deletions tests/cases/divWithNoAssignedAttributes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div foo Bar STAR />
3 changes: 3 additions & 0 deletions tests/references/divWithNoAssignedAttributes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var Inferno = require("inferno");
var createVNode = Inferno.createVNode;
createVNode(2, "div", null, null, { "foo": true, "Bar": true, "STAR": true });

0 comments on commit 7323a76

Please sign in to comment.