Skip to content

Commit 4ececf2

Browse files
committed
added js.Module (closes #56)
1 parent 1e24c6d commit 4ececf2

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/expressions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
475475
if len(c.flattened) != 0 {
476476
args = "$args"
477477
}
478-
479478
return c.formatExpr(`new ($sliceType(%s.Object))($global.Array.prototype.slice.call(%s))`, c.p.pkgVars["github.com/gopherjs/gopherjs/js"], args)
479+
case "Module":
480+
return c.formatExpr("$module")
480481
default:
481482
panic("Invalid js package object: " + obj.Name())
482483
}

compiler/prelude.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package compiler
33
var prelude = `
44
Error.stackTraceLimit = -1;
55
6-
var $global;
6+
var $global, $module;
77
if (typeof window !== "undefined") { /* web page */
88
$global = window;
99
} else if (typeof self !== "undefined") { /* web worker */
@@ -14,6 +14,9 @@ if (typeof window !== "undefined") { /* web page */
1414
} else {
1515
console.log("warning: no global object found")
1616
}
17+
if (typeof module !== "undefined") {
18+
$module = module;
19+
}
1720
1821
var $idCounter = 0;
1922
var $keys = function(m) { return m ? Object.keys(m) : []; };

js/js.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ var This Object
103103
// Arguments gives the value of JavaScript's "arguments" keyword. It can be used when passing Go functions to JavaScript as callbacks. Set this to a mock for testing with pure Go.
104104
var Arguments []Object
105105

106+
// Module gives the value of the "module" variable set by Node.js.
107+
var Module Object
108+
106109
// Returns the internal JavaScript object that represents i. Not intended for public use.
107110
func InternalObject(i interface{}) Object {
108111
return nil

0 commit comments

Comments
 (0)