Revert "js: Remove type from VariableInput"

This reverts commit 8f66924fe9.
This commit is contained in:
Thomas Weber committed 2020-08-30 16:37:25 -05:00
1 parent 8f66924fe9
commit c50aeaf740
1 file changed
+10
+10
View File
@@ -158,6 +158,7 @@ class SafeConstantInput extends ConstantInput {
class VariableInput {
constructor (source) {
this.source = source;
this.type = TYPE_UNKNOWN;
/**
* The value this variable was most recently set to, if any.
* @type {Input}
@@ -176,17 +177,26 @@ class VariableInput {
return;
}
this._lastInput = input;
if (input instanceof TypedInput) {
this.type = input.type;
} else {
this.type = TYPE_UNKNOWN;
}
}
asNumber () {
if (this.type === TYPE_NUMBER) return this.source;
if (this.type === TYPE_NUMBER_NAN) return `(${this.source} || 0)`;
return `(+${this.source} || 0)`;
}
asString () {
if (this.type === TYPE_STRING) return this.source;
return `("" + ${this.source})`;
}
asBoolean () {
if (this.type === TYPE_BOOLEAN) return this.source;
return `toBoolean(${this.source})`;
}