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

Whitespace following <:Window/> #943

Closed
Rich-Harris opened this issue Nov 23, 2017 · 0 comments · Fixed by #946
Closed

Whitespace following <:Window/> #943

Rich-Harris opened this issue Nov 23, 2017 · 0 comments · Fixed by #946

Comments

@Rich-Harris
Copy link
Member

Fairly minor issue, but whereas this code...

<!-- a comment -->

<p>whitespace before this element is ignored</p>

...is compiled to this...

function create_main_fragment(state, component) {
  var p;

  return {
    c: function create() {
      p = createElement("p");
      p.textContent = "whitespace before this element is ignored";
    },

    m: function mount(target, anchor) {
      insertNode(p, target, anchor);
    },

    p: noop,

    u: function unmount() {
      detachNode(p);
    },

    d: noop
  };
}

...this code...

<:Window bind:scrollX/>

<p>whitespace before this element is NOT ignored</p>

...is compiled to this:

function create_main_fragment(state, component) {
  var window_updating = false, text, p;

  function onwindowscroll(event) {
    window_updating = true;

    component.set({
      scrollX: this.scrollX
    });
    window_updating = false;
  };
  window.addEventListener("scroll", onwindowscroll);

  component.observe("scrollX", function(x) {
    if (window_updating) return;
    window.scrollTo(x, window.scrollY);
  });

  return {
    c: function create() {
      text = createText("\n\n");
      p = createElement("p");
      p.textContent = "whitespace before this element is NOT ignored";
    },

    m: function mount(target, anchor) {
      insertNode(text, target, anchor);
      insertNode(p, target, anchor);
    },

    p: noop,

    u: function unmount() {
      detachNode(text);
      detachNode(p);
    },

    d: function destroy() {
      window.removeEventListener("scroll", onwindowscroll);
    }
  };
}

Note the text = createText("\n\n");, which also has to be mounted and detached etc.

Rich-Harris added a commit that referenced this issue Nov 23, 2017
remove whitespace around <:Window/>
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

Successfully merging a pull request may close this issue.

1 participant