@samitouri / QOS-React-2 / commits / ed9ea81e4a

Snap/sprout use new pragma parser and compiler defaults

Updates Snap and Sprout to use the new pragma parser, which also means they will always use the same default flags as the compiler itself sets. A side benefit of this is that you no longer need to rebuild snap/sprout to update their flags, since they will take flags from the version of the compiler being executed.

Joe Savona committed Oct 5, 2023 at 10:57 UTC ed9ea81e4a73b02bf138508b4c4ec6acf71b9676
37 files changed +80 -78
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/disable-jsx-memoization.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @memoizeJsxElements false
5 +// @memoizeJsxElements:false
6 function Component(props) {
7 const [name, setName] = useState(null);
8 const onChange = function (e) {
@@ -26,7 +26,7 @@ export const FIXTURE_ENTRYPOINT = {
26 ## Code
27
28 ```javascript
29 -import { unstable_useMemoCache as useMemoCache } from "react"; // @memoizeJsxElements false
29 +import { unstable_useMemoCache as useMemoCache } from "react"; // @memoizeJsxElements:false
30 function Component(props) {
31 const $ = useMemoCache(1);
32 const [name, setName] = useState(null);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/disable-jsx-memoization.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @memoizeJsxElements false
1 +// @memoizeJsxElements:false
2 function Component(props) {
3 const [name, setName] = useState(null);
4 const onChange = function (e) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-validate-no-set-state-not-all-mutable-range-extensions-are-bad.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateNoSetStateInRender
6 function Component(props) {
7 const logEvent = useLogging(props.appId);
8 const [currentStep, setCurrentStep] = useState(0);
@@ -33,7 +34,7 @@ function Component(props) {
34 ## Error
35
36 ```
36 -[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (11:11)
37 +[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (12:12)
38 ```
39
40
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-validate-no-set-state-not-all-mutable-range-extensions-are-bad.js
+1
@@ -1,3 +1,4 @@
1 +// @validateNoSetStateInRender
2 function Component(props) {
3 const logEvent = useLogging(props.appId);
4 const [currentStep, setCurrentStep] = useState(0);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.expect.md
+1 -1
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @debug
5 +// @validateRefAccessDuringRender
6 function Component(props) {
7 const ref = useRef(null);
8 const value = ref.current;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @debug
1 +// @validateRefAccessDuringRender
2 function Component(props) {
3 const ref = useRef(null);
4 const value = ref.current;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-capture-func-passed-to-jsx.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateFrozenLambdas
6 function component(a, b) {
7 let y = { b };
8 let z = { a };
@@ -20,7 +21,7 @@ function component(a, b) {
21 ## Error
22
23 ```
23 -[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (8:8)
24 +[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (9:9)
25 ```
26
27
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-capture-func-passed-to-jsx.js
+1
@@ -1,3 +1,4 @@
1 +// @validateFrozenLambdas
2 function component(a, b) {
3 let y = { b };
4 let z = { a };
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-conditionally-mutable-lambda.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateFrozenLambdas
6 function Component(props) {
7 const x = {};
8 let fn;
@@ -25,7 +26,7 @@ function Component(props) {
26 ## Error
27
28 ```
28 -[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (15:15)
29 +[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (16:16)
30 ```
31
32
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-conditionally-mutable-lambda.js
+1
@@ -1,3 +1,4 @@
1 +// @validateFrozenLambdas
2 function Component(props) {
3 const x = {};
4 let fn;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-mutable-lambda-mutate-local.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateFrozenLambdas
6 function Component(props) {
7 const x = {};
8 const onChange = (e) => {
@@ -18,7 +19,7 @@ function Component(props) {
19 ## Error
20
21 ```
21 -[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (8:8)
22 +[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (9:9)
23 ```
24
25
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-mutable-lambda-mutate-local.js
+1
@@ -1,3 +1,4 @@
1 +// @validateFrozenLambdas
2 function Component(props) {
3 const x = {};
4 const onChange = (e) => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-mutable-lambda-reassign-local.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateFrozenLambdas
6 function Component(props) {
7 let x = "";
8 const onChange = (e) => {
@@ -16,7 +17,7 @@ function Component(props) {
17 ## Error
18
19 ```
19 -[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (6:6)
20 +[ReactForget] InvalidReact: This mutates a variable that is managed by React, where an immutable value or a function was expected (7:7)
21 ```
22
23
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-freeze-mutable-lambda-reassign-local.js
+1
@@ -1,3 +1,4 @@
1 +// @validateFrozenLambdas
2 function Component(props) {
3 let x = "";
4 const onChange = (e) => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateRefAccessDuringRender
6 function Component(props) {
7 const ref = useRef(null);
8 const x = foo(ref);
@@ -14,7 +15,7 @@ function Component(props) {
15 ## Error
16
17 ```
17 -[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at mutate? $21[6:8]:TObject<BuiltInUseRefId> (3:3)
18 +[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at mutate? $21[6:8]:TObject<BuiltInUseRefId> (4:4)
19 ```
20
21
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.js
+1
@@ -1,3 +1,4 @@
1 +// @validateRefAccessDuringRender
2 function Component(props) {
3 const ref = useRef(null);
4 const x = foo(ref);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.expect.md
+1 -1
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @debug
5 +// @validateRefAccessDuringRender
6 function Component(props) {
7 const ref = useRef(null);
8 const renderItem = (item) => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @debug
1 +// @validateRefAccessDuringRender
2 function Component(props) {
3 const ref = useRef(null);
4 const renderItem = (item) => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-value-as-props.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateRefAccessDuringRender
6 function Component(props) {
7 const ref = useRef(null);
8 return <Foo ref={ref.current} />;
@@ -13,7 +14,7 @@ function Component(props) {
14 ## Error
15
16 ```
16 -[ReactForget] InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at freeze $19:TObject<BuiltInRefValue> (3:3)
17 +[ReactForget] InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at freeze $19:TObject<BuiltInRefValue> (4:4)
18 ```
19
20
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-value-as-props.js
+1
@@ -1,3 +1,4 @@
1 +// @validateRefAccessDuringRender
2 function Component(props) {
3 const ref = useRef(null);
4 return <Foo ref={ref.current} />;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-set-and-read-ref-during-render.expect.md
+3 -2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateRefAccessDuringRender
6 function Component(props) {
7 const ref = useRef(null);
8 ref.current = props.value;
@@ -14,9 +15,9 @@ function Component(props) {
15 ## Error
16
17 ```
17 -[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at store $21[7:9]:TObject<BuiltInUseRefId> (3:3)
18 +[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at store $21[7:9]:TObject<BuiltInUseRefId> (4:4)
19
19 -[ReactForget] InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at freeze $24:TObject<BuiltInRefValue> (4:4)
20 +[ReactForget] InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at freeze $24:TObject<BuiltInRefValue> (5:5)
21 ```
22
23
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-set-and-read-ref-during-render.js
+1
@@ -1,3 +1,4 @@
1 +// @validateRefAccessDuringRender
2 function Component(props) {
3 const ref = useRef(null);
4 ref.current = props.value;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-unconditional-set-state-in-render.expect.md
+3 -2
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateNoSetStateInRender
6 function Component(props) {
7 const [x, setX] = useState(0);
8 const aliased = setX;
@@ -18,9 +19,9 @@ function Component(props) {
19 ## Error
20
21 ```
21 -[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (5:5)
22 -
22 [ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (6:6)
23 +
24 +[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (7:7)
25 ```
26
27
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-unconditional-set-state-in-render.js
+1
@@ -1,3 +1,4 @@
1 +// @validateNoSetStateInRender
2 function Component(props) {
3 const [x, setX] = useState(0);
4 const aliased = setX;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-use-ref-added-to-dep-without-type-info.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateRefAccessDuringRender
6 function Foo({ a }) {
7 const ref = useRef();
8 // type information is lost here as we don't track types of fields
@@ -21,7 +22,7 @@ function Foo({ a }) {
22 ## Error
23
24 ```
24 -[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at capture $29:TObject<BuiltInUseRefId> (4:4)
25 +[ReactForget] InvalidReact: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. (https://react.dev/reference/react/useRef). Cannot access ref object at capture $29:TObject<BuiltInUseRefId> (5:5)
26 ```
27
28
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-use-ref-added-to-dep-without-type-info.js
+1
@@ -1,3 +1,4 @@
1 +// @validateRefAccessDuringRender
2 function Foo({ a }) {
3 const ref = useRef();
4 // type information is lost here as we don't track types of fields
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-unconditional-set-state-lambda.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @validateNoSetStateInRender
6 function Component(props) {
7 let y = 0;
8 const [x, setX] = useState(0);
@@ -21,7 +22,7 @@ function Component(props) {
22 ## Error
23
24 ```
24 -[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (6:6)
25 +[ReactForget] InvalidReact: This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState) (7:7)
26 ```
27
28
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-unconditional-set-state-lambda.js
+1
@@ -1,3 +1,4 @@
1 +// @validateNoSetStateInRender
2 function Component(props) {
3 let y = 0;
4 const [x, setX] = useState(0);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-not-added-to-dep-2.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @validateRefAccessDuringRender false
5 function Foo({ a }) {
6 const ref = useRef();
7 const val = ref.current;
@@ -16,7 +15,7 @@ function Foo({ a }) {
15 ## Code
16
17 ```javascript
19 -import { unstable_useMemoCache as useMemoCache } from "react"; // @validateRefAccessDuringRender false
18 +import { unstable_useMemoCache as useMemoCache } from "react";
19 function Foo(t20) {
20 const $ = useMemoCache(4);
21 const { a } = t20;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-not-added-to-dep-2.js
-1
@@ -1,4 +1,3 @@
1 -// @validateRefAccessDuringRender false
1 function Foo({ a }) {
2 const ref = useRef();
3 const val = ref.current;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep-2.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @validateRefAccessDuringRender false
5 function Foo({ a }) {
6 const ref = useRef();
7 const x = { a, val: ref.current };
@@ -15,7 +14,7 @@ function Foo({ a }) {
14 ## Code
15
16 ```javascript
18 -import { unstable_useMemoCache as useMemoCache } from "react"; // @validateRefAccessDuringRender false
17 +import { unstable_useMemoCache as useMemoCache } from "react";
18 function Foo(t17) {
19 const $ = useMemoCache(4);
20 const { a } = t17;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep-2.js
-1
@@ -1,4 +1,3 @@
1 -// @validateRefAccessDuringRender false
1 function Foo({ a }) {
2 const ref = useRef();
3 const x = { a, val: ref.current };
compiler/packages/fixture-test-utils/src/compiler-utils.ts
+4 -42
@@ -2,6 +2,7 @@ import assert from "assert";
2 import type { runReactForgetBabelPlugin as RunReactForgetBabelPlugin } from "babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin";
3 import { CompilationMode } from "babel-plugin-react-forget/src/Entrypoint";
4 import type { Effect, ValueKind } from "babel-plugin-react-forget/src/HIR";
5 +import type { parseConfigPragma as ParseConfigPragma } from "babel-plugin-react-forget/src/HIR/Environment";
6
7 export function parseLanguage(source: string): "flow" | "typescript" {
8 return source.indexOf("@flow") !== -1 ? "flow" : "typescript";
@@ -11,6 +12,7 @@ export function transformFixtureInput(
12 input: string,
13 basename: string,
14 pluginFn: typeof RunReactForgetBabelPlugin,
15 + parseConfigPragmaFn: typeof ParseConfigPragma,
16 includeAst: boolean = false
17 ) {
18 // Extract the first line to quickly check for custom test directives
@@ -19,16 +21,8 @@ export function transformFixtureInput(
21 let language = parseLanguage(firstLine);
22 let gating = null;
23 let instrumentForget = null;
22 - let memoizeJsxElements = true;
23 - let enableAssumeHooksFollowRulesOfReact = false;
24 - let disableAllMemoization = false;
25 - let validateRefAccessDuringRender = true;
26 - let validateNoSetStateInRender = true;
24 let enableEmitFreeze = null;
25 let compilationMode: CompilationMode = "all";
29 - let enableForest = false;
30 - let enableMergeConsecutiveScopes = false;
31 - let bailoutOnHoleyArrays = false;
26
27 if (firstLine.indexOf("@compilationMode(annotation)") !== -1) {
28 assert(
@@ -57,37 +51,13 @@ export function transformFixtureInput(
51 importSpecifierName: "useRenderCounter",
52 };
53 }
60 - if (firstLine.includes("@memoizeJsxElements false")) {
61 - memoizeJsxElements = false;
62 - }
63 - if (firstLine.includes("@enableAssumeHooksFollowRulesOfReact true")) {
64 - enableAssumeHooksFollowRulesOfReact = true;
65 - }
66 - if (firstLine.includes("@disableAllMemoization true")) {
67 - disableAllMemoization = true;
68 - }
69 - if (firstLine.includes("@validateRefAccessDuringRender false")) {
70 - validateRefAccessDuringRender = false;
71 - }
72 - if (firstLine.includes("@validateNoSetStateInRender false")) {
73 - validateNoSetStateInRender = false;
74 - }
54 if (firstLine.includes("@enableEmitFreeze")) {
55 enableEmitFreeze = {
56 source: "react-forget-runtime",
57 importSpecifierName: "makeReadOnly",
58 };
59 }
81 - if (firstLine.includes("@enableForest true")) {
82 - enableForest = true;
83 - }
84 - if (firstLine.includes("@bailoutOnHoleyArrays")) {
85 - bailoutOnHoleyArrays = true;
86 - }
87 -
88 - if (firstLine.includes("@enableMergeConsecutiveScopes")) {
89 - enableMergeConsecutiveScopes = true;
90 - }
60 + const config = parseConfigPragmaFn(firstLine);
61
62 return pluginFn(
63 input,
@@ -95,6 +65,7 @@ export function transformFixtureInput(
65 language,
66 {
67 environment: {
68 + ...config,
69 customHooks: new Map([
70 [
71 "useFreeze",
@@ -124,17 +95,8 @@ export function transformFixtureInput(
95 },
96 ],
97 ]),
127 - enableAssumeHooksFollowRulesOfReact,
128 - disableAllMemoization,
129 - memoizeJsxElements,
130 - validateRefAccessDuringRender,
131 - validateFrozenLambdas: true,
132 - validateNoSetStateInRender,
98 enableEmitFreeze,
134 - enableMergeConsecutiveScopes,
99 assertValidMutableRanges: true,
136 - bailoutOnHoleyArrays,
137 - enableForest,
100 },
101 compilationMode,
102 logger: null,
compiler/packages/fixture-test-utils/src/constants.ts
+6
@@ -13,6 +13,12 @@ export const LOGGER_PATH = path.join(
13 "Utils",
14 "logger.js"
15 );
16 +export const PARSE_CONFIG_PRAGMA_PATH = path.join(
17 + process.cwd(),
18 + "dist",
19 + "HIR",
20 + "Environment.js"
21 +);
22 export const FIXTURES_PATH = path.join(
23 process.cwd(),
24 "src",
compiler/packages/snap/src/compiler-worker.ts
+7 -1
@@ -6,6 +6,7 @@
6 */
7
8 import type { runReactForgetBabelPlugin as RunReactForgetBabelPlugin } from "babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin";
9 +import type { parseConfigPragma as ParseConfigPragma } from "babel-plugin-react-forget/src/HIR/Environment";
10 import {
11 TestFixture,
12 transformFixtureInput,
@@ -39,6 +40,7 @@ export type TestResult = {
40 export async function compile(
41 compilerPath: string,
42 loggerPath: string,
43 + parseConfigPragmaPath: string,
44 fixture: TestFixture,
45 compilerVersion: number,
46 implicitDebugMode: boolean,
@@ -78,6 +80,9 @@ export async function compile(
80 runReactForgetBabelPlugin: typeof RunReactForgetBabelPlugin;
81 };
82 const { toggleLogging } = require(loggerPath);
83 + const { parseConfigPragma } = require(parseConfigPragmaPath) as {
84 + parseConfigPragma: typeof ParseConfigPragma;
85 + };
86
87 // only try logging if we filtered out all but one fixture,
88 // since console log order is non-deterministic
@@ -86,7 +91,8 @@ export async function compile(
91 code = transformFixtureInput(
92 input,
93 basename,
89 - runReactForgetBabelPlugin
94 + runReactForgetBabelPlugin,
95 + parseConfigPragma
96 ).code;
97 } catch (e) {
98 e.message = e.message.replace(/\u001b[^m]*m/g, "");
compiler/packages/snap/src/runner.ts
+8 -5
@@ -9,12 +9,14 @@ import watcher from "@parcel/watcher";
9 import chalk from "chalk";
10 import {
11 COMPILER_PATH,
12 - LOGGER_PATH,
13 - FIXTURES_PATH,
12 FILTER_FILENAME,
13 FILTER_PATH,
16 - readTestFilter,
14 + FIXTURES_PATH,
15 + LOGGER_PATH,
16 + PARSE_CONFIG_PRAGMA_PATH,
17 TestFilter,
18 + getFixtures,
19 + readTestFilter,
20 } from "fixture-test-utils";
21 import fs from "fs";
22 import invariant from "invariant";
@@ -26,9 +28,8 @@ import * as readline from "readline";
28 import ts from "typescript";
29 import yargs from "yargs";
30 import { hideBin } from "yargs/helpers";
29 -import { TestResult } from "./compiler-worker";
31 import * as compiler from "./compiler-worker";
31 -import { getFixtures } from "fixture-test-utils";
32 +import { TestResult } from "./compiler-worker";
33
34 const WORKER_PATH = require.resolve("./compiler-worker.js");
35
@@ -126,6 +127,7 @@ async function run(
127 .compile(
128 COMPILER_PATH,
129 LOGGER_PATH,
130 + PARSE_CONFIG_PRAGMA_PATH,
131 fixture,
132 compilerVersion,
133 filter?.debug ?? false,
@@ -142,6 +144,7 @@ async function run(
144 let output = await compiler.compile(
145 COMPILER_PATH,
146 LOGGER_PATH,
147 + PARSE_CONFIG_PRAGMA_PATH,
148 fixture,
149 compilerVersion,
150 filter?.debug ?? false,
compiler/packages/sprout/src/runner-worker.ts
+11 -4
@@ -5,24 +5,30 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 +import { NodePath, PluginItem, transformFromAstSync } from "@babel/core";
9 +import * as parser from "@babel/parser";
10 +import * as t from "@babel/types";
11 import type { runReactForgetBabelPlugin as RunReactForgetBabelPlugin } from "babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin";
12 +import type { parseConfigPragma as ParseConfigPragma } from "babel-plugin-react-forget/src/HIR/Environment";
13 import {
14 COMPILER_PATH,
15 + PARSE_CONFIG_PRAGMA_PATH,
16 parseLanguage,
17 TestFixture,
18 transformFixtureInput,
19 } from "fixture-test-utils";
15 -import { NodePath, PluginItem, transformFromAstSync } from "@babel/core";
20 import fs from "fs/promises";
17 -import * as parser from "@babel/parser";
18 -import * as t from "@babel/types";
19 -import { doEval, EvaluatorResult } from "./runner-evaluator";
21 import path from "path";
22 +import { doEval, EvaluatorResult } from "./runner-evaluator";
23
24 const { runReactForgetBabelPlugin } = require(COMPILER_PATH) as {
25 runReactForgetBabelPlugin: typeof RunReactForgetBabelPlugin;
26 };
27
28 +const { parseConfigPragma } = require(PARSE_CONFIG_PRAGMA_PATH) as {
29 + parseConfigPragma: typeof ParseConfigPragma;
30 +};
31 +
32 // TODO: save output in .sprout.md files
33 export type TestResult =
34 | {
@@ -118,6 +124,7 @@ function transformFixtureForget(
124 input,
125 filename,
126 runReactForgetBabelPlugin,
127 + parseConfigPragma,
128 true
129 );
130