Object Getter triggers yield to incorrectly parse as YieldExpression

Aperta
#1,982 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, typescript
Ambito
compilers

Direzione di ricerca

Inizia in parser.ts intorno alla riga 3257 e riproduci il problema con l’esempio esprima.parse fornito. Confronta l’AST risultante con l’output previsto, concentrandoti sul fatto che il parsing del getter lasci o meno context.allowYield modificato. È fatto quando il yield successivo è rappresentato come un Identifier e il getter continua a essere analizzato correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When any get property is encountered the context.allowYield property is set to false and not reverted after parsing the getter body. This results in any future yield to be parsed as a yield expression incorrectly.

esprima.parse(`
({get a(){}});
yield;
`)
Expected output
{
  "type": "Program",
  "sourceType": "script",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "ObjectExpression",
        "properties": [
          {
            "type": "Property",
            "key": {
              "type": "Identifier",
              "name": "a"
            },
            "computed": false,
            "kind": "get",
            "method": false,
            "shorthand": false,
            "value": {
              "type": "FunctionExpression",
              "id": null,
              "params": [],
              "body": {
                "type": "BlockStatement",
                "body": []
              },
              "generator": false,
              "async": false,
              "expression": false
            }
          }
        ]
      }
    },
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "Identifier",
        "name": "yield"
      }
    }
  ]
}
Actual output
{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "ObjectExpression",
                "properties": [
                    {
                        "type": "Property",
                        "key": {
                            "type": "Identifier",
                            "name": "a"
                        },
                        "computed": false,
                        "value": {
                            "type": "FunctionExpression",
                            "id": null,
                            "params": [],
                            "body": {
                                "type": "BlockStatement",
                                "body": []
                            },
                            "generator": false,
                            "expression": false,
                            "async": false
                        },
                        "kind": "get",
                        "method": false,
                        "shorthand": false
                    }
                ]
            }
        },
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "YieldExpression",
                "argument": null,
                "delegate": false
            }
        }
    ],
    "sourceType": "script"
}

This is pulled directly from everything.js

Using this file as and example, I was surprised that removing line 84 will cause this to parse differently as they are completely unrelated.

I believe the offending code is located on line 3257 of parser.ts.

I believe the correct path in the ecma262 spec for line 200 would be

  1. StatementListItem
  2. Statement
  3. ExpressionStatement
  4. Expression
  5. AssignmentExpression
  6. ConditionalExpression
  7. LogicalORExpression
  8. LogicalANDExpression
  9. BitwiseORExpression
  10. BitwiseXORExpression
  11. BitwiseANDExpression
  12. EqualityExpression
  13. RelationalExpression
  14. ShiftExpression
  15. AdditiveExpression
  16. MultiplicativeExpression
  17. ExponentiationExpression
  18. UnaryExpression
  19. UpdateExpression
  20. LeftHandSideExpression
  21. NewExpression
  22. MemberExpression
  23. PrimaryExpression
  24. IdentifierReference
  25. Identifier
Lingua principale
TypeScript
Stelle
7.1k
Fork
772
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jquery/esprima

Tutte le issue di jquery/esprima

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.