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";
let buildDefine = template(`
define(MODULE_NAME, [SOURCES], function (PARAMS) {
define(MODULE_NAME, [SOURCES], FACTORY);
`);
let buildFactory = template(`
(function (PARAMS) {
BODY;
});
})
`);
export default function ({ types: t }) {
@ -73,7 +77,7 @@ export default function ({ types: t }) {
exit(path) {
if (this.ran) return;
this.ran = true;
path.traverse(amdVisitor, this);
let params = this.sources.map(source => source[0]);
@ -96,11 +100,18 @@ export default function ({ types: t }) {
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,
SOURCES: sources,
PARAMS: params,
BODY: path.node.body
FACTORY: factory
})];
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
"use strict";
define(["exports"], function (exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
@ -21,4 +21,4 @@ define(["exports"], function (exports) {
class 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) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
"use strict";
define(["foo"], function (_foo) {
"use strict";
_foo.bar;
_foo.bar2;
_foo.baz;
_foo.bar;
_foo.bar;
_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 () {
"use strict";
foobar();
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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