The Mozilla Web Extension validator complains that my code contains Function declarations which are an eval. Can I configure Babel to avoid this? | Hashnode
The Mozilla Web Extension validator complains that my code contains Function declarations which are an eval. Can I configure Babel to avoid this?
I'm using ES6 to develop a Web Extension. The Mozilla add-on approval process requires that your code to pass a validation tool which doesn't like the resulting code. More information at developer.mozilla.org/en/XUL_School/Appendix_C:_A…
How does your code make use of eval()? If you're trying to evaluate strings one way I've been able to refactor eval() out of my code has been by using new Function() with a string that includes return plus whatever you're trying to evaluate. Consider this test:
var string = 'innerWidth * 2'var result1 = eval(string)
var result2 = newFunction('return ' + string)console.log(result1)console.log(result2())
The result of both should be the same. Normally 'innerWidth * 2' is just a string and would be handled as text, but when you run it through eval(string) or new Function('return ' + string) it should print a number equal to 2x your browser's width in the console.
Maybe using a trick like this can help you refactor eval() out of your code :D
Tommy Hodgins
CSS & Element Queries
How does your code make use of
eval()? If you're trying to evaluate strings one way I've been able to refactoreval()out of my code has been by usingnew Function()with a string that includesreturnplus whatever you're trying to evaluate. Consider this test:var string = 'innerWidth * 2' var result1 = eval(string) var result2 = new Function('return ' + string) console.log(result1) console.log(result2())The result of both should be the same. Normally
'innerWidth * 2'is just a string and would be handled as text, but when you run it througheval(string)ornew Function('return ' + string)it should print a number equal to 2x your browser's width in the console.Maybe using a trick like this can help you refactor
eval()out of your code :D