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.
Joe Savona committed
Dec 20, 2022 at 16:27 UTC
079cfe68bfa7ee04a90af69b6186097598b2e3ea
1 file changed
+7
-26
compiler/forget/scripts/test262-preprocessor.js
+7
-26
@@ -1,35 +1,16 @@
1
-const generate = require("@babel/generator").default;
2
-const parser = require("@babel/parser");
3
-const traverse = require("@babel/traverse").default;
4
-const run = require("../dist/CompilerPipeline").default;
5
-const prettier = require("prettier");
1
+const BabelPluginReactForget = require("../dist/BabelPlugin").default;
2
+const transformSync = require("@babel/core").transformSync;
3
4
// Preprocessor that runs Forget on the test262 test prior to execution. Compilation errors short
5
// circuit test execution and report an error immediately.
6
module.exports = (test) => {
7
try {
11
- let codegenText = null;
12
- // todo: replace with a better entrypoint
13
- const sourceAst = parser.parse(test.contents, {
14
- sourceFilename: test.file,
15
- plugins: ["jsx"],
8
+ const generated = transformSync(test.contents, {
9
+ filename: test.file,
10
+ plugins: [BabelPluginReactForget],
11
});
17
- traverse(sourceAst, {
18
- FunctionDeclaration: {
19
- enter(nodePath) {
20
- const { ast } = run(nodePath);
21
- codegenText = prettier.format(
22
- generate(ast).code.replace("\n\n", "\n"),
23
- {
24
- semi: true,
25
- parser: "babel-ts",
26
- }
27
- );
28
- },
29
- },
30
- });
31
- if (codegenText != null) {
32
- test.contents = codegenText;
12
+ if (generated.code != null && generated.code !== "") {
13
+ test.contents = generated.code;
14
} else {
15
throw new Error("Codegen returned an empty string");
16
}