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

test: Add tests for duplicate private methods (early-errors) #1769

Merged
merged 2 commits into from
Sep 18, 2018

Conversation

mkubilayk
Copy link
Contributor

@mkubilayk mkubilayk commented Sep 16, 2018

Adds tests for duplicate private methods according to the test plan posted in #1343.

Valid Case Description
🔴 grammar-privatemeth-duplicate-meth-meth Cannot have multiple private methods with the same name
🔴 grammar-privatemeth-duplicate-meth-get Cannot have a private method and a private getter with the same name
🔴 grammar-privatemeth-duplicate-meth-set Cannot have a private method and a private setter with the same name
🔴 grammar-privatemeth-duplicate-get-get Cannot have multiple private getters with the same name
🔴 grammar-privatemeth-duplicate-set-set Cannot have multiple private setters with the same name
grammar-privatemeth-duplicate-get-set Can have a private getter and a private setter with the same name
🔴 grammar-privatemeth-duplicate-meth-field Cannot have a private method and a private field with the same name
🔴 grammar-privatemeth-duplicate-get-field Cannot have a private getter and a private field with the same name
🔴 grammar-privatemeth-duplicate-set-field Cannot have a private setter and a private field with the same name
🔴 grammar-privatemeth-duplicate-meth-staticmeth Cannot have a private method and a private static method with the same name
🔴 grammar-privatemeth-duplicate-meth-staticfield Cannot have a private method and a private static field with the same name
grammar-privatemeth-duplicate-meth-nestedclassmeth Nested class can shadow private methods

@littledan Could you please have a look and see if I missed anything? One thing I wasn't clear is whether we can have a private getter/setter and a private field with the same name.

class C {
   #x;

   get #x() {} 
}

I can add a test for this if you tell me what the correct behavior should be.


Tracking Issue: #1343
cc: @jbhoosreddy

@littledan
Copy link
Member

Yes, that last sample would be invalid as well. Is there anything about the specification that makes this ambiguous?

@mkubilayk
Copy link
Contributor Author

On a second look, it is clear in the spec. My bad. I will add a test for that. Thanks for the answer!

@mkubilayk
Copy link
Contributor Author

Added tests for that.

@jbhoosreddy
Copy link
Contributor

I think in the contributing docs it says we should not PR the generated tests

@mkubilayk
Copy link
Contributor Author

You are right. However, #1761 includes them.

@leobalter @rwaldron: Should I remove generated tests?

Copy link
Contributor

@jbhoosreddy jbhoosreddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


//- elements
get #m() {}
set #m() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to produce an unexpected SyntaxError. There is no grammar that allows writing a set accessor method definition without a formal parameter.

MethodDefinition :
    set PropertyName ( PropertySetParameterList ) { FunctionBody }

PropertySetParameterList :
    FormalParameter

FormalParameter :
    BindingElement

BindingElement :
    SingleNameBinding

SingleNameBinding :
    BindingPattern Initializer opt

BindingIdentifier :
    Identifier

Identifier :
    IdentifierName but not ReservedWord

// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: It's a SyntaxError if a class contains a private method and a private static field with the same name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this surprising and potentially unintended. I'm going to open an issue in the relevant proposals to determine if these semantics are intended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've verified that this is intentional here: tc39/proposal-private-methods#46

// This code is governed by the BSD license found in the LICENSE file.

/*---
desc: It's a SyntaxError if a class contains a private method and a private static method with the same name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above


//- elements
set #m() {}
set #m() {}
Copy link
Contributor

@rwaldron rwaldron Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is additionally invalid for an unintended reason, see previous comment regarding PropertySetParameterList

@rwaldron
Copy link
Contributor

Should I remove generated tests?

Yes, generate the tests after the PR is approved.

@mkubilayk mkubilayk force-pushed the private-methods-duplicate branch from 2419054 to 090825b Compare September 17, 2018 19:59
@mkubilayk
Copy link
Contributor Author

@rwaldron thanks for the review. I removed generated tests and added missing parameters for the setters.

@rwaldron
Copy link
Contributor

Ok, now that review is complete and approved, please squash the first four commits (you can squash into as many commits as you'd like, but I think 2 makes sense here), then generate the tests and make a commit with just the generated tests. I will merge as soon as I can!

@mkubilayk mkubilayk force-pushed the private-methods-duplicate branch from 090825b to 375ae59 Compare September 17, 2018 20:53
@mkubilayk
Copy link
Contributor Author

@rwaldron done. Thanks again!

@rwaldron
Copy link
Contributor

Excellent, thanks!

@rwaldron rwaldron merged commit 395adc3 into tc39:master Sep 18, 2018
@mkubilayk mkubilayk deleted the private-methods-duplicate branch October 9, 2018 09:24
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 this pull request may close these issues.

4 participants