-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow] Slight haste_namespace config tweak and add tests
Summary: Previously, I reversed the list here because I think the lines in flowconfig are processed in order but they are prepended to the list in reverse order. However, that's my misunderstanding and flowconfig processing will reverse the lines first. This diff removes the reverse here to be consitent with other flowconfig options. In addition, I also added the compatibility mode that allow common code to import 1-namespace only code (choosing the first namespace). I also added test to test the namespace resolution behavior and the precedence rule change. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D66710892 fbshipit-source-id: 728f804ddb40032cce62401e8a93a8fb35948fcc
- Loading branch information
1 parent
5a53109
commit 726a642
Showing
10 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[options] | ||
all=true | ||
module.system=haste | ||
module.system.haste.experimental.namespaces=web | ||
module.system.haste.experimental.namespaces=native | ||
module.system.haste.experimental.namespace_path_mapping='<PROJECT_ROOT>/common/web' -> 'web' | ||
module.system.haste.experimental.namespace_path_mapping='<PROJECT_ROOT>/common/' -> 'web,native' | ||
module.system.haste.experimental.namespace_path_mapping='<PROJECT_ROOT>/web/' -> 'web' | ||
module.system.haste.experimental.namespace_path_mapping='<PROJECT_ROOT>/native/' -> 'native' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { native } from "NativeOnly"; // error: common code cannot import native-only code | ||
import { web } from "WebOnly"; // ok: common code can import web-only code, because web-only code is treated as implicit common interface. TODO: common interface validation is missing for now | ||
|
||
web as empty; // error: string ~> empty | ||
native as empty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare export const foo: string; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Error -------------------------------------------------------------------------------------------- common/Common.js:1:24 | ||
|
||
Cannot resolve module `NativeOnly`. [cannot-resolve-module] | ||
|
||
1| import { native } from "NativeOnly"; // error: common code cannot import native-only code | ||
^^^^^^^^^^^^ | ||
|
||
|
||
Error --------------------------------------------------------------------------------------------- common/Common.js:4:1 | ||
|
||
Cannot cast `web` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] | ||
|
||
common/Common.js:4:1 | ||
4| web as empty; // error: string ~> empty | ||
^^^ | ||
|
||
References: | ||
web/WebOnly.js:6:27 | ||
6| declare export const web: string; | ||
^^^^^^ [1] | ||
common/Common.js:4:8 | ||
4| web as empty; // error: string ~> empty | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------- native/NativeOnly.js:4:1 | ||
|
||
Cannot cast `foo` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] | ||
|
||
native/NativeOnly.js:4:1 | ||
4| foo as empty; // error: string ~> empty | ||
^^^ | ||
|
||
References: | ||
common/CommonLib.js:1:27 | ||
1| declare export const foo: string; | ||
^^^^^^ [1] | ||
native/NativeOnly.js:4:8 | ||
4| foo as empty; // error: string ~> empty | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------- native/NativeOnly.js:8:8 | ||
|
||
Cannot resolve module `WebInCommon`. [cannot-resolve-module] | ||
|
||
8| import 'WebInCommon' // error: native code cannot import web code. This one tests the precedence rule in flowconfig | ||
^^^^^^^^^^^^^ | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------------- web/WebOnly.js:4:1 | ||
|
||
Cannot cast `foo` to empty because string [1] is incompatible with empty [2]. [incompatible-cast] | ||
|
||
web/WebOnly.js:4:1 | ||
4| foo as empty; // error: string ~> empty | ||
^^^ | ||
|
||
References: | ||
common/CommonLib.js:1:27 | ||
1| declare export const foo: string; | ||
^^^^^^ [1] | ||
web/WebOnly.js:4:8 | ||
4| foo as empty; // error: string ~> empty | ||
^^^^^ [2] | ||
|
||
|
||
|
||
Found 5 errors |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { foo } from "CommonLib"; | ||
|
||
foo as string; | ||
foo as empty; // error: string ~> empty | ||
|
||
declare export const native: string; | ||
|
||
import 'WebInCommon' // error: native code cannot import web code. This one tests the precedence rule in flowconfig |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { foo } from "CommonLib"; | ||
|
||
foo as string; | ||
foo as empty; // error: string ~> empty | ||
|
||
declare export const web: string; |