Skip to content

Commit

Permalink
chore: compact loc information in parser fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Mar 23, 2020
1 parent d23f0ae commit a3f5dcd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/babel-parser/test/helpers/runFixtureTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,23 @@ export function runThrowTestsWithEstree(fixturesPath, parseFunction) {
});
}

// compact loc properties into a single line
function compactFixture(jsonString) {
return jsonString.replace(
/"start": (\d+),\s+"end": (\d+),\s+"loc": \{\s+"start":\s\{\s+"line": (\d+),\s+"column": (\d+)\s+\},\s+"end":\s\{\s+"line": (\d+),\s+"column": (\d+)\s+\s+\}(?:,\s+"identifierName": "(\S)+")?\s+\}/gm,
(_, p1, p2, p3, p4, p5, p6, p7) => {
return (
`"start":${p1},"end":${p2},"loc":{"start":{"line":${p3},"column":${p4}},"end":{"line":${p5},"column":${p6}}` +
(p7 ? `,"identifierName":"${p7}"}` : "}")
);
},
);
}

function save(test, ast) {
fs.writeFileSync(
test.expect.loc,
JSON.stringify(ast, (k, v) => serialize(v), 2),
compactFixture(JSON.stringify(ast, (k, v) => serialize(v, k), 2)),
);
}

Expand Down

0 comments on commit a3f5dcd

Please sign in to comment.