Skip to content

Commit

Permalink
Merge 7ae19b7 into 1b3375c
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Dec 17, 2020
2 parents 1b3375c + 7ae19b7 commit 1637410
Show file tree
Hide file tree
Showing 53 changed files with 1,731 additions and 1,047 deletions.
9 changes: 6 additions & 3 deletions bin/debug
Expand Up @@ -73,13 +73,16 @@ for (const key of enabled) {
let got = ''
try {
got = fn()
} catch (err) {}
} catch (err) {
console.error(err.stack)
continue
}
try {
assertSanHTMLEqual(got, expected)
console.log(chalk.cyan(desc))
console.log(chalk.cyan(desc) + ' ' + key)
console.log(chalk.green(got))
} catch (err) {
console.log(chalk.red(desc))
console.log(chalk.red(desc) + ' ' + key)
console.log(chalk.red(got))
exitCode = 1
}
Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions src/ast/renderer-ast-factory.ts
@@ -0,0 +1,67 @@
import { MapLiteral, UnaryOperator, UnaryExpression, NewExpression, VariableDefinition, ReturnStatement, BinaryOperator, If, Null, AssignmentStatement, Statement, Expression, Identifier, ExpressionStatement, BinaryExpression, Literal } from './renderer-ast-node'

export function createHTMLLiteralAppend (html: string) {
return STATMENT(BINARY(I('html'), '+=', L(html)))
}

export function createHTMLExpressionAppend (expr: Expression) {
return STATMENT(BINARY(I('html'), '+=', expr))
}

export function createDefaultValue (expr: Expression, value: Expression): Statement {
return createIfNull(expr, [ASSIGN(expr, value)])
}

export function createIfNotNull (expr: Expression, statements: Statement[]) {
return new If(BINARY(NULL, '!=', expr), statements)
}

export function createIfNull (expr: Expression, statements: Statement[]) {
return new If(BINARY(NULL, '==', expr), statements)
}

export function createIfStrictEqual (lhs: Expression, rhs: Expression, statements: Statement[]) {
return new If(BINARY(lhs, '===', rhs), statements)
}

export function L (val: any) {
return Literal.create(val)
}

export function I (name: string) {
return Identifier.create(name)
}

export const NULL = Null.create()

export const CTX_DATA = BINARY(I('ctx'), '.', I('data'))

export function BINARY (lhs: Expression, op: BinaryOperator, rhs: Expression) {
return new BinaryExpression(lhs, op, rhs)
}

export function UNARY (op: UnaryOperator, val: Expression) {
return new UnaryExpression(op, val)
}

export function ASSIGN (lhs: Expression, rhs: Expression) {
return new AssignmentStatement(lhs, rhs)
}

export function RETURN (val: Expression) {
return new ReturnStatement(val)
}

export function STATMENT (expr: Expression) {
return new ExpressionStatement(expr)
}

export function DEF (name: string, expr?: Expression) {
return new VariableDefinition(name, expr)
}

export function NEW (name: Expression, args: Expression[]) {
return new NewExpression(name, args)
}

export const EMPTY_MAP = new MapLiteral([])

0 comments on commit 1637410

Please sign in to comment.