Skip to content

Certain combinations of indentation will lead to incorrect placement of calls #3910

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
joepie91 opened this issue Mar 23, 2015 · 1 comment
Closed

Comments

@joepie91
Copy link

I've been working with a lot of functional constructs today, and I've now run into the same indentation issue twice. The below example shows the simplest case I've run into. I am not sure where the problem is being caused, and being unfamiliar with the Coffeescript internals, I am unable to reduce the testcase further.

Note the different placement in the JS of profile.images = vs profile.tags =, despite them being in conceptually the same place in the CS source. The former interpretation is as intended (and as it is normally interpreted).

Interpreting the profile.tags = statement one tab further 'solves' the issue in that it results in the correct interpretation, but obviously this is not a good idea :)

Source:

# Does not bug:
        $ "#result-images"
            .each ->
                # Poor quality Google Images thumbnails, but eh. It'll do.
                profile.images ?= []

                imageList = $ this
                    .find ".img-info-link img"
                    .map -> $(this).attr "src"
                    .get()

                profile.images = profile.images.concat imageList

# Bugs:
        $ "#result-tags"
            .each ->
                profile.tags ?= []

                tagList = $ this
                    .find ".tag"
                    .map ->
                        tagName = $ this
                            .children "a.tag-link"
                            .text()
                            .trim()

                        tagSources = $ this
                            .find ".tag-source a"
                            .map -> $(this).attr "href"
                            .get()

                        {name: tagName, sources: tagSources}
                    .get()

                profile.tags = profile.tags.concat tagList

Compiled JS:

// Generated by CoffeeScript 1.9.1
(function() {
  $("#result-images").each(function() {
    var imageList;
    if (profile.images == null) {
      profile.images = [];
    }
    imageList = $(this).find(".img-info-link img").map(function() {
      return $(this).attr("src");
    }).get();
    return profile.images = profile.images.concat(imageList);
  });

  $("#result-tags").each(function() {
    var tagList;
    if (profile.tags == null) {
      profile.tags = [];
    }
    return tagList = $(this).find(".tag").map(function() {
      var tagName, tagSources;
      tagName = $(this).children("a.tag-link").text().trim();
      tagSources = $(this).find(".tag-source a").map(function() {
        return $(this).attr("href");
      }).get();
      return {
        name: tagName,
        sources: tagSources
      };
    }).get();
  });

  profile.tags = profile.tags.concat(tagList);

}).call(this);
@vendethiel
Copy link
Collaborator

duplicate of #3866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants