Skip to content

Commit

Permalink
Update to TypeScript 3.7 (denoland/deno#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/deno#3273
  • Loading branch information
kitsonk authored and caspervonb committed Jan 31, 2021
1 parent 2a95c76 commit 4a69614
Show file tree
Hide file tree
Showing 39 changed files with 432 additions and 500 deletions.
64 changes: 29 additions & 35 deletions archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,28 +384,26 @@ export class Tar {
*/
getReader(): Deno.Reader {
const readers: Deno.Reader[] = [];
this.data.forEach(
(tarData): void => {
let { reader } = tarData;
const { filePath } = tarData;
const headerArr = formatHeader(tarData);
readers.push(new Deno.Buffer(headerArr));
if (!reader) {
reader = new FileReader(filePath!);
}
readers.push(reader);

// to the nearest multiple of recordSize
readers.push(
new Deno.Buffer(
clean(
recordSize -
(parseInt(tarData.fileSize!, 8) % recordSize || recordSize)
)
)
);
this.data.forEach((tarData): void => {
let { reader } = tarData;
const { filePath } = tarData;
const headerArr = formatHeader(tarData);
readers.push(new Deno.Buffer(headerArr));
if (!reader) {
reader = new FileReader(filePath!);
}
);
readers.push(reader);

// to the nearest multiple of recordSize
readers.push(
new Deno.Buffer(
clean(
recordSize -
(parseInt(tarData.fileSize!, 8) % recordSize || recordSize)
)
)
);
});

// append 2 empty records
readers.push(new Deno.Buffer(clean(recordSize * 2)));
Expand Down Expand Up @@ -462,22 +460,18 @@ export class Untar {
"mtime",
"uid",
"gid"
]).forEach(
(key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = parseInt(decoder.decode(arr), 8);
}
]).forEach((key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = parseInt(decoder.decode(arr), 8);
}
);
(["owner", "group"] as ["owner", "group"]).forEach(
(key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = decoder.decode(arr);
}
});
(["owner", "group"] as ["owner", "group"]).forEach((key): void => {
const arr = trim(header[key]);
if (arr.byteLength > 0) {
meta[key] = decoder.decode(arr);
}
);
});

// read the file content
const len = parseInt(decoder.decode(header.fileSize), 8);
Expand Down
66 changes: 31 additions & 35 deletions encoding/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,23 @@ async function read(
result = line.split(opt.comma!);

let quoteError = false;
result = result.map(
(r): string => {
if (opt.trimLeadingSpace) {
r = r.trimLeft();
}
if (r[0] === '"' && r[r.length - 1] === '"') {
r = r.substring(1, r.length - 1);
} else if (r[0] === '"') {
r = r.substring(1, r.length);
}
result = result.map((r): string => {
if (opt.trimLeadingSpace) {
r = r.trimLeft();
}
if (r[0] === '"' && r[r.length - 1] === '"') {
r = r.substring(1, r.length - 1);
} else if (r[0] === '"') {
r = r.substring(1, r.length);
}

if (!opt.lazyQuotes) {
if (r[0] !== '"' && r.indexOf('"') !== -1) {
quoteError = true;
}
if (!opt.lazyQuotes) {
if (r[0] !== '"' && r.indexOf('"') !== -1) {
quoteError = true;
}
return r;
}
);
return r;
});
if (quoteError) {
throw new ParseError(Startline, lineIndex, 'bare " in non-quoted-field');
}
Expand Down Expand Up @@ -226,27 +224,25 @@ export async function parse(
);
i++;
}
return r.map(
(e): unknown => {
if (e.length !== headers.length) {
throw `Error number of fields line:${i}`;
}
i++;
const out: Record<string, unknown> = {};
for (let j = 0; j < e.length; j++) {
const h = headers[j];
if (h.parse) {
out[h.name] = h.parse(e[j]);
} else {
out[h.name] = e[j];
}
}
if (opt.parse) {
return opt.parse(out);
return r.map((e): unknown => {
if (e.length !== headers.length) {
throw `Error number of fields line:${i}`;
}
i++;
const out: Record<string, unknown> = {};
for (let j = 0; j < e.length; j++) {
const h = headers[j];
if (h.parse) {
out[h.name] = h.parse(e[j]);
} else {
out[h.name] = e[j];
}
return out;
}
);
if (opt.parse) {
return opt.parse(out);
}
return out;
});
}
if (opt.parse) {
return r.map((e: string[]): unknown => opt.parse!(e));
Expand Down
46 changes: 37 additions & 9 deletions encoding/csv_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const testCases = [
{
Name: "CRLF",
Input: "a,b\r\nc,d\r\n",
Output: [["a", "b"], ["c", "d"]]
Output: [
["a", "b"],
["c", "d"]
]
},
{
Name: "BareCR",
Expand Down Expand Up @@ -64,12 +67,18 @@ const testCases = [
{
Name: "BlankLine",
Input: "a,b,c\n\nd,e,f\n\n",
Output: [["a", "b", "c"], ["d", "e", "f"]]
Output: [
["a", "b", "c"],
["d", "e", "f"]
]
},
{
Name: "BlankLineFieldCount",
Input: "a,b,c\n\nd,e,f\n\n",
Output: [["a", "b", "c"], ["d", "e", "f"]],
Output: [
["a", "b", "c"],
["d", "e", "f"]
],
UseFieldsPerRecord: true,
FieldsPerRecord: 0
},
Expand All @@ -93,7 +102,10 @@ const testCases = [
{
Name: "NoComment",
Input: "#1,2,3\na,b,c",
Output: [["#1", "2", "3"], ["a", "b", "c"]]
Output: [
["#1", "2", "3"],
["a", "b", "c"]
]
},
{
Name: "LazyQuotes",
Expand Down Expand Up @@ -159,7 +171,10 @@ const testCases = [
{
Name: "FieldCount",
Input: "a,b,c\nd,e",
Output: [["a", "b", "c"], ["d", "e"]]
Output: [
["a", "b", "c"],
["d", "e"]
]
},
{
Name: "TrailingCommaEOF",
Expand All @@ -186,7 +201,11 @@ const testCases = [
{
Name: "TrailingCommaLine3",
Input: "a,b,c\nd,e,f\ng,hi,",
Output: [["a", "b", "c"], ["d", "e", "f"], ["g", "hi", ""]],
Output: [
["a", "b", "c"],
["d", "e", "f"],
["g", "hi", ""]
],
TrimLeadingSpace: true
},
{
Expand Down Expand Up @@ -223,13 +242,19 @@ x,,,
{
Name: "TrailingCommaIneffective1",
Input: "a,b,\nc,d,e",
Output: [["a", "b", ""], ["c", "d", "e"]],
Output: [
["a", "b", ""],
["c", "d", "e"]
],
TrimLeadingSpace: true
},
{
Name: "ReadAllReuseRecord",
Input: "a,b\nc,d",
Output: [["a", "b"], ["c", "d"]],
Output: [
["a", "b"],
["c", "d"]
],
ReuseRecord: true
},
// {
Expand Down Expand Up @@ -496,7 +521,10 @@ const parseTestCases = [
name: "multiline",
in: "a,b,c\ne,f,g\n",
header: false,
result: [["a", "b", "c"], ["e", "f", "g"]]
result: [
["a", "b", "c"],
["e", "f", "g"]
]
},
{
name: "header mapping boolean",
Expand Down
36 changes: 15 additions & 21 deletions encoding/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,9 @@ function joinKeys(keys: string[]): string {
// Dotted keys are a sequence of bare or quoted keys joined with a dot.
// This allows for grouping similar properties together:
return keys
.map(
(str: string): string => {
return str.match(/[^A-Za-z0-9_-]/) ? `"${str}"` : str;
}
)
.map((str: string): string => {
return str.match(/[^A-Za-z0-9_-]/) ? `"${str}"` : str;
})
.join(".");
}

Expand All @@ -417,24 +415,20 @@ class Dumper {
_parse(obj: Record<string, unknown>, keys: string[] = []): string[] {
const out = [];
const props = Object.keys(obj);
const propObj = props.filter(
(e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return !this._isSimplySerializable(d[0]);
}
return !this._isSimplySerializable(obj[e]);
const propObj = props.filter((e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return !this._isSimplySerializable(d[0]);
}
);
const propPrim = props.filter(
(e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return this._isSimplySerializable(d[0]);
}
return this._isSimplySerializable(obj[e]);
return !this._isSimplySerializable(obj[e]);
});
const propPrim = props.filter((e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return this._isSimplySerializable(d[0]);
}
);
return this._isSimplySerializable(obj[e]);
});
const k = propPrim.concat(propObj);
for (let i = 0; i < k.length; i++) {
const prop = k[i];
Expand Down
10 changes: 8 additions & 2 deletions encoding/toml_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ test({
fn(): void {
const expected = {
arrays: {
data: [["gamma", "delta"], [1, 2]],
data: [
["gamma", "delta"],
[1, 2]
],
hosts: ["alpha", "omega"]
}
};
Expand Down Expand Up @@ -344,7 +347,10 @@ test({
sf4: NaN,
sf5: NaN,
sf6: NaN,
data: [["gamma", "delta"], [1, 2]],
data: [
["gamma", "delta"],
[1, 2]
],
hosts: ["alpha", "omega"]
};
const expected = `deno = "is"
Expand Down
16 changes: 6 additions & 10 deletions flags/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ export function parse(
? [options.boolean]
: options.boolean;

booleanArgs.filter(Boolean).forEach(
(key: string): void => {
flags.bools[key] = true;
}
);
booleanArgs.filter(Boolean).forEach((key: string): void => {
flags.bools[key] = true;
});
}
}

Expand Down Expand Up @@ -114,11 +112,9 @@ export function parse(
flags.strings[key] = true;
const alias = get(aliases, key);
if (alias) {
alias.forEach(
(alias: string): void => {
flags.strings[alias] = true;
}
);
alias.forEach((alias: string): void => {
flags.strings[alias] = true;
});
}
});
}
Expand Down

0 comments on commit 4a69614

Please sign in to comment.