diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index 1e1ff8ef..6c558b52 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -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)}"`; }