Skip to content

Commit

Permalink
Update to TypeScript 3.7 (denoland#3275)
Browse files Browse the repository at this point in the history
and update to prettier 1.19

Also, update `assert()` and remove not null assertions where possibly
in `cli`.

Closes denoland#3273
  • Loading branch information
kitsonk authored and bartlomieju committed Dec 28, 2019
1 parent 567bbe9 commit b0cb6cb
Show file tree
Hide file tree
Showing 80 changed files with 987 additions and 1,160 deletions.
82 changes: 37 additions & 45 deletions cli/js/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,35 @@ function concatenate(...arrays: Uint8Array[]): ArrayBuffer {
}

function bufferFromStream(stream: ReadableStreamReader): Promise<ArrayBuffer> {
return new Promise(
(resolve, reject): void => {
const parts: Uint8Array[] = [];
const encoder = new TextEncoder();
// recurse
(function pump(): void {
stream
.read()
.then(
({ done, value }): void => {
if (done) {
return resolve(concatenate(...parts));
}
return new Promise((resolve, reject): void => {
const parts: Uint8Array[] = [];
const encoder = new TextEncoder();
// recurse
(function pump(): void {
stream
.read()
.then(({ done, value }): void => {
if (done) {
return resolve(concatenate(...parts));
}

if (typeof value === "string") {
parts.push(encoder.encode(value));
} else if (value instanceof ArrayBuffer) {
parts.push(new Uint8Array(value));
} else if (!value) {
// noop for undefined
} else {
reject("unhandled type on stream read");
}
if (typeof value === "string") {
parts.push(encoder.encode(value));
} else if (value instanceof ArrayBuffer) {
parts.push(new Uint8Array(value));
} else if (!value) {
// noop for undefined
} else {
reject("unhandled type on stream read");
}

return pump();
}
)
.catch(
(err): void => {
reject(err);
}
);
})();
}
);
return pump();
})
.catch((err): void => {
reject(err);
});
})();
});
}

function getHeaderValueParams(value: string): Map<string, string> {
Expand Down Expand Up @@ -275,19 +269,17 @@ export class Body implements domTypes.Body {
body
.trim()
.split("&")
.forEach(
(bytes): void => {
if (bytes) {
const split = bytes.split("=");
const name = split.shift()!.replace(/\+/g, " ");
const value = split.join("=").replace(/\+/g, " ");
formData.append(
decodeURIComponent(name),
decodeURIComponent(value)
);
}
.forEach((bytes): void => {
if (bytes) {
const split = bytes.split("=");
const name = split.shift()!.replace(/\+/g, " ");
const value = split.join("=").replace(/\+/g, " ");
formData.append(
decodeURIComponent(name),
decodeURIComponent(value)
);
}
);
});
} catch (e) {
throw new TypeError("Invalid form urlencoded format");
}
Expand Down
31 changes: 14 additions & 17 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type CompilerRequest = {
| {
type: CompilerRequestType.Bundle;
outFile?: string;
});
}
);

interface ConfigureResponse {
ignoredOptions?: string[];
Expand Down Expand Up @@ -186,11 +187,7 @@ class SourceFile {
throw new Error("SourceFile has already been processed.");
}
assert(this.sourceCode != null);
const preProcessedFileInfo = ts.preProcessFile(
this.sourceCode!,
true,
true
);
const preProcessedFileInfo = ts.preProcessFile(this.sourceCode, true, true);
this.processed = true;
const files = (this.importedFiles = [] as Array<[string, string]>);

Expand Down Expand Up @@ -511,10 +508,10 @@ class Host implements ts.CompilerHost {
? this._getAsset(fileName)
: SourceFile.get(fileName);
assert(sourceFile != null);
if (!sourceFile!.tsSourceFile) {
sourceFile!.tsSourceFile = ts.createSourceFile(
if (!sourceFile.tsSourceFile) {
sourceFile.tsSourceFile = ts.createSourceFile(
fileName,
sourceFile!.sourceCode,
sourceFile.sourceCode,
languageVersion
);
}
Expand Down Expand Up @@ -577,7 +574,7 @@ class Host implements ts.CompilerHost {
emitBundle(this._rootNames, this._outFile, data, sourceFiles!);
} else {
assert(sourceFiles.length == 1);
const url = sourceFiles![0].fileName;
const url = sourceFiles[0].fileName;
const sourceFile = SourceFile.get(url);

if (sourceFile) {
Expand Down Expand Up @@ -635,9 +632,9 @@ window.compilerMain = function compilerMain(): void {
// This will recursively analyse all the code for other imports, requesting
// those from the privileged side, populating the in memory cache which
// will be used by the host, before resolving.
const resolvedRootModules = (await processImports(
rootNames.map(rootName => [rootName, rootName])
)).map(info => info.url);
const resolvedRootModules = (
await processImports(rootNames.map(rootName => [rootName, rootName]))
).map(info => info.url);

const host = new Host(
request.type,
Expand Down Expand Up @@ -669,8 +666,9 @@ window.compilerMain = function compilerMain(): void {
const options = host.getCompilationSettings();
const program = ts.createProgram(rootNames, options, host);

diagnostics = ts.getPreEmitDiagnostics(program).filter(
({ code }): boolean => {
diagnostics = ts
.getPreEmitDiagnostics(program)
.filter(({ code }): boolean => {
// TS1103: 'for-await-of' statement is only allowed within an async
// function or async generator.
if (code === 1103) return false;
Expand All @@ -692,8 +690,7 @@ window.compilerMain = function compilerMain(): void {
// so we will ignore complaints about this compiler setting.
if (code === 5070) return false;
return true;
}
);
});

// We will only proceed with the emit if there are no diagnostics.
if (diagnostics && diagnostics.length === 0) {
Expand Down
76 changes: 35 additions & 41 deletions cli/js/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,18 @@ function createRawObjectString(
shouldShowClassName = true;
}
const keys = Object.keys(value);
const entries: string[] = keys.map(
(key): string => {
if (keys.length > OBJ_ABBREVIATE_SIZE) {
return key;
} else {
return `${key}: ${stringifyWithQuotes(
value[key],
ctx,
level + 1,
maxLevel
)}`;
}
const entries: string[] = keys.map((key): string => {
if (keys.length > OBJ_ABBREVIATE_SIZE) {
return key;
} else {
return `${key}: ${stringifyWithQuotes(
value[key],
ctx,
level + 1,
maxLevel
)}`;
}
);
});

ctx.delete(value);

Expand Down Expand Up @@ -640,43 +638,39 @@ export class Console {
let idx = 0;
resultData = {};

data.forEach(
(v: unknown, k: unknown): void => {
resultData[idx] = { Key: k, Values: v };
idx++;
}
);
data.forEach((v: unknown, k: unknown): void => {
resultData[idx] = { Key: k, Values: v };
idx++;
});
} else {
resultData = data!;
}

Object.keys(resultData).forEach(
(k, idx): void => {
const value: unknown = resultData[k]!;

if (value !== null && typeof value === "object") {
Object.entries(value as { [key: string]: unknown }).forEach(
([k, v]): void => {
if (properties && !properties.includes(k)) {
return;
}
Object.keys(resultData).forEach((k, idx): void => {
const value: unknown = resultData[k]!;

if (objectValues[k]) {
objectValues[k].push(stringifyValue(v));
} else {
objectValues[k] = createColumn(v, idx);
}
if (value !== null && typeof value === "object") {
Object.entries(value as { [key: string]: unknown }).forEach(
([k, v]): void => {
if (properties && !properties.includes(k)) {
return;
}
);

values.push("");
} else {
values.push(stringifyValue(value));
}
if (objectValues[k]) {
objectValues[k].push(stringifyValue(v));
} else {
objectValues[k] = createColumn(v, idx);
}
}
);

indexKeys.push(k);
values.push("");
} else {
values.push(stringifyValue(value));
}
);

indexKeys.push(k);
});

const headerKeys = Object.keys(objectValues);
const bodyValues = Object.values(objectValues);
Expand Down
4 changes: 2 additions & 2 deletions cli/js/console_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function cliTable(head: string[], columns: string[][]): string {
}
}

const divider = columnWidths.map(
(i: number): string => tableChars.middleMiddle.repeat(i + 2)
const divider = columnWidths.map((i: number): string =>
tableChars.middleMiddle.repeat(i + 2)
);

let result =
Expand Down

0 comments on commit b0cb6cb

Please sign in to comment.