Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Wrong serialization order of Array.from() result #1962

Closed
gaearon opened this issue May 14, 2018 · 1 comment
Closed

Wrong serialization order of Array.from() result #1962

gaearon opened this issue May 14, 2018 · 1 comment

Comments

@gaearon
Copy link
Contributor

gaearon commented May 14, 2018

Serializer test:

function fn(arg) {
  if (!arg.condition) {
    return null;
  }

  var fooArr = Array.from(arg.foo);
  return arg.calculate(function() {
    return fooArr;
  });
}

if (global.__optimize) __optimize(fn);

inspect = function() {
  return JSON.stringify([
    fn({condition: false}),
    fn({
      condition: true,
      foo: 10,
      calculate(f) { return f().length; }
    }),
    fn({
      condition: true,
      foo: [1, 2, 3],
      calculate(f) { return f().length; }
    }),
  ])
}

Output:

var fn;
(function () {
  var _$5 = this;

  var _$6 = _$5.Object;
  var _$7 = _$6.assign;
  var _$8 = _$5.Array;
  var _$9 = _$8.from;

  var _1 = function (arg) {
    var _B = function () {
      return _C;
    };

    var _$0 = _$7(arg).condition;

    var _4 = !_$0;

    var _C = _4 ? void 0 : _$2; // <--------- _$2 is used before definition

    if (!_4) {
      var _$1 = _$7(arg).foo;

      var _$2 = _$9(_$1); // <---------- _$2 is defined

      var _$3 = _$7(arg).calculate;

      var _$4 = arg.calculate(_B);
    }

    return _4 ? null : _$4;
  };

  var _0 = function () {
    return JSON.stringify([fn({
      condition: false
    }), fn({
      condition: true,
      foo: 10,

      calculate(f) {
        return f().length;
      }

    }), fn({
      condition: true,
      foo: [1, 2, 3],

      calculate(f) {
        return f().length;
      }

    })]);
  };

  _$5.fn = _1;
  inspect = _0;
}).call(this);

This seems similar to #1924 but #1926 does not fix it. So I filed a separate issue.

facebook-github-bot pushed a commit that referenced this issue May 16, 2018
Summary:
Release notes: none

This is a follow up to the changes in #1926. This PR correctly fixes the derived values for waiting and ensures that the unknown array objects have their dependencies properly resolved. This fixes part of the issue in #1962, but it brought about another issue that this PR doesn't aim to solve – dependencies on an abstract function call's unbound/bound bindings.
Closes #1970

Differential Revision: D8024402

Pulled By: trueadm

fbshipit-source-id: b9f9e725b7b22241209ef5a6f3b29dc0f2eeddeb
@gaearon
Copy link
Contributor Author

gaearon commented May 21, 2018

The Array.from-specific part has been fixed in #1970.
The remaining issue is tracked as #1973 (and might be "by design").

@gaearon gaearon closed this as completed May 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant