Add Input.asNumberOrNaN
Might be used later
This commit is contained in:
1 file changed
+10
@@ -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)}"`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user