tree-sitter-cli icon indicating copy to clipboard operation
tree-sitter-cli copied to clipboard

Use Object cast for safe property access

Open maxnordlund opened this issue 7 years ago • 2 comments

Without these you'll get one of these errors TypeError: Cannot read property 'constructor' of undefined or TypeError: Cannot read property 'constructor' of null.

maxnordlund avatar Nov 03 '18 15:11 maxnordlund

Oh thanks for catching that; that's a really bad error message.

Regarding the implementation, it seems a bit more straightforward to just explicitly check for value is null (or undefined)

if (value == null) {
  throw new Error('Missing rule value');
}

switch (value.constructor) {
  // ...
}

Thoughts?

maxbrunsfeld avatar Nov 21 '18 00:11 maxbrunsfeld

Yes, that's a good idea. But I didn't want to change anything, especially not throw new errors.

But if you think it's better I can change it.

maxnordlund avatar Nov 21 '18 09:11 maxnordlund