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
This commit is contained in:
parent
11e8aa26f6
commit
ae49085481
12
modules/angular1_router/build.js
vendored
12
modules/angular1_router/build.js
vendored
@ -51,9 +51,10 @@ function main(modulesDirectory) {
|
|||||||
*/
|
*/
|
||||||
var IMPORT_RE = new RegExp("import \\{?([\\w\\n_, ]+)\\}? from '(.+)';?", 'g');
|
var IMPORT_RE = new RegExp("import \\{?([\\w\\n_, ]+)\\}? from '(.+)';?", 'g');
|
||||||
var INJECT_RE = new RegExp("@Inject\\(ROUTER_PRIMARY_COMPONENT\\)", 'g');
|
var INJECT_RE = new RegExp("@Inject\\(ROUTER_PRIMARY_COMPONENT\\)", 'g');
|
||||||
var IMJECTABLE_RE = new RegExp("@Injectable\\(\\)", 'g');
|
var INJECTABLE_RE = new RegExp("@Injectable\\(\\)", 'g');
|
||||||
|
var REQUIRE_RE = new RegExp("require\\('(.*?)'\\);", 'g');
|
||||||
function transform(contents) {
|
function transform(contents) {
|
||||||
contents = contents.replace(INJECT_RE, '').replace(IMJECTABLE_RE, '');
|
contents = contents.replace(INJECT_RE, '').replace(INJECTABLE_RE, '');
|
||||||
contents = contents.replace(IMPORT_RE, function (match, imports, includePath) {
|
contents = contents.replace(IMPORT_RE, function (match, imports, includePath) {
|
||||||
//TODO: remove special-case
|
//TODO: remove special-case
|
||||||
if (isFacadeModule(includePath) || includePath === './router_outlet') {
|
if (isFacadeModule(includePath) || includePath === './router_outlet') {
|
||||||
@ -61,10 +62,15 @@ function transform(contents) {
|
|||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
return ts.transpile(contents, {
|
contents = ts.transpile(contents, {
|
||||||
target: ts.ScriptTarget.ES5,
|
target: ts.ScriptTarget.ES5,
|
||||||
module: ts.ModuleKind.CommonJS
|
module: ts.ModuleKind.CommonJS
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Rename require functions from transpiled imports
|
||||||
|
contents = contents.replace(REQUIRE_RE, 'routerRequire(\'$1\');');
|
||||||
|
|
||||||
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFacadeModule(modulePath) {
|
function isFacadeModule(modulePath) {
|
||||||
|
@ -17,7 +17,7 @@ function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootSc
|
|||||||
OpaqueToken: function () {},
|
OpaqueToken: function () {},
|
||||||
Inject: function () {}
|
Inject: function () {}
|
||||||
};
|
};
|
||||||
var require = function () {return exports;};
|
var routerRequire = function () {return exports;};
|
||||||
|
|
||||||
// When this file is processed, the line below is replaced with
|
// When this file is processed, the line below is replaced with
|
||||||
// the contents of the compiled TypeScript classes.
|
// the contents of the compiled TypeScript classes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user