From 105834ae27597704744375ec020ba3c6d045622d Mon Sep 17 00:00:00 2001 From: nicco Date: Tue, 6 Feb 2018 21:15:39 +0100 Subject: [PATCH] Fixed if statement for properties of objects --- src/actions.ts | 8 ++++---- src/options.ts | 2 ++ views/new.html | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/actions.ts b/src/actions.ts index c705220..0df7d7f 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -2,8 +2,7 @@ import { compileBlock } from './compiler' import { ActionFunction, re, error, options, Part } from './options' import { getFromObject, readFileSync } from './util' import { join } from 'path' -import 'colors' -import { computeParts } from './parser'; +import { computeParts } from './parser' export const comment: ActionFunction = html => { @@ -21,7 +20,7 @@ export const comment: ActionFunction = html => { export const logic: ActionFunction = html => { const rexp = { - start: new RegExp(`${re.begin}\\${re.if} *\\${re.if_else}?[A-z]\\w*? *${re.ending}`, 'g'), + start: new RegExp(`${re.begin}\\${re.if} *\\${re.if_else}?${re.valid_variable} *${re.ending}`, 'g'), else: new RegExp(`${re.begin} *\\${re.if_else} *${re.ending}`, 'g'), end: RegExp(`${re.begin} *\\${re.closing_tag} *\\${re.if} *${re.ending}`, 'g'), } @@ -65,6 +64,7 @@ export const logic: ActionFunction = html => { return { parts: [(data: any) => { const ret: any = getFromObject(data, current.variable) + console.log('IF', typeof ret, ret) let isTrue: boolean = ret !== undefined && ret !== false && ret !== null && ret !== '' if (current.inverted) isTrue = !isTrue @@ -118,7 +118,7 @@ export const variables: ActionFunction = html => { export const loop: ActionFunction = html => { const rexp = { - start: new RegExp(`${re.begin}\\${re.for} *([A-z]\\w*?) *${re.for_in} *([A-z]\\w*?) *${re.ending}`, 'g'), + start: new RegExp(`${re.begin}\\${re.for} *${re.valid_variable} *${re.for_in} *${re.valid_variable} *${re.ending}`, 'g'), end: RegExp(`${re.begin} *\\${re.closing_tag} *\\${re.for} *${re.ending}`, 'g'), } diff --git a/src/options.ts b/src/options.ts index 83e335f..a57e5cc 100644 --- a/src/options.ts +++ b/src/options.ts @@ -68,6 +68,7 @@ interface Expressions { for: string for_in: string closing_tag: string + valid_variable: string } export const re: Expressions = { @@ -81,4 +82,5 @@ export const re: Expressions = { for: '*', for_in: 'in', closing_tag: '/', + valid_variable: '[A-z](\\w|\\.)*?', } \ No newline at end of file diff --git a/views/new.html b/views/new.html index c29aa7b..ad0cd4b 100644 --- a/views/new.html +++ b/views/new.html @@ -1,5 +1,5 @@ \ No newline at end of file