1'use strict'; 2 3var acorn = require('acorn'); 4var objectAssign = require('object-assign'); 5 6module.exports = isExpression; 7 8var DEFAULT_OPTIONS = { 9 throw: false, 10 strict: false, 11 lineComment: false 12}; 13 14function isExpression(src, options) { 15 options = objectAssign({}, DEFAULT_OPTIONS, options); 16 17 try { 18 var parser = new acorn.Parser(options, src, 0); 19 20 if (options.strict) { 21 parser.strict = true; 22 } 23 24 if (!options.lineComment) { 25 parser.skipLineComment = function (startSkip) { 26 this.raise(this.pos, 'Line comments not allowed in an expression'); 27 }; 28 } 29 30 parser.nextToken(); 31 parser.parseExpression(); 32 33 if (parser.type !== acorn.tokTypes.eof) { 34 parser.unexpected(); 35 } 36 } catch (ex) { 37 if (!options.throw) { 38 return false; 39 } 40 41 throw ex; 42 } 43 44 return true; 45} 46