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

switch to expr-eval for dynamic module #1729

Merged
merged 12 commits into from Feb 15, 2021
Merged

switch to expr-eval for dynamic module #1729

merged 12 commits into from Feb 15, 2021

Conversation

jywarren
Copy link
Member

Fixes #1728 by replacing eval() with expr-eval for mathematical expressions

@jywarren jywarren requested a review from a team as a code owner October 17, 2020 18:53
@gitpod-io
Copy link

gitpod-io bot commented Oct 17, 2020

@jywarren jywarren requested a review from a team as a code owner October 17, 2020 18:58
@harshkhandeparkar
Copy link
Member

It's breaking, I think we should do this in 3.6.1.

@harshkhandeparkar harshkhandeparkar added this to To Do in v3.7.0 Oct 17, 2020
@harshkhandeparkar harshkhandeparkar moved this from To Do to In Progress in v3.7.0 Oct 17, 2020
@jywarren
Copy link
Member Author

jywarren commented Oct 17, 2020 via email

@jywarren
Copy link
Member Author

I'm seeing some MinifyImage issues related to => the ES6 function syntax... odd.

@harshkhandeparkar
Copy link
Member

npm install must have bumped some of the deeper dependencies in the lockfile. This is the same reason that is causing the audits to fail...

@jywarren jywarren added this to the v3.7.0 milestone Oct 28, 2020
@jywarren
Copy link
Member Author

aha! also:

      throw new Error('parse error [' + coords.line + ':' + coords.column + ']: Expected ' + (value || type));
      ^
Error: parse error [1:6]: Expected EOF
    at ParserState.expect (/home/travis/build/publiclab/image-sequencer/node_modules/expr-eval/dist/bundle.js:1049:13)
    at Parser.parse (/home/travis/build/publiclab/image-sequencer/node_modules/expr-eval/dist/bundle.js:1772:17)
    at Function.Parser.parse (/home/travis/build/publiclab/image-sequencer/node_modules/expr-eval/dist/bundle.js:1784:25)
    at generator (/home/travis/build/publiclab/image-sequencer/src/modules/Dynamic/Module.js:9:1245)
    at /home/travis/build/publiclab/image-sequencer/src/modules/Dynamic/Module.js:9:1952
    at Array.forEach (<anonymous>)
    at Object.draw (/home/travis/build/publiclab/image-sequencer/src/modules/Dynamic/Module.js:9:1505)
    at drawStep (/home/travis/build/publiclab/image-sequencer/src/Run.js:9:2704)
    at drawSteps (/home/travis/build/publiclab/image-sequencer/src/Run.js:9:3842)
    at Run (/home/travis/build/publiclab/image-sequencer/src/Run.js:9:4953)

@harshkhandeparkar harshkhandeparkar removed this from the v3.7.0 milestone Nov 2, 2020
@jywarren
Copy link
Member Author

Now the only error seems to be:

> TEST=true istanbul cover tape test/core/*.js test/core/ui/user-interface.js test/core/modules/*.js | tap-spec;

    Failed to parse file: /home/runner/work/image-sequencer/image-sequencer/src/modules/MinifyImage/Module.js
Transformation error; return original code
Error: Line 67: Unexpected token =>

which is an ES6 issue.

Sorry, that's not an issue here, that occurs in main branch too and i made an issue: #1810

OK, so what else in that test run?

  dynamic module works correctly with different options


    ✖ dynamic module works correctly with initial option undefined
    ---------------------------------------------------------------
      operator: equal
      expected: true
      actual:   false
      at: Immediate._onImmediate (/home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/lib/utils.js:75:17)
      stack: |-
  Error: dynamic module works correctly with initial option undefined
  at Test.assert [as _assert] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:228:54)
  at Test.bound [as _assert] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:80:32)
  at Test.equal (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:389:10)
  at Test.bound [as equal] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:80:32)
  at /home/runner/work/image-sequencer/image-sequencer/test/core/templates/options-test.js:40:11
  at /home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/index.js:183:13
  at Immediate._onImmediate (/home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/lib/utils.js:75:17)
  at processImmediate (internal/timers.js:461:21)


    ✖ dynamic module works correctly when the option is changed to undefined
    -------------------------------------------------------------------------
      operator: equal
      expected: true
      actual:   false
      at: Immediate._onImmediate (/home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/lib/utils.js:75:17)
      stack: |-
  Error: dynamic module works correctly when the option is changed to undefined
  at Test.assert [as _assert] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:228:54)
  at Test.bound [as _assert] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:80:32)
  at Test.equal (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:389:10)
  at Test.bound [as equal] (/home/runner/work/image-sequencer/image-sequencer/node_modules/tape/lib/test.js:80:32)
  at /home/runner/work/image-sequencer/image-sequencer/test/core/templates/options-test.js:57:13
  at /home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/index.js:183:13
  at Immediate._onImmediate (/home/runner/work/image-sequencer/image-sequencer/node_modules/looks-same/lib/utils.js:75:17)
  at processImmediate (internal/timers.js:461:21)

Let's see if it passed earlier tests. Maybe our new expr-eval doesn't handle undefineds and we need to screen.

@jywarren jywarren requested a review from a team as a code owner February 15, 2021 17:10
@jywarren
Copy link
Member Author

This looks like it could be a similar issue as @blurry-x-face faced using looks-same, as I can't see any other reason it'd be different. The test that's failing is this, and we haven't changed much before/after:

looksSame(result, benchmark[0], function(err, res) {
if (err) console.log(err);
t.equal(res.equal, true, `${moduleName} module works correctly with initial option ${options[0]}`);
});

Although perhaps it's that the expr-eval package is generating a function differently. Let me add a test for that.

@jywarren
Copy link
Member Author

OK, got it - this implementation didn't work, the generator function outputs:

> generator('B+B')+''
'function () {\n      return f.apply(expr, arguments);\n    }'

@jywarren
Copy link
Member Author

OK it was struggling with undefineds in let expr = Parser.parse('R = r; G = g; B = b; A = a; ' + expression); so i'll just copy the options rather than try to assign them within the expression

@jywarren
Copy link
Member Author

Nice! @harshkhandeparkar got this to work!!!

@jywarren jywarren merged commit 4609d0a into main Feb 15, 2021
v3.7.0 automation moved this from In Progress to Done Feb 15, 2021
@harshkhandeparkar
Copy link
Member

Wow! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
v3.7.0
  
Done
Development

Successfully merging this pull request may close these issues.

CRITICAL: Dynamic module uses eval
2 participants