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

Wrong directive #99

Closed
neumatho opened this issue Sep 30, 2020 · 1 comment
Closed

Wrong directive #99

neumatho opened this issue Sep 30, 2020 · 1 comment

Comments

@neumatho
Copy link

Hi,

If you parse the expression "valueOf" in __proto with the Directives option enabled, then a directive property is added to the ExpressionStatement node, which is wrong. The directive property should only be added for "use strict" literals.

Meriyah also adds a BinaryExpression in the expression property, which is not legal according to the AST specification for directives. See https://github.com/estree/estree/blob/master/es5.md#directive

For these two lines:

"use strict";
"valueOf" in __proto

the tree looks like:

{
  "type": "Program",
  "sourceType": "script",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "Literal",
        "value": "use strict",
        "raw": "\"use strict\""
      },
      "directive": "use strict"
    },
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "BinaryExpression",
        "left": {
          "type": "Literal",
          "value": "valueOf",
          "raw": "\"valueOf\""
        },
        "right": {
          "type": "Identifier",
          "name": "__proto"
        },
        "operator": "in"
      },
      "directive": "valueOf"    <!-- this one should be removed
    }
  ]
}

A fix could be that you in the parseDirective() function when checking for the directive option, also test the node type stored in expression variable and only add the directive property if it is a Literal.

-Thomas

@KFlash
Copy link
Contributor

KFlash commented Oct 4, 2020

cc @3cp @aladdin-add

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

No branches or pull requests

2 participants