nodejs question - using the latest JavaScript syntax errors

nodejs question - using the latest JavaScript syntax errors

von Ed Wright -
Anzahl Antworten: 4

Hi,

I'm fairly new to using code runner and have set some questions that test some basic functions in JavaScript successfully.  In those tests, I was trying to use some newer ECMAScript features, such as the ** raise to power operator.  Initially, using this syntax failed with the out-of-the-box options but I found that I could add {esversion: 7} to the Template params box and this solved the problem.

As I evolve my usage of CodeRunner, I am now wanting my students to write other methods for testing.  However, I'm finding that some of the very recent JavaScript methods, syntax and functions - such as optional chaining, the trim() function on a string, declaring class fields and the nullish coalescing operator, do not work and produce errors like the one shown below:

Syntax Error using latest JavaScript

As I am keen for my students to be using the latest JavaScript syntax, is there a way I can get CodeRunner to recognise these functions, operators and syntax?  I've tried upping the Template params to set the esversion to 8, 9, 10 and 11 but with no success!  Is this the right thing to do? Do I need to update the NodeJS version on the Jobe Server?

Thanks.

Ed Wright.

Als Antwort auf Ed Wright

Re: nodejs question - using the latest JavaScript syntax errors

von Richard Lobb -
Almost certainly you need to upgrade the version of Node on your Jobe server. I'm not a Node user, but I see that optional chaining was added to NodeJS in version 14. You can find what version is running on your Jobe server by running the script (e.g. from within CodeRunner):

console.log("Version: ", process.version);
Als Antwort auf Richard Lobb

Re: nodejs question - using the latest JavaScript syntax errors

von Ed Wright -
Thanks Richard, updating the version of node on the Jobe server has certainly helped! The code as shown above now runs without errors. However, the editing window still shows the red X and the advice in the pop-up as shown. I can work with that, but it doesn't give immediate confidence that the code will work!
Als Antwort auf Ed Wright

Re: nodejs question - using the latest JavaScript syntax errors

von Richard Lobb -
This doesn't have such an easy fix. The version of the Ace editor embedded in CodeRunner will need to be upgraded to correctly parse the new syntax. This isn't something I'm game to do in a hurry. Ace is fundamental to CodeRunner, but it's not compatible with the normal Moodle AMD module conventions, so we use it in a somewhat unconventional manner. We also use extra non-standard Ace modules for some of our in-house question types, like Parsons Problems. All of which means I don't wish to attempt an upgrade mid-semester when I'm busy teaching.

The only work-around I can suggest is that you set the Ace language field in the Advanced Customisation panel of the nodejs prototype to some nonexistent language, such as "nonexistent". That will turn off the Ace editor's parsing altogether, so you'll lose the error messages. But you'll also lose syntax colouring and various other functionality you probably want.

Sorry but you'll likely have to wait till the end of the year for a fix.
Als Antwort auf Richard Lobb

Re: nodejs question - using the latest JavaScript syntax errors

von Ed Wright -

Absolutely understandable Richard and thanks for your prompt replies!

As I said, I can live with it so I'm happy to carry on until you have the time and inclination to upgrade!