From 079cfe68bfa7ee04a90af69b6186097598b2e3ea Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 20 Dec 2022 16:27:11 -0800 Subject: [PATCH] Fix test262 preprocessor The test262 preprocessor was correctly running forget against all the functions in each test file, but it was incorrectly transforming the file contents overall. Previously we swapped the contents of the file for the transformed output of the last function, now we use the babel plugin to rewrite functions in place and keep the rest of the file intact. Of course, the tests that failed before still fail. But when we fix them the tests will work now. --- .../forget/scripts/test262-preprocessor.js | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/compiler/forget/scripts/test262-preprocessor.js b/compiler/forget/scripts/test262-preprocessor.js index db9353aabf..3d367bb02f 100644 --- a/compiler/forget/scripts/test262-preprocessor.js +++ b/compiler/forget/scripts/test262-preprocessor.js @@ -1,35 +1,16 @@ -const generate = require("@babel/generator").default; -const parser = require("@babel/parser"); -const traverse = require("@babel/traverse").default; -const run = require("../dist/CompilerPipeline").default; -const prettier = require("prettier"); +const BabelPluginReactForget = require("../dist/BabelPlugin").default; +const transformSync = require("@babel/core").transformSync; // Preprocessor that runs Forget on the test262 test prior to execution. Compilation errors short // circuit test execution and report an error immediately. module.exports = (test) => { try { - let codegenText = null; - // todo: replace with a better entrypoint - const sourceAst = parser.parse(test.contents, { - sourceFilename: test.file, - plugins: ["jsx"], + const generated = transformSync(test.contents, { + filename: test.file, + plugins: [BabelPluginReactForget], }); - traverse(sourceAst, { - FunctionDeclaration: { - enter(nodePath) { - const { ast } = run(nodePath); - codegenText = prettier.format( - generate(ast).code.replace("\n\n", "\n"), - { - semi: true, - parser: "babel-ts", - } - ); - }, - }, - }); - if (codegenText != null) { - test.contents = codegenText; + if (generated.code != null && generated.code !== "") { + test.contents = generated.code; } else { throw new Error("Codegen returned an empty string"); }