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

[bug] Missed token for regular expressions #22

Closed
EgorBu opened this issue Jul 27, 2018 · 2 comments
Closed

[bug] Missed token for regular expressions #22

EgorBu opened this issue Jul 27, 2018 · 2 comments
Labels

Comments

@EgorBu
Copy link

EgorBu commented Jul 27, 2018

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.

@dennwc
Copy link
Member

dennwc commented Nov 7, 2018

Blocked by bblfsh/sdk#318

@dennwc
Copy link
Member

dennwc commented Jan 3, 2019

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.

dennwc pushed a commit to dennwc/javascript-driver that referenced this issue Jan 3, 2019
Signed-off-by: Denys Smirnov <denys@sourced.tech>
dennwc pushed a commit to dennwc/javascript-driver that referenced this issue Jan 3, 2019
Signed-off-by: Denys Smirnov <denys@sourced.tech>
dennwc pushed a commit to dennwc/javascript-driver that referenced this issue Jan 22, 2019
Signed-off-by: Denys Smirnov <denys@sourced.tech>
@dennwc dennwc closed this as completed in ecdce1f Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants