Skip to content

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

Merged
GeoffreyBooth merged 2 commits into
jashkenas:2from
GeoffreyBooth:do-super
Aug 3, 2017
Merged

[CS2] fix for “do super in constructor” bug#4627
GeoffreyBooth merged 2 commits into
jashkenas:2from
GeoffreyBooth:do-super

Conversation

@zdenko

@zdenko zdenko commented Jul 30, 2017

Copy link
Copy Markdown
Collaborator

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

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

@GeoffreyBooth GeoffreyBooth left a comment

Copy link
Copy Markdown
Collaborator

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

zdenko commented Jul 30, 2017

Copy link
Copy Markdown
Collaborator Author

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

Comment thread src/lexer.coffee
@token 'CALL_START', '('
@token 'CALL_END', ')'
[input, sup] = regExSuper
return sup.length + 3

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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