Closed calico-crusade closed 4 months ago
Version
With which version did you encounter this behavior. Please check against 3.x beta if you haven't yet, it might have the fix already.
Version: 3.1.1 (Nuget) No beta version for 3.1.1
Describe the bug
Exception thrown: Esprima.ParserException: 'Line 1: Unexpected token' when attempting to use modules and evaluate
Esprima.ParserException: 'Line 1: Unexpected token'
To Reproduce
using Jint; const string MODULE = @"export const add = (a, b) => return a + b"; const string CODE = @"import { add } from 'maths'; return add(1, 2);"; var engine = new Engine(); engine.Modules.Add("maths", MODULE); var result = engine.Evaluate(CODE); Console.WriteLine("Result: " + result);
Expected behavior
Code should execute and output Result: 3
Result: 3
Additional context
Tested in versions 3.1.1 and 3.1.0 and neither worked.
Nevermind. Didn't read the discussions first!
For anyone else; Evaluate and Execute are not run in the scope of a module so it cannot access modules.
Evaluate
Execute
Examples of how to do it here
Version
With which version did you encounter this behavior. Please check against 3.x beta if you haven't yet, it might have the fix already.
Version: 3.1.1 (Nuget) No beta version for 3.1.1
Describe the bug
Exception thrown:
Esprima.ParserException: 'Line 1: Unexpected token'
when attempting to use modules and evaluateTo Reproduce
Expected behavior
Code should execute and output
Result: 3
Additional context
Tested in versions 3.1.1 and 3.1.0 and neither worked.