diff --git a/src/index.js b/src/index.js index ccf50c07..e7a31b0e 100644 --- a/src/index.js +++ b/src/index.js @@ -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); } diff --git a/test/fixtures/program/element/actual.js b/test/fixtures/program/element/actual.js new file mode 100644 index 00000000..4c2f3a3d --- /dev/null +++ b/test/fixtures/program/element/actual.js @@ -0,0 +1 @@ +var div =
; diff --git a/test/fixtures/program/element/expected.js b/test/fixtures/program/element/expected.js new file mode 100644 index 00000000..aff61209 --- /dev/null +++ b/test/fixtures/program/element/expected.js @@ -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"); +}); \ No newline at end of file diff --git a/test/fixtures/program/expression-children/actual.js b/test/fixtures/program/expression-children/actual.js new file mode 100644 index 00000000..740c3038 --- /dev/null +++ b/test/fixtures/program/expression-children/actual.js @@ -0,0 +1 @@ +var div =
; diff --git a/test/fixtures/program/expression-children/expected.js b/test/fixtures/program/expression-children/expected.js new file mode 100644 index 00000000..aef97c35 --- /dev/null +++ b/test/fixtures/program/expression-children/expected.js @@ -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++]); \ No newline at end of file diff --git a/test/fixtures/program/hoist/actual.js b/test/fixtures/program/hoist/actual.js new file mode 100644 index 00000000..740c3038 --- /dev/null +++ b/test/fixtures/program/hoist/actual.js @@ -0,0 +1 @@ +var div =
; diff --git a/test/fixtures/program/hoist/expected.js b/test/fixtures/program/hoist/expected.js new file mode 100644 index 00000000..f0af9361 --- /dev/null +++ b/test/fixtures/program/hoist/expected.js @@ -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++]); \ No newline at end of file diff --git a/test/fixtures/program/hoist/options.json b/test/fixtures/program/hoist/options.json new file mode 100644 index 00000000..e773c7e2 --- /dev/null +++ b/test/fixtures/program/hoist/options.json @@ -0,0 +1,5 @@ +{ + "options": { + "hoist": true + } +}