Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Transpile JSX orphaned under Program #62

Merged
merged 1 commit into from
Jun 8, 2016
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
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export default function ({ types: t, traverse: _traverse }) {
},

exit(path) {
path.traverse(elementVisitor, Object.assign({}, this, {
secondaryTree: true,
root: null,
replacedElements: new Set(),
closureVarsStack: [],
}));

hoist(path, this);
injectHelpers(this);
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/program/element/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var div = <div></div>;
12 changes: 12 additions & 0 deletions test/fixtures/program/element/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var _jsxWrapper = function _jsxWrapper(func, args) {
var wrapper = args ? function wrapper() {
return func.apply(this, args);
} : func;
wrapper.__jsxDOMWrapper = true;
return wrapper;
};

var div = _jsxWrapper(function () {
elementOpen("div");
return elementClose("div");
});
1 change: 1 addition & 0 deletions test/fixtures/program/expression-children/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var div = <div key={i++}></div>;
12 changes: 12 additions & 0 deletions test/fixtures/program/expression-children/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var _jsxWrapper = function _jsxWrapper(func, args) {
var wrapper = args ? function wrapper() {
return func.apply(this, args);
} : func;
wrapper.__jsxDOMWrapper = true;
return wrapper;
};

var div = _jsxWrapper(function (_ref) {
elementOpen("div", _ref, ["key", _ref]);
return elementClose("div");
}, [i++]);
1 change: 1 addition & 0 deletions test/fixtures/program/hoist/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var div = <div key={i++}></div>;
15 changes: 15 additions & 0 deletions test/fixtures/program/hoist/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var _jsxWrapper = function _jsxWrapper(func, args) {
var wrapper = args ? function wrapper() {
return func.apply(this, args);
} : func;
wrapper.__jsxDOMWrapper = true;
return wrapper;
};

var _statics = ["key", ""],
_wrapper = function _wrapper(_ref) {
elementOpen("div", _ref, (_statics[1] = _ref, _statics));
return elementClose("div");
};

var div = _jsxWrapper(_wrapper, [i++]);
5 changes: 5 additions & 0 deletions test/fixtures/program/hoist/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"options": {
"hoist": true
}
}