Incorrect error thrown when function is in comments

This commit is contained in:
Stuart Taylor
2016-09-26 22:19:33 +01:00
parent d3f8757e92
commit d5c3731536

View File

@ -7,6 +7,9 @@ window.common = (function(global) {
const detectFunctionCall = /function\s*?\(|function\s+\w+\s*?\(/gi;
const detectUnsafeJQ = /\$\s*?\(\s*?\$\s*?\)/gi;
const detectUnsafeConsoleCall = /if\s\(null\)\sconsole\.log\(1\);/gi;
const detectInComments = new RegExp(['\\/\\/.*?function.*?|',
'\\/\\*[\\s\\w\\W]*?function',
'[\\s\\w\\W]*?\\*\\/'].join(''), 'gi');
common.detectUnsafeCode$ = function detectUnsafeCode$(code) {
const openingComments = code.match(/\/\*/gi);
@ -35,7 +38,8 @@ window.common = (function(global) {
if (
code.match(/function/g) &&
!code.match(detectFunctionCall)
!code.match(detectFunctionCall) &&
!code.match(detectInComments)
) {
return Observable.throw(
new Error('SyntaxError: Unsafe or unfinished function declaration')