Navigation Menu

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

Properly serialize non-json values in parser tests #10858

Merged
merged 1 commit into from Dec 12, 2019

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 11, 2019

Q                       A
Fixed Issues? Follow up to #10854
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT
  1. I reused the same serialization logic used for BigInts also for RegExps
  2. I removed the .prototype.toJSON override hack and used the mysterious second parameter of JSON.stringify

Please disable whitespace diff while reviewing this PR.

@nicolo-ribaudo nicolo-ribaudo added area: tests PR: Internal 🏠 A type of pull request used for our changelog categories pkg: parser labels Dec 11, 2019
}

return result;
fs.writeFileSync(test.expect.loc, JSON.stringify(ast, serialize, 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
consider explicitly specify the ReplaceFunction:

JSON.stringify(ast, (key, value) => serialize(value), 2)

@@ -221,22 +189,43 @@ function runTest(test, parseFunction) {
}
}

function serialize(value) {
function serialize(key, value) {
if (typeof value === "bigint") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it imply that the serialization result is dependent on node versions? Because BigInt is not supported in Node.js 6 and 8.

I am surprised that they do not bail.

Copy link
Member Author

Choose a reason for hiding this comment

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

When the AST should contain a bigint, null is used instead. For this reason, I made the serialisation dependent on BigInt support.

This is also true before this PR: if you delete packages/babel-parser/test/fixtures/estree/bigInt/basic/output.json and run the tests on node 6, you'll get a different output.

@nicolo-ribaudo nicolo-ribaudo merged commit 8732203 into babel:master Dec 12, 2019
@nicolo-ribaudo nicolo-ribaudo deleted the parser-tests-serialize branch December 12, 2019 09:20
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: tests outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants