-
Notifications
You must be signed in to change notification settings - Fork 15
Compiler/Line Number Metadata #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
@elia - Sound interesting? I think it could start as a monkey patch but maybe the compiler could add a framework some day. |
This was referenced Mar 23, 2016
Does opal-rspec support latest opal master? If it does you can do it with a custom AST rewriter: class RSpecMetadataRewriter < Opal::Rewriters::Base
RSPEC_METHODS = %i(describe context it)
def on_send(node)
node = super
recv, meth, *args = *node
if RSPEC_METHODS.include?(meth)
file = node.loc.expression.source_buffer.name
line = node.loc.line
column = node.loc.column
loc_metadata = "#{file}:#{line}:#{column}"
loc_metadata_pair = s(:pair, s(:sym, :loc), s(:str, loc_metadata))
if args.last.type == :iter
*args, iter = *args
end
if args.last.type == :hash
*args, last_hash_arg = *args
else
last_hash_arg = s(:hash)
end
pairs = *last_hash_arg
pairs += [loc_metadata_pair]
last_hash_arg = last_hash_arg.updated(nil, pairs)
args = [*args, last_hash_arg, iter].compact
node.updated(nil, [recv, meth, *args])
else
node
end
end
end
Opal::Rewriter::LIST << RSpecMetadataRewriter test.rb: def describe(*args)
puts "describe"
puts args
yield
end
def context(*args)
puts "context"
puts args
yield
end
def it(*args)
puts "it"
puts args
end
describe 'MyClass1', type: :some_type do
context 'when something happens' do
it 'does the following'
end
end
|
It did but it's currently broken (Sprockets is the first reason). |
I'm inclined to rely on source-maps for browser and possibly for node too. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add an optional compiler helper that will
add_special
call nodes for describe, context, it, etc.The modified code will still call describe, call, etc. but it will add a
caller
metadata attribute in implicitly to the arguments list. Caller should be an array with 1 element containing the filename and line number of the spec.Will need to handle cases where:
describe;do;end
is valid)It should be bootstrap compatible and configurable as to when this runs, some ideas:
_spec.rb
compiler
object in the call node, we can add an additional setting)Testing:
Compiler test, the compiled version with the patch on:
should equal this with the patch off:
The text was updated successfully, but these errors were encountered: