From a40fcee10c4d2ad8244f7a597d82f722eddc8799 Mon Sep 17 00:00:00 2001
From: Pawel Siemienik
Date: Sat, 18 Apr 2020 20:12:48 +0200
Subject: [PATCH] Refactoring: Suppress nonsense output, Add returns types for
ts. `
---
src/Scope.ts | 23 ++++++++++-------------
src/cell/VariableCell.ts | 4 ++--
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/src/Scope.ts b/src/Scope.ts
index a2a1e36..dfc7804 100644
--- a/src/Scope.ts
+++ b/src/Scope.ts
@@ -23,14 +23,14 @@ export class Scope {
return this.template.worksheets[this.templateCell.ws].getCell(this.templateCell.r, this.templateCell.c);
}
- public setCurrentOutputValue(value: CellValue) {
+ public setCurrentOutputValue(value: CellValue): void {
if (this.frozen) {
return;
}
this.output.worksheets[this.outputCell.ws].getCell(this.outputCell.r, this.outputCell.c).value = value;
}
- public applyStyles() {
+ public applyStyles(): void {
if (this.frozen) {
return;
}
@@ -45,7 +45,7 @@ export class Scope {
}
}
- public applyMerge() {
+ public applyMerge(): void {
const tws = this.template.worksheets[this.templateCell.ws];
const tc = tws.getCell(this.templateCell.r, this.templateCell.c);
@@ -62,7 +62,7 @@ export class Scope {
}
}
- public incrementCol() {
+ public incrementCol(): void {
if (!this.finished) {
this.templateCell = Object.freeze({ ...this.templateCell, c: this.templateCell.c + 1 });
}
@@ -70,7 +70,7 @@ export class Scope {
this.outputCell = Object.freeze({ ...this.outputCell, c: this.outputCell.c + 1 });
}
- public incrementRow() {
+ public incrementRow(): void {
if (!this.finished) {
this.templateCell = Object.freeze({ ...this.templateCell, r: this.templateCell.r + 1, c: 1 });
}
@@ -83,27 +83,24 @@ export class Scope {
}
}
- public freezeOutput() {
+ public freezeOutput(): void {
this.frozen++;
}
- public unfreezeOutput() {
+ public unfreezeOutput(): void {
this.frozen = Math.max(this.frozen - 1, 0);
}
- /**
- * @returns {boolean}
- */
- public isFrozen() {
+ public isFrozen(): boolean {
return this.frozen > 0;
}
- public finish() {
+ public finish(): void {
this.finished = true;
this.unfreezeOutput();
}
- public isFinished() {
+ public isFinished(): boolean {
return this.finished;
}
}
diff --git a/src/cell/VariableCell.ts b/src/cell/VariableCell.ts
index 3f4ecef..adc1f07 100644
--- a/src/cell/VariableCell.ts
+++ b/src/cell/VariableCell.ts
@@ -23,11 +23,11 @@ export class VariableCell extends BaseCell {
.split('.') || [];
const value = path.reduce((p, c) => (typeof p === 'object' ? p[c] : p), scope.vm);
- if (value === undefined) {
+ if (value === undefined && !scope.isFrozen()) {
// todo do it better (use logger or somethink like that)
// tslint:disable-next-line:no-console
console.warn(
- `WARN: ${path} is undefined for output: ${scope.outputCell} when template is:${scope.templateCell}`,
+ `WARN: ${path} is undefined for output: ${JSON.stringify(scope.outputCell)} when template is:${JSON.stringify(scope.templateCell)}`,
);
}
scope.setCurrentOutputValue(value);