Skip to content

Commit

Permalink
Module do not need a constructor to be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 6, 2013
1 parent 13cf9b1 commit f58c758
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion corelib/runtime.js
Expand Up @@ -188,7 +188,7 @@
};

// Define new module (or return existing module)
Opal.module = function(base, id, constructor) {
Opal.module = function(base, id) {
var module;

if (!base._isClass) {
Expand Down
12 changes: 5 additions & 7 deletions lib/opal/parser.rb
Expand Up @@ -1007,9 +1007,8 @@ def process_module(sexp, level)
indent do
in_scope(:module) do
@scope.name = name
@scope.add_temp "self = #{name}",
"#{@scope.proto} = #{name}._proto",
"$scope = #{name}._scope"
@scope.add_temp "#{@scope.proto} = self._proto",
"$scope = self._scope"
body = process body, :stmt

code << f(@indent)
Expand All @@ -1022,10 +1021,9 @@ def process_module(sexp, level)
end

spacer = "\n#{@indent}#{INDENT}"
cls = "function #{name}() {};"
boot = "self = #{name} = $module($base, #{name.inspect}, #{name});"
boot = "var self = $module($base, #{name.inspect});"

code.unshift f("(function($base){#{spacer}#{cls}#{spacer}#{boot}\n", sexp)
code.unshift f("(function($base){#{spacer}#{boot}\n", sexp)
code << f("\n#@indent})(")
code << base
code << f(")")
Expand Down Expand Up @@ -1159,7 +1157,7 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp, level)

def_code = if recvr
if smethod
[f("#{@scope.name}.constructor.prototype['$#{mid}'] = ", sexp), result]
[f("self.constructor.prototype['$#{mid}'] = ", sexp), result]
else
[recv, f("#{jsid} = ", sexp), result]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/opal/target_scope.rb
Expand Up @@ -149,7 +149,7 @@ def f(code, sexp = nil)
# Generates code for this module to donate methods
def to_donate_methods
if should_donate? and !@methods.empty?
f("%s;$opal.donate(#{@name}, [%s]);" % [@parser.parser_indent, @methods.map(&:inspect).join(', ')])
f("%s;$opal.donate(self, [%s]);" % [@parser.parser_indent, @methods.map(&:inspect).join(', ')])
else
f("")
end
Expand Down

0 comments on commit f58c758

Please sign in to comment.