Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack+JSX + generators: Did not recognize object of type "JSXElement" #930

Closed
Naddiseo opened this issue Mar 2, 2015 · 4 comments
Closed
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@Naddiseo
Copy link
Contributor

Naddiseo commented Mar 2, 2015

I have my own custom JSX transformer based upon the react one, except that its output it pre-compiled into the mithril's output format: { "tag": "TAG", "attrs", {}, "children": [] }

If in the same file I have a generator function I'm getting the following build error:

Module build failed: AssertionError: ~/projects/test/test.jsx: did not recognize object of type "JSXElement"
    at Object.getFieldNames (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/types.js:595:16)
    at visitChildren (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:203:32)
    at Visitor.PVp.visitWithoutReset (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:188:16)
    at visitChildren (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:226:21)
    at Visitor.PVp.visitWithoutReset (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:188:16)
    at NodePath.each (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path.js:96:22)
    at visitChildren (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:199:14)
    at Visitor.PVp.visitWithoutReset (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:188:16)
    at visitChildren (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:226:21)
    at Visitor.PVp.visitWithoutReset (~/projects/test/node_modules/babel-core/node_modules/ast-types/lib/path-visitor.js:188:16)

If I remove the generator, it works fine. I've tried stepping through with node-debug and as far as I can tell, my loader is called and properly transforms the code, so I think there may be a conflict somewhere in the regenerator transforms. My intuition is because regenerator/ast-types uses XJS* whereas babel uses JSX* for the ast tags.

I've created a gist with my webpack conf, a test file, and my jsx loader/transformer: https://gist.github.com/Naddiseo/800aab5c780d9440ba70

@fkling
Copy link
Contributor

fkling commented Mar 2, 2015

XJS* nodes have been recently renamed to JSX* nodes in various parsers (e.g. facebookarchive/esprima#85).

I just created a pull request for ast-types: benjamn/ast-types#93 . I assume that something sets a custom parser (acorn-babel ?) which doesn't produce XJS* nodes anymore.

@neVERberleRfellerER
Copy link
Contributor

@Naddiseo I've had some problems with your code but I have something I have to ask.
Do you know about this?

/** @jsx dom */

function dom(tag, attrs, ...children) { // dom - the name after @jsx, put whatever you want
    return { tag, attrs, children };
}

console.log(JSON.stringify(
<div>
  <span>Something<span>else</span></span>
  <span>Somethign else</span>
  <span>Hahah</span>
</div>, null, 2
));

output

{
  "tag": "div",
  "attrs": null,
  "children": [
    {
      "tag": "span",
      "attrs": null,
      "children": [
        "Something",
        {
          "tag": "span",
          "attrs": null,
          "children": [
            "else"
          ]
        }
      ]
    },
    {
      "tag": "span",
      "attrs": null,
      "children": [
        "Somethign else"
      ]
    },
    {
      "tag": "span",
      "attrs": null,
      "children": [
        "Hahah"
      ]
    }
  ]
}

I am sorry if you know this and does not fit your needs and I am just wasting your time. I'll look into your gist again later.

However, from quick look:

{( for (item of ctrl.getList()) inner(item) )}

This might be problem when XJS/JSX is solved: you need something to replace this:

{ items.map(item) }

Array or single item should be here. You do not return anything to JSX. Maybe something like this:

<span>{
  (function () {
    var items = [];
    for (item of ctrl.getList()) {
     items.push(inner(item));
    }
    return items;
  })()
}</span>

@Naddiseo
Copy link
Contributor Author

Naddiseo commented Mar 2, 2015

@fkling That PR to ast-types does fix my problem, I guess my intuition was right.

@neVERberleRfellerER, I didn't know about the /** jsx */ thing until this morning, but it doesn't apply since I wanted to pre-compile the output anyway.

I guess this can be closed once the ast-types dependency has been updated.

@sebmck
Copy link
Contributor

sebmck commented Mar 6, 2015

Fixed as of 4.7.0, thanks!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 26, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants