Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular_1_router): Renamed transpiled require functions #7049

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions modules/angular1_router/build.js
Expand Up @@ -48,20 +48,26 @@ function main(modulesDirectory) {
*/
var IMPORT_RE = new RegExp("import \\{?([\\w\\n_, ]+)\\}? from '(.+)';?", '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) {
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) {
//TODO: remove special-case
if (isFacadeModule(includePath) || includePath === './router_outlet') {
return '';
}
return match;
});
return ts.transpile(contents, {
contents = ts.transpile(contents, {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS
});

// Rename require functions from transpiled imports
contents = contents.replace(REQUIRE_RE, 'routerRequire(\'$1\');');

return contents;
}

function isFacadeModule(modulePath) {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular1_router/src/module_template.js
Expand Up @@ -17,7 +17,7 @@ function routerFactory($q, $location, $$directiveIntrospector, $browser, $rootSc
OpaqueToken: function () {},
Inject: function () {}
};
var require = function () {return exports;};
var routerRequire = function () {return exports;};

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