Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Opal::Fragment into opal/fragment.rb
- Loading branch information
1 parent
9f21010
commit 2de3af2
Showing
4 changed files
with
38 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Opal | ||
class Parser | ||
# A fragment holds a string of generated javascript that will be written | ||
# to the destination. It also keeps hold of the original sexp from which | ||
# it was generated. Using this sexp, when writing fragments in order, a | ||
# mapping can be created of the original location => target location, | ||
# aka, source-maps! | ||
class Fragment | ||
# String of javascript this fragment holds | ||
attr_reader :code | ||
|
||
def initialize(code, sexp = nil) | ||
@code = code.to_s | ||
@sexp = sexp | ||
end | ||
|
||
# In debug mode we may wish to include the original line as a comment | ||
def to_code | ||
if @sexp | ||
"/*:#{@sexp.line}*/#{@code}" | ||
else | ||
@code | ||
end | ||
end | ||
|
||
# inspect the contents of this fragment, f("fooo") | ||
def inspect | ||
"f(#{@code.inspect})" | ||
end | ||
|
||
def line | ||
@sexp.line if @sexp | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters