Skip to content

Commit

Permalink
master: [snapshot]
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed May 2, 2018
1 parent f11374d commit 5a73190
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/opal/compiler.rb
Expand Up @@ -172,7 +172,11 @@ def initialize(source, options = {})
def compile
parse

@fragments = process(@sexp).flatten
begin
@fragments = process(@sexp).flatten
rescue => error
raise ::Opal.error_with_opal_backtrace(error, file)
end

@result = @fragments.map(&:code).join('')
end
Expand All @@ -186,7 +190,7 @@ def parse
begin
sexp, comments, tokens = @parser.tokenize(@buffer)
rescue ::Opal::Error, ::Parser::SyntaxError => error
raise ::Opal::SyntaxError.with_opal_backtrace(error, file)
raise ::Opal.error_with_opal_backtrace(error, file, ::Opal::SyntaxError)
end

@sexp = s(:top, sexp || s(:nil))
Expand Down
16 changes: 8 additions & 8 deletions lib/opal/errors.rb
Expand Up @@ -29,15 +29,15 @@ class RewritingError < ParsingError

class SyntaxError < ::SyntaxError
attr_accessor :location
end

# Not redefining #backtrace because of https://bugs.ruby-lang.org/issues/14693
def self.with_opal_backtrace(error, path)
new_error = new(error.message)
backtrace = error.backtrace.to_a
backtrace.unshift OpalBacktraceLocation.new(error, path).to_s
new_error.set_backtrace backtrace
new_error
end
# Not redefining #backtrace because of https://bugs.ruby-lang.org/issues/14693
def self.error_with_opal_backtrace(error, path, error_class = nil)
new_error = error_class ? error_class.new(error.message) : error.dup
backtrace = error.backtrace.to_a
backtrace.unshift OpalBacktraceLocation.new(error, path).to_s
new_error.set_backtrace backtrace
new_error
end

# Loosely compatible with Thread::Backtrace::Location
Expand Down

0 comments on commit 5a73190

Please sign in to comment.