From c50aeaf74009d40bb9842eb9914f0f40f351c6c4 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 30 Aug 2020 16:37:25 -0500 Subject: [PATCH] Revert "js: Remove type from VariableInput" This reverts commit 8f66924fe9006ec73bfda1d57f40e1bd7b125c5c. --- src/compiler/jsgen.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index 42755cf2..a140c399 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -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})`; }