Skip to content

Commit

Permalink
Actually, rather than test for Node, let’s specifically check that re…
Browse files Browse the repository at this point in the history
…quire(‘fs’) returns something before we try to use it
  • Loading branch information
GeoffreyBooth committed Jan 21, 2017
1 parent 45b66e5 commit 444563f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ lrGeneratorMixin.generateCommonJSModule = function generateCommonJSModule (opt)
opt = typal.mix.call({}, this.options, opt);
var moduleName = opt.moduleName || "parser";
var out = this.generateModule(opt)
+ "\n\n\nif (typeof require !== 'undefined' && typeof exports !== 'undefined' && new Function('try{return this===global;}catch(e){return false;}')()) {"
+ "\n\n\nif (typeof require !== 'undefined' && typeof exports !== 'undefined') {"
+ "\nexports.parser = "+moduleName+";"
+ "\nexports.Parser = "+moduleName+".Parser;"
+ "\nexports.parse = function () { return "+moduleName+".parse.apply("+moduleName+", arguments); };"
Expand Down Expand Up @@ -1280,7 +1280,12 @@ function commonjsMain (args) {
console.log('Usage: '+args[0]+' FILE');
process.exit(1);
}
var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
var source = null;
var fs = require('fs');
var path = require('path');
if (typeof fs !== 'undefined' && fs !== null) {
source = fs.readFileSync(path.normalize(args[1]), "utf8");
}
return exports.parser.parse(source);
}

Expand Down

0 comments on commit 444563f

Please sign in to comment.