X Tutup
Skip to content

Commit ae49085

Browse files
fix(angular_1_router): Renamed require statements after TypeScript files are transpiled
The require function was causing failures when bundled using Browserify and SystemJS Closes #7049
1 parent 11e8aa2 commit ae49085

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

modules/angular1_router/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,26 @@ function main(modulesDirectory) {
5151
*/
5252
var IMPORT_RE = new RegExp("import \\{?([\\w\\n_, ]+)\\}? from '(.+)';?", 'g');
5353
var INJECT_RE = new RegExp("@Inject\\(ROUTER_PRIMARY_COMPONENT\\)", 'g');
54-
var IMJECTABLE_RE = new RegExp("@Injectable\\(\\)", 'g');
54+
var INJECTABLE_RE = new RegExp("@Injectable\\(\\)", 'g');
55+
var REQUIRE_RE = new RegExp("require\\('(.*?)'\\);", 'g');
5556
function transform(contents) {
56-
contents = contents.replace(INJECT_RE, '').replace(IMJECTABLE_RE, '');
57+
contents = contents.replace(INJECT_RE, '').replace(INJECTABLE_RE, '');
5758
contents = contents.replace(IMPORT_RE, function (match, imports, includePath) {
5859
//TODO: remove special-case
5960
if (isFacadeModule(includePath) || includePath === './router_outlet') {
6061
return '';
6162
}
6263
return match;
6364
});
64-
return ts.transpile(contents, {
65+
contents = ts.transpile(contents, {
6566
target: ts.ScriptTarget.ES5,
6667
module: ts.ModuleKind.CommonJS
6768
});
69+
70+
// Rename require functions from transpiled imports
71+
contents = contents.replace(REQUIRE_RE, 'routerRequire(\'$1\');');
72+
73+
return contents;
6874
}
6975

7076
function isFacadeModule(modulePath) {

modules/angular1_router/src/module_template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootSc
1717
OpaqueToken: function () {},
1818
Inject: function () {}
1919
};
20-
var require = function () {return exports;};
20+
var routerRequire = function () {return exports;};
2121

2222
// When this file is processed, the line below is replaced with
2323
// the contents of the compiled TypeScript classes.

0 commit comments

Comments
 (0)
X Tutup