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

Commit

Permalink
Ensure JSX elements under Program are transpiled
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jun 8, 2016
1 parent ab9909e commit c9b798b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
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
}
}

0 comments on commit c9b798b

Please sign in to comment.