Add Input.asNumberOrNaN

Might be used later
This commit is contained in:
Thomas Weber committed 2020-09-09 14:29:50 -05:00
1 parent f190934150
commit eebd40fec4
1 file changed
+10
+10
View File
@@ -42,6 +42,7 @@ const generatorNameVariablePool = new VariablePool('gen');
/**
* @typedef Input
* @property {() => string} asNumber
* @property {() => string} asNumberOrNaN
* @property {() => string} asString
* @property {() => string} asBoolean
* @property {() => string} asUnknown
@@ -66,6 +67,11 @@ class TypedInput {
return `(+${this.source} || 0)`;
}
asNumberOrNaN () {
if (this.type === TYPE_NUMBER || this.type === TYPE_NUMBER_NAN) return this.source;
return `(+${this.source})`;
}
asString () {
if (this.type === TYPE_STRING) return this.source;
return `("" + ${this.source})`;
@@ -106,6 +112,10 @@ class ConstantInput {
return '0';
}
asNumberOrNaN () {
return this.asNumber();
}
asString () {
return `"${sanitize('' + this.constantValue)}"`;
}