Skip to content

Methods "is_a?", "kind_of?" and "instance_of?" do not support conditional chaining #222

@esb

Description

@esb

The methods is_a?, kind_of? and instance_of? can be used in a conditional chaining expression, but cannot be converted to an equivalent Javascript expression.

if event && event.is_a?(Event)
  puts "TEST"
end

if event&.is_a?(Event)
  puts "TEST"
end

if event && event.kind_of?(Event)
  puts "TEST"
end

if event&.kind_of?(Event)
  puts "TEST"
end
    
if event && event.instance_of?(Event)
  puts "TEST"
end
    
if event&.instance_of?(Event)
  puts "TEST"
end

This is translated to

if (event?.is_a?(Event)) console.log("TEST");
if (event?.is_a?(Event)) console.log("TEST");
if (event?.kind_of?(Event)) console.log("TEST");
if (event?.kind_of?(Event)) console.log("TEST");
if (event?.instance_of?(Event)) console.log("TEST");
if (event?.instance_of?(Event)) console.log("TEST");

The correct translation would be

if (event && (event instanceof Event)) console.log("TEST");
if (event && (event instanceof Event)) console.log("TEST");
if (event && (event instanceof Event)) console.log("TEST");
if (event && (event instanceof Event)) console.log("TEST");
if (event && (event.constructor == Event)) console.log("TEST");
if (event && (event.constructor == Event)) console.log("TEST");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions