forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add variance node type and generate property variance annotations (ba…
…bel#4697) * Add variance node type and generate property variance annotations babel/babylon#161 adds parsing support for property variance annotations. This PR adds the necessary node type for the new Variance node and generate support for all the positions where variance can now appear. * Variance is no longer a separate node type This diff also adds tests to class properties and to the flow-strip-types transform. * Add test + fix for edge case with variance and class proeprties
- Loading branch information
1 parent
9edf24d
commit f732bc2
Showing
10 changed files
with
76 additions
and
10 deletions.
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
16 changes: 15 additions & 1 deletion
16
packages/babel-generator/test/fixtures/flow/def-site-variance/actual.js
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 |
---|---|---|
@@ -1,3 +1,17 @@ | ||
class C<+T, -U> {} | ||
class C1<+T, -U> {} | ||
function f<+T, -U>() {} | ||
type T<+T, -U> = {}; | ||
type T = { +p: T }; | ||
type T = { -p: T }; | ||
type T = { +[k:K]: V }; | ||
type T = { -[k:K]: V }; | ||
interface I { +p: T }; | ||
interface I { -p: T }; | ||
interface I { +[k:K]: V }; | ||
interface I { -[k:K]: V }; | ||
declare class I { +p: T }; | ||
declare class I { -p: T }; | ||
declare class I { +[k:K]: V }; | ||
declare class I { -[k:K]: V }; | ||
class C2 { +p: T = e }; | ||
class C3 { -p: T = e }; |
20 changes: 19 additions & 1 deletion
20
packages/babel-generator/test/fixtures/flow/def-site-variance/expected.js
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 |
---|---|---|
@@ -1,3 +1,21 @@ | ||
class C<+T, -U> {} | ||
class C1<+T, -U> {} | ||
function f<+T, -U>() {} | ||
type T<+T, -U> = {}; | ||
type T = { +p: T }; | ||
type T = { -p: T }; | ||
type T = { +[k: K]: V }; | ||
type T = { -[k: K]: V }; | ||
interface I { +p: T }; | ||
interface I { -p: T }; | ||
interface I { +[k: K]: V }; | ||
interface I { -[k: K]: V }; | ||
declare class I { +p: T }; | ||
declare class I { -p: T }; | ||
declare class I { +[k: K]: V }; | ||
declare class I { -[k: K]: V }; | ||
class C2 { | ||
+p: T = e; | ||
}; | ||
class C3 { | ||
-p: T = e; | ||
}; |
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
3 changes: 3 additions & 0 deletions
3
...ow-strip-types/test/fixtures/regression/property-variance-with-class-properties/actual.js
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,3 @@ | ||
class C { | ||
+p: T = e; | ||
} |
3 changes: 3 additions & 0 deletions
3
...-strip-types/test/fixtures/regression/property-variance-with-class-properties/expected.js
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,3 @@ | ||
class C { | ||
p = e; | ||
} |
3 changes: 3 additions & 0 deletions
3
...strip-types/test/fixtures/regression/property-variance-with-class-properties/options.json
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,3 @@ | ||
{ | ||
"plugins": ["transform-flow-strip-types", "syntax-class-properties"] | ||
} |
18 changes: 16 additions & 2 deletions
18
...l-plugin-transform-flow-strip-types/test/fixtures/strip-types/def-site-variance/actual.js
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 |
---|---|---|
@@ -1,3 +1,17 @@ | ||
class C<+T, -U> {} | ||
class C1<+T, -U> {} | ||
function f<+T, -U>() {} | ||
type T<+T, -U> = {}; | ||
type T<+T, -U> = {} | ||
type T = { +p: T } | ||
type T = { -p: T } | ||
type T = { +[k:K]: V } | ||
type T = { -[k:K]: V } | ||
interface I { +p: T } | ||
interface I { -p: T } | ||
interface I { +[k:K]: V } | ||
interface I { -[k:K]: V } | ||
declare class I { +p: T } | ||
declare class I { -p: T } | ||
declare class I { +[k:K]: V } | ||
declare class I { -[k:K]: V } | ||
class C2 { +p: T } | ||
class C3 { -p: T } |
5 changes: 4 additions & 1 deletion
5
...plugin-transform-flow-strip-types/test/fixtures/strip-types/def-site-variance/expected.js
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class C {} | ||
class C1 {} | ||
function f() {} | ||
|
||
class C2 {} | ||
class C3 {} |