fix(compiler): remove i18n markup even if no translations (#17999)

Fixes #11042
This commit is contained in:
Victor Berchet
2017-07-07 16:16:49 -07:00
committed by Jason Aden
parent 2ba3ada27f
commit 9c3386b1b7
11 changed files with 149 additions and 31 deletions

View File

@ -0,0 +1,12 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {BasicComp} from '../../src/basic';
import {MainModuleNgFactory} from './module.ngfactory';
MainModuleNgFactory.create(null).instance.appRef.bootstrap(BasicComp);

View File

@ -12,6 +12,7 @@ import * as path from 'path';
import {MultipleComponentsMyComp} from '../src/a/multiple_components';
import {BasicComp} from '../src/basic';
import {createComponent} from './util';
import {createComponentAlt} from './util_alt';
describe('template codegen output', () => {
const outDir = 'src';
@ -88,5 +89,17 @@ describe('template codegen output', () => {
const pText = pElement.children.map((c: any) => c.data).join('').trim();
expect(pText).toBe('tervetuloa');
});
it('should have removed i18n markup', () => {
const containerElement = createComponent(BasicComp).debugElement.children[0];
expect(containerElement.attributes['title']).toBe('käännä teksti');
expect(containerElement.attributes['i18n-title']).toBeUndefined();
});
it('should have removed i18n markup event without translations', () => {
const containerElement = createComponentAlt(BasicComp).debugElement.children[0];
expect(containerElement.attributes['title']).toBe('translate me');
expect(containerElement.attributes['i18n-title']).toBeUndefined();
});
});
});

View File

@ -0,0 +1,33 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {NgModuleRef} from '@angular/core';
import {ComponentFixture} from '@angular/core/testing';
import {platformServerTesting} from '@angular/platform-server/testing';
import {MainModuleNgFactory} from '../alt/src/module.ngfactory';
import {MainModule} from '../src/module';
let mainModuleRef: NgModuleRef<MainModule> = null !;
beforeEach((done) => {
platformServerTesting().bootstrapModuleFactory(MainModuleNgFactory).then((moduleRef: any) => {
mainModuleRef = moduleRef;
done();
});
});
export function createModule(): NgModuleRef<MainModule> {
return mainModuleRef;
}
export function createComponentAlt<C>(comp: {new (...args: any[]): C}): ComponentFixture<C> {
const moduleRef = createModule();
const compRef =
moduleRef.componentFactoryResolver.resolveComponentFactory(comp).create(moduleRef.injector);
return new ComponentFixture(compRef, null, false);
}

View File

@ -0,0 +1,32 @@
{
"angularCompilerOptions": {
// For TypeScript 1.8, we have to lay out generated files
// in the same source directory with your code.
"genDir": "./alt",
"debug": true,
"enableSummariesForJit": true,
"alwaysCompileGeneratedCode": true
},
"compilerOptions": {
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"strictNullChecks": true,
"skipLibCheck": true,
"moduleResolution": "node",
"rootDir": "",
"declaration": true,
"lib": ["es6", "dom"],
"baseUrl": ".",
// Prevent scanning up the directory tree for types
"typeRoots": ["node_modules/@types"],
"noUnusedLocals": true,
"sourceMap": true
},
"files": [
"src/module",
"alt/src/bootstrap"
]
}