Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,731 additions
and
1,047 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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([]) |
Oops, something went wrong.