lib/phlex/compiler/break_scanner.rb
Lines
100%10 of 10 covered
Branches
—0 of 0 covered
Methods
83%5 of 6 covered
- Never called
| 1 | # frozen_string_literal: true | |
| 2 | ||
| 3 | # Detects a `break` belonging to a block, which makes the call it's passed to | |
| 4 | # return the break's value. | |
| 5 | 1 | class Phlex::Compiler::BreakScanner < Refract::Visitor |
| 6 | 1 | def self.breaks?(node) |
| 7 | 235 | catch(:break) do |
| 8 | 235 | new.visit(node) |
| 9 | 231 | false |
| 10 | end | |
| 11 | end | |
| 12 | ||
| 13 | 1 | visit Refract::BreakNode do |node| |
| 14 | 4 | throw :break, true |
| 15 | end | |
| 16 | ||
| 17 | # A `break` in these belongs to them. | |
| 18 | 1 | [Refract::BlockNode, Refract::LambdaNode, Refract::WhileNode, Refract::UntilNode].each do |node_class| |
| 19 | 4 | visit node_class do |node| |
| 20 | 40 | nil |
| 21 | end | |
| 22 | end | |
| 23 | end |