Skip to content

Commit

Permalink
fix: crashes on IE11 and ReflectMetadata typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Rodik committed Aug 8, 2017
1 parent a48f462 commit 65b037b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 9 additions & 3 deletions decorators/ng-module/metadata-handlers/import.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {findFirst} from "../../../helpers/array";

type ng1Module = { $inject?: Array<string> } | any;

export default function importHandler(imports: Array<ng1Module>) {
let ng1ModuleIds: Array<string> = [];

const modules = imports.filter((mdl: ng1Module) => {
return !(mdl.$inject && mdl.$inject.find((i: any) => i === "$stateProvider"));
return !(
mdl.$inject
&& findFirst(mdl.$inject, (i: any) => i === "$stateProvider")
);
});

const ng1RouterConfig = imports.find((mdl: ng1Module) => {
return mdl.$inject && mdl.$inject.find((i: any) => i === "$stateProvider");
const ng1RouterConfig = findFirst(imports, (mdl: ng1Module) => {
return mdl.$inject
&& findFirst(mdl.$inject, (i: any) => i === "$stateProvider");
});

if (modules.length) {
Expand Down
3 changes: 3 additions & 0 deletions example/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const {NgModule, BrowserModule, UIRouterModule} = require("./export-switch");

import "reflect-metadata";

import {AppComponent} from "./component";
import {NgShiftModule} from "./module";
import {NgShiftComponentModule} from "./component/index";
import {NgShiftRouterTestModule} from "./router";

@NgModule({
id: "app-module",
imports: [
...UIRouterModule,
...BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion example/src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</body>
</html>
<% } else { %>
<html lang="en-US" ng-app="AppModule" ng-strict-di>
<html lang="en-US" ng-app="app-module" ng-strict-di>
<head>
<meta charset="UTF-8">
<title>NG1-shift Example</title>
Expand Down
15 changes: 15 additions & 0 deletions helpers/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function findFirst<T>(array: Array<T>, expression: (value: T) => boolean): T {
if (!angular.isFunction(expression)) {
let first = array[0];
if (!first) {
return null;
}
return first;
}
for (let i = 0; i < array.length; i++) {
if (expression(array[i])) {
return array[i];
}
}
return null;
}

0 comments on commit 65b037b

Please sign in to comment.