Skip to content

Commit

Permalink
Merge pull request #2 from handlebars-lang/feat/add-types
Browse files Browse the repository at this point in the history
[FEAT] Adds types
  • Loading branch information
Chris Garrett committed Sep 18, 2020
2 parents 6f8f05e + cb0c081 commit 723df21
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint .",
"prepublishOnly": "npm run build",
Expand Down
144 changes: 144 additions & 0 deletions types/ast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
export interface Node {
type: string;
loc: SourceLocation;
}

export interface SourceLocation {
source: string;
start: Position;
end: Position;
}

export interface Position {
line: number;
column: number;
}

export interface Program extends Node {
body: Statement[];
blockParams: string[];
}

export interface Statement extends Node {}

export interface MustacheStatement extends Statement {
type: 'MustacheStatement';
path: PathExpression | Literal;
params: Expression[];
hash: Hash;
escaped: boolean;
strip: StripFlags;
}

export interface Decorator extends MustacheStatement { }

export interface BlockStatement extends Statement {
type: 'BlockStatement';
path: PathExpression;
params: Expression[];
hash: Hash;
program: Program;
inverse: Program;
openStrip: StripFlags;
inverseStrip: StripFlags;
closeStrip: StripFlags;
}

export interface DecoratorBlock extends BlockStatement { }

export interface PartialStatement extends Statement {
type: 'PartialStatement';
name: PathExpression | SubExpression;
params: Expression[];
hash: Hash;
indent: string;
strip: StripFlags;
}

export interface PartialBlockStatement extends Statement {
type: 'PartialBlockStatement';
name: PathExpression | SubExpression;
params: Expression[];
hash: Hash;
program: Program;
openStrip: StripFlags;
closeStrip: StripFlags;
}

export interface ContentStatement extends Statement {
type: 'ContentStatement';
value: string;
original: StripFlags;
}

export interface CommentStatement extends Statement {
type: 'CommentStatement';
value: string;
strip: StripFlags;
}

export interface Expression extends Node {}

export interface SubExpression extends Expression {
type: 'SubExpression';
path: PathExpression;
params: Expression[];
hash: Hash;
}

export interface PathExpression extends Expression {
type: 'PathExpression';
data: boolean;
depth: number;
parts: string[];
original: string;
}

export interface Literal extends Expression {}
export interface StringLiteral extends Literal {
type: 'StringLiteral';
value: string;
original: string;
}

export interface BooleanLiteral extends Literal {
type: 'BooleanLiteral';
value: boolean;
original: boolean;
}

export interface NumberLiteral extends Literal {
type: 'NumberLiteral';
value: number;
original: number;
}

export interface UndefinedLiteral extends Literal {
type: 'UndefinedLiteral';
}

export interface NullLiteral extends Literal {
type: 'NullLiteral';
}

export interface Hash extends Node {
type: 'Hash';
pairs: HashPair[];
}

export interface HashPair extends Node {
type: 'HashPair';
key: string;
value: Expression;
}

export interface StripFlags {
open: boolean;
close: boolean;
}

export interface helpers {
helperExpression(node: Node): boolean;
scopeId(path: PathExpression): boolean;
simpleId(path: PathExpression): boolean;
}
11 changes: 11 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as AST from './ast';

export { AST };

export interface ParseOptions {
srcName?: string;
ignoreStandalone?: boolean;
}

export function parse(input: string, options?: ParseOptions): AST.Program;
export function parseWithoutProcessing(input: string, options?: ParseOptions): AST.Program;

0 comments on commit 723df21

Please sign in to comment.