forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_module.ts
More file actions
40 lines (34 loc) · 1.21 KB
/
Copy pathsource_module.ts
File metadata and controls
40 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
var MODULE_REGEXP = /#MODULE\[([^\]]*)\]/g;
export function moduleRef(moduleId): string {
return `#MODULE[${moduleId}]`;
}
export class SourceModule {
constructor(public moduleId: string, public sourceWithModuleRefs: string) {}
getSourceWithImports(): SourceWithImports {
var moduleAliases = {};
var imports: string[][] = [];
var newSource =
StringWrapper.replaceAllMapped(this.sourceWithModuleRefs, MODULE_REGEXP, (match) => {
var moduleId = match[1];
var alias = moduleAliases[moduleId];
if (isBlank(alias)) {
if (moduleId == this.moduleId) {
alias = '';
} else {
alias = `import${imports.length}`;
imports.push([moduleId, alias]);
}
moduleAliases[moduleId] = alias;
}
return alias.length > 0 ? `${alias}.` : '';
});
return new SourceWithImports(newSource, imports);
}
}
export class SourceExpression {
constructor(public declarations: string[], public expression: string) {}
}
export class SourceWithImports {
constructor(public source: string, public imports: string[][]) {}
}