forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
setPublicClassFields
and privateFieldsAsProperties
assu…
…mptions (babel#12497)
- Loading branch information
1 parent
665de74
commit cbc1d89
Showing
165 changed files
with
2,595 additions
and
28 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
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
...plugin/test/fixtures/plugin-proposal-class-properties/warn-loose-and-assumptions/input.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 A { | ||
foo; | ||
} |
9 changes: 9 additions & 0 deletions
9
...in/test/fixtures/plugin-proposal-class-properties/warn-loose-and-assumptions/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,9 @@ | ||
{ | ||
"validateLogs": true, | ||
"plugins": [ | ||
["proposal-class-properties", { "loose": true }] | ||
], | ||
"assumptions": { | ||
"setPublicClassFields": true | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...lugin/test/fixtures/plugin-proposal-class-properties/warn-loose-and-assumptions/output.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,6 @@ | ||
class A { | ||
constructor() { | ||
this.foo = void 0; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...ugin/test/fixtures/plugin-proposal-class-properties/warn-loose-and-assumptions/stderr.txt
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 @@ | ||
[proposal-class-properties]: You are using the "loose: true" option and you are explicitly setting a value for the "setPublicClassFields" assumption. The "loose" option can cause incompatibilities with the other class features plugins, so it's recommended that you replace it with the following top-level option: | ||
"assumptions": { | ||
"setPublicClassFields": true, | ||
"privateFieldsAsProperties": true | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...rties/test/fixtures/assumption-setPublicClassFields/computed-initialization-order/exec.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,38 @@ | ||
const actualOrder = []; | ||
|
||
const track = i => { | ||
actualOrder.push(i); | ||
return i; | ||
}; | ||
|
||
class MyClass { | ||
static [track(1)] = track(10); | ||
[track(2)] = track(13); | ||
get [track(3)]() { | ||
return "foo"; | ||
} | ||
set [track(4)](value) { | ||
this.bar = value; | ||
} | ||
[track(5)] = track(14); | ||
static [track(6)] = track(11); | ||
static [track(7)] = track(12); | ||
[track(8)]() {} | ||
[track(9)] = track(15); | ||
} | ||
|
||
const inst = new MyClass(); | ||
|
||
const expectedOrder = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
expect(actualOrder).toEqual(expectedOrder); | ||
|
||
expect(MyClass[1]).toBe(10); | ||
expect(inst[2]).toBe(13); | ||
expect(inst[3]).toBe("foo"); | ||
inst[4] = "baz"; | ||
expect(inst.bar).toBe("baz"); | ||
expect(inst[5]).toBe(14); | ||
expect(MyClass[6]).toBe(11); | ||
expect(MyClass[7]).toBe(12); | ||
expect(typeof inst[8]).toBe("function"); | ||
expect(inst[9]).toBe(15); |
25 changes: 25 additions & 0 deletions
25
...proposal-class-properties/test/fixtures/assumption-setPublicClassFields/computed/input.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,25 @@ | ||
const foo = "foo"; | ||
const bar = () => {}; | ||
const four = 4; | ||
|
||
class MyClass { | ||
static [one()] = "test"; | ||
static [2 * 4 + 7] = "247"; | ||
static [2 * four + 7] = "247"; | ||
static [2 * four + seven] = "247"; | ||
[null] = "null"; | ||
[undefined] = "undefined"; | ||
[void 0] = "void 0"; | ||
get ["whatever"]() {} | ||
set ["whatever"](value) {} | ||
get [computed()]() {} | ||
set [computed()](value) {} | ||
["test" + one]() {} | ||
static [10]() {} | ||
[/regex/] = "regex"; | ||
[foo] = "foo"; | ||
[bar] = "bar"; | ||
[baz] = "baz"; | ||
[`template`] = "template"; | ||
[`template${expression}`] = "template-with-expression"; | ||
} |
Oops, something went wrong.