|
1 | 1 | import outdent from 'outdent';
|
2 |
| -import {getTester, parsers} from './utils/test.js'; |
| 2 | +import {getTester, parsers, avoidTestTitleConflict} from './utils/test.js'; |
3 | 3 |
|
4 | 4 | const {test} = getTester(import.meta);
|
5 | 5 |
|
6 |
| -test.snapshot({ |
7 |
| - valid: [ |
8 |
| - 'function foo () { this.bar }', |
9 |
| - 'function foo () { this.foo }', |
10 |
| - 'function foo (value) { this.bar = value }', |
11 |
| - 'this.foo = foo', |
12 |
| - outdent` |
13 |
| - { |
14 |
| - this.foo = foo; |
| 6 | +const validCases = [ |
| 7 | + 'console.log(this)', |
| 8 | + 'function foo () { this.bar }', |
| 9 | + 'function foo () { this.foo }', |
| 10 | + 'function foo (value) { this.bar = value }', |
| 11 | + 'this.foo = foo', |
| 12 | + outdent` |
| 13 | + { |
| 14 | + this.foo = foo; |
| 15 | + } |
| 16 | + `, |
| 17 | + 'this.foo = function () { this.foo }', |
| 18 | + 'const foo = () => this.foo', |
| 19 | + outdent` |
| 20 | + const foo = { |
| 21 | + bar() { |
| 22 | + this.bar = void 0; |
| 23 | + return this.bar; |
15 | 24 | }
|
16 |
| - `, |
17 |
| - 'this.foo = function () { this.foo }', |
18 |
| - 'const foo = () => this.foo', |
19 |
| - outdent` |
20 |
| - const foo = { |
21 |
| - bar() { |
22 |
| - this.bar = void 0; |
23 |
| - return this.bar; |
24 |
| - } |
25 |
| - }; |
26 |
| - `, |
27 |
| - outdent` |
28 |
| - class Foo { |
29 |
| - foo() { |
30 |
| - this.foo = void 0; |
31 |
| - return this.foo; |
32 |
| - } |
| 25 | + }; |
| 26 | + `, |
| 27 | + outdent` |
| 28 | + class Foo { |
| 29 | + foo() { |
| 30 | + this.foo = void 0; |
| 31 | + return this.foo; |
33 | 32 | }
|
34 |
| - `, |
35 |
| - // Deep property setter |
36 |
| - outdent` |
37 |
| - class Foo { |
38 |
| - set bar(value) { |
39 |
| - this.bar.baz = value; |
40 |
| - } |
| 33 | + } |
| 34 | + `, |
| 35 | + // Deep property setter |
| 36 | + outdent` |
| 37 | + class Foo { |
| 38 | + set bar(value) { |
| 39 | + this.bar.baz = value; |
41 | 40 | }
|
42 |
| - `, |
43 |
| - // Define this to alias |
44 |
| - outdent` |
45 |
| - class Foo { |
46 |
| - get bar() { |
47 |
| - const self = this; |
48 |
| - return self.bar; |
49 |
| - } |
| 41 | + } |
| 42 | + `, |
| 43 | + // Define this to alias |
| 44 | + outdent` |
| 45 | + class Foo { |
| 46 | + get bar() { |
| 47 | + const self = this; |
| 48 | + return self.bar; |
50 | 49 | }
|
51 |
| - `, |
52 |
| - outdent` |
53 |
| - class Foo { |
54 |
| - set bar(value) { |
55 |
| - const self = this; |
56 |
| - return self.bar = value; |
57 |
| - } |
| 50 | + } |
| 51 | + `, |
| 52 | + outdent` |
| 53 | + class Foo { |
| 54 | + set bar(value) { |
| 55 | + const self = this; |
| 56 | + return self.bar = value; |
58 | 57 | }
|
59 |
| - `, |
60 |
| - outdent` |
61 |
| - const foo = { |
62 |
| - get bar() { |
63 |
| - return this._bar; |
| 58 | + } |
| 59 | + `, |
| 60 | + outdent` |
| 61 | + const foo = { |
| 62 | + get bar() { |
| 63 | + return this._bar; |
| 64 | + } |
| 65 | + }; |
| 66 | + `, |
| 67 | + // Access this in function scope |
| 68 | + outdent` |
| 69 | + const foo = { |
| 70 | + get bar() { |
| 71 | + function baz() { |
| 72 | + return this.bar; |
64 | 73 | }
|
65 |
| - }; |
66 |
| - `, |
67 |
| - // Access this in function scope |
68 |
| - outdent` |
69 |
| - const foo = { |
70 |
| - get bar() { |
71 |
| - function baz() { |
| 74 | + } |
| 75 | + }; |
| 76 | + `, |
| 77 | + // Nest getter |
| 78 | + outdent` |
| 79 | + const foo = { |
| 80 | + get bar() { |
| 81 | + const qux = { |
| 82 | + get quux () { |
72 | 83 | return this.bar;
|
73 | 84 | }
|
74 | 85 | }
|
75 |
| - }; |
76 |
| - `, |
77 |
| - // Nest getter |
78 |
| - outdent` |
79 |
| - const foo = { |
80 |
| - get bar() { |
81 |
| - const qux = { |
82 |
| - get quux () { |
83 |
| - return this.bar; |
84 |
| - } |
85 |
| - } |
86 |
| - } |
87 |
| - }; |
88 |
| - `, |
89 |
| - // Test computed property |
90 |
| - outdent` |
91 |
| - const foo = { |
92 |
| - get bar() { |
93 |
| - return this[bar]; |
94 |
| - } |
95 |
| - }; |
96 |
| - `, |
97 |
| - outdent` |
98 |
| - const foo = { |
99 |
| - get [bar]() { |
100 |
| - return this.bar; |
101 |
| - } |
102 |
| - }; |
103 |
| - `, |
104 |
| - // Setter access in the right of AssignmentExpression |
105 |
| - outdent` |
106 |
| - const foo = { |
107 |
| - set bar(value) { |
108 |
| - a = this.bar; |
109 |
| - } |
110 |
| - }; |
111 |
| - `, |
112 |
| - // Private field without recursion access |
113 |
| - outdent` |
114 |
| - class Foo{ |
115 |
| - get bar() { |
116 |
| - return this.#bar; |
117 |
| - } |
| 86 | + } |
| 87 | + }; |
| 88 | + `, |
| 89 | + // Test computed property |
| 90 | + outdent` |
| 91 | + const foo = { |
| 92 | + get bar() { |
| 93 | + return this[bar]; |
| 94 | + } |
| 95 | + }; |
| 96 | + `, |
| 97 | + outdent` |
| 98 | + const foo = { |
| 99 | + get [bar]() { |
| 100 | + return this.bar; |
| 101 | + } |
| 102 | + }; |
| 103 | + `, |
| 104 | + // Setter access in the right of AssignmentExpression |
| 105 | + outdent` |
| 106 | + const foo = { |
| 107 | + set bar(value) { |
| 108 | + a = this.bar; |
| 109 | + } |
| 110 | + }; |
| 111 | + `, |
| 112 | + // Private field without recursion access |
| 113 | + outdent` |
| 114 | + class Foo{ |
| 115 | + get bar() { |
| 116 | + return this.#bar; |
| 117 | + } |
118 | 118 |
|
119 |
| - get #bar() { |
120 |
| - return 0; |
121 |
| - } |
| 119 | + get #bar() { |
| 120 | + return 0; |
122 | 121 | }
|
123 |
| - `, |
124 |
| - // Destructuring assignment with computed property |
125 |
| - outdent` |
126 |
| - class Foo{ |
127 |
| - get bar() { |
128 |
| - const {[bar]: bar} = this; |
129 |
| - } |
| 122 | + } |
| 123 | + `, |
| 124 | + // Destructuring assignment with computed property |
| 125 | + outdent` |
| 126 | + class Foo{ |
| 127 | + get bar() { |
| 128 | + const {[bar]: bar} = this; |
130 | 129 | }
|
131 |
| - `, |
132 |
| - // Static block |
133 |
| - outdent` |
134 |
| - const foo = { |
135 |
| - get bar() { |
136 |
| - class Foo { |
137 |
| - static { |
138 |
| - this.bar |
139 |
| - } |
| 130 | + } |
| 131 | + `, |
| 132 | + // Static block |
| 133 | + outdent` |
| 134 | + const foo = { |
| 135 | + get bar() { |
| 136 | + class Foo { |
| 137 | + static { |
| 138 | + this.bar |
140 | 139 | }
|
141 | 140 | }
|
142 |
| - }; |
143 |
| - `, |
144 |
| - // Static property |
145 |
| - outdent` |
146 |
| - const foo = { |
147 |
| - get bar() { |
148 |
| - class Foo { |
149 |
| - bar = 1; |
150 |
| - baz = this.bar; |
151 |
| - } |
| 141 | + } |
| 142 | + }; |
| 143 | + `, |
| 144 | + // Static property |
| 145 | + outdent` |
| 146 | + const foo = { |
| 147 | + get bar() { |
| 148 | + class Foo { |
| 149 | + bar = 1; |
| 150 | + baz = this.bar; |
152 | 151 | }
|
153 |
| - }; |
154 |
| - `, |
155 |
| - ], |
| 152 | + } |
| 153 | + }; |
| 154 | + `, |
| 155 | +]; |
| 156 | + |
| 157 | +test.snapshot({ |
| 158 | + valid: validCases, |
156 | 159 | invalid: [
|
157 | 160 | // Getter
|
158 | 161 | outdent`
|
@@ -307,3 +310,23 @@ test.snapshot({
|
307 | 310 | `,
|
308 | 311 | ],
|
309 | 312 | });
|
| 313 | + |
| 314 | +test.snapshot(avoidTestTitleConflict({ |
| 315 | + testerOptions: { |
| 316 | + languageOptions: { |
| 317 | + sourceType: 'commonjs', |
| 318 | + }, |
| 319 | + }, |
| 320 | + valid: validCases, |
| 321 | + invalid: [], |
| 322 | +}, 'commonjs')); |
| 323 | + |
| 324 | +test.snapshot(avoidTestTitleConflict({ |
| 325 | + testerOptions: { |
| 326 | + languageOptions: { |
| 327 | + sourceType: 'script', |
| 328 | + }, |
| 329 | + }, |
| 330 | + valid: validCases, |
| 331 | + invalid: [], |
| 332 | +}, 'script')); |
0 commit comments