treycordova / nativejsx-loader Goto Github PK
View Code? Open in Web Editor NEWWebpack loader for nativejsx. :yellow_heart:
License: MIT License
Webpack loader for nativejsx. :yellow_heart:
License: MIT License
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]
webpack loader for nativejsx-loader is unable to load the correct file
I noticed that version 2.0.0 is now adding global prototypes like HTMLElement.prototype.setStyles
even if nativejsx
is configured to use inline prototypes. Our project has strict modularity requirements which prohibit modification of any global variables or objects.
Moved to the main repo
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)
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.
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);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.