All files / babel-plugin-hyperscript-to-jsx manualRun.js

100% Statements 6/6
100% Branches 0/0
100% Functions 0/0
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 1421x 1x   1x                                                                                                                                                                                                                                                                 1x       1x   1x      
const babel = require("babel-core");
const prettier = require("prettier");
 
const check = `import h from "react-hyperscript"
import { Component, PropTypes } from 'react'
import hx from "shit"
 
const StatelessComponent = props => h("h1");
 
const StatelessWithReturn = props => {
  return h(".class")
};
 
const HandlesAssignment = ({ title }) => {
  title = h('span')
}
 
handleArrays = [h(Sidebar, { categories }), h(CategoryQuestions, { ...question, isBusiness })]
 
const ClassNameWithDashesSingle = props => h('.this-is-dashes')
const ClassNameWithDashesMulti = props => h('.this-is-dashes.dash-afterDash')
const JustPropField = h(Stuff, { children: h(FormattedMessage, { ...commonMessages.learnMore }) })
 
function HyperscriptAsRegularFunction(props) {
  return h("h1");
}
 
const HyperscriptAsVariable = h("div.lol", {
  someProp: "lol"
});
 
const HyperscriptWithExpressionAsChildren = h(
  AnotherComponent,
  { foo: "bar", bar: () => ({}), shouldRender: thing.length > 0 },
  [arr.map(() => h('h1'))]
)
 
// Should be ignored from transforming
const FirstArgTemplateLiteralWithComputedExpressions = h(\`div.lol\${stuff}\`, {
  someProp: "lol"
});
 
// Not computed so should be fine
const FirstArgTemplateLiteral = h(\`div.lol\`, {
  someProp: "lol"
});
 
// Should be ignored
const WhenFirstArgumentIsFunctionThatIsCalled = () => h(getLoadableAnimation('pageCareersDeliver'), [h(fn())])
 
const ComputedRootWithObjectPropertyDeclaration = () =>
  h(
    ANIMATIONS[country],
    {
      className: "lol",
      content: h(".selectItem", [
        h("div", label),
        h(".flag", [
          h(RoundFlag, {
            mix: "flag",
            size: "xs",
            code: currencyData.countryCode
          }),
          // Computed not root should be wrapped in {}
          h(ANIMATIONS[country], { className: "lol" })
        ])
      ])
    },
    // This first children in array will be ignored FOR THIS UGLY HACK IN INDEX
    [h(ANIMATIONS[country], { className: "lol" }), h("h1"), kek && mem, surreal ? lol : kek, t.tabName, lol, <div/>]
  );
  
h('div' + 'div')
 
const ThirdArgOnIgnoredIsNotArray = () =>
  h(
    ANIMATIONS[country],
    {
      className: "lol",
    },
    // This first children in array will be ignored FOR THIS UGLY HACK IN INDEX
    children
  );
  
const SecondArgOnIgnoredIsNotArray = () =>
  h(ANIMATIONS[country], children);
  
const MultiMemberExpressionWithClosingTag = () => h(Pricing.lol.kek, { className }, [ h('h1') ])
 
// to handle h(Abc, { [kek]: 0, ["norm"]: 1 }) to < Abc {...{ [kek]: 0 }} {...{ ["norm" + lol]: 1 }} norm={1} /> 
const ComplexComputedAttibutesHandling = () => h(Abc, { [kek]: 0, ["norm" + lol]: 1, ["ok"]: 2 })
 
// Handle multi classNames css modules (Rev only)
h(".bar.fuzz.stuff", ["bar fuzz"])
 
// Should process children but ignore computed parent
h(\`calcualted \${stuff}\`, { amazing: "stuff" }, [
  h("h1"),
  h("h2"),
  h("h3"),
  h("div", [ h("div") ])
])
 
class Comp extends React.Component {
  render() {
    return h("div.example", [
      isStuff && h("h1#heading", { ...getProps, ...getKnobs(), stuff: "" }),
      isStuff
        ? h("h1#heading", { ...getProps, ...getKnobs(), stuff: "" })
        : h("h1#heading", "heading"),
      h("h1#heading", { ...getProps, ...getKnobs(), stuff: "" }),
      h("h1#heading", getChildren),
      h(ANIMATIONS[country], {
        className: "lol"
      }),
      h("h1#heading", getChildren(), [h("div")]),
      h("div", [h("div", "Some content")]),
      h("h1#heading", "This is hyperscript"),
      h("h2", "creating React.js markup"),
      h(
        AnotherComponent,
        { foo: "bar", bar: () => ({}), shouldRender: thing.length > 0 },
        [
          h("li", [h("a", { href: "http://whatever.com" }, "One list item")]),
          h("li", "Another list item")
        ]
      )
    ]);
  }
}
`;
 
const result = babel.transform(check, {
  plugins: [["./src/index.js"]]
}).code;
 
console.log(prettier.format(result, { semi: false, singleQuote: true }));
 
module.exports = {
  check
}