Skip to content

Commit

Permalink
added missing type fields in typings and tests for them
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindar authored and nknapp committed Oct 8, 2019
1 parent b793350 commit 0440af2
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
21 changes: 19 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ declare namespace hbs {
interface Statement extends Node {}

interface MustacheStatement extends Statement {
type: 'MustacheStatement';
path: PathExpression | Literal;
params: Expression[];
hash: Hash;
Expand All @@ -280,6 +281,7 @@ declare namespace hbs {
interface Decorator extends MustacheStatement { }

interface BlockStatement extends Statement {
type: 'BlockStatement';
path: PathExpression;
params: Expression[];
hash: Hash;
Expand All @@ -293,6 +295,7 @@ declare namespace hbs {
interface DecoratorBlock extends BlockStatement { }

interface PartialStatement extends Statement {
type: 'PartialStatement';
name: PathExpression | SubExpression;
params: Expression[];
hash: Hash;
Expand All @@ -301,6 +304,7 @@ declare namespace hbs {
}

interface PartialBlockStatement extends Statement {
type: 'PartialBlockStatement';
name: PathExpression | SubExpression;
params: Expression[];
hash: Hash;
Expand All @@ -310,24 +314,28 @@ declare namespace hbs {
}

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

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

interface Expression extends Node {}

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

interface PathExpression extends Expression {
type: 'PathExpression';
data: boolean;
depth: number;
parts: string[];
Expand All @@ -336,29 +344,38 @@ declare namespace hbs {

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

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

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

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

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

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

interface HashPair extends Node {
type: 'HashPair';
key: string;
value: Expression;
}
Expand Down
84 changes: 83 additions & 1 deletion types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,86 @@ Handlebars.compile('test', {

Handlebars.compile('test')({},{allowCallsToHelperMissing: true});

Handlebars.compile('test')({},{});
Handlebars.compile('test')({},{});


const allthings = {} as hbs.AST.MustacheStatement |
hbs.AST.BlockStatement |
hbs.AST.PartialStatement |
hbs.AST.PartialBlockStatement |
hbs.AST.ContentStatement |
hbs.AST.CommentStatement |
hbs.AST.SubExpression |
hbs.AST.PathExpression |
hbs.AST.StringLiteral |
hbs.AST.BooleanLiteral |
hbs.AST.NumberLiteral |
hbs.AST.UndefinedLiteral |
hbs.AST.NullLiteral |
hbs.AST.Hash |
hbs.AST.HashPair;

switch(allthings.type) {
case "MustacheStatement":
let mustacheStatement: hbs.AST.MustacheStatement;
mustacheStatement = allthings;
break;
case "BlockStatement":
let blockStatement: hbs.AST.BlockStatement;
blockStatement = allthings;
break;
case "PartialStatement":
let partialStatement: hbs.AST.PartialStatement;
partialStatement = allthings;
break;
case "PartialBlockStatement":
let partialBlockStatement: hbs.AST.PartialBlockStatement;
partialBlockStatement = allthings;
break;
case "ContentStatement":
let ContentStatement: hbs.AST.ContentStatement;
ContentStatement = allthings;
break;
case "CommentStatement":
let CommentStatement: hbs.AST.CommentStatement;
CommentStatement = allthings;
break;
case "SubExpression":
let SubExpression: hbs.AST.SubExpression;
SubExpression = allthings;
break;
case "PathExpression":
let PathExpression: hbs.AST.PathExpression;
PathExpression = allthings;
break;
case "StringLiteral":
let StringLiteral: hbs.AST.StringLiteral;
StringLiteral = allthings;
break;
case "BooleanLiteral":
let BooleanLiteral: hbs.AST.BooleanLiteral;
BooleanLiteral = allthings;
break;
case "NumberLiteral":
let NumberLiteral: hbs.AST.NumberLiteral;
NumberLiteral = allthings;
break;
case "UndefinedLiteral":
let UndefinedLiteral: hbs.AST.UndefinedLiteral;
UndefinedLiteral = allthings;
break;
case "NullLiteral":
let NullLiteral: hbs.AST.NullLiteral;
NullLiteral = allthings;
break;
case "Hash":
let Hash: hbs.AST.Hash;
Hash = allthings;
break;
case "HashPair":
let HashPair: hbs.AST.HashPair;
HashPair = allthings;
break;
default:
break;
}

0 comments on commit 0440af2

Please sign in to comment.