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

Unexpected private field #203

Closed
julianjensen opened this issue Feb 15, 2022 · 1 comment · Fixed by #210
Closed

Unexpected private field #203

julianjensen opened this issue Feb 15, 2022 · 1 comment · Fixed by #210

Comments

@julianjensen
Copy link

I get an error of Unexpected private field when using the super keyword in a class function with a private name. It works fine if the method is not private, i.e. no hash (#) in front of the method name. Here's a minimal example with a comparison to acorn.

import { parse } from 'meriyah';
import { parse as aparse } from 'acorn';

const test = `class A extends B
{
    #xyz()
    {
        super.abc();
    }
}
`;

console.log( `------------------------ ACORN` );
console.log( aparse( test, { ecmaVersion: 2022 }) );
console.log( `------------------------ MERIYAH` );
console.log( parse( test, { next: true }) );

which produces the following output:

------------------------ ACORN
Node {
  type: 'Program',
  start: 0,
  end: 66,
  body: [
    Node {
      type: 'ClassDeclaration',
      start: 0,
      end: 65,
      id: [Node],
      superClass: [Node],
      body: [Node]
    }
  ],
  sourceType: 'script'
}
------------------------ MERIYAH
file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:181
    throw new ParseError(parser.index, parser.line, parser.column, type, ...params);
          ^

ParseError [SyntaxError]: [5:14]: Unexpected private field
    at report (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:181:11)
    at parseSuperExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6090:17)
    at parsePrimaryExpression (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6355:20)
    at parseExpressionOrLabelledStatement (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:4935:20)
    at parseStatement (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:4920:20)
    at parseStatementListItem (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:4870:20)
    at parseFunctionBody (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6061:19)
    at parseMethodDefinition (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:6994:18)
    at parseClassElementList (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:8407:19)
    at parseClassBody (file:///home/.../project/node_modules/meriyah/dist/meriyah.esm.js:8285:19) {
  index: 51,
  line: 5,
  column: 14,
  description: '[5:14]: Unexpected private field',
  loc: { line: 5, column: 14 }
}
3cp added a commit that referenced this issue Mar 18, 2022
Also fixed the error message for invalid super call.

closes #203
@3cp 3cp closed this as completed in #210 Mar 18, 2022
@3cp
Copy link
Member

3cp commented Mar 31, 2022

Released v4.2.1.

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

Successfully merging a pull request may close this issue.

2 participants