2015-11-07 01:34:07 +00:00
|
|
|
import {StringWrapper, isBlank} from 'angular2/src/facade/lang';
|
2015-09-14 22:59:09 +00:00
|
|
|
|
|
|
|
|
var MODULE_REGEXP = /#MODULE\[([^\]]*)\]/g;
|
|
|
|
|
|
2015-10-01 17:07:49 +00:00
|
|
|
export function moduleRef(moduleUrl): string {
|
|
|
|
|
return `#MODULE[${moduleUrl}]`;
|
2015-09-14 22:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-03 23:49:09 +00:00
|
|
|
/**
|
|
|
|
|
* Represents generated source code with module references. Internal to the Angular compiler.
|
|
|
|
|
*/
|
2015-09-14 22:59:09 +00:00
|
|
|
export class SourceModule {
|
2015-12-02 18:35:51 +00:00
|
|
|
static getSourceWithoutImports(sourceWithModuleRefs: string): string {
|
|
|
|
|
return StringWrapper.replaceAllMapped(sourceWithModuleRefs, MODULE_REGEXP, (match) => '');
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 17:07:49 +00:00
|
|
|
constructor(public moduleUrl: string, public sourceWithModuleRefs: string) {}
|
2015-09-14 22:59:09 +00:00
|
|
|
|
|
|
|
|
getSourceWithImports(): SourceWithImports {
|
|
|
|
|
var moduleAliases = {};
|
|
|
|
|
var imports: string[][] = [];
|
2015-09-17 16:58:18 +00:00
|
|
|
var newSource =
|
|
|
|
|
StringWrapper.replaceAllMapped(this.sourceWithModuleRefs, MODULE_REGEXP, (match) => {
|
2015-10-01 17:07:49 +00:00
|
|
|
var moduleUrl = match[1];
|
|
|
|
|
var alias = moduleAliases[moduleUrl];
|
2015-09-17 16:58:18 +00:00
|
|
|
if (isBlank(alias)) {
|
2015-10-01 17:07:49 +00:00
|
|
|
if (moduleUrl == this.moduleUrl) {
|
2015-09-17 16:58:18 +00:00
|
|
|
alias = '';
|
|
|
|
|
} else {
|
|
|
|
|
alias = `import${imports.length}`;
|
2015-10-01 17:07:49 +00:00
|
|
|
imports.push([moduleUrl, alias]);
|
2015-09-17 16:58:18 +00:00
|
|
|
}
|
2015-10-01 17:07:49 +00:00
|
|
|
moduleAliases[moduleUrl] = alias;
|
2015-09-17 16:58:18 +00:00
|
|
|
}
|
|
|
|
|
return alias.length > 0 ? `${alias}.` : '';
|
|
|
|
|
});
|
2015-09-14 22:59:09 +00:00
|
|
|
return new SourceWithImports(newSource, imports);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class SourceExpression {
|
|
|
|
|
constructor(public declarations: string[], public expression: string) {}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 17:33:23 +00:00
|
|
|
export class SourceExpressions {
|
|
|
|
|
constructor(public declarations: string[], public expressions: string[]) {}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 23:49:09 +00:00
|
|
|
/**
|
|
|
|
|
* Represents generated source code with imports. Internal to the Angular compiler.
|
|
|
|
|
*/
|
2015-09-14 22:59:09 +00:00
|
|
|
export class SourceWithImports {
|
|
|
|
|
constructor(public source: string, public imports: string[][]) {}
|
|
|
|
|
}
|