Skip to content

Commit

Permalink
feat: add tab size option and set emitted tab size to 2 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
R-unic committed Sep 10, 2023
1 parent 09a6da8 commit 52e0644
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ await main
- for..in
- macro the rest of the `console` library
- macro the `??` operator
- tab size option
- emit comments
- disallow:
- call expressions on arrow functions directly
Expand Down
5 changes: 3 additions & 2 deletions src/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export default class CodeGenerator extends StringBuilder {

public constructor(
private readonly sourceNode: SourceFile,
private readonly testing = false
) { super(); }
private readonly testing = false,
tabSize = 2
) { super(tabSize); }

public generate(): string {
if (!this.testing) {
Expand Down
6 changes: 5 additions & 1 deletion src/string-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export default class StringBuilder {
protected indentation = 0;
private readonly parts: string[] = [];

public constructor(
private readonly tabSize: number
) {}

protected get generated(): string {
return this.parts.join("");
}
Expand All @@ -27,6 +31,6 @@ export default class StringBuilder {
}

protected newLine(amount = 1): void {
this.append(("\n" + " ".repeat(this.indentation)).repeat(amount));
this.append(("\n" + " ".repeat(this.tabSize).repeat(this.indentation)).repeat(amount));
}
}

0 comments on commit 52e0644

Please sign in to comment.