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

[CS2] fix for “do super in constructor” bug #4627

Merged
merged 2 commits into from
Aug 3, 2017

Conversation

zdenko
Copy link
Collaborator

@zdenko zdenko commented Jul 30, 2017

A small fix for the #4623 (do super in constructor)

class b extends a
  constructor: ->
    do super
b = class b extends a {
    constructor() {
      super();
    }
}

Copy link
Collaborator

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

Should use test instead of exec.

@zdenko
Copy link
Collaborator Author

zdenko commented Jul 30, 2017

I improved RegExp and used exec so I can catch whitespace between do and super, and return correct length.

@token 'CALL_START', '('
@token 'CALL_END', ')'
[input, sup] = regExSuper
return sup.length + 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

When would sup.length not be 5? And 3 is the length of do plus a space? What if someone types do super with two or more spaces between the words?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, 3 is the length of do plus a space.
The \s* in \s*super was added to catch all spaces between do and super.
So, when do is detected, the regex will match zero or more spaces before super, starting from third characters of current match e.g. do␣.

If you change line 144 in lexer to return 8 it will work for one space, but will fail when you add more spaces, e.g. do␣␣␣␣super.

@GeoffreyBooth GeoffreyBooth changed the title fix for " 'do super' in constructor" bug [CS2] fix for “do super in constructor” bug Aug 2, 2017
@GeoffreyBooth GeoffreyBooth added this to the 2.0.0 milestone Aug 2, 2017
@GeoffreyBooth
Copy link
Collaborator

Verified that this works with any number of whitespace characters between do and super.

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.

2 participants