Skip to content

Commit

Permalink
fix(ngc): don't codegen foo.d.ngfactory.ts from foo.d.ts (#10833)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored and kara committed Aug 18, 2016
1 parent 292ccf8 commit cd8cbd3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion modules/@angular/compiler-cli/integrationtest/src/module.ts
Expand Up @@ -9,6 +9,7 @@
import {ApplicationRef, NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {MdButtonModule} from '@angular2-material/button';

import {AnimateCmp} from './animate';
import {BasicComp} from './basic';
Expand All @@ -25,7 +26,10 @@ import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
CompWithReferences, CompUsingPipes
],
imports: [BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements],
imports: [
BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements,
MdButtonModule
],
providers: [SomeService],
entryComponents: [
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
Expand Down
Expand Up @@ -36,6 +36,12 @@ describe('template codegen output', () => {
expect(fs.readFileSync(dtsOutput, {encoding: 'utf-8'})).toContain('Basic');
});

it('should write .ngfactory.ts for .d.ts inputs', () => {
const factoryOutput =
path.join('node_modules', '@angular2-material', 'button', 'button.ngfactory.ts');
expect(fs.existsSync(factoryOutput)).toBeTruthy();
});

it('should be able to create the basic component', () => {
var compFixture = createComponent(BasicComp);
expect(compFixture.componentInstance).toBeTruthy();
Expand Down
9 changes: 6 additions & 3 deletions modules/@angular/compiler/src/offline_compiler.ts
Expand Up @@ -58,7 +58,7 @@ export class OfflineCompiler {
compile(
moduleUrl: string, ngModulesSummary: NgModulesSummary, components: StaticSymbol[],
ngModules: StaticSymbol[]): Promise<SourceModule[]> {
let fileSuffix = _splitLastSuffix(moduleUrl)[1];
let fileSuffix = _splitTypescriptSuffix(moduleUrl)[1];
let statements: o.Statement[] = [];
let exportedVars: string[] = [];
let outputSourceModules: SourceModule[] = [];
Expand Down Expand Up @@ -203,7 +203,7 @@ function _resolveStyleStatements(
}

function _ngfactoryModuleUrl(compUrl: string): string {
var urlWithSuffix = _splitLastSuffix(compUrl);
var urlWithSuffix = _splitTypescriptSuffix(compUrl);
return `${urlWithSuffix[0]}.ngfactory${urlWithSuffix[1]}`;
}

Expand All @@ -221,7 +221,10 @@ function _assertComponent(meta: CompileDirectiveMetadata) {
}
}

function _splitLastSuffix(path: string): string[] {
function _splitTypescriptSuffix(path: string): string[] {
if (/\.d\.ts$/.test(path)) {
return [path.substring(0, path.length - 5), '.ts'];
}
let lastDot = path.lastIndexOf('.');
if (lastDot !== -1) {
return [path.substring(0, lastDot), path.substring(lastDot)];
Expand Down
1 change: 1 addition & 0 deletions scripts/ci-lite/offline_compiler_test.sh
Expand Up @@ -13,6 +13,7 @@ PKGS=(
rxjs
@types/{node,jasmine}
jasmine
@angular2-material/{core,button}
)

TMPDIR=${TMPDIR:-.}
Expand Down

0 comments on commit cd8cbd3

Please sign in to comment.