Skip to content

Commit

Permalink
feat: upgrade to typescript 3.7 (#988)
Browse files Browse the repository at this point in the history
Enjoy the benefits of optional chaining, a null-coalescing operator, and other
fun new features and enhancements TypeScript brought in 3.7.  For more
information about the TypeScript features, refer to the [TypeScript release notes].

[TypeScript release notes]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html
  • Loading branch information
RomainMuller authored and mergify[bot] committed Nov 26, 2019
1 parent c2c9912 commit 6e0a7e6
Show file tree
Hide file tree
Showing 78 changed files with 374 additions and 390 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"@typescript-eslint/eslint-plugin": "^2.9.0",
"@typescript-eslint/parser": "^2.9.0",
"eslint": "^6.7.1",
"lerna": "^3.19.0",
"typescript": "~3.6.4"
"lerna": "^3.19.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/codemaker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@typescript-eslint/parser": "^2.9.0",
"eslint": "^6.7.1",
"jest": "^24.9.0",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
},
"jest": {
"collectCoverage": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-calc/lib/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class Calculator extends composition.CompositeOperation {
constructor(props?: CalculatorProps) {
super();

props = props || { };
props = props ?? { };

const initialValue = props.initialValue ? props.initialValue : 0;
this.curr = new Number(initialValue);
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ export class SupportsNiceJavaBuilder extends SupportsNiceJavaBuilderWithRequired
* @param rest a variadic continuation
*/
public constructor(public readonly id: number, defaultBar = 1337, props?: SupportsNiceJavaBuilderProps, ...rest: string[]) {
super(id, props || { bar: defaultBar });
super(id, props ?? { bar: defaultBar });
this.rest = rest;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-calc/lib/documented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DocumentedClass {
* @returns A number that everyone knows very well
*/
public greet(greetee: Greetee = {}) {
process.stdout.write(`Hello, ${greetee.name || 'world'}\n`);
process.stdout.write(`Hello, ${greetee.name ?? 'world'}\n`);
return 42;
}

Expand Down Expand Up @@ -58,4 +58,4 @@ export class Old {
public doAThing() {
// Nothing to do
}
}
}
2 changes: 1 addition & 1 deletion packages/jsii-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint": "^6.7.1",
"jest": "^24.9.0",
"jest-expect-message": "^1.0.2",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
},
"dependencies": {
"inquirer": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-diff/lib/type-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class TypePairs {
if (!a.fqn || !b.fqn) { return false; } // Only for user-defined types

const image = this.pairs.get(a.fqn);
return !!image && image.has(b.fqn);
return !!image?.has(b.fqn);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-diff/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Mismatches {
this.mismatches.push({
violationKey: key,
message: `${describeApiElement(options.violator)} ${fqn}: ${options.message}`,
stability: options.violator.docs.stability || this.defaultStability
stability: options.violator.docs.stability ?? this.defaultStability
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"jsii-reflect": "^0.20.8",
"jsii-spec": "^0.20.8",
"log4js": "^6.1.0",
"typescript": "~3.6.4",
"typescript": "~3.7.2",
"yargs": "^15.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-dotnet-jsonmodel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
},
"devDependencies": {
"jsii-build-tools": "^0.20.8",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/jsii-dotnet-runtime-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"jsii-calc": "^0.20.8",
"jsii-dotnet-runtime": "^0.20.8",
"jsii-pacmak": "^0.20.8",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/jsii-dotnet-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"jsii-dotnet-jsonmodel": "^0.20.8",
"jsii-runtime": "^0.20.8",
"semver": "^6.3.0",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/jsii-java-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"devDependencies": {
"jsii-build-tools": "^0.20.8",
"jsii-runtime": "^0.20.8",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
}
}
44 changes: 22 additions & 22 deletions packages/jsii-kernel/lib/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Kernel {

return {
assembly: assm.metadata.name,
types: Object.keys(assm.metadata.types || {}).length,
types: Object.keys(assm.metadata.types ?? {}).length,
};
}
// untar the archive to a staging directory, read the jsii spec from it
Expand All @@ -122,7 +122,7 @@ export class Kernel {

return {
assembly: assmSpec.name,
types: Object.keys(assmSpec.types || {}).length,
types: Object.keys(assmSpec.types ?? {}).length,
};
} finally {
this._debug('removing staging directory:', staging);
Expand Down Expand Up @@ -231,7 +231,7 @@ export class Kernel {

public invoke(req: api.InvokeRequest): api.InvokeResponse {
const { objref, method } = req;
const args = req.args || [];
const args = req.args ?? [];

this._debug('invoke', objref, method, args);
const { ti, obj, fn } = this._findInvokeTarget(objref, method, args);
Expand All @@ -245,15 +245,15 @@ export class Kernel {
return this._wrapSandboxCode(() => fn.apply(obj, this._toSandboxValues(args, ti.parameters)));
});

const result = this._fromSandbox(ret, ti.returns || 'void');
const result = this._fromSandbox(ret, ti.returns ?? 'void');
this._debug('invoke result', result);

return { result };
}

public sinvoke(req: api.StaticInvokeRequest): api.InvokeResponse {
const { fqn, method } = req;
const args = req.args || [];
const args = req.args ?? [];

this._debug('sinvoke', fqn, method, args);

Expand All @@ -276,12 +276,12 @@ export class Kernel {
});

this._debug('method returned:', ret);
return { result: this._fromSandbox(ret, ti.returns || 'void') };
return { result: this._fromSandbox(ret, ti.returns ?? 'void') };
}

public begin(req: api.BeginRequest): api.BeginResponse {
const { objref, method } = req;
const args = req.args || [];
const args = req.args ?? [];

this._debug('begin', objref, method, args);

Expand Down Expand Up @@ -331,7 +331,7 @@ export class Kernel {
throw mapSource(e, this.sourceMaps);
}

return { result: this._fromSandbox(result, method.returns || 'void') };
return { result: this._fromSandbox(result, method.returns ?? 'void') };
}

public callbacks(_req?: api.CallbacksRequest): api.CallbacksResponse {
Expand Down Expand Up @@ -370,7 +370,7 @@ export class Kernel {
this._debug('completed with error:', err);
cb.fail(new Error(err));
} else {
const sandoxResult = this._toSandbox(result, cb.expectedReturnType || 'void');
const sandoxResult = this._toSandbox(result, cb.expectedReturnType ?? 'void');
this._debug('completed with result:', sandoxResult);
cb.succeed(sandoxResult);
}
Expand Down Expand Up @@ -409,7 +409,7 @@ export class Kernel {

// add the __jsii__.fqn property on every constructor. this allows
// traversing between the javascript and jsii worlds given any object.
for (const fqn of Object.keys(assm.metadata.types || {})) {
for (const fqn of Object.keys(assm.metadata.types ?? {})) {
const typedef = assm.metadata.types![fqn];
switch (typedef.kind) {
case spec.TypeKind.Interface:
Expand Down Expand Up @@ -450,12 +450,12 @@ export class Kernel {
this._debug('create', req);
const { fqn, interfaces, overrides } = req;

const requestArgs = req.args || [];
const requestArgs = req.args ?? [];

const ctorResult = this._findCtor(fqn, requestArgs);
const ctor = ctorResult.ctor;
const obj = this._wrapSandboxCode(() => new ctor(...this._toSandboxValues(requestArgs, ctorResult.parameters)));
const objref = this.objects.registerObject(obj, fqn, req.interfaces || []);
const objref = this.objects.registerObject(obj, fqn, req.interfaces ?? []);

// overrides: for each one of the override method names, installs a
// method on the newly created object which represents the remote "reverse proxy".
Expand Down Expand Up @@ -529,7 +529,7 @@ export class Kernel {

// save the old property under $jsii$super$<prop>$ so that property overrides
// can still access it via `super.<prop>`.
const prev = Object.getOwnPropertyDescriptor(obj, propertyName) || {
const prev = Object.getOwnPropertyDescriptor(obj, propertyName) ?? {
value: undefined,
writable: true,
enumerable: true,
Expand Down Expand Up @@ -620,7 +620,7 @@ export class Kernel {
objref,
override,
args,
expectedReturnType: methodInfo.returns || 'void',
expectedReturnType: methodInfo.returns ?? 'void',
succeed,
fail
};
Expand Down Expand Up @@ -648,7 +648,7 @@ export class Kernel {
}
});
this._debug('Result', result);
return this._toSandbox(result, methodInfo.returns || 'void');
return this._toSandbox(result, methodInfo.returns ?? 'void');
}
});
}
Expand Down Expand Up @@ -677,7 +677,7 @@ export class Kernel {
}

private _validateMethodArguments(method: spec.Callable | undefined, args: any[]) {
const params: spec.Parameter[] = method && method.parameters || [];
const params: spec.Parameter[] = method?.parameters ?? [];

// error if args > params
if (args.length > params.length && !(method && method.variadic)) {
Expand Down Expand Up @@ -737,7 +737,7 @@ export class Kernel {
throw new Error(`Module '${moduleName}' not found`);
}

const types = assembly.metadata.types || {};
const types = assembly.metadata.types ?? {};
const fqnInfo = types[fqn];
if (!fqnInfo) {
throw new Error(`Type '${fqn}' not found`);
Expand All @@ -762,7 +762,7 @@ export class Kernel {
if (fqn === 'Object') { continue; }
const typeinfo = this._typeInfoForFqn(fqn);

const methods = (typeinfo as (spec.ClassType | spec.InterfaceType)).methods || [];
const methods = (typeinfo as (spec.ClassType | spec.InterfaceType)).methods ?? [];

for (const m of methods) {
if (m.name === methodName) {
Expand All @@ -771,7 +771,7 @@ export class Kernel {
}

// recursion to parent type (if exists)
const bases = [(typeinfo as spec.ClassType).base, ...(typeinfo as spec.InterfaceType).interfaces || []];
const bases = [(typeinfo as spec.ClassType).base, ...(typeinfo as spec.InterfaceType).interfaces ?? []];
for (const base of bases) {
if (!base) { continue; }

Expand Down Expand Up @@ -800,12 +800,12 @@ export class Kernel {
} else if (spec.isInterfaceType(typeInfo)) {
const interfaceTypeInfo = typeInfo as spec.InterfaceType;
properties = interfaceTypeInfo.properties;
bases = interfaceTypeInfo.interfaces || [];
bases = interfaceTypeInfo.interfaces ?? [];
} else {
throw new Error(`Type of kind ${typeInfo.kind} does not have properties`);
}

for (const p of properties || []) {
for (const p of properties ?? []) {
if (p.name === property) {
return p;
}
Expand Down Expand Up @@ -895,7 +895,7 @@ export class Kernel {
}

private _boxUnboxParameters(xs: any[], parameters: spec.Parameter[] | undefined, boxUnbox: (x: any, t: wire.OptionalValueOrVoid) => any) {
parameters = [...parameters || []];
parameters = [...parameters ?? []];
const variadic = parameters.length > 0 && !!parameters[parameters.length - 1].variadic;
// Repeat the last (variadic) type to match the number of actual arguments
while (variadic && parameters.length < xs.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-kernel/lib/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const JSII_SYMBOL = Symbol.for('__jsii__');
*/
export function jsiiTypeFqn(obj: any): string | undefined {
const jsii = obj.constructor[JSII_SYMBOL];
return jsii && jsii.fqn;
return jsii?.fqn;
}

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ export class ObjectTable {
if (existingRef) {
if (interfaces) {
const allIfaces = new Set(interfaces);
for (const iface of existingRef[api.TOKEN_INTERFACES] || []) {
for (const iface of existingRef[api.TOKEN_INTERFACES] ?? []) {
allIfaces.add(iface);
}
this.objects[existingRef[api.TOKEN_REF]].interfaces =
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-kernel/lib/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const SERIALIZERS: {[k: string]: Serializer} = {
return host.objects.registerObject(value, 'Object', [(optionalValue.type as spec.NamedTypeReference).fqn]);
},
deserialize(value, optionalValue, host) {
if (typeof value === 'object' && Object.keys(value || {}).length === 0) {
if (typeof value === 'object' && Object.keys(value ?? {}).length === 0) {
// Treat empty structs as `undefined` (see https://github.com/aws/jsii/issues/411)
value = undefined;
}
Expand Down Expand Up @@ -674,7 +674,7 @@ function propertiesOf(t: spec.Type, lookup: TypeLookup): {[name: string]: spec.P
ret = { ...ret, ...propertiesOf(lookup(t.base), lookup) };
}

for (const prop of t.properties || []) {
for (const prop of t.properties ?? []) {
ret[prop.name] = prop;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"jest-expect-message": "^1.0.2",
"jsii-build-tools": "^0.20.8",
"jsii-calc": "^0.20.8",
"typescript": "~3.6.4"
"typescript": "~3.7.2"
},
"jest": {
"collectCoverage": true,
Expand Down
Loading

0 comments on commit 6e0a7e6

Please sign in to comment.