<commit_before>require 'typescript/rails'
require 'typescript-node'

module Typescript::Rails::Compiler
  class << self
    # @!scope class
    cattr_accessor :default_options

    # Replace relative paths specified in /// <reference path="..." /> with absolute paths.
    #
    # @param [String] ts_path Source .ts path
    # @param [String] source. It might be pre-processed by erb.
    # @return [String] replaces source
    def replace_relative_references(ts_path, source)
      ts_dir = File.dirname(File.expand_path(ts_path))
      escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'

      # Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
      # So we go the long way around.
      output = (source.each_line.map do |l|
        if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path="([^"]+)"\s*/>\s*!.match(l)).nil?
          l = l.sub(m.captures[0], File.join(escaped_dir, m.captures[0]))
        end
        next l
      end).join

      output
    end

    # @param [String] ts_path
    # @param [String] source TypeScript source code
    # @return [String] compiled JavaScript source code
    def compile(ts_path, source, *options)
      s = replace_relative_references(ts_path, source)
      ::TypeScript::Node.compile(s, *default_options, *options)
    end

  end

  self.default_options = [
      '--target', 'ES5',
      '--noImplicitAny'<commit_msg>tweak reference regexp<commit_after>require 'typescript/rails'
require 'typescript-node'

module Typescript::Rails::Compiler
  class << self
    # @!scope class
    cattr_accessor :default_options

    # Replace relative paths specified in /// <reference path="..." /> with absolute paths.
    #
    # @param [String] ts_path Source .ts path
    # @param [String] source. It might be pre-processed by erb.
    # @return [String] replaces source
    def replace_relative_references(ts_path, source)
      ts_dir = File.dirname(File.expand_path(ts_path))
      escaped_dir = ts_dir.gsub(/["\\]/, '\\\\\&') # "\"" => "\\\"", '\\' => '\\\\'

      # Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
      # So we go the long way around.
      output = (source.each_line.map do |l|
        if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
          matched_path = m.captures.compact[0]
          l = l.sub(matched_path, File.join(escaped_dir, matched_path))
        end
        next l
      end).join

      output
    end

    # @param [String] ts_path
    # @param [String] source TypeScript source code
    # @return [String] compiled JavaScript source code
    def compile(ts_path, source, *options)
      s = replace_relative_references(ts_path, source)
      ::TypeScript::Node.compile(s, *default_options, *options)
    end

  end

  self.default_options = [
      '--target', 'ES5',
      '--noImplicitAny'
{'fraction_non_alphanumeric': 0.16112618724559022, 'fraction_numerical': 0.0030529172320217096, 'mean_word_length': 2.7519083969465647, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5302788', 'n_tokens_mistral': 998, 'n_tokens_neox': 962, 'n_words': 243}