Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report compilation error upon invalid JavaScript code #354

Closed
pdawyndt opened this issue Apr 26, 2023 · 3 comments · Fixed by #381
Closed

Report compilation error upon invalid JavaScript code #354

pdawyndt opened this issue Apr 26, 2023 · 3 comments · Fixed by #381
Labels
bug Something isn't working programming language

Comments

@pdawyndt
Copy link
Contributor

pdawyndt commented Apr 26, 2023

Example: submission 13892016

Comment by @niknetniko:

Het probleem zit op de lijnen 52-53: daar worden "octal literals" gebruikt, maar die zijn niet toegestaan in "strict mode", en alle code in een klasse is per definitie in "strict mode". De reden dat de oefeningen niet de status "compilatiefout" heeft, is waarschijnlijk een bug in TESTed.

De foutboodschap die verschijnt is omdat we in JavaScript, voor we de oplossing beoordelen, de AST parsen om alle functies en klassen te exporteren uit de oplossing (zodat we later "import ..." kunnen doen). Het parsen van de AST loopt echter fout (want het is geen geldige syntaxis), en dus zijn er geen exports, en dus krijg je "ReferenceError: Qlocktwo is not defined".

Ik kijk na waarom de compilatiefout niet doorgegeven wordt.

@pdawyndt pdawyndt added the bug Something isn't working label Apr 26, 2023
@niknetniko
Copy link
Member

It seems like Node (and Chrome) don't enforce strict mode in this case, even though they should.
For example, the following code violates strict mode:

class Example {
    static test = {
        00: '',
        05: 'VIJF NA',
        10: 'TIEN NA'
    };
}

However, both node --check and the Chrome console accept it without issue:
image

However, most libraries do not accept it, and neither does Firefox:
image

Some solutions could be:

  • Enable strict mode everywhere.
  • Use an alternative to node --check that does check it
  • Somehow propagate errors from a later step inside TESTed

That last one is annoying, since that step shouldn't fail (so if it does, it should be an internal error instead).

@niknetniko
Copy link
Member

Enabling strict mode everywhere is not as simple as it looks, since NodeJS apparently doesn't honour the --use-strict flag (see nodejs/node#30039). It also became clear that the NodeJS people aren't a big fan of the flag.

A more robust way to enforce strict mode would then be to add "use strict" to every submission, but that is more work, although we do have support for this kind of thing.

A check of all the latest submissions from "Scriptingtalen" didn't reveal any instance where enabling strict mode changed the result.

@pdawyndt
Copy link
Contributor Author

FYI: Here's an example of a submission where the student enabled strict mode himself.

@pdawyndt pdawyndt changed the title Report compilation error when JavaScript code is not valid Report compilation error upon invalid JavaScript code May 19, 2023
This was referenced May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working programming language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants