esprima icon indicating copy to clipboard operation
esprima copied to clipboard

Should not allow duplicate exported names

Open ljqx opened this issue 5 years ago • 0 comments

Steps to reproduce

esprima.parse(`
export let a = '1';
export let a = '2';
`)

Expected output

Syntax error.

Actual output

{
  "type": "Program",
  "body": [
    {
      "type": "ExportNamedDeclaration",
      "declaration": {
        "type": "VariableDeclaration",
        "declarations": [
          {
            "type": "VariableDeclarator",
            "id": {
              "type": "Identifier",
              "name": "a"
            },
            "init": {
              "type": "Literal",
              "value": "1",
              "raw": "'1'"
            }
          }
        ],
        "kind": "let"
      },
      "specifiers": [],
      "source": null
    },
    {
      "type": "ExportNamedDeclaration",
      "declaration": {
        "type": "VariableDeclaration",
        "declarations": [
          {
            "type": "VariableDeclarator",
            "id": {
              "type": "Identifier",
              "name": "a"
            },
            "init": {
              "type": "Literal",
              "value": "2",
              "raw": "'2'"
            }
          }
        ],
        "kind": "let"
      },
      "specifiers": [],
      "source": null
    }
  ],
  "sourceType": "module"
}

Relevant references

The spec: https://tc39.es/ecma262/#sec-module-semantics-static-semantics-early-errors

It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.

ljqx avatar Dec 07 '20 06:12 ljqx