UNPKG

747 Btext/coffeescriptView Raw
1config = require "./config"
2kit = require "./kit"
3
4# common parent for visitors for AST
5class Visitor
6 setCtx: (@ctx) ->
7 @policy = @ctx.policy
8 @
9
10# visitor in translating state
11class ActiveVisitor extends Visitor
12 update: -> @
13 subScope: ->
14 new ActiveVisitor()
15
16# disabled state visitor, it skips most of AST nodes searching
17# for statements activating translation
18class DisabledVisitor extends Visitor
19 update: (ctx) ->
20 return (new ActiveVisitor()).setCtx(ctx) if @policy.opts.compile
21 @
22 subScope: ->
23 if @policy.opts.compile
24 new ActiveVisitor()
25 else new DisabledVisitor()
26 noChanges: true
27
28defaultVisitor = -> new DisabledVisitor()
29
30module.exports = {defaultVisitor,Visitor,ActiveVisitor,DisabledVisitor}
31