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

use import instead global Inferno reference #35

Merged
merged 1 commit into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
'use strict';

const babel = require('babel-core');

const plugin = require('./lib');

const code = `
<div>Hello world, { ['Foo! ', 'Bar!'] }</div>
<div>
<span>Hello</span>
<div>Another</div>
</div>
`;

console.log(
babel.transform(code, {
presets: ['es2015'],
presets: [['es2015', {modules: false}]],
plugins: [
[plugin],
'syntax-jsx'
Expand Down
21 changes: 0 additions & 21 deletions lib/flags.js

This file was deleted.

15 changes: 6 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const isComponent = require('./helpers/is-component');
const isNullOrUndefined = require('./helpers/is-null-or-undefined');
const VNodeFlags = require('./flags');
const VNodeFlags = require('inferno-vnode-flags');

function _stringLiteralTrimmer(lastNonEmptyLine, lineCount, line, i) {
const isFirstLine = (i === 0);
Expand Down Expand Up @@ -64,16 +64,13 @@ function getHoistedNode(lastNode, path) {
}
}

function addHoistedCreateVNode(t, toInsert) {
function addCreateVNodeImportStatement(t, toInsert) {
const node = toInsert.node;
const index = toInsert.index;

node.body.splice(index, 0, t.VariableDeclaration('var', [
t.VariableDeclarator(
t.Identifier('createVNode'),
t.memberExpression(t.identifier('Inferno'), t.identifier('createVNode'))
)
]));
node.body.splice(index, 0, t.importDeclaration([
t.ImportSpecifier(t.identifier('createVNode'), t.identifier('createVNode')),
], t.stringLiteral('inferno')));
}

function getVNodeType(t, type) {
Expand Down Expand Up @@ -383,7 +380,7 @@ module.exports = function (options) {
path.replaceWith(node);
if (!opts.hoistCreateVNode) {
opts.hoistCreateVNode = true;
addHoistedCreateVNode(t, getHoistedNode(path.node, path.parentPath));
addCreateVNodeImportStatement(t, getHoistedNode(path.node, path.parentPath));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"jsx"
],
"dependencies": {
"babel-plugin-syntax-jsx": "^6.18.0"
"babel-plugin-syntax-jsx": "^6.18.0",
"inferno-vnode-flags": "^1.0.7"
},
"engines": {
"node": ">= 4.6.0"
Expand Down