feat(compiler): support a non-null postfix assert (#16672)

Template expressions can now use a post-fix `!` operator
that asserts the target of the operator is not null. This is
similar to the TypeScript non-null assert operator. Expressions
generated in factories will be generated with the non-null assert
operator.

Closes: #10855
This commit is contained in:
Chuck Jazdzewski
2017-05-11 10:15:54 -07:00
committed by Jason Aden
parent 2eca6e67e1
commit b9521b568f
16 changed files with 122 additions and 5 deletions

View File

@ -14,7 +14,7 @@ import * as ts from 'typescript';
import {extractSourceMap, originalPositionFor} from '../output/source_map_util';
import {EmittingCompilerHost, MockData, MockDirectory, MockMetadataBundlerHost, arrayToMockDir, arrayToMockMap, compile, settings, setup, toMockFileArray} from './test_util';
import {EmittingCompilerHost, MockData, MockDirectory, MockMetadataBundlerHost, arrayToMockDir, arrayToMockMap, compile, expectNoDiagnostics, settings, setup, toMockFileArray} from './test_util';
describe('compiler (unbundled Angular)', () => {
let angularFiles = setup();
@ -215,6 +215,32 @@ describe('compiler (unbundled Angular)', () => {
});
}));
it('should be able to supress a null access', async(() => {
const FILES: MockDirectory = {
app: {
'app.ts': `
import {Component, NgModule} from '@angular/core';
interface Person { name: string; }
@Component({
selector: 'my-comp',
template: '{{maybe_person!.name}}'
})
export class MyComp {
maybe_person?: Person;
}
@NgModule({
declarations: [MyComp]
})
export class MyModule {}
`
}
};
compile([FILES, angularFiles], {postCompile: expectNoDiagnostics});
}));
});
it('should add the preamble to generated files', async(() => {