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

Breaking: syncing start/end with range (fixes #349) #461

Merged
merged 3 commits into from Apr 28, 2021

Conversation

anikethsaha
Copy link
Member

Syncing the range and loc with start and end for both program and templateElement nodes.

lib/espree.js Outdated Show resolved Hide resolved
lib/espree.js Outdated Show resolved Hide resolved
lib/espree.js Outdated Show resolved Hide resolved
@nzakas nzakas changed the title Fix: (Breaking) syncing range and loc with start/end (fixes #349) Breaking: syncing range and loc with start/end (fixes #349) Dec 4, 2020
@anikethsaha
Copy link
Member Author

Sorry for the delay,

I have update the code as suggested. Let me know if anything else is required to change.

@mdjermanovic mdjermanovic changed the title Breaking: syncing range and loc with start/end (fixes #349) Breaking: syncing start/end with range (fixes #349) Jan 12, 2021
Comment on lines +175 to +180
this[STATE].templateElements.forEach(templateElement => {
const terminalDollarBraceL = this.input.slice(templateElement.end, templateElement.end + 2) === "${";

templateElement.start--;
templateElement.end += (terminalDollarBraceL ? 2 : 1);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment about why we decided to modify start/end at this point instead of while finishing the node?

Comment on lines +82 to +84
const ast = espree.parse("/* foo */ bar /* baz */", {
range: true
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add another test like this for Program, but without range: true and loc: true?

Comment on lines +157 to +166
it("should output the same value for loc, range and start and end in templateElement", () => {
const ast = espree.parse("`foo ${bar}`;", {
ecmaVersion: 6
});

assert.strictEqual(ast.body[0].expression.quasis[0].start, 0);
assert.strictEqual(ast.body[0].expression.quasis[0].end, 7);
assert.strictEqual(ast.body[0].expression.quasis[1].start, 10);
assert.strictEqual(ast.body[0].expression.quasis[1].end, 12);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the title doesn't explain this test.

Comment on lines +144 to +155
it("should output the same value for loc, range and start and end in templateElement with loc and range", () => {
const ast = espree.parse("`foo ${bar}`;", {
ecmaVersion: 6,
loc: true,
range: true
});

assert.strictEqual(ast.body[0].expression.quasis[0].start, ast.body[0].expression.quasis[0].loc.start.column);
assert.strictEqual(ast.body[0].expression.quasis[0].end, ast.body[0].expression.quasis[0].loc.end.column);
assert.strictEqual(ast.body[0].expression.quasis[1].start, ast.body[0].expression.quasis[1].range[0]);
assert.strictEqual(ast.body[0].expression.quasis[1].end, ast.body[0].expression.quasis[1].range[1]);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a bit confusing, quasis[0] start/end is compared to loc only, while quasis[1] to range only.

@mdjermanovic
Copy link
Member

@anikethsaha are you still working on this?

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. I'll address the remaining comments in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants