Skip to content

Commit 444563f

Browse files
committed
Actually, rather than test for Node, let’s specifically check that require(‘fs’) returns something before we try to use it
1 parent 45b66e5 commit 444563f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/jison.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ lrGeneratorMixin.generateCommonJSModule = function generateCommonJSModule (opt)
966966
opt = typal.mix.call({}, this.options, opt);
967967
var moduleName = opt.moduleName || "parser";
968968
var out = this.generateModule(opt)
969-
+ "\n\n\nif (typeof require !== 'undefined' && typeof exports !== 'undefined' && new Function('try{return this===global;}catch(e){return false;}')()) {"
969+
+ "\n\n\nif (typeof require !== 'undefined' && typeof exports !== 'undefined') {"
970970
+ "\nexports.parser = "+moduleName+";"
971971
+ "\nexports.Parser = "+moduleName+".Parser;"
972972
+ "\nexports.parse = function () { return "+moduleName+".parse.apply("+moduleName+", arguments); };"
@@ -1280,7 +1280,12 @@ function commonjsMain (args) {
12801280
console.log('Usage: '+args[0]+' FILE');
12811281
process.exit(1);
12821282
}
1283-
var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
1283+
var source = null;
1284+
var fs = require('fs');
1285+
var path = require('path');
1286+
if (typeof fs !== 'undefined' && fs !== null) {
1287+
source = fs.readFileSync(path.normalize(args[1]), "utf8");
1288+
}
12841289
return exports.parser.parse(source);
12851290
}
12861291

0 commit comments

Comments
 (0)