Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messed up location in TemplateLiteral #167

Closed
jods4 opened this issue Jan 24, 2021 · 8 comments
Closed

Messed up location in TemplateLiteral #167

jods4 opened this issue Jan 24, 2021 · 8 comments

Comments

@jods4
Copy link

jods4 commented Jan 24, 2021

Open this in AST explorer:
https://astexplorer.net/#/gist/5456736625f73c2da2f35c1d2d7deca5/679cef422dad9ffff19e0894129d3f58ecb98740

The code is simply:

function f() {
  return `123456789${10}1234567890${20}`;
}

Now observe the loc of the TemplateLiteral and its quasis (the expressions seem ok).
TemplateLiteral.loc seem to start at the first expression hole.
Quasis loc end before they start, or are zero-length.

@fisker
Copy link
Collaborator

fisker commented Jan 25, 2021

I thought this was fixed? ff71744

I'm on cellphone, can't confirm.

The AST explorer version is old.

@jods4
Copy link
Author

jods4 commented Jan 25, 2021

You're right AST explorer is pretty old, which is quite inconvenient for testing and debugging :(

Based on the initial observations in my real program, it looked like the start of the TemplateLiteral seems to be at the first expression hole even in 4.0.0.

If you think this isn't the case I can debug further with my real program, I didn't notice AST Explorer was so old.

@3cp
Copy link
Member

3cp commented Jan 25, 2021

Yes, pls verify with latest meriyah locally.

@jods4
Copy link
Author

jods4 commented Jan 25, 2021

@3cp You can put the same code in there: https://meriyah.github.io/meriyah/
And the TemplateLiteral also supposedly starts at column 21, which matches the problems I observe on my machine :(

I also observed that if you remove the return, for some weird reason the starting column position is correct.

@KFlash
Copy link
Contributor

KFlash commented Jan 25, 2021

@jods This is JSX not template

@jods4
Copy link
Author

jods4 commented Jan 25, 2021

@KFlash I don't understand? I unchecked JSX and checked module in the left sidebar.

EDIT: I think I understand, you saw the default page content :)
This page doesn't seem to allow saving or direct linking specific code. You'll need to copy-paste the code from this issue into the page yourself.

(Also to whomever maintains this page: in AST explorer the ability to hover code and highlight AST -- and vice-versa -- is really handy.)

@KFlash
Copy link
Contributor

KFlash commented Jan 25, 2021

I did a comparison here. start & end values is off by 1 a few places,. I guess the whitespace screw this up.

Template tail start at 54 and end at 54. If you consume a backtick the end value should increase with +1. So the value should be 54 - 55.

Not sure about column values

@jods4
Copy link
Author

jods4 commented Jan 25, 2021

Here's an illustration of the problem:
image

3cp added a commit that referenced this issue Jan 28, 2021
@3cp 3cp closed this as completed in a893c16 Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants