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

Does not work when currency object is implicitly returned from another module / file #29

Open
tennox opened this issue May 21, 2020 · 3 comments

Comments

@tennox
Copy link

tennox commented May 21, 2020

When I define a class with a method that returns a currency object, this plugin doesn't know it's a currency object, as I don't explicitly create it in the same file.

I understand that this is hard to impossible to do in duck-typed Javascript, but it would be great to warn about this in the Readme!

@scurker
Copy link
Owner

scurker commented May 23, 2020

I'm not sure I follow. Do you have an example of what you're trying to do?

@tennox
Copy link
Author

tennox commented Jun 5, 2020

product.js

export class Product {
  getPrice() {
    return currency(123.4)
  }
}

something.js

const totalPrice = product.getPrice() * productAmount

@scurker
Copy link
Owner

scurker commented Jun 6, 2020

Ah yes, that makes sense. The transforms work with the expectation that the export is a currency object.

The easiest workaround here I could think of would be to include the quantity as part of the class:

export class Product {
  setQuantity(quantity) {
    this.quantity = quantity
  }
  getTotal() { 
    return currency(this.price) * this.total
  }
}

Right now, this babel transform looks just at variable assignment, but it's possible that method or function exports could be added as well.

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

No branches or pull requests

2 participants