From 774ed3866863cfe16c7f5711ebcd2a0d395220d3 Mon Sep 17 00:00:00 2001 From: Joeylene <23741509+jorenrui@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:41:27 +0800 Subject: [PATCH] fix: non conditional :class not working --- lib/generators/lexer.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/generators/lexer.js b/lib/generators/lexer.js index c6cf19b..32cb1ec 100644 --- a/lib/generators/lexer.js +++ b/lib/generators/lexer.js @@ -363,8 +363,11 @@ export class Lexer { const ast = this.replaceAST() const output = [] + let hasConditionals = false + walk.simple(ast, { ConditionalExpression(node) { + hasConditionals = true const test = escodegen.generate(node.test) const consequent = escodegen.generate(node.consequent) const alternate = escodegen.generate(node.alternate) @@ -372,6 +375,7 @@ export class Lexer { output.push({ test, consequent, alternate, isExpression: true }) }, IfStatement(node) { + hasConditionals = true const test = escodegen.generate(node.test) let consequent = escodegen.generate(node.consequent) let alternate = escodegen.generate(node.alternate) @@ -384,6 +388,20 @@ export class Lexer { }, }) + if (!hasConditionals) { + const output = escodegen.generate(ast) + + if (Lexer.debug) + console.log({ + type: 'Lexer.conditional', + input: this._code, + output, + ids: this._replacedIdentifiers, + }) + + return output + } + if (Lexer.debug) console.log({ type: 'Lexer.conditional',