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

Cannot read properties of null (reading 'type') #41

Open
mureinik opened this issue Nov 10, 2023 · 0 comments · May be fixed by #42
Open

Cannot read properties of null (reading 'type') #41

mureinik opened this issue Nov 10, 2023 · 0 comments · May be fixed by #42

Comments

@mureinik
Copy link

mureinik commented Nov 10, 2023

The defaultTraveler implicitly assumes that a node always has a value.

This is usually true, but no always.

Consider the following:
required dependencies from package.json:

  "dependencies": {
    "@babel/runtime": "^7.23.2",
    "acorn": "^8.11.2",
    "astravel": "^0.6.1"
  }
'use strict';

class MyClass {
    // property with no value - this may look odd, but it's valid syntax
    prop
};

const acorn = require('acorn');
const astravel = require('astravel');

const comments = []
const tree = acorn.parse(MyClass.toString(), {ecmaVersion: 2023, onComment: comments});
astravel.attachComments(tree, comments);

With the current astravel, this will error out:

/home/mureinik/src/git/test-astravel/node_modules/astravel/dist/require/defaultTraveler.js:23
    if (this[node.type]) {
                  ^

TypeError: Cannot read properties of null (reading 'type')
    at Object.go (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/defaultTraveler.js:23:19)
    at Object.MethodDefinition (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/defaultTraveler.js:356:10)
    at attachCommentsToNode (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/attachComments.js:70:25)
    at Object.Block (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/attachComments.js:90:3)
    at Object.go (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/defaultTraveler.js:24:22)
    at Object.ClassDeclaration (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/defaultTraveler.js:305:10)
    at attachCommentsToNode (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/attachComments.js:70:25)
    at Object.Block (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/attachComments.js:90:3)
    at Object.attachComments (/home/allon/src/git/test-astravel/node_modules/astravel/dist/require/attachComments.js:112:22)
    at Object.<anonymous> (/home/allon/src/git/test-astravel/index.js:13:10)
mureinik added a commit to mureinik/astravel that referenced this issue Nov 10, 2023
@mureinik mureinik linked a pull request Nov 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant