(edge)
| 29 | * ``` |
| 30 | */ |
| 31 | export const edgePluginSession: PluginFn<undefined> = (edge) => { |
| 32 | debug('registering session tags with edge') |
| 33 | |
| 34 | edge.registerTag({ |
| 35 | tagName: 'flashMessage', |
| 36 | seekable: true, |
| 37 | block: true, |
| 38 | compile(parser, buffer, token) { |
| 39 | const expression = parser.utils.transformAst( |
| 40 | parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), |
| 41 | token.filename, |
| 42 | parser |
| 43 | ) |
| 44 | |
| 45 | const key = parser.utils.stringify(expression) |
| 46 | |
| 47 | /** |
| 48 | * Write an if statement |
| 49 | */ |
| 50 | buffer.writeStatement( |
| 51 | `if (state.flashMessages.has(${key})) {`, |
| 52 | token.filename, |
| 53 | token.loc.start.line |
| 54 | ) |
| 55 | |
| 56 | /** |
| 57 | * Define a local variable |
| 58 | */ |
| 59 | buffer.writeExpression( |
| 60 | `let $message = state.flashMessages.get(${key})`, |
| 61 | token.filename, |
| 62 | token.loc.start.line |
| 63 | ) |
| 64 | |
| 65 | /** |
| 66 | * Create a local variables scope and tell the parser about |
| 67 | * the existence of the "message" variable |
| 68 | */ |
| 69 | parser.stack.defineScope() |
| 70 | parser.stack.defineVariable('$message') |
| 71 | |
| 72 | /** |
| 73 | * Process component children using the parser |
| 74 | */ |
| 75 | token.children.forEach((child) => { |
| 76 | parser.processToken(child, buffer) |
| 77 | }) |
| 78 | |
| 79 | /** |
| 80 | * Clear the scope of the local variables before we |
| 81 | * close the if statement |
| 82 | */ |
| 83 | parser.stack.clearScope() |
| 84 | |
| 85 | /** |
| 86 | * Close if statement |
| 87 | */ |
| 88 | buffer.writeStatement(`}`, token.filename, token.loc.start.line) |
nothing calls this directly
no outgoing calls
no test coverage detected