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

External scope vars used in computed method key not captured where var with same name used inside method #102

Open
overlookmotel opened this issue Feb 11, 2021 · 5 comments
Labels
bug Something isn't working instrumentation Relates to instrumentation maybe fixed Maybe fixed but needs tests

Comments

@overlookmotel
Copy link
Owner

Input:

const x = 'q';
export default () => ( {
  [x](x) {
    return x;
  }
} );

Serialized output:

export default () => ({
  [x](x) {
    return x;
  }
});

The external scope var x with value 'q' has not been captured, so this serialized output will throw an error when run.

This is at least partly due to bug in Babel babel/babel#12790 but may also require a fix in Livepack's Babel plugin to correctly track what function the visitor is currently in while processing computed method keys.

@overlookmotel overlookmotel added the bug Something isn't working label Feb 11, 2021
@overlookmotel
Copy link
Owner Author

Babel bug babel/babel#12790 now fixed and fix is in latest Babel releases.

overlookmotel added a commit that referenced this issue Jul 27, 2021
This doesn't actually work yet due to #102.
@overlookmotel
Copy link
Owner Author

Uncomment these tests once this is fixed:

describe('defined in method key', () => {

overlookmotel added a commit that referenced this issue Jul 27, 2021
This doesn't actually work yet due to #102.
@overlookmotel overlookmotel added the instrumentation Relates to instrumentation label Sep 30, 2021
@overlookmotel
Copy link
Owner Author

This is at least partially solved after the bug fix in Babel. The example above does now serialize correctly.

However, does not work for this, arguments or super in computed method key.

@overlookmotel
Copy link
Owner Author

This may have been fixed by ebf9322. Need to check.

@overlookmotel
Copy link
Owner Author

overlookmotel commented Jan 27, 2022

These inputs are now serialized as expected:

const x = 'q';
let fn;
({
  [ fn = (0, () => x) ](x) {}
});
export default fn;
let fn;
(function() {
  ({
    [ fn = (0, () => [this, arguments]) ]() {}
  });
}).call( 1, 2, 3, 4 );
export default fn;
export default function() {
  return () => ({
    [ () => [this, arguments] ]() {}
  });
}.call(1, 2, 3, 4);
let fn;
class X {
  constructor() {
    ({
      [ fn = (0, () => super.toString) ]() {}
    });
  }
}
new X();
export default fn;
let fn;
({
  foo() {
    ({
      [ fn = (0, () => super.toString) ]() {}
    });
  }
}).foo();
export default fn;

Appears to be fixed. Leaving issue open as still need to write tests.

@overlookmotel overlookmotel added the maybe fixed Maybe fixed but needs tests label Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working instrumentation Relates to instrumentation maybe fixed Maybe fixed but needs tests
Projects
None yet
Development

No branches or pull requests

1 participant