Fix T2929, T6796, stop leaking directives

This commit is contained in:
Casey Foster 2016-01-08 13:21:35 -06:00
parent fb0977b4b3
commit c7c4d7f5fd
32 changed files with 94 additions and 93 deletions

View File

@ -1,9 +1,13 @@
import template from "babel-template"; import template from "babel-template";
let buildDefine = template(` let buildDefine = template(`
define(MODULE_NAME, [SOURCES], function (PARAMS) { define(MODULE_NAME, [SOURCES], FACTORY);
`);
let buildFactory = template(`
(function (PARAMS) {
BODY; BODY;
}); })
`); `);
export default function ({ types: t }) { export default function ({ types: t }) {
@ -73,7 +77,7 @@ export default function ({ types: t }) {
exit(path) { exit(path) {
if (this.ran) return; if (this.ran) return;
this.ran = true; this.ran = true;
path.traverse(amdVisitor, this); path.traverse(amdVisitor, this);
let params = this.sources.map(source => source[0]); let params = this.sources.map(source => source[0]);
@ -96,11 +100,18 @@ export default function ({ types: t }) {
params.unshift(t.identifier("module")); params.unshift(t.identifier("module"));
} }
path.node.body = [buildDefine({ let { node } = path;
let factory = buildFactory({
PARAMS: params,
BODY: node.body
});
factory.expression.body.directives = node.directives;
node.directives = [];
node.body = [buildDefine({
MODULE_NAME: moduleName, MODULE_NAME: moduleName,
SOURCES: sources, SOURCES: sources,
PARAMS: params, FACTORY: factory
BODY: path.node.body
})]; })];
} }
} }

View File

@ -1,9 +1,9 @@
"use strict";
define(["exports"], function (exports) { define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
var a = 1; var a = 1;
exports.default = a; exports.default = a;
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports"], function (exports) { define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports", "foo"], function (exports, _foo) { define(["exports", "foo"], function (exports, _foo) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -57,4 +57,4 @@ define(["exports", "foo"], function (exports, _foo) {
return _foo.bar; return _foo.bar;
} }
}); });
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports"], function (exports) { define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -11,4 +11,4 @@ define(["exports"], function (exports) {
exports.default = foo; exports.default = foo;
exports.default = foo; exports.default = foo;
exports.bar = bar; exports.bar = bar;
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports"], function (exports) { define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -21,4 +21,4 @@ define(["exports"], function (exports) {
class foo8 {} class foo8 {}
exports.foo8 = foo8; exports.foo8 = foo8;
}); });

View File

@ -1,3 +1 @@
"use strict"; define("my custom module name", [], function () {});
define("my custom module name", [], function () {});

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports", "./evens"], function (exports, _evens) { define(["exports", "./evens"], function (exports, _evens) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });

View File

@ -1,8 +1,8 @@
"use strict";
define(["foo"], function (_foo) { define(["foo"], function (_foo) {
"use strict";
var _foo2 = babelHelpers.interopRequireDefault(_foo); var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo2.default; _foo2.default;
_foo2.default; _foo2.default;
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["foo"], function (_foo) { define(["foo"], function (_foo) {
"use strict";
var foo = babelHelpers.interopRequireWildcard(_foo); var foo = babelHelpers.interopRequireWildcard(_foo);
foo; foo;
}); });

View File

@ -1,8 +1,8 @@
"use strict";
define(["foo"], function (_foo) { define(["foo"], function (_foo) {
"use strict";
var _foo2 = babelHelpers.interopRequireDefault(_foo); var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo2.default; _foo2.default;
_foo.baz; _foo.baz;
}); });

View File

@ -1,10 +1,10 @@
"use strict";
define(["foo"], function (_foo) { define(["foo"], function (_foo) {
"use strict";
_foo.bar; _foo.bar;
_foo.bar2; _foo.bar2;
_foo.baz; _foo.baz;
_foo.bar; _foo.bar;
_foo.bar; _foo.bar;
_foo.xyz; _foo.xyz;
}); });

View File

@ -1,3 +1 @@
"use strict"; define(["foo", "foo-bar", "./directory/foo-bar"], function () {});
define(["foo", "foo-bar", "./directory/foo-bar"], function () {});

View File

@ -1,5 +1,5 @@
"use strict";
define("amd/module-name/expected", [], function () { define("amd/module-name/expected", [], function () {
"use strict";
foobar(); foobar();
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo) { define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -13,4 +13,4 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
foo2; foo2;
_foo.bar; _foo.bar;
_foo.foo; _foo.foo;
}); });

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports"], function (exports) { define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -24,4 +24,4 @@ define(["exports"], function (exports) {
exports.e = d; exports.e = d;
exports.f = d; exports.f = d;
exports.f = exports.e = d = 4; exports.f = exports.e = d = 4;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports"], factory); define(["exports"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports) { })(this, function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports", "foo"], factory); define(["exports", "foo"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports, _foo) { })(this, function (exports, _foo) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -69,4 +69,4 @@
return _foo.bar; return _foo.bar;
} }
}); });
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports"], factory); define(["exports"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports) { })(this, function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -23,4 +23,4 @@
exports.default = foo; exports.default = foo;
exports.default = foo; exports.default = foo;
exports.bar = bar; exports.bar = bar;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports"], factory); define(["exports"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports) { })(this, function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -33,4 +33,4 @@
class foo8 {} class foo8 {}
exports.foo8 = foo8; exports.foo8 = foo8;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define("my custom module name", [], factory); define("my custom module name", [], factory);
@ -12,4 +10,4 @@
factory(); factory();
global.myCustomModuleName = mod.exports; global.myCustomModuleName = mod.exports;
} }
})(this, function () {}); })(this, function () {});

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports", "./evens"], factory); define(["exports", "./evens"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports, _evens) { })(this, function (exports, _evens) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["foo"], factory); define(["foo"], factory);
@ -13,8 +11,10 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (_foo) { })(this, function (_foo) {
"use strict";
var _foo2 = babelHelpers.interopRequireDefault(_foo); var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo2.default; _foo2.default;
_foo2.default; _foo2.default;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["foo"], factory); define(["foo"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (_foo) { })(this, function (_foo) {
"use strict";
var foo = babelHelpers.interopRequireWildcard(_foo); var foo = babelHelpers.interopRequireWildcard(_foo);
foo; foo;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["foo"], factory); define(["foo"], factory);
@ -13,7 +11,9 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (_foo) { })(this, function (_foo) {
"use strict";
var _foo2 = babelHelpers.interopRequireDefault(_foo); var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo.baz; _foo.baz;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["foo"], factory); define(["foo"], factory);
@ -13,10 +11,12 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (_foo) { })(this, function (_foo) {
"use strict";
_foo.bar; _foo.bar;
_foo.bar2; _foo.bar2;
_foo.baz; _foo.baz;
_foo.bar; _foo.bar;
_foo.bar; _foo.bar;
_foo.xyz; _foo.xyz;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["foo", "foo-bar", "./directory/foo-bar"], factory); define(["foo", "foo-bar", "./directory/foo-bar"], factory);
@ -12,4 +10,4 @@
factory(global.foo, global.fooBar, global.fooBar); factory(global.foo, global.fooBar, global.fooBar);
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function () {}); })(this, function () {});

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define("MyLib", [], factory); define("MyLib", [], factory);
@ -13,5 +11,7 @@
global.MyLib = mod.exports; global.MyLib = mod.exports;
} }
})(this, function () { })(this, function () {
"use strict";
foobar(); foobar();
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define("umd/module-name/expected", [], factory); define("umd/module-name/expected", [], factory);
@ -13,5 +11,7 @@
global.umdModuleNameExpected = mod.exports; global.umdModuleNameExpected = mod.exports;
} }
})(this, function () { })(this, function () {
"use strict";
foobar(); foobar();
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["./lib/render"], factory); define(["./lib/render"], factory);
@ -12,4 +10,4 @@
factory(global.render); factory(global.render);
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (_render) {}); })(this, function (_render) {});

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory); define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports, _foo) { })(this, function (exports, _foo) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -23,4 +23,4 @@
exports.default = test; exports.default = test;
_foo.bar; _foo.bar;
_foo.foo; _foo.foo;
}); });

View File

@ -1,5 +1,3 @@
"use strict";
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(["exports"], factory); define(["exports"], factory);
@ -13,6 +11,8 @@
global.actual = mod.exports; global.actual = mod.exports;
} }
})(this, function (exports) { })(this, function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
@ -36,4 +36,4 @@
exports.e = d; exports.e = d;
exports.f = d; exports.f = d;
exports.f = exports.e = d = 4; exports.f = exports.e = d = 4;
}); });