Skip to content

Babel 8 Beta 3: TypeError: Cannot read properties of null (reading 'isMethod') #17567

@coderaiser

Description

@coderaiser

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

import * as parser from "@babel/parser";
import traverse from "@babel/traverse";
import * as t from "@babel/types";

const code = `
    const a = {
        "files": [],
    }
`;

const ast = parser.parse(code, {
  sourceType: "module",
});

traverse(ast, {
  ObjectProperty(path) {
      traverse(path.node, {
          noScope: true,
          ArrayExpression(path) {
              console.log('x');
          }
      });
  }
});

Configuration file name

No response

Configuration

No response

Current and expected behavior

Current:

file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4955
  if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {
                                                                    ^

TypeError: Cannot read properties of null (reading 'isMethod')
    at NodePath.setScope (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4955:69)
    at NodePath.setContext (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4976:12)
    at NodePath.pushContext (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:5028:8)
    at _visitPaths (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4781:19)
    at _traverse (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4860:11)
    at traverseNode (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4875:12)
    at traverse (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:5106:3)
    at ObjectProperty (file:///Users/coderaiser/putout/1.mjs:17:7)
    at NodePath._call (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4896:20)
    at _visit (file:///Users/coderaiser/putout/node_modules/@babel/traverse/lib/index.js:4822:15)

Expected:

x

Environment

Babel 8 Beta 3

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions