Use of 'extends' keyword in class definition - is it supported? #1201
Replies: 4 comments
-
Posted at 2018-09-26 by @gfwilliams I'm not sure I understand? Are you running with a minifier turned on? The code you posted below has no mention of Uploading the code in your attached file from the main IDE window:
works perfectly for me on a recent build of Espruino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-27 by Robin Wed 2018.09.26 I'm surprised and disappointed @gordon that you missed that one. In your code, instance is of base class and not the derived class. It does however show that syntax checking is working. I left in the commented out instantiation lines that followed to show the difference between the two, valid syntax vs run-time, without the need of submitting two files. Was it necessary to add the obvious comment to un-comment the subsequent lines?
Yes, agreed, and as I mentioned that 'never specified an 'inherits' function' also, so that puzzled me too. Per your suggestion, when I checked, I had 'Closure Simple Optimizations' turned on, so your presumption is proved. But, that brings up another issue, does this mean the minification process is bad? I turned off minification and code passes fine, but fails when turned on. And even more puzzling, when I pass the source through https://closure-compiler.appspot.com
that source compiles with:
Sending that code, default.js, to the device results in the same error as in #1. How does one troubleshoot that type of error? If I understand this correctly, converting the minified code to byte code is where the issue lies. Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-27 by @allObjects Uploaded
Interesting are also the stats:
Instead of 'optimization' the opposite happens by a fatty -279.68% to -463.55% (g- and un-zipped). Espruino has (some) ES6 native support... and the support is growing, so no need for using ES5 output generation - the ES6 native support for class and constructor saves a lot. Espruiono works off of source code, so there is no bytecode generation involved. Espruino though has an option to speed interpretation from source code up by tokenizing before uploading. Even though closure-compiler is called blabla-compiler, it is - strictly looked at - more a transpilation... one form of javascript into another (less powerfull) one and - most often - using some poly-filler js library/libraries. Initially, Espruino was completely dependent on google's closure compiler, but it had it's issues on different levels:
For this reasons - and to support Espruino independent and very concisely - @gordon established the Espruino services in addition to the module services. Your experience using the google closure compiler service and ending up w/ code not running on Espruino makes me a bit jittery, because I have an extended set of very small, but tightly dependent modules that I developed this way. I may have to go thru a re-minify to get them all working for current and future Espruino versions. May be I got lucky because they were built with an 8-grader English - I mean JS 1.3 mind, even predating ES5, and would not be that susceptive to that issue. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-27 by @gfwilliams
You gave me code that you tell me isn't working, and I ran it and it works. As it happens on the first line I said "Are you running with a minifier turned on?" which is exactly what the issue is. You commonly upload huge files with massive areas of commented code, so I just assumed it was much the same. I'm trying to help you out here - it's not my job to try and decode the mangled bits of code you post up. But just to be clear:
Works perfectly on cutting edge Espruino builds.
Doesn't work, because as I have explained before in answer to one of your other questions, you're using a getter. In that case If you get errors running code, can you please just run it on the JS interpreter in your browser first to make sure you're actually writing valid JS? But in this case, your errors seem to be because the Closure minifier has converted your code into the following:
Which obviously doesn't resemble your original classes much. We can't easily set the compiler up such that it uses some ES6 features but not others, so it tries to convert your ES6 code to ES5. As it happens this code actually hit what looks like a bug in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-09-26 by Robin
Tue 2018.09.25
I am breaking up my now too large code file into smaller size class objects, leaving out un-necessary develop time functions. The user will add additional functionality by attaching functions.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends
When I attempt to use either the 'extends' or 'super' keyword
Note that I never specified an 'inherits' function.
Is there support for both keywords?
EDIT Wed 2018.09.26
After many more divide and conquer attempts found that:
The answer is yes. Here is an example where a line of code produces an unexpected and unusual error. How good are your debug skills? See if you can spot it!
See the function definitions from the MDN docs. Despite this isn't detected as a syntax error, the run-time error occurs.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions