Skip to content

Commit

Permalink
chore(package): update parser
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 4, 2018
1 parent f8d6d02 commit 726142a
Show file tree
Hide file tree
Showing 17 changed files with 14 additions and 56 deletions.
2 changes: 0 additions & 2 deletions fixtures/each-tag-array/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
ctx.newFrame()
ctx.setOnFrame('user', user)
ctx.setOnFrame('key', key)
out += '\n'
out += ' - Hello '
out += `${ctx.escape(ctx.resolve('user').username)}`
out += '\n'
ctx.removeFrame()
})
out += '\n'
return out
})(template, ctx)
3 changes: 0 additions & 3 deletions fixtures/each-tag-else/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
ctx.newFrame()
ctx.setOnFrame('user', user)
ctx.setOnFrame('key', key)
out += '\n'
out += ' - Hello '
out += `${ctx.escape(ctx.resolve('user').username)}`
out += '\n'
ctx.removeFrame()
})
} else {
out += '\n'
out += ' No users found'
out += '\n'
}
out += '\n'
return out
})(template, ctx)
2 changes: 0 additions & 2 deletions fixtures/each-tag-index/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
ctx.newFrame()
ctx.setOnFrame('user', user)
ctx.setOnFrame('index', index)
out += '\n'
out += ' - Hello '
out += `${ctx.escape(ctx.resolve('user').username)}`
out += '\n'
ctx.removeFrame()
})
out += '\n'
return out
})(template, ctx)
2 changes: 0 additions & 2 deletions fixtures/each-tag/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
ctx.newFrame()
ctx.setOnFrame('user', user)
ctx.setOnFrame('key', key)
out += '\n'
out += ' - Hello '
out += `${ctx.escape(ctx.resolve('user').username)}`
out += '\n'
ctx.removeFrame()
})
out += '\n'
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/else-if-tag/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
out += '\n'
} else {
out += ' Hello Guest!'
out += '\n'
}
out += '\n'
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/else-tag/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
out += '\n'
} else {
out += ' Hello guest!'
out += '\n'
}
out += '\n'
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/if-tag/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if(ctx.resolve('username')) {
out += ' Hello '
out += `${ctx.escape(ctx.resolve('username'))}`
out += '\n'
}
out += '\n'
return out
})(template, ctx)
1 change: 0 additions & 1 deletion fixtures/include-conditionals/compiled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (template, ctx) {
let out = ''
out += template.renderInline(`include-conditionals/${ctx.resolve('username') === 'virk' ? 'virk.edge' : 'guest.edge'}`)(template, ctx)
out += '\n'
return out
})(template, ctx)
1 change: 0 additions & 1 deletion fixtures/include-identifier/compiled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (template, ctx) {
let out = ''
out += template.renderInline(ctx.resolve('partial'))(template, ctx)
out += '\n'
return out
})(template, ctx)
1 change: 0 additions & 1 deletion fixtures/include-literal/compiled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (template, ctx) {
let out = ''
out += template.renderInline('include-literal/partial')(template, ctx)
out += '\n'
return out
})(template, ctx)
1 change: 0 additions & 1 deletion fixtures/include-nested/compiled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (template, ctx) {
let out = ''
out += template.renderInline('include-nested/partial')(template, ctx)
out += '\n'
return out
})(template, ctx)
1 change: 0 additions & 1 deletion fixtures/include-shared-ctx/compiled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function (template, ctx) {
let out = ''
out += template.renderInline('include-shared-ctx/partial')(template, ctx)
out += '\n'
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/nested-if-tag/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
if(ctx.resolve('age') > 18) {
out += ' Hello '
out += `${ctx.escape(ctx.resolve('username'))}`
out += '\n'
}
}
out += '\n'
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion japaFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Assertion.use((chai, utils) => {
}
})

cli.run('test/**/*.spec.ts')
cli.run('test/*.spec.ts')
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"dependencies": {
"deep-extend": "^0.6.0",
"edge-parser": "^1.0.7",
"edge-parser": "^1.0.8",
"he": "^1.1.1",
"macroable": "^1.0.0",
"node-exceptions": "^3.0.0"
Expand Down
30 changes: 1 addition & 29 deletions src/Tags/If.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Parser } from 'edge-parser'
import { EdgeBuffer } from 'edge-parser/build/src/EdgeBuffer'
import { IBlockNode, INode } from 'edge-lexer/build/src/Contracts'
import { IBlockNode } from 'edge-lexer/build/src/Contracts'
import { disAllowExpressions } from '../utils'

export class IfTag {
Expand All @@ -25,19 +25,6 @@ export class IfTag {
*/
protected bannedExpressions = ['SequenceExpression']

/**
* Returns a boolean telling whether the node with newline has a parent
* of else or elseif.
*/
private _childOfElse (children: (IBlockNode | INode)[], index: number): boolean {
const node = children[index - 1]
if (!node || node.type !== 'block') {
return false
}

return ['else', 'elseif'].indexOf((node as IBlockNode).properties.name) > -1
}

/**
* Compiles the if block node to a Javascript if statement
*/
Expand All @@ -55,25 +42,10 @@ export class IfTag {
*/
buffer.indent()

/**
* Removing first and last newlines, they are redudant and will hurt
* when not using HTML as the markup language
*/
token.children.shift()
token.children.pop()

/**
* Process of all kids recursively
*/
token.children.forEach((child, index) => {
/**
* Ignoring newlines right after the else tag, since else itself
* doesn't have children and if has to handle it
*/
if (child.type === 'newline' && this._childOfElse(token.children, index)) {
return
}

parser.processToken(child, buffer)
})

Expand Down

0 comments on commit 726142a

Please sign in to comment.