fix(compiler): Update types for TypeScript nullability support

This commit is contained in:
Miško Hevery
2017-03-24 09:59:58 -07:00
committed by Hans
parent d8b73e4223
commit 09d9f5fe54
118 changed files with 2086 additions and 1859 deletions

View File

@ -285,7 +285,7 @@ export function main() {
});
it('should allow nested implicit elements', () => {
let result: any[];
let result: any[] = undefined !;
expect(() => {
result = extract('<div>outer<div>inner</div></div>', ['div']);
@ -490,7 +490,7 @@ function fakeTranslate(
messages.forEach(message => {
const id = digest(message);
const text = serializeI18nNodes(message.nodes).join('').replace(/</g, '[');
i18nMsgMap[id] = [new i18n.Text(`**${text}**`, null)];
i18nMsgMap[id] = [new i18n.Text(`**${text}**`, null !)];
});
const translations = new TranslationBundle(i18nMsgMap, null, digest);

View File

@ -36,13 +36,13 @@ export function main(): void {
const visitor = new RecurseVisitor();
const container = new i18n.Container(
[
new i18n.Text('', null),
new i18n.Placeholder('', '', null),
new i18n.IcuPlaceholder(null, '', null),
new i18n.Text('', null !),
new i18n.Placeholder('', '', null !),
new i18n.IcuPlaceholder(null !, '', null !),
],
null);
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null);
const icu = new i18n.Icu('', '', {tag}, null);
null !);
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null !);
const icu = new i18n.Icu('', '', {tag}, null !);
icu.visit(visitor);
expect(visitor.textCount).toEqual(1);

View File

@ -117,7 +117,7 @@ export function main(): void {
</translationbundle>`;
// Invalid messages should not cause the parser to throw
let i18nNodesByMsgId: {[id: string]: i18n.Node[]};
let i18nNodesByMsgId: {[id: string]: i18n.Node[]} = undefined !;
expect(() => {
i18nNodesByMsgId = serializer.load(XTB, 'url').i18nNodesByMsgId;
}).not.toThrow();

View File

@ -18,11 +18,11 @@ export function main(): void {
describe('TranslationBundle', () => {
const file = new ParseSourceFile('content', 'url');
const location = new ParseLocation(file, 0, 0, 0);
const span = new ParseSourceSpan(location, null);
const span = new ParseSourceSpan(location, null !);
const srcNode = new i18n.Text('src', span);
it('should translate a plain message', () => {
const msgMap = {foo: [new i18n.Text('bar', null)]};
const msgMap = {foo: [new i18n.Text('bar', null !)]};
const tb = new TranslationBundle(msgMap, null, (_) => 'foo');
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
expect(serializeNodes(tb.get(msg))).toEqual(['bar']);
@ -31,8 +31,8 @@ export function main(): void {
it('should translate a message with placeholder', () => {
const msgMap = {
foo: [
new i18n.Text('bar', null),
new i18n.Placeholder('', 'ph1', null),
new i18n.Text('bar', null !),
new i18n.Placeholder('', 'ph1', null !),
]
};
const phMap = {
@ -46,12 +46,12 @@ export function main(): void {
it('should translate a message with placeholder referencing messages', () => {
const msgMap = {
foo: [
new i18n.Text('--', null),
new i18n.Placeholder('', 'ph1', null),
new i18n.Text('++', null),
new i18n.Text('--', null !),
new i18n.Placeholder('', 'ph1', null !),
new i18n.Text('++', null !),
],
ref: [
new i18n.Text('*refMsg*', null),
new i18n.Text('*refMsg*', null !),
],
};
const refMsg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
@ -70,13 +70,13 @@ export function main(): void {
const digest = (_: any) => `no matching id`;
// Empty message map -> use source messages in Ignore mode
let tb = new TranslationBundle({}, null, digest, null, MissingTranslationStrategy.Ignore);
let tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Ignore);
expect(serializeNodes(tb.get(messages[0])).join('')).toEqual(src);
// Empty message map -> use source messages in Warning mode
tb = new TranslationBundle({}, null, digest, null, MissingTranslationStrategy.Warning);
tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Warning);
expect(serializeNodes(tb.get(messages[0])).join('')).toEqual(src);
// Empty message map -> throw in Error mode
tb = new TranslationBundle({}, null, digest, null, MissingTranslationStrategy.Error);
tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Error);
expect(() => serializeNodes(tb.get(messages[0])).join('')).toThrow();
});
@ -84,7 +84,7 @@ export function main(): void {
it('should report unknown placeholders', () => {
const msgMap = {
foo: [
new i18n.Text('bar', null),
new i18n.Text('bar', null !),
new i18n.Placeholder('', 'ph1', span),
]
};
@ -95,7 +95,7 @@ export function main(): void {
it('should report missing translation', () => {
const tb =
new TranslationBundle({}, null, (_) => 'foo', null, MissingTranslationStrategy.Error);
new TranslationBundle({}, null, (_) => 'foo', null !, MissingTranslationStrategy.Error);
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
expect(() => tb.get(msg)).toThrowError(/Missing translation for message "foo"/);
});
@ -108,7 +108,7 @@ export function main(): void {
};
const tb = new TranslationBundle(
{}, 'en', (_) => 'foo', null, MissingTranslationStrategy.Warning, console);
{}, 'en', (_) => 'foo', null !, MissingTranslationStrategy.Warning, console);
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
expect(() => tb.get(msg)).not.toThrowError();
@ -117,8 +117,8 @@ export function main(): void {
});
it('should not report missing translation with MissingTranslationStrategy.Ignore', () => {
const tb =
new TranslationBundle({}, null, (_) => 'foo', null, MissingTranslationStrategy.Ignore);
const tb = new TranslationBundle(
{}, null, (_) => 'foo', null !, MissingTranslationStrategy.Ignore);
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
expect(() => tb.get(msg)).not.toThrowError();
});
@ -132,15 +132,15 @@ export function main(): void {
let count = 0;
const digest = (_: any) => count++ ? 'ref' : 'foo';
const tb =
new TranslationBundle(msgMap, null, digest, null, MissingTranslationStrategy.Error);
new TranslationBundle(msgMap, null, digest, null !, MissingTranslationStrategy.Error);
expect(() => tb.get(msg)).toThrowError(/Missing translation for message "ref"/);
});
it('should report invalid translated html', () => {
const msgMap = {
foo: [
new i18n.Text('text', null),
new i18n.Placeholder('', 'ph1', null),
new i18n.Text('text', null !),
new i18n.Placeholder('', 'ph1', null !),
]
};
const phMap = {