diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.expect.md new file mode 100644 index 0000000000..0f9f6287d2 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.expect.md @@ -0,0 +1,30 @@ + +## Input + +```javascript +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsAnnotation() { + type Foo = Bar; + const fun = (f: Foo) => { + console.log(f); + }; + fun("hello, world"); +} + +``` + + +## Error + +``` + 3 | function TypeAliasUsedAsAnnotation() { + 4 | type Foo = Bar; +> 5 | const fun = (f: Foo) => { + | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (5:5) + 6 | console.log(f); + 7 | }; + 8 | fun("hello, world"); +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.js new file mode 100644 index 0000000000..748635b321 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-annotation_.flow.js @@ -0,0 +1,9 @@ +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsAnnotation() { + type Foo = Bar; + const fun = (f: Foo) => { + console.log(f); + }; + fun("hello, world"); +} diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.expect.md new file mode 100644 index 0000000000..ab781e8db9 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.expect.md @@ -0,0 +1,31 @@ + +## Input + +```javascript +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsAnnotation() { + type Foo = Bar; + const fun = (f) => { + let g: Foo = f; + console.log(g); + }; + fun("hello, world"); +} + +``` + + +## Error + +``` + 4 | type Foo = Bar; + 5 | const fun = (f) => { +> 6 | let g: Foo = f; + | ^^^ [ReactForget] Invariant: [hoisting] Expected value for identifier to be initialized. Foo$0 (6:6) + 7 | console.log(g); + 8 | }; + 9 | fun("hello, world"); +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.js new file mode 100644 index 0000000000..64966640a9 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.type-alias-used-as-variable-annotation_.flow.js @@ -0,0 +1,10 @@ +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsAnnotation() { + type Foo = Bar; + const fun = (f) => { + let g: Foo = f; + console.log(g); + }; + fun("hello, world"); +} diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.expect.md new file mode 100644 index 0000000000..02a31ec938 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.expect.md @@ -0,0 +1,44 @@ + +## Input + +```javascript +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsParamAnnotation() { + type Foo = Bar; + const fun = (f: Foo) => { + console.log(f); + }; + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsParamAnnotation, + params: [], +}; + +``` + +## Code + +```javascript +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsParamAnnotation() { + const fun = (f) => { + console.log(f); + }; + + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsParamAnnotation, + params: [], +}; + +``` + +### Eval output +(kind: ok) +logs: ['hello, world'] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.ts new file mode 100644 index 0000000000..d8eb6093d5 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-annotation.ts @@ -0,0 +1,14 @@ +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsParamAnnotation() { + type Foo = Bar; + const fun = (f: Foo) => { + console.log(f); + }; + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsParamAnnotation, + params: [], +}; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.expect.md new file mode 100644 index 0000000000..f97bcbb3a6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.expect.md @@ -0,0 +1,46 @@ + +## Input + +```javascript +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsVariableAnnotation() { + type Foo = Bar; + const fun = (f) => { + let g: Foo = f; + console.log(g); + }; + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsVariableAnnotation, + params: [], +}; + +``` + +## Code + +```javascript +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsVariableAnnotation() { + const fun = (f) => { + const g = f; + console.log(g); + }; + + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsVariableAnnotation, + params: [], +}; + +``` + +### Eval output +(kind: ok) +logs: ['hello, world'] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.ts new file mode 100644 index 0000000000..8b8b0bfb41 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-alias-used-as-variable-annotation.ts @@ -0,0 +1,15 @@ +// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +type Bar = string; +function TypeAliasUsedAsVariableAnnotation() { + type Foo = Bar; + const fun = (f) => { + let g: Foo = f; + console.log(g); + }; + fun("hello, world"); +} + +export const FIXTURE_ENTRYPOINT = { + fn: TypeAliasUsedAsVariableAnnotation, + params: [], +};