Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

[bug] Missed token for regular expressions #22

Closed

Description

@EgorBu

Hi,
I found that token information for node with regexp is missed.
Code:

function addResponsiveClass(str) {
  return str.replace(/\<img/g, '<img class="img-responsive"');
}

Let's visualize code without nodes with tokens:

function __________________(___) {
  return ___._______(/\<img/g, _____________________________);
}

If we check the node with /\<img/g we will see:

internal_type: "RegExpLiteral"
properties {
  key: "flags"
  value: "g"
}
properties {
  key: "internalRole"
  value: "arguments"
}
properties {
  key: "pattern"
  value: "\\<img"
}
start_position {
  offset: 283
  line: 14
  col: 22
}
end_position {
  offset: 291
  line: 14
  col: 30
}
roles: EXPRESSION
roles: LITERAL
roles: REGEXP
roles: CALL
roles: ARGUMENT

I think this node should contain token with /\<img.

Activity

  1. dennwc commented on Nov 7, 2018

    @dennwc
    Member

    Blocked by bblfsh/sdk#318

  2. dennwc commented on Jan 3, 2019

    @dennwc
    Member

    Can confirm that it's related to an issue above. But if we can solve it right now if we duplicate some information in the node.

    For the context, the native AST node contains the following fields:

    • raw = /\<img/g (both regexp and the flag)
    • pattern = \<img (regexp only, unescaped)
    • flags = g (flag only)

    Right now we set @token to the regexp pattern (\<img) and leave flag (g) as a separate field. And it fails ML expectations.

    Instead, I will set the @token to the full regexp, while preserving pattern and flag fields separately.

  3. added 2 commits that reference this issue on Jan 3, 2019
    9bb1d02
    4e75d41
  4. added a commit that references this issue on Jan 22, 2019
    e2a484a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions