Skip to content

Commit

Permalink
chore: fix writing files in tools (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored Jun 18, 2024
1 parent c7584e4 commit ef88e37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tools/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import shelljs from "shelljs";
import { parse } from "../espree.js";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fs from "node:fs";

//------------------------------------------------------------------------------
// Initialization
Expand Down Expand Up @@ -119,11 +120,11 @@ code.forEach((source, index) => {

recursivelyRemoveStartAndEnd(result);

sourceCode.to(testSourceFilename);
fs.writeFileSync(testSourceFilename, sourceCode);

let resultCode = `export default ${JSON.stringify(result, (key, value) =>
((typeof value === "bigint") ? `bigint<${value}n>` : value), 4)};`;

resultCode = resultCode.replace(/"bigint<(\d+n)>"/gu, "$1");
resultCode.to(testResultFilename);
fs.writeFileSync(testResultFilename, resultCode);
});
5 changes: 3 additions & 2 deletions tools/update-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import shelljs from "shelljs";
import tester from "../tests/lib/tester.js";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fs from "node:fs";

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -54,7 +55,7 @@ function getLibraryFilenames(directory) {
* @returns {void}
*/
function outputResult(result, testResultFilename) {
`export default ${tester.getAstCode(result)};`.to(testResultFilename);
fs.writeFileSync(testResultFilename, `export default ${tester.getAstCode(result)};`);
}

//------------------------------------------------------------------------------
Expand All @@ -76,7 +77,7 @@ libraryFiles.forEach(filename => {
tokens: true
});

JSON.stringify(result).to(testResultFilename);
fs.writeFileSync(testResultFilename, JSON.stringify(result));
});

// update all tests in ecma-features
Expand Down

0 comments on commit ef88e37

Please sign in to comment.