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

TypeError: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null at Object.validate #10335

Open
Scrum opened this issue Aug 14, 2019 · 5 comments

Comments

@Scrum
Copy link

commented Aug 14, 2019

Bug Report

Current Behavior
TypeError: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null at Object.validate

Input Code

class MyClass {
  constructor(element) {
    Object.assign(this, {element});
    this.element.addEventListener('change', ::this.#privateMethod)
  }
  #privateMethod(event) {
    console.log(event);
  }
}

Expected behavior/code
transpilation will happen without error

Babel Configuration (.babelrc, package.json, cli command)

const presets = [
    '@babel/preset-env'
];

const plugins = [
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-nullish-coalescing-operator',
    '@babel/plugin-proposal-function-bind',
    '@babel/plugin-proposal-private-methods'
]

module.exports = {presets, plugins};

Environment

  • Babel version(s):
    "@babel/core": "^7.4.3",
    "@babel/plugin-proposal-function-bind": "^7.2.0",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
    "@babel/plugin-proposal-optional-chaining": "^7.2.0",
    "@babel/plugin-proposal-pipeline-operator": "^7.5.0",
    "@babel/plugin-proposal-private-methods": "^7.4.4",
    "@babel/polyfill": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "babel-loader": "^8.0.5",
  • Node/npm version: Node 11.15.0/npm 6.7.0
  • OS: OSX 10.14.6
  • Monorepo: no
  • How you are using Babel: loader

Additional context/Screenshots

TypeError: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null at Object.validate (/home/ivan/Project/node_modules/@babel/types/lib/definitions/utils.js:129:13) at validate (/home/ivan/Project/node_modules/@babel/types/lib/validators/validate.js:17:9) at builder (/home/ivan/Project/node_modules/@babel/types/lib/builders/builder.js:46:27) at Object.AssignmentExpression (/home/ivan/Project/node_modules/@babel/types/lib/builders/generated/index.js:243:31) at inferBindContext (/home/ivan/Project/node_modules/@babel/plugin-proposal-function-bind/lib/index.js:63:42) at PluginPass.BindExpression (/home/ivan/Project/node_modules/@babel/plugin-proposal-function-bind/lib/index.js:89:25) at newFn (/home/ivan/Project/node_modules/@babel/traverse/lib/visitors.js:193:21) at NodePath._call (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:53:20) at NodePath.call (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:40:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:88:12) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:118:16) at TraversalContext.visitMultiple (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:85:17) at TraversalContext.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:144:19) at Function.traverse.node (/home/ivan/Project/node_modules/@babel/traverse/lib/index.js:94:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:95:18) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:118:16) at TraversalContext.visitSingle (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:90:19) at TraversalContext.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:146:19) at Function.traverse.node (/home/ivan/Project/node_modules/@babel/traverse/lib/index.js:94:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:95:18) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:118:16) at TraversalContext.visitMultiple (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:85:17) at TraversalContext.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:144:19) at Function.traverse.node (/home/ivan/Project/node_modules/@babel/traverse/lib/index.js:94:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:95:18) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:118:16) at TraversalContext.visitSingle (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:90:19) at TraversalContext.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:146:19) at Function.traverse.node (/home/ivan/Project/node_modules/@babel/traverse/lib/index.js:94:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:95:18) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:118:16) at TraversalContext.visitQueue (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:124:21) at TraversalContext.visitSingle (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:90:19) at TraversalContext.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/context.js:146:19) at Function.traverse.node (/home/ivan/Project/node_modules/@babel/traverse/lib/index.js:94:17) at NodePath.visit (/home/ivan/Project/node_modules/@babel/traverse/lib/path/context.js:95:18)
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Aug 14, 2019

Hey @Scrum! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@eventualbuddha

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

Here’s a minimal reproduction (repl):

class MyClass {
  constructor() {
    ::this.#a
  }
  #a() {}
}

If you remove the :: then it works fine. When you check “Time Travel” you can see the code right before it blows up:

function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }

class MyClass {
  constructor() {
    _a.add(this);

    ::_classPrivateMethodGet(this, _a, _a2);
  }

}

var _a = new WeakSet();

var _a2 = function _a2() {};

It makes sense that this would fail, though it doesn’t fail the same way as if you started with this code and then tried to transpile it.

@Scrum

This comment has been minimized.

Copy link
Author

commented Aug 15, 2019

I can use the declared binding method with the same success and this will work
this.element.addEventListener('change', this.#privateMethod.bind(this))

but I intentionally using the notation suggested in function-bind

@eventualbuddha

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

To be clear, I do think this is a Babel bug and not user error.

@JLHwung

This comment has been minimized.

Copy link
Contributor

commented Aug 15, 2019

function-bind is a Stage 0 proposal and is still subjected to possible dramatic changes. For example in an active issue people is proposing to drop unary binding operator ::object.func usage in favor of object.func.bind(object).

The supports to Stage-0 proposal transforms in Babel should be considered minimum, which means generally we would prioritize issues related to more mature proposals over the others. However, feel free to send a PR if you are interested at this issue and we are more than happy to work with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.