Git Product home page Git Product logo

nativejsx-loader's People

Contributors

odzb avatar sankhasp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nativejsx-loader's Issues

JSXText not supported

I'm getting this error when trying to use the loader with JSX with text, simple nodes like:

<div>
    foo
</div>

Or even nested nodes if there are newlines between. These don't work while <div></div> does because the former has text. The traceback is at the end of this issue, seems to be more related to nativejsx dependency or acorn but I wanted to put it here because I'm using it in webpack and may be related.

I modified the code from the traceback a bit into this to get logging info that led me to the issue:

function simple(node, visitors, baseVisitor, state, override) {
  if (!baseVisitor) { baseVisitor = base
  ; }(function c(node, st, override) {
    var type = override || node.type, found = visitors[type];
    if (!(baseVisitor[type] instanceof Function)) {
      console.log("node = ", node);
      console.log("visitors = ", visitors);
      console.log("baseVisitor = ", baseVisitor);
      console.log("type = ", type);
      console.log("baseVisitor[type] = ", baseVisitor[type])
    }
    baseVisitor[type](node, st, c);
    if (found) { found(node, st); }
  })(node, state, override);
}

I got output like this that showed me the issue:

node = Node { type: 'JSXText', start: 5, end: 7, value: '\n\n', raw: '\n\n' }
visitors = {
  INLINE_NATIVEJSX_HELPERS: false,
  MODULE_NATIVEJSX_HELPERS: false,
  JSXAttribute: [Function (anonymous)],
  JSXSpreadAttribute: [Function (anonymous)],
  JSXElement: [Function (anonymous)],
  JSXExpressionContainer: [Function (anonymous)],
  Literal: [Function (anonymous)]
}
baseVisitor = {
  AssignmentExpression: [Function (anonymous)],
  CallExpression: [Function (anonymous)],
  ConditionalExpression: [Function (anonymous)],
  LogicalExpression: [Function (anonymous)],
  ReturnStatement: [Function (anonymous)],
  VariableDeclarator: [Function (anonymous)],
  ArrowFunctionExpression: [Function (anonymous)],
  AssignmentPattern: [Function (anonymous)],
  Property: [Function (anonymous)],
  JSXElement: [Function (anonymous)],
  JSXExpressionContainer: [Function (anonymous)],
  JSXSpreadAttribute: [Function (anonymous)],
  JSXAttribute: [Function (anonymous)]
}
type = JSXText
baseVisitor[type] = undefined

Here's the traceback

ERROR in [file]
Module build failed (from ../node_modules/nativejsx-loader/index.js):
TypeError: baseVisitor[type] is not a function
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.walkers.JSXElement (D:\User\Project\node_modules\nativejsx\source\walkers.js:184:9)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.walkers.VariableDeclarator (D:\User\Project\node_modules\nativejsx\source\walkers.js:94:7)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.base.VariableDeclaration (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:281:5)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.skipThrough (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:187:37)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.base.Program.base.BlockStatement (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:199:5)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.skipThrough (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:187:37)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.base.ScopeBody (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:301:50)
    at c (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:33:22)
    at Object.base.Function (D:\User\Project\node_modules\nativejsx\node_modules\acorn\dist\walk.js:297:3)
 @ [file]

Compatibility with Webpack 2 + ES6 modules

Webpack 2.2 has native support for ES6 modules (import and export keywords). But when I try to use nativejsx-loader with a project that uses that module syntax not through Babel, I get the following error:

    ERROR in [filename]
    Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (5:0)
        at Parser.pp.raise (C:\Projects\[path]\node_modules\nativejsx\node_modules\acorn\dist\acorn.js:943:13)
        at Parser.pp.parseStatement (C:\Projects\[path]\node_modules\nativejsx\node_modules\acorn\dist\acorn.js:1739:34)
        at Parser.pp.parseTopLevel (C:\Projects\[path]\node_modules\nativejsx\node_modules\acorn\dist\acorn.js:1666:21)
        at Parser.parse (C:\Projects\[path]\node_modules\nativejsx\node_modules\acorn\dist\acorn.js:1636:17)
        at Object.parse (C:\Projects\[path]\node_modules\nativejsx\node_modules\acorn\dist\acorn.js:905:44)
        at Object.nativejsx.transpile (C:\Projects\[path]\node_modules\nativejsx\source\nativejsx.js:74:19)
        at Object.module.exports (C:\Projects\[path]\node_modules\nativejsx-loader\index.js:10:15)

Tested with Babel or any other loaders in tandem?

Do you have any idea how this could be used in tandem with babel-loader or any other preloaders?

It does not seem to play nicely with babel-loader. I think this could be due to the fact that this is a preloader and babel-loader is a loader.

I've tried:

            preLoaders: [
                {
                    test: /\.jsx$/,
                    loader: [ 'babel', 'jsxdom' ],
                    query: {
                        presets: [ 'es2015' ]
                    }
                }
            ]

with your test .jsx file.

Ecma5 support

Hi!
First of all thanks for the awesome loader!
One question: how can I add support for ecma5? I've tried something like this:

{
	test: /\.jsx$/,
	use: [{
		loader: 'nativejsx-loader',
		query: {
			variablePrefix: '_',
			declarationType: 'const'
		}
	}, {
		loader: 'babel-loader'
	}],
	exclude: [
		/node_modules/
	]
}

But it didn't work. The problem is the arrow function and the const syntax:

function template() {
    return function () {
        const _a = document.createElement('div');
        _a.setAttribute('class', 'btn-group');
        _a.setAttribute('role', 'group');
        _a.setAttribute('aria-label', 'Basic example');
        const _b = document.createElement('button');
        _b.setAttribute('type', 'button');
        _b.setAttribute('class', 'btn btn-secondary');
        _a.appendChild(_b);
        const _c = document.createTextNode('Left');
        _b.appendChild(_c);
        const _d = document.createElement('button');
        _d.setAttribute('type', 'button');
        _d.setAttribute('class', 'btn btn-secondary');
        (ref => this.middleButton = ref)(_d);
        _a.appendChild(_d);
        const _e = document.createTextNode('Middle');
        _d.appendChild(_e);
        const _f = document.createElement('button');
        _f.setAttribute('type', 'button');
        _f.setAttribute('class', 'btn btn-secondary');
        _a.appendChild(_f);
        const _g = document.createTextNode('Right');
        _f.appendChild(_g);
        const _h = document.createElement('button');
        _h.setAttribute('type', 'button');
        _h.setAttribute('class', 'btn btn-secondary');
        _h.setStyles({ backgroundColor: 'peachpuff' });
        _a.appendChild(_h);
        const _i = document.createTextNode('Primary');
        _h.appendChild(_i);
        return _a;
    }.call(this);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.