-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Opal::Compiler as main compiler class
- Loading branch information
1 parent
05ed472
commit 74e004a
Showing
19 changed files
with
79 additions
and
96 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
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 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 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 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 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 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
10 changes: 5 additions & 5 deletions
10
lib/opal/require_parser.rb → lib/opal/dependency_compiler.rb
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 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 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 |
---|---|---|
@@ -1,36 +1,34 @@ | ||
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 | ||
# 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 | ||
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 | ||
# 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 | ||
# inspect the contents of this fragment, f("fooo") | ||
def inspect | ||
"f(#{@code.inspect})" | ||
end | ||
|
||
def line | ||
@sexp.line if @sexp | ||
end | ||
def line | ||
@sexp.line if @sexp | ||
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 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 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 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 |
---|---|---|
@@ -1,43 +1,43 @@ | ||
require 'spec_helper' | ||
|
||
describe Opal::Parser do | ||
describe Opal::Compiler do | ||
describe "irb parser option" do | ||
before do | ||
@parser = Opal::Parser.new | ||
@compiler = Opal::Compiler.new | ||
end | ||
|
||
it "creates Opal.irb_vars if it does not exist" do | ||
$global["Opal"].irb_vars = nil | ||
eval_js(@parser.parse "nil", :irb => true) | ||
eval_js(@compiler.compile "nil", :irb => true) | ||
|
||
($global["Opal"].irb_vars == nil).should be_false | ||
end | ||
|
||
it "does not create Opal.irb_vars if :irb option not passed" do | ||
$global["Opal"].irb_vars = nil | ||
eval_js(@parser.parse "nil") | ||
eval_js(@compiler.compile "nil") | ||
|
||
($global["Opal"].irb_vars == nil).should be_true | ||
end | ||
|
||
it "sets each s(:lasgn) in the top level onto irb_vars" do | ||
eval_js @parser.parse "foo = 42", :irb => true | ||
eval_js @compiler.compile "foo = 42", :irb => true | ||
$global["Opal"].irb_vars.foo.should == 42 | ||
end | ||
|
||
it "gets each s(:lvar) in the top level from irb_vars" do | ||
eval_js @parser.parse "foo = 3.142; bar = foo", :irb => true | ||
eval_js @compiler.compile "foo = 3.142; bar = foo", :irb => true | ||
$global["Opal"].irb_vars.bar.should == 3.142 | ||
end | ||
|
||
it "persists local vars between parses" do | ||
eval_js @parser.parse "foo = 'hello world'", :irb => true | ||
eval_js @parser.parse "bar = foo.upcase", :irb => true | ||
eval_js @compiler.compile "foo = 'hello world'", :irb => true | ||
eval_js @compiler.compile "bar = foo.upcase", :irb => true | ||
$global["Opal"].irb_vars.bar.should == "HELLO WORLD" | ||
end | ||
|
||
it "can still call top level methods" do | ||
eval_js(@parser.parse("to_s", :irb => true)).should == "main" | ||
eval_js(@compiler.compile("to_s", :irb => true)).should == "main" | ||
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 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
Oops, something went wrong.