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

Incorrect line calculation after invalid escape sequence in tagged template #1275

Closed
fasttime opened this issue Feb 4, 2024 · 3 comments
Closed

Comments

@fasttime
Copy link

fasttime commented Feb 4, 2024

For example, in the following source, bar; is located on line 5:

foo`
\x

`;
bar;

But the parser seems to ignore the line breaks after the invalid escape sequence inside the template and makes it a 3:

// test.mjs
import { parse } from 'acorn';

const ast = parse(
    "foo`\n\\x\n\n`;\nbar;",
    { ecmaVersion: "latest", locations: true }
);

console.log(ast.body[1].loc);

The output is:

SourceLocation {
  start: Position { line: 3, column: 0 },
  end: Position { line: 3, column: 4 }
}
@marijnh
Copy link
Member

marijnh commented Feb 7, 2024

This patch should help here.

@fasttime
Copy link
Author

fasttime commented Feb 7, 2024

Thanks @marijnh, that was quick! But won't this patch still produce wrong line numbers for "\r\n" terminator sequences? E.g. "foo`\r\n\\x\r\n\r\n`;\r\nbar;".

@marijnh
Copy link
Member

marijnh commented Feb 7, 2024

You are entirely right. Attached patch should make that better.

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

2 participants