Skip to content

Commit

Permalink
feat: finalize @unless tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 26, 2020
1 parent 202f03b commit 9fc5fe5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 7 additions & 9 deletions fixtures/unless-tag/compiled.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
return (function (template, ctx) {
let out = "";
ctx.$lineNumber = 1;
ctx.$filename = "{{__dirname}}index.edge";
let $lineNumber = 1;
let $filename = "{{__dirname}}index.edge";
try {
if (!ctx.resolve('age')) {
if (!state.age) {
out += " Hello ";
ctx.$lineNumber = 2;
out += `${ctx.escape(ctx.resolve('username'))}`;
$lineNumber = 2;
out += `${ctx.escape(state.username)}`;
}
} catch (error) {
ctx.reThrow(error);
ctx.reThrow(error, $filename, $lineNumber);
}
return out;
})(template, ctx)
return out;
12 changes: 6 additions & 6 deletions src/Tags/Unless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { expressions } from 'edge-parser'

import { TagContract } from '../Contracts'
import { isNotSubsetOf, unallowedExpression } from '../utils'
import { isNotSubsetOf, unallowedExpression, parseJsArg } from '../utils'

/**
* Inverse of the `if` condition. The term `unless` is more readable and logical
Expand All @@ -31,11 +31,11 @@ export const unlessTag: TagContract = {
* Compiles the if block node to a Javascript if statement
*/
compile (parser, buffer, token) {
const parsed = parser.utils.transformAst(
parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),
token.filename,
)
const parsed = parseJsArg(parser, token)

/**
* Disallow sequence expressions
*/
isNotSubsetOf(
parsed,
[expressions.SequenceExpression],
Expand All @@ -54,7 +54,7 @@ export const unlessTag: TagContract = {
buffer.writeStatement(`if (!${parser.utils.stringify(parsed)}) {`, token.filename, token.loc.start.line)

/**
* Process of all kids recursively
* Process of all children recursively
*/
token.children.forEach((child) => parser.processToken(child, buffer))

Expand Down

0 comments on commit 9fc5fe5

Please sign in to comment.