Skip to content

Generating super(...arguments) in constructor #11543

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

Closed
yulianovdey opened this issue Oct 11, 2016 · 5 comments
Closed

Generating super(...arguments) in constructor #11543

yulianovdey opened this issue Oct 11, 2016 · 5 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@yulianovdey
Copy link

Hello!

MR #10189 is causing an issue after I compile TypeScript with target set to es6 and run it through Babel using babel-preset-es2015-node4.

You can find a repro here. Test by running npm i && npm run compile && node dist/test.js. To summarize, the following code:

abstract class Base {
  public abstract myProperty: string;
}

class Child extends Base {
  myProperty = 'A value';
}

Results in an error:

super(...arguments);
      ^^^
SyntaxError: Unexpected token ...

Caused by the fact that spread is still being used in the constructor:

class Child extends Base {
    constructor() {
        super(...arguments);
        this.myProperty = 'A value';
    }
}

Not touching arguments is deliberate behavior on Babel's part, so I'm wondering if there is a way to make the change in #10189 more compatible with Node 4 without having to transpile to es5.

@DanielRosenwasser
Copy link
Member

@kittens @chancancode - I'm not sure why arguments is specifically not being touched here.

@DanielRosenwasser DanielRosenwasser added the Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. label Oct 11, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 11, 2016

this is valid ES6 code. spread operator is allowed on arguments as well. not sure how transforming the rest of the ES6 expressions but leaving ...arguments would be ok.

#10175 was mainly done to address emit quality for babel. i will let @chancancode reply.

@mhegazy mhegazy added Needs More Info The issue still hasn't been fully clarified and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Oct 11, 2016
@chancancode
Copy link
Contributor

Yes, it is valid ES6 code.

Since Babel has the ability to parse/compile that down to ES5 (meaning it understands the native syntax, and knows what to do if it decides the target platform doesn't support the native syntax), it seems like a bug in the babel-preset-es2015-node4 preset?

@yulianovdey
Copy link
Author

Thank you for your input guys. I found a relevant issue that was opened with Babel, maybe someone can provide more info there.

@mhegazy mhegazy added External Relates to another program, environment, or user action which we cannot control. and removed Needs More Info The issue still hasn't been fully clarified labels Oct 13, 2016
@yulianovdey
Copy link
Author

I was able to get some clarification on the Babel Slack. Usingtransform-es2015-classes seems to a requirement in this case because super is not a function and requires native spread.

Thanks again!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants