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

isCoalesce returns false on "return variable || defaultValue" #219

Closed
tarnowsc opened this issue Dec 10, 2015 · 2 comments
Closed

isCoalesce returns false on "return variable || defaultValue" #219

tarnowsc opened this issue Dec 10, 2015 · 2 comments
Assignees

Comments

@tarnowsc
Copy link

The method isCoalesce of BranchHelper class could be enhanced like that:

public boolean isCoalesce(AstNode node) {
        return node.getType() == Token.OR && (node.getParent().getType() == Token.ASSIGN || node.getParent().getType() == Token.VAR
                || node.getParent().getType() == Token.RETURN);
}
@tntim96 tntim96 self-assigned this Dec 10, 2015
@tntim96
Copy link
Owner

tntim96 commented Dec 10, 2015

Sure, so with this test case added to BranchHelperTest

    @Test
    public void shouldDetectCoalesceOnReturn() {
        String script = "function f(y) {return y || {};}";
        AstRoot astRoot = parser.parse(script, null, 1);
        AstNode orNode = NodeTestHelper.findNode(astRoot, Token.OR);
        assertThat(helper.isCoalesce(orNode), is(true));
    }

@tarnowsc
Copy link
Author

Works like a charm.

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

No branches or pull requests

2 participants