Skip to content

Commit

Permalink
refactor(tsc-wrapped): update tsc-wrapped to pass strictNullCheck (an…
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckjaz authored and mhevery committed Jul 21, 2017
1 parent 619e625 commit abee785
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 232 deletions.
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ if [[ ${BUILD_TOOLS} == true || ${BUILD_ALL} == true ]]; then
$(npm bin)/tsc -p packages/tsc-wrapped/tsconfig-build.json
cp ./packages/tsc-wrapped/package.json ./dist/packages-dist/tsc-wrapped
cp ./packages/tsc-wrapped/README.md ./dist/packages-dist/tsc-wrapped
(
cd dist/packages-dist/tsc-wrapped
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
)
fi

for PACKAGE in ${PACKAGES[@]}
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class CodeGenerator {
}
const {compiler: aotCompiler} = compiler.createAotCompiler(ngCompilerHost, {
translations: transContent,
i18nFormat: cliOptions.i18nFormat,
locale: cliOptions.locale, missingTranslation,
i18nFormat: cliOptions.i18nFormat || undefined,
locale: cliOptions.locale || undefined, missingTranslation,
enableLegacyTemplate: options.enableLegacyTemplate !== false,
enableSummariesForJit: options.enableSummariesForJit !== false,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/test/aot/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class MockMetadataBundlerHost implements MetadataBundlerHost {

constructor(private host: ts.CompilerHost) {}

getMetadataFor(moduleName: string): ModuleMetadata {
getMetadataFor(moduleName: string): ModuleMetadata|undefined {
const source = this.host.getSourceFile(moduleName + '.ts', ts.ScriptTarget.Latest);
return this.collector.getMetadata(source);
}
Expand Down
61 changes: 33 additions & 28 deletions packages/tsc-wrapped/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ export interface BundledModule {
privates: BundlePrivateEntry[];
}

export interface MetadataBundlerHost { getMetadataFor(moduleName: string): ModuleMetadata; }
export interface MetadataBundlerHost {
getMetadataFor(moduleName: string): ModuleMetadata|undefined;
}

type StaticsMetadata = {
[name: string]: MetadataValue | FunctionMetadata;
};

export class MetadataBundler {
private symbolMap = new Map<string, Symbol>();
private metadataCache = new Map<string, ModuleMetadata>();
private metadataCache = new Map<string, ModuleMetadata|undefined>();
private exports = new Map<string, Symbol[]>();
private rootModule: string;
private exported: Set<Symbol>;
Expand All @@ -98,14 +100,14 @@ export class MetadataBundler {
const privates = Array.from(this.symbolMap.values())
.filter(s => s.referenced && s.isPrivate)
.map(s => ({
privateName: s.privateName,
name: s.declaration.name,
module: s.declaration.module
privateName: s.privateName !,
name: s.declaration !.name,
module: s.declaration !.module
}));
const origins = Array.from(this.symbolMap.values())
.filter(s => s.referenced && !s.reexport)
.reduce<{[name: string]: string}>((p, s) => {
p[s.isPrivate ? s.privateName : s.name] = s.declaration.module;
p[s.isPrivate ? s.privateName ! : s.name] = s.declaration !.module;
return p;
}, {});
const exports = this.getReExports(exportedSymbols);
Expand All @@ -114,7 +116,7 @@ export class MetadataBundler {
__symbolic: 'module',
version: VERSION,
exports: exports.length ? exports : undefined, metadata, origins,
importAs: this.importAs
importAs: this.importAs !
},
privates
};
Expand All @@ -124,7 +126,7 @@ export class MetadataBundler {
return resolveModule(importName, from);
}

private getMetadata(moduleName: string): ModuleMetadata {
private getMetadata(moduleName: string): ModuleMetadata|undefined {
let result = this.metadataCache.get(moduleName);
if (!result) {
if (moduleName.startsWith('.')) {
Expand All @@ -138,7 +140,7 @@ export class MetadataBundler {

private exportAll(moduleName: string): Symbol[] {
const module = this.getMetadata(moduleName);
let result: Symbol[] = this.exports.get(moduleName);
let result = this.exports.get(moduleName);

if (result) {
return result;
Expand All @@ -148,7 +150,7 @@ export class MetadataBundler {

const exportSymbol = (exportedSymbol: Symbol, exportAs: string) => {
const symbol = this.symbolOf(moduleName, exportAs);
result.push(symbol);
result !.push(symbol);
exportedSymbol.reexportedAs = symbol;
symbol.exports = exportedSymbol;
};
Expand Down Expand Up @@ -266,7 +268,7 @@ export class MetadataBundler {
name = newPrivateName();
symbol.privateName = name;
}
result[name] = symbol.value;
result[name] = symbol.value !;
}
});

Expand All @@ -279,9 +281,10 @@ export class MetadataBundler {
const exportAlls = new Set<string>();
for (const symbol of exportedSymbols) {
if (symbol.reexport) {
const declaration = symbol.declaration;
// symbol.declaration is guarenteed to be defined during the phase this method is called.
const declaration = symbol.declaration !;
const module = declaration.module;
if (declaration.name == '*') {
if (declaration !.name == '*') {
// Reexport all the symbols.
exportAlls.add(declaration.module);
} else {
Expand All @@ -304,11 +307,13 @@ export class MetadataBundler {
}

private convertSymbol(symbol: Symbol) {
const canonicalSymbol = symbol.canonicalSymbol;
// canonicalSymbol is ensured to be defined before this is called.
const canonicalSymbol = symbol.canonicalSymbol !;

if (!canonicalSymbol.referenced) {
canonicalSymbol.referenced = true;
const declaration = canonicalSymbol.declaration;
// declaration is ensured to be definded before this method is called.
const declaration = canonicalSymbol.declaration !;
const module = this.getMetadata(declaration.module);
if (module) {
const value = module.metadata[declaration.name];
Expand Down Expand Up @@ -336,10 +341,10 @@ export class MetadataBundler {
return {
__symbolic: 'class',
arity: value.arity,
extends: this.convertExpression(moduleName, value.extends),
extends: this.convertExpression(moduleName, value.extends) !,
decorators:
value.decorators && value.decorators.map(d => this.convertExpression(moduleName, d)),
members: this.convertMembers(moduleName, value.members),
value.decorators && value.decorators.map(d => this.convertExpression(moduleName, d) !),
members: this.convertMembers(moduleName, value.members !),
statics: value.statics && this.convertStatics(moduleName, value.statics)
};
}
Expand All @@ -356,11 +361,11 @@ export class MetadataBundler {
private convertMember(moduleName: string, member: MemberMetadata) {
const result: MemberMetadata = {__symbolic: member.__symbolic};
result.decorators =
member.decorators && member.decorators.map(d => this.convertExpression(moduleName, d));
member.decorators && member.decorators.map(d => this.convertExpression(moduleName, d) !);
if (isMethodMetadata(member)) {
(result as MethodMetadata).parameterDecorators = member.parameterDecorators &&
member.parameterDecorators.map(
d => d && d.map(p => this.convertExpression(moduleName, p)));
d => d && d.map(p => this.convertExpression(moduleName, p) !));
if (isConstructorMetadata(member)) {
if (member.parameters) {
(result as ConstructorMetadata).parameters =
Expand Down Expand Up @@ -397,7 +402,7 @@ export class MetadataBundler {
return this.convertError(moduleName, value);
}
if (isMetadataSymbolicExpression(value)) {
return this.convertExpression(moduleName, value);
return this.convertExpression(moduleName, value) !;
}
if (Array.isArray(value)) {
return value.map(v => this.convertValue(moduleName, v));
Expand All @@ -413,8 +418,8 @@ export class MetadataBundler {
}

private convertExpression(
moduleName: string, value: MetadataSymbolicExpression|MetadataError|
undefined): MetadataSymbolicExpression|MetadataError|undefined {
moduleName: string, value: MetadataSymbolicExpression|MetadataError|null|
undefined): MetadataSymbolicExpression|MetadataError|undefined|null {
if (value) {
switch (value.__symbolic) {
case 'error':
Expand All @@ -439,9 +444,9 @@ export class MetadataBundler {
}

private convertReference(moduleName: string, value: MetadataSymbolicReferenceExpression):
MetadataSymbolicReferenceExpression|MetadataError {
MetadataSymbolicReferenceExpression|MetadataError|undefined {
const createReference = (symbol: Symbol): MetadataSymbolicReferenceExpression => {
const declaration = symbol.declaration;
const declaration = symbol.declaration !;
if (declaration.module.startsWith('.')) {
// Reference to a symbol defined in the module. Ensure it is converted then return a
// references to the final symbol.
Expand All @@ -450,11 +455,11 @@ export class MetadataBundler {
__symbolic: 'reference',
get name() {
// Resolved lazily because private names are assigned late.
const canonicalSymbol = symbol.canonicalSymbol;
const canonicalSymbol = symbol.canonicalSymbol !;
if (canonicalSymbol.isPrivate == null) {
throw Error('Invalid state: isPrivate was not initialized');
}
return canonicalSymbol.isPrivate ? canonicalSymbol.privateName : canonicalSymbol.name;
return canonicalSymbol.isPrivate ? canonicalSymbol.privateName ! : canonicalSymbol.name;
}
};
} else {
Expand Down Expand Up @@ -564,7 +569,7 @@ export class CompilerHostAdapter implements MetadataBundlerHost {

constructor(private host: ts.CompilerHost) {}

getMetadataFor(fileName: string): ModuleMetadata {
getMetadataFor(fileName: string): ModuleMetadata|undefined {
const sourceFile = this.host.getSourceFile(fileName + '.ts', ts.ScriptTarget.Latest);
return this.collector.getMetadata(sourceFile);
}
Expand Down
22 changes: 11 additions & 11 deletions packages/tsc-wrapped/src/cli_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
export class CliOptions {
public basePath: string;
constructor({basePath = null}: {basePath?: string}) { this.basePath = basePath; }
public basePath: string|null;
constructor({basePath = null}: {basePath?: string | null}) { this.basePath = basePath; }
}

export class I18nExtractionCliOptions extends CliOptions {
Expand All @@ -28,18 +28,18 @@ export class I18nExtractionCliOptions extends CliOptions {
}

export class NgcCliOptions extends CliOptions {
public i18nFormat: string;
public i18nFile: string;
public locale: string;
public missingTranslation: string;
public i18nFormat: string|null;
public i18nFile: string|null;
public locale: string|null;
public missingTranslation: string|null;

constructor({i18nFormat = null, i18nFile = null, locale = null, missingTranslation = null,
basePath = null}: {
i18nFormat?: string,
i18nFile?: string,
locale?: string,
missingTranslation?: string,
basePath?: string
i18nFormat?: string | null,
i18nFile?: string|null,
locale?: string|null,
missingTranslation?: string|null,
basePath?: string|null
}) {
super({basePath: basePath});
this.i18nFormat = i18nFormat;
Expand Down
Loading

0 comments on commit abee785

Please sign in to comment.