Skip to content

Commit

Permalink
Merge pull request #30 from typescript-ruby/printing_filename_on_error
Browse files Browse the repository at this point in the history
Added file name on TS compilation error
  • Loading branch information
bdrazhzhov committed Jul 27, 2015
2 parents f74adf0 + 2c12227 commit bd2e685
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
@@ -1,3 +1,7 @@
## v0.6.1 2015-07-27 21:52:50+0300

* Now code raises exception with correct file name when TS compilation error occurs

## v0.6.0 2015-07-06 22:36:25+0300

* Updated version to 0.6.0 for using Typescript source 1.4.1.3
Expand Down
6 changes: 5 additions & 1 deletion lib/typescript/rails/compiler.rb
Expand Up @@ -57,7 +57,11 @@ def compile(ts_path, source, context=nil, *options)
end
end
s = replace_relative_references(ts_path, source)
::TypeScript::Node.compile(s, *default_options, *options)
begin
::TypeScript::Node.compile(s, *default_options, *options)
rescue Exception => e
raise "Typescript error in file '#{ts_path}':\n#{e.message}"
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/typescript/rails/version.rb
@@ -1,5 +1,5 @@
module Typescript
module Rails
VERSION = '0.6.0'
VERSION = '0.6.1'
end
end
12 changes: 6 additions & 6 deletions test/assets_test.rb
@@ -1,8 +1,8 @@
require File.join(File.dirname(__FILE__), 'test_helper.rb')
require 'typescript-rails'

require "action_controller/railtie"
require "sprockets/railtie"
require 'action_controller/railtie'
require 'sprockets/railtie'


class AssetsTest < ActiveSupport::TestCase
Expand All @@ -19,7 +19,7 @@ def setup
env.cache = ActiveSupport::Cache.lookup_store(:memory_store)
end
@app.config.assets.paths << "#{File.dirname(__FILE__)}/fixtures/assets"
@app.paths["log"] = "#{tmp_path}/log/test.log"
@app.paths['log'] = "#{tmp_path}/log/test.log"
@app.initialize!
end

Expand All @@ -41,8 +41,8 @@ def assets
end

test 'assets .js.ts is compiled from TypeScript to JavaScript' do
assert { assets["javascripts/hello"].present? }
assert { assets["javascripts/hello"].source.include?('var log_to_console = function (x) {') }
assert { assets["javascripts/hello"].source.include?('var s = "Hello, world!";') }
assert { assets['javascripts/hello'].present? }
assert { assets['javascripts/hello'].source.include?('var log_to_console = function (x) {') }
assert { assets['javascripts/hello'].source.include?('var s = "Hello, world!";') }
end
end
20 changes: 10 additions & 10 deletions test/template_handler_test.rb
@@ -1,9 +1,9 @@
require 'test_helper'
require File.join(File.dirname(__FILE__), 'test_helper.rb')
require 'action_controller'
require 'typescript-rails'

class SiteController < ActionController::Base
self.view_paths = File.expand_path("../fixtures", __FILE__)
self.view_paths = File.expand_path('../fixtures', __FILE__)
end

DummyApp = ActionDispatch::Routing::RouteSet.new
Expand All @@ -29,26 +29,26 @@ def source
last_response.body.gsub(%r{^//[^\n]*}m, '')
end

test "typescript views are served as javascript" do
get "/site/index.js"
test 'typescript views are served as javascript' do
get '/site/index.js'
assert_match /var x = 5;\s*/,
source
end

test "<reference> to other .ts file works" do
get "/site/ref1_2.js"
test '<reference> to other .ts file works' do
get '/site/ref1_2.js'
assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
source
end

test "<reference> to other .d.ts file works" do
get "/site/ref2_2.js"
test '<reference> to other .d.ts file works' do
get '/site/ref2_2.js'
assert_match /f\(1, 2\);\s*/,
source
end

test "<reference> to multiple .ts files works" do
get "/site/ref3_1.js"
test '<reference> to multiple .ts files works' do
get '/site/ref3_1.js'
assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
source
end
Expand Down

0 comments on commit bd2e685

Please sign in to comment.