Skip to content

Commit

Permalink
improvement: raise exception when super is used outside the section tag
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 17, 2020
1 parent f0b93b0 commit 452e648
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class Compiler implements CompilerContract {
* Concat children when super was called
*/
if (extendedNode.children.length && lexerUtils.isTag(extendedNode.children[0], 'super')) {
extendedNode.children.shift()
extendedNode.children = node.children.concat(extendedNode.children)
}

Expand Down
14 changes: 11 additions & 3 deletions src/Tags/Super.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* file that was distributed with this source code.
*/

import { EdgeError } from 'edge-error'
import { TagContract } from '../Contracts'

/**
Expand All @@ -21,8 +22,15 @@ export const superTag: TagContract = {
seekable: false,
tagName: 'super',

compile () {
// The super tag is handled by the compiler itself. I am just a way to
// tell lexer to parse me as an inline node
compile (_, __, token) {
throw new EdgeError(
'@super tag must appear as top level tag inside the @section tag',
'E_ORPHAN_SUPER_TAG',
{
line: token.loc.start.line,
col: token.loc.start.col,
filename: token.filename,
},
)
},
}
1 change: 0 additions & 1 deletion test/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ test.group('Compiler | Compile', (group) => {

try {
const fn = compiler.compile('index.edge').template
console.log(fn.toString())
new Function('state', 'ctx', fn)({}, new Context())
} catch (error) {
assert.equal(error.message, 'getUserName is not a function')
Expand Down

0 comments on commit 452e648

Please sign in to comment.