Skip to content

Commit 7ff2786

Browse files
minht11Borewit
authored andcommitted
Refactor constructors to use explicit property assignments
1 parent 9d2d2a7 commit 7ff2786

24 files changed

+157
-40
lines changed

lib/ParseError.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ export class UnsupportedFileTypeError extends makeParseError('UnsupportedFileTyp
2525

2626
// Concrete error class representing unexpected file content.
2727
class UnexpectedFileContentError extends makeParseError('UnexpectedFileContentError') {
28-
constructor(public readonly fileType: string, message: string) {
28+
public readonly fileType: string;
29+
30+
constructor(fileType: string, message: string) {
2931
super(message);
32+
this.fileType = fileType;
3033
}
3134

3235
// Override toString to include file type information.

lib/aiff/AiffToken.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export class Common implements IGetToken<ICommon> {
4141

4242
public len: number;
4343

44-
public constructor(header: iff.IChunkHeader, private isAifc: boolean) {
44+
private isAifc: boolean;
45+
46+
public constructor(header: iff.IChunkHeader, isAifc: boolean) {
47+
this.isAifc = isAifc;
4548
const minimumChunkSize = isAifc ? 22 : 18;
4649
if (header.chunkSize < minimumChunkSize) throw new AiffContentError(`COMMON CHUNK size should always be at least ${minimumChunkSize}`);
4750
this.len = header.chunkSize;

lib/asf/AsfObject.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,10 @@ export class WmPictureToken implements IGetToken<IWmPicture> {
587587
return pic.get(buffer, 0);
588588
}
589589

590-
constructor(public len: number) {
590+
public len: number;
591+
592+
constructor(len: number) {
593+
this.len = len;
591594
}
592595

593596
public get(buffer: Uint8Array, offset: number): IWmPicture {

lib/asf/GUID.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ export default class GUID {
118118
return bin;
119119
}
120120

121-
public constructor(public str: string) {
121+
public str: string;
122+
123+
public constructor(str: string) {
124+
this.str = str;
122125
}
123126

124127
public equals(guid: GUID) {

lib/common/BasicParser.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ import type { INativeMetadataCollector } from './MetadataCollector.js';
66

77
export abstract class BasicParser implements ITokenParser {
88

9+
protected readonly metadata: INativeMetadataCollector;
10+
11+
protected readonly tokenizer: ITokenizer;
12+
13+
protected readonly options: IOptions;
14+
915
/**
1016
* Initialize parser with output (metadata), input (tokenizer) & parsing options (options).
1117
* @param {INativeMetadataCollector} metadata Output
1218
* @param {ITokenizer} tokenizer Input
1319
* @param {IOptions} options Parsing options
1420
*/
1521
constructor(
16-
protected readonly metadata: INativeMetadataCollector,
17-
protected readonly tokenizer: ITokenizer,
18-
protected readonly options: IOptions
22+
metadata: INativeMetadataCollector,
23+
tokenizer: ITokenizer,
24+
options: IOptions
1925
) {
26+
this.metadata = metadata;
27+
this.tokenizer = tokenizer;
28+
this.options = options;
2029
}
2130

2231
public abstract parse(): Promise<void>;

lib/common/GenericTagMapper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ export class CommonTagMapper implements IGenericTagMapper {
4343
};
4444
}
4545

46-
public constructor(public tagTypes: generic.TagType[], public tagMap: generic.INativeTagMap) {
46+
public tagTypes: generic.TagType[];
47+
48+
public tagMap: generic.INativeTagMap;
49+
50+
public constructor(tagTypes: generic.TagType[], tagMap: generic.INativeTagMap) {
51+
this.tagTypes = tagTypes;
52+
this.tagMap = tagMap;
4753
}
4854

4955
/**

lib/common/MetadataCollector.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ export class MetadataCollector implements INativeMetadataCollector {
9292

9393
private tagMapper = new CombinedTagMapper();
9494

95-
public constructor(private opts?: IOptions) {
95+
private opts?: IOptions;
96+
97+
public constructor(opts?: IOptions) {
98+
this.opts = opts;
9699
let priority = 1;
97100
for (const tagType of TagPriority) {
98101
this.originPriority[tagType] = priority++;

lib/ebml/EbmlIterator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ export class EbmlIterator {
5252
private ebmlMaxIDLength = 4;
5353
private ebmlMaxSizeLength = 8;
5454

55+
private tokenizer: ITokenizer;
56+
5557
/**
5658
* @param {ITokenizer} tokenizer Input
5759
* @param tokenizer
5860
*/
59-
constructor(private tokenizer: ITokenizer) {
61+
constructor(tokenizer: ITokenizer) {
62+
this.tokenizer = tokenizer;
6063
this.parserMap.set(DataType.uint, e => this.readUint(e));
6164
this.parserMap.set(DataType.string, e => this.readString(e));
6265
this.parserMap.set(DataType.binary, e => this.readBuffer(e));

lib/id3v1/ID3v1Parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ const Iid3v1Token: IGetToken<IId3v1Header | null> = {
9393

9494
class Id3v1StringType implements IGetToken<string | undefined> {
9595

96+
public len: number;
97+
9698
private stringType;
9799

98-
constructor(public len: number) {
100+
constructor(len: number) {
101+
this.len = len;
99102
this.stringType = new StringType(len, 'latin1');
100103
}
101104

lib/id3v2/FrameParser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ function parseGenreCode(code: string): string | undefined{
100100
}
101101

102102
export class FrameParser {
103+
private major: ID3v2MajorVersion;
104+
105+
private warningCollector: IWarningCollector;
103106

104107
/**
105108
* Create id3v2 frame parser
106109
* @param major - Major version, e.g. (4) for id3v2.4
107110
* @param warningCollector - Used to collect decode issue
108111
*/
109-
constructor(private major: ID3v2MajorVersion, private warningCollector: IWarningCollector) {
112+
constructor(major: ID3v2MajorVersion, warningCollector: IWarningCollector) {
113+
this.major = major;
114+
this.warningCollector = warningCollector;
110115
}
111116

112117
public readData(uint8Array: Uint8Array, type: string, includeCovers: boolean) {

0 commit comments

Comments
 (0)