Skip to content

Reading properties of JS values fails if value is undefined #87

@JohanWiltink

Description

@JohanWiltink
TypeError: Cannot read properties of null (reading 'term')
    at runEval (file:///workspace/node_modules/@codewars/lambda-calculus/src/lambda-calculus.js:395:20)
    at result (file:///workspace/node_modules/@codewars/lambda-calculus/src/lambda-calculus.js:336:16)

This error was encountered in this code in line 395 of runeval

        } else { // lastTerm is a JS function
          const res = lastTerm(term);
          if ( res.term ) {
            ({term, env} = res);
            if ( ! env ) env = new Env;
          } else
            term = res;
        }

res may be null or undefined, and res.term should be res?.term

Metadata

Metadata

Assignees

Labels

improvementImprove existing behaviour or code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions