Skip to content

esify assumes foo is defined with "for x, y of foo" #240

@WillsonSmith

Description

@WillsonSmith

Right now when translating a for of coffeescript loop, we use Object.entries(object) so:

for code, option of @selectedShipmentOptions[@rateCode]
  rows.push(Shopify.Templates.render(@shipmentOptionsTemplate, {
    optionName: option.name,
    optionPrice: @money(option.amount)
  }))

becomes

for (const [code, option] of Object.entries(this.selectedShipmentOptions[this.rateCode])) {
  rows.push(Templates.render(this.shipmentOptionsTemplate, {
    optionName: option.name,
    optionPrice: this.money(option.amount),
  }));
}

This assumes that this.selectedShipmentOptions[this.rateCode] is defined, but that is not always the case. Since this is how it is translated, Object.entries(undefined) throws. I can get around it by doing something like:

const selectedShipmentOption = this.selectedShipmentOptions[this.rateCode]) || {};
for (const [code, option] of Object.entries(selectedShipmentOption) {
...

but ideally this wouldn't be necessary.

@GoodForOneFare

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions