klipse
klipse copied to clipboard
JavaScript evaluation: x is not a function, a.split is not a function in klipse_plugin.min.js
When using klipse_plugin.min.js instead of klipse_plugin.js, the console shows the following two errors with Firefox (62.0 and 60.1.0esr on GNU/Linux):
- TypeError: x is not a function[Learn More] klipse_plugin.min.js:1799:43
- TypeError: a.split is not a function[Learn More] klipse_plugin.min.js:306:123
Minimal example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel= "stylesheet" type= "text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<script>
window.klipse_settings = { selector_eval_js: ".klipse" };
</script>
</head>
<body>
<pre><code class="klipse" >
var x = "Hello World!";
x
</code></pre>
<!-- <script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script> -->
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>
</body>
</html>
The output "Hello World!" appears, but further edits do not have effects.
The root cause of this is described in #330.
Specifically, the minified klipse_plugin.min.js
exposes its global variables (including functions) to the window
object. In the snippet var x
refers to the global window.x
. So, window.x
is overwritten to become the "Hello World!"
string instead of the (apparently) function that Klipse expects it to be. To fix this, the minified Klipse bundle should be built so that it properly scopes its globals and does not expose them via the window
object.
I want to contribute
@codeR49 Please do!
let x = "Hello World!";
x
@irynadunets started working on this issue via WorksHub.
@Jacsonrai started working on this issue via WorksHub.
@murtaza63 started working on this issue via WorksHub.
@nbittich started working on this issue via WorksHub.
@curest0x1021 started working on this issue via WorksHub.