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

@babel/plugin-proposal-optional-chaining@7.0.0 compilation fails on expression that chains a function call with a chained argument #9012

Closed
matthewadams opened this issue Nov 10, 2018 · 3 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@matthewadams
Copy link

Bug Report

Current Behavior
Compilation fails on a legal optional chaining expression const transpileBug = (a, b) => a?.bar(b?.foo) with

ReferenceError: Container is falsy
    at NodePath._replaceWith (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/path/replacement.js:188:11)
    at NodePath.replaceWith (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/path/replacement.js:178:8)
    at optional (/Users/matthewadams/dev/node_modules/@babel/plugin-proposal-optional-chaining/lib/index.js:115:23)
    at PluginPass.OptionalCallExpression|OptionalMemberExpression (/Users/matthewadams/dev/node_modules/@babel/plugin-proposal-optional-chaining/lib/index.js:152:9)
    at newFn (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitMultiple (/Users/matthewadams/dev/node_modules/@babel/traverse/lib/context.js:85:17)

Input Code

const transpileBug = (a, b) => a?.bar(b?.foo)

// the following is a successful workaround:
const foo = b?.foo
const transpileBug2 = (a, b) => a?.bar(foo)

Expected behavior/code
The given expression should not cause compiler to fail.

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

{
  "name": "foobar",
  "version": "0.1.0-dev.0",
  "engines": {
    "node": ">=10.12.0"
  },
  "scripts": {
    "build": "run-s test",
    "transpile": "run-s transpile-main transpile-test",
    "transpile-main": "babel --delete-dir-on-start --verbose --out-dir lib/main --copy-files src/main",
    "transpile-test": "babel --delete-dir-on-start --verbose --out-dir lib/test --copy-files src/test",
    "unit-integration": "nyc -x 'lib/test' mocha --opts mocha.opts 'lib/test/unit/**/*.spec.js' 'lib/test/integration/**/*.spec.js'",
    "integration": "nyc -x 'lib/test' mocha --opts mocha.opts 'lib/test/integration/**/*.spec.js'",
    "i": "mocha --opts mocha.opts 'src/test/integration/**/*.spec.js' | npx bunyan",
    "unit": "nyc -x 'lib/test' mocha --opts mocha.opts 'lib/test/unit/**/*.spec.js'",
    "u": "mocha --opts mocha.opts 'src/test/unit/**/*.spec.js' | npx bunyan",
    "test": "run-s transpile unit-integration lint",
    "lint": "standard --verbose 'src/**/*.js'",
    "format": "standard --fix 'src/**/*.js'"
  },
  "dependencies": {
    "@babel/polyfill": "7.0.0",
    "bluebird": "3.5.2",
    "bunyan": "1.8.12",
    "bunyaner": "1.0.1",
    "config": "2.0.1",
    "enumify": "1.0.4",
    "firebase-admin": "6.0.0",
    "flaverr": "1.9.2",
    "lodash": "4.17.11",
    "moment": "2.22.2",
    "moment-timezone": "0.5.21",
    "mutrait": "1.0.0-pre.9",
    "recurrify": "0.1.0-pre.1",
    "uuid": "3.3.2"
  },
  "devDependencies": {
    "@babel/cli": "7.1.2",
    "@babel/core": "7.1.2",
    "@babel/plugin-proposal-class-properties": "7.1.0",
    "@babel/plugin-proposal-decorators": "7.1.2",
    "@babel/plugin-proposal-optional-chaining": "7.0.0",
    "@babel/preset-env": "7.1.0",
    "@babel/register": "7.0.0",
    "babel-eslint": "10.0.1",
    "chai": "4.2.0",
    "config-cev-generator": "0.1.6",
    "dirty-chai": "2.0.1",
    "firebase-tools": "5.1.1",
    "fs-extra": "7.0.0",
    "intercept-stdout": "0.1.2",
    "mocha": "5.2.0",
    "npm-run-all": "4.1.3",
    "nyc": "13.1.0",
    "standard": "12.0.1"
  },
  "babel": {
    "sourceMaps": "inline",
    "retainLines": true,
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": {
            "node": true
          }
        }
      ]
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-optional-chaining",
        {
          "loose": false
        }
      ],
      [
        "@babel/plugin-proposal-decorators",
        {
          "decoratorsBeforeExport": false
        }
      ],
      [
        "@babel/plugin-proposal-class-properties"
      ]
    ]
  },
  "standard": {
    "parser": "babel-eslint"
  }
}

Environment

  • Babel version(s): 7.1.2 (@babel/core 7.1.2)
  • Node/npm version: v10.12.0/6.4.1
  • OS: macOS Mojave 10.14.1
  • Monorepo: no
  • How you are using Babel: cli by running npm run transpile

Possible Solution

Additional context/Screenshots

@babel-bot
Copy link
Collaborator

Hey @matthewadams! 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.

@harsh-tamr
Copy link

I've also encountered this issue

@jridgewell
Copy link
Member

This was fixed by #9073, released in v7.2.0. Repl builds fine with current version.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants