Skip to content

Commit

Permalink
fix: non conditional :class not working
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Mar 8, 2024
1 parent 76ab73a commit 774ed38
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/generators/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,19 @@ 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)

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)
Expand All @@ -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',
Expand Down

0 comments on commit 774ed38

Please sign in to comment.