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

Should grammar generation use eval? #386

Closed
jeromesimeon opened this issue Jul 9, 2019 · 2 comments
Closed

Should grammar generation use eval? #386

jeromesimeon opened this issue Jul 9, 2019 · 2 comments

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Jul 9, 2019

I'm wondering if there is a better way to load the Nearly parser generated from the template grammar.

In addition complicating the security analysis, the corresponding code seems also quite brittle:
https://github.com/accordproject/cicero/blob/f79abd8c37d01def5e3525270e3889dc5a405c3e/packages/cicero-core/src/parsermanager.js#L421

E.g., The reliance on the module variable seems to trip certain versions of Babel.
The generated code for @babel/[email protected], the generated code is the intended:

      const module = (cov_23ep5x5niw.s[152]++, {
        exports: {}
      });
      cov_23ep5x5niw.s[153]++;
      eval(grammarJs);
      cov_23ep5x5niw.s[154]++;
      return module.exports;

While with @babel/[email protected] the code escapes the module variable to _module so the grammar is not extracted properly:

      var _module = (cov_23ep5x5niw.s[152]++, {
        exports: {}
      });

      cov_23ep5x5niw.s[153]++;
      eval(grammarJs);
      cov_23ep5x5niw.s[154]++;
      return _module.exports;
@jeromesimeon
Copy link
Member Author

Note that there is an open issue on babel about this module question babel/babel#5718

@jeromesimeon
Copy link
Member Author

jeromesimeon commented Jul 5, 2020

The new parser no longer uses JavaScript eval for parser construction (or nearley for that matter)...

The corresponding module construction code is also gone.

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

No branches or pull requests

1 participant