question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

incorrect arguments by default with `this`

See original GitHub issue

๐“ญ๐“ฎ๐“ฌ๐“ช๐“ฏ๐“ฏ๐“ฎ๐“ฒ๐“ท๐“ช๐“ฝ๐“ฎ is incorrectly transpiling my CoffeeScript input:

source

class Component extends React.PureComponent
  state: {intent: null, yearMonth: null}
  loadData: ({ intent = @state.intent, yearMonth = @state.yearMonth } = {}) =>
    @loadable.request =>
      Api.get '/admin/document_checks/stat_data', { yearMonth, intent }
        .then ({ stats, teams, operators }) => @setState { stats, teams, operators }

REPL

incorrect result (indentation issue is there too):

class Component extends React.PureComponent {
  // ...
  loadData({ intent = intent1, yearMonth = yearMonth1 } = {}) { // ๐Ÿ˜› UNDEF
    this.state = state; // ๐Ÿ˜› 
    this.intent = intent1; // ๐Ÿ˜›
    this.state = state1; // ๐Ÿ˜›
    this.yearMonth = yearMonth1; // ๐Ÿ˜›
    return this.loadable.request(() => {
      return Api.get('/admin/document_checks/stat_data', { yearMonth, intent })
        .then(({ stats, teams, operators }) => this.setState({ stats, teams, operators }));
  });
  }

expected:

class Component extends React.PureComponent {
  // ...
  loadData({ intent = this.state.intent, yearMonth = this.state.yearMonth } = {}) {
    return this.loadable.request(() => {
      return Api.get('/admin/document_checks/stat_data', { yearMonth, intent })
        .then(({ stats, teams, operators }) => this.setState({ stats, teams, operators }));
    });
  }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
eventualbuddhacommented, Feb 11, 2019

This definitely appears to be a bug. Hereโ€™s a minimal reproduction:

({ a = @a }) ->
(function({ a = a1 }) {
  this.a = a1;
});

I think the problem is that itโ€™s inspecting the whole subtree of nodes for default values to assign, when it shouldnโ€™t be doing so with the right hand side of the assignment. I donโ€™t know thatโ€™s the case, but thatโ€™s what it feels like. Iโ€™d be happy to review a PR to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Am I using default arguments incorrectly? - Stack Overflow
Default arguments go in the declaration. And to format the code, paste it in, don't put any backticks, highlight it all, and click...
Read more >
Incorrect handling of default arguments for type Type ... - GitHub
Consider a function which takes type and returns instance of that type. This is handled correctly by mypy: from typing import Type,ย ...
Read more >
Default function arguments are the devil โ€“ Arthur O'Dwyer
Conclusion: Default function arguments do not directly cause boolean parameter tarpits, but they make their pernicious effects worse. Booleanย ...
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
incorrect number of arguments for default constructor for ...
Hi All, I am getting this error for one of the Type defined as below create or replace TYPE CONTRACTOR_TYPE AS OBJECT (...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found