code: def generate(self, tree):
          '''
          generates code based on templates and gen functions
          defined in the <x> lang generator
          '''
          for middleware in DEFAULT_MIDDLEWARES + self.middlewares:
              tree = middleware.process(tree) # changed in place!!
          original = self._generate_node(tree)
          # first n lines n dependencies
          # after that additional code
  
          if self.a and tree.type == 'module':
              p = original.split('\n')
              r = '\n'.join(p[:len(tree.dependencies)] + (['\n'] if tree.dependencies else []) + self.a + ['\n'] + p[len(tree.dependencies):]) + '\n'
          else:
              r = original
          r = re.sub(CLOSING_CURLY_ENDLINES, r'}\n\2}', r)
          r = re.sub(JS_BRACKET, r'}\1', r)
          return re.sub(TOO_MANY_ENDLINES, r'\n\n', rf generate(self, tree):
          '''
          generates code based on templates and gen functions
          defined in the <x> lang generator
          '''
          for middleware in DEFAULT_MIDDLEWARES + self.middlewares:
              tree = middleware.process(tree) # changed in place!!
          original = self._generate_node(tree)
          # first n lines n dependencies
          # after that additional code
  
          if self.a and tree.type == 'module':
              p = original.split('\n')
              r = '\n'.join(p[:len(tree.dependencies)] + (['\n'] if tree.dependencies else []) + self.a + ['\n'] + p[len(tree.dependencies):]) + '\n'
          else:
              r = original
          r = re.sub(CLOSING_CURLY_ENDLINES, r'}\n\2}', r)
          r = re.sub(JS_BRACKET, r'}\1', r)
          return re.sub(TOO_MANY_ENDLINES, r'\n\n', r)
docs: generates code based on templates and gen functions
          defined in the <x> lang generator