Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit d2e2ae5

Browse files
committed
Ensure module is defined.
1 parent 22a75bf commit d2e2ae5

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

lib/handler/CommonCoffeeHandler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/handler/CommonJsHandler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handler/CommonCoffeeHandler.coffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ HandlerError = require './error/HandlerError'
88
module.exports = class CommonCoffeeHandler
99

1010
constructor: (@template) ->
11-
@template ?=
12-
"(function () {\n\n%s\nreturn module.exports;\n}).call(this);"
11+
@template ?= '''
12+
(function () {
13+
if (!module) { var module = {}; }
14+
15+
%s
16+
return module.exports;
17+
}).call(this);
18+
'''
1319

1420
handleFile: (filePath) => new Promise (resolve, reject) =>
1521
return resolve null if path.extname(filePath) isnt '.coffee'

src/handler/CommonJsHandler.coffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ HandlerError = require './error/HandlerError'
88
module.exports = class CommonJsHandler
99

1010
constructor: (@template) ->
11-
@template ?=
12-
"(function () {\n\n%s\nreturn module.exports;\n}).call(this);"
11+
@template ?= '''
12+
(function () {
13+
if (!module) { var module = {}; }
14+
15+
%s
16+
return module.exports;
17+
}).call(this);
18+
'''
1319

1420
handleFile: (filePath) => new Promise (resolve, reject) =>
1521
return resolve null if path.extname(filePath) isnt '.js'

test/suite/handler/CommonCoffeeHandler.spec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe 'CommonCoffeeHandler', ->
1414
'coffee'
1515
'''
1616
(function () {
17+
if (!module) { var module = {}; }
1718
1819
var test;
1920

test/suite/handler/CommonJsHandler.spec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe 'CommonJsHandler', ->
1414
'js'
1515
'''
1616
(function () {
17+
if (!module) { var module = {}; }
1718
1819
var test = 'It works.';
1920
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };

test/suite/index.spec.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe 'Module', ->
88
it 'builds a result using the correct handlers', ->
99
expectedCoffee = '''
1010
(function () {
11+
if (!module) { var module = {}; }
1112
1213
var test;
1314
@@ -22,6 +23,7 @@ describe 'Module', ->
2223
'''
2324
expectedJs = '''
2425
(function () {
26+
if (!module) { var module = {}; }
2527
2628
var test = 'It works.';
2729
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };

0 commit comments

Comments
 (0)