Enforcing strict/non-strict mode

31 views
Skip to first unread message

Petar Maksimovic

unread,
Mar 7, 2018, 7:58:52 PM3/7/18
to esprima
Hi everyone,

Is there a way of enforcing strict/non-strict mode when calling esprima.parse? I've been having issues with parsing test262 cases that are meant to be run in non-strict mode (trivial example: 'yield : 1;'). 

I've also noticed that the online parser changes mode depending on what the code is - if I type 'eval = 42', it seems to run in non-strict and passes, but if I type 'eval = 42; yield : 1', it switches to strict and gives back the message ''Error: Line 1: Assignment to eval or arguments is not allowed in strict mode".

Many thanks,
Petar

Ariya Hidayat

unread,
Mar 8, 2018, 12:43:27 AM3/8/18
to esp...@googlegroups.com

Currently there is no such strict/non-strict mode initial enforcement. Also, whenever possible, use parseScript and parseModule: http://esprima.readthedocs.io/en/latest/syntactic-analysis.html#distinguishing-a-script-and-a-module.

The online parser demo is not for power users. It currently tries to guess the input (script vs module) and indirectly impact the strictness (but that's not the intention) and hence it may be confusing at times.

Thank you!



--
Ariya Hidayat, https://ariya.io

Petar Maksimovic

unread,
Mar 8, 2018, 9:33:32 AM3/8/18
to esp...@googlegroups.com
Thanks for your answer. From that, I gather that the current way to enforce strict mode evaluation would be to add "use strict;" to the code that I would like to parse, and otherwise it would be parsed in non-strict?

Finally, I've raised an issue about how yield is parsed, I believe there's a discrepancy with respect to the ECMAScript specification.

--
You received this message because you are subscribed to a topic in the Google Groups "esprima" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/esprima/AVHw9DoSvyc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to esprima+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ariya Hidayat

unread,
Mar 8, 2018, 11:28:38 AM3/8/18
to esp...@googlegroups.com

Yes, prefixing the code with "use strict" will guarantee the initial strict mode. Make sure you use parseScript and not parseModule.

If you encounter a buggy behavior of Esprima parser, feel free to file it on the issue tracker. Thank you very much!
Reply all
Reply to author
Forward
0 new messages