add allowTopLevelThis option to babel-plugin-transform-es2015-modules-commonjs

This commit is contained in:
Sebastian McKenzie
2015-11-05 11:29:39 +00:00
parent 3b56b295b2
commit 51143beab2

View File

@@ -121,8 +121,12 @@ export default function () {
inherits: require("babel-plugin-transform-strict-mode"),
visitor: {
ThisExpression(path) {
if (!path.findParent((path) => !path.is("shadow") && THIS_BREAK_KEYS.indexOf(path.type) >= 0)) {
ThisExpression(path, state) {
if (
state.opts.allowTopLevelThis !== true &&
!path.findParent((path) => !path.is("shadow") &&
THIS_BREAK_KEYS.indexOf(path.type) >= 0)
) {
path.replaceWith(t.identifier("undefined"));
}
},