Skip to content

Commit cfe9f27

Browse files
committed
chore: Upgrade babel dependencies and adjust tests for ne parser
1 parent 2c42e8c commit cfe9f27

File tree

4 files changed

+1013
-700
lines changed

4 files changed

+1013
-700
lines changed

src/__tests__/parse-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ describe('parse', () => {
4343
fs.writeFileSync(`${dir}/.babelrc`, '{}');
4444

4545
expect(() =>
46-
parse('const chained = () => foo?.bar?.join?.()', () => {}, null, {
46+
parse('const chained = () => a |> b', () => {}, null, {
4747
cwd: dir,
4848
filename: `${dir}/component.js`,
4949
}),
5050
).toThrowError(
51-
/.*Support for the experimental syntax 'optionalChaining' isn't currently enabled.*/,
51+
/.*Support for the experimental syntax 'pipelineOperator' isn't currently enabled.*/,
5252
);
5353
} finally {
5454
fs.unlinkSync(`${dir}/.babelrc`);

src/utils/__tests__/__snapshots__/getMembers-test.js.snap

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ Array [
2626
"callee": Node {
2727
"computed": false,
2828
"end": 8,
29-
"innerComments": undefined,
30-
"leadingComments": undefined,
3129
"loc": SourceLocation {
3230
"end": Position {
3331
"column": 8,
@@ -40,8 +38,6 @@ Array [
4038
},
4139
"object": Node {
4240
"end": 4,
43-
"innerComments": undefined,
44-
"leadingComments": undefined,
4541
"loc": SourceLocation {
4642
"end": Position {
4743
"column": 4,
@@ -55,13 +51,10 @@ Array [
5551
},
5652
"name": "foo",
5753
"start": 1,
58-
"trailingComments": undefined,
5954
"type": "Identifier",
6055
},
6156
"property": Node {
6257
"end": 8,
63-
"innerComments": undefined,
64-
"leadingComments": undefined,
6558
"loc": SourceLocation {
6659
"end": Position {
6760
"column": 8,
@@ -75,16 +68,12 @@ Array [
7568
},
7669
"name": "bar",
7770
"start": 5,
78-
"trailingComments": undefined,
7971
"type": "Identifier",
8072
},
8173
"start": 1,
82-
"trailingComments": undefined,
8374
"type": "MemberExpression",
8475
},
8576
"end": 13,
86-
"innerComments": undefined,
87-
"leadingComments": undefined,
8877
"loc": SourceLocation {
8978
"end": Position {
9079
"column": 13,
@@ -96,14 +85,11 @@ Array [
9685
},
9786
},
9887
"start": 1,
99-
"trailingComments": undefined,
10088
"type": "CallExpression",
10189
},
10290
"computed": false,
10391
"path": Node {
10492
"end": 8,
105-
"innerComments": undefined,
106-
"leadingComments": undefined,
10793
"loc": SourceLocation {
10894
"end": Position {
10995
"column": 8,
@@ -117,7 +103,6 @@ Array [
117103
},
118104
"name": "bar",
119105
"start": 5,
120-
"trailingComments": undefined,
121106
"type": "Identifier",
122107
},
123108
},
@@ -126,8 +111,6 @@ Array [
126111
"computed": true,
127112
"path": Node {
128113
"end": 22,
129-
"innerComments": undefined,
130-
"leadingComments": undefined,
131114
"loc": SourceLocation {
132115
"end": Position {
133116
"column": 22,
@@ -141,7 +124,6 @@ Array [
141124
},
142125
"name": "baz",
143126
"start": 19,
144-
"trailingComments": undefined,
145127
"type": "Identifier",
146128
},
147129
},

src/utils/__tests__/getTSType-test.js

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
*
77
*/
88

9-
import { expression as expr, statement as stmt } from '../../../tests/utils';
9+
import { statement as stmt } from '../../../tests/utils';
1010
import getTSType from '../getTSType';
1111

12-
function expression(code) {
13-
return expr(code, {
14-
filename: 'test.ts',
15-
babelrc: false,
16-
});
17-
}
1812
function statement(code) {
1913
return stmt(code, {
2014
filename: 'test.ts',
@@ -43,7 +37,9 @@ describe('getTSType', () => {
4337
];
4438

4539
simplePropTypes.forEach(type => {
46-
const typePath = expression('x: ' + type)
40+
const typePath = statement(`let x: ${type};`)
41+
.get('declarations', 0)
42+
.get('id')
4743
.get('typeAnnotation')
4844
.get('typeAnnotation');
4945
expect(getTSType(typePath)).toEqual({ name: type });
@@ -54,7 +50,9 @@ describe('getTSType', () => {
5450
const literalTypes = ['"foo"', 1234, true];
5551

5652
literalTypes.forEach(value => {
57-
const typePath = expression(`x: ${value}`)
53+
const typePath = statement(`let x: ${value};`)
54+
.get('declarations', 0)
55+
.get('id')
5856
.get('typeAnnotation')
5957
.get('typeAnnotation');
6058
expect(getTSType(typePath)).toEqual({
@@ -65,14 +63,18 @@ describe('getTSType', () => {
6563
});
6664

6765
it('detects external type', () => {
68-
const typePath = expression('x: xyz')
66+
const typePath = statement('let x: xyz;')
67+
.get('declarations', 0)
68+
.get('id')
6969
.get('typeAnnotation')
7070
.get('typeAnnotation');
7171
expect(getTSType(typePath)).toEqual({ name: 'xyz' });
7272
});
7373

7474
it('detects array type shorthand', () => {
75-
const typePath = expression('x: number[]')
75+
const typePath = statement('let x: number[];')
76+
.get('declarations', 0)
77+
.get('id')
7678
.get('typeAnnotation')
7779
.get('typeAnnotation');
7880
expect(getTSType(typePath)).toEqual({
@@ -83,7 +85,9 @@ describe('getTSType', () => {
8385
});
8486

8587
it('detects array type', () => {
86-
const typePath = expression('x: Array<number>')
88+
const typePath = statement('let x: Array<number>;')
89+
.get('declarations', 0)
90+
.get('id')
8791
.get('typeAnnotation')
8892
.get('typeAnnotation');
8993
expect(getTSType(typePath)).toEqual({
@@ -94,7 +98,9 @@ describe('getTSType', () => {
9498
});
9599

96100
it('detects array type with multiple types', () => {
97-
const typePath = expression('x: Array<number, xyz>')
101+
const typePath = statement('let x: Array<number, xyz>;')
102+
.get('declarations', 0)
103+
.get('id')
98104
.get('typeAnnotation')
99105
.get('typeAnnotation');
100106
expect(getTSType(typePath)).toEqual({
@@ -105,7 +111,9 @@ describe('getTSType', () => {
105111
});
106112

107113
it('detects class type', () => {
108-
const typePath = expression('x: Class<Boolean>')
114+
const typePath = statement('let x: Class<Boolean>;')
115+
.get('declarations', 0)
116+
.get('id')
109117
.get('typeAnnotation')
110118
.get('typeAnnotation');
111119
expect(getTSType(typePath)).toEqual({
@@ -116,7 +124,9 @@ describe('getTSType', () => {
116124
});
117125

118126
it('detects function type with subtype', () => {
119-
const typePath = expression('x: Function<xyz>')
127+
const typePath = statement('let x: Function<xyz>;')
128+
.get('declarations', 0)
129+
.get('id')
120130
.get('typeAnnotation')
121131
.get('typeAnnotation');
122132
expect(getTSType(typePath)).toEqual({
@@ -127,7 +137,9 @@ describe('getTSType', () => {
127137
});
128138

129139
it('detects object types', () => {
130-
const typePath = expression('x: { a: string, b?: xyz }')
140+
const typePath = statement('let x: { a: string, b?: xyz };')
141+
.get('declarations', 0)
142+
.get('id')
131143
.get('typeAnnotation')
132144
.get('typeAnnotation');
133145
expect(getTSType(typePath)).toEqual({
@@ -144,7 +156,9 @@ describe('getTSType', () => {
144156
});
145157

146158
it('detects union type', () => {
147-
const typePath = expression('x: string | xyz | "foo" | void')
159+
const typePath = statement('let x: string | xyz | "foo" | void;')
160+
.get('declarations', 0)
161+
.get('id')
148162
.get('typeAnnotation')
149163
.get('typeAnnotation');
150164
expect(getTSType(typePath)).toEqual({
@@ -160,7 +174,9 @@ describe('getTSType', () => {
160174
});
161175

162176
it('detects intersection type', () => {
163-
const typePath = expression('x: string & xyz & "foo" & void')
177+
const typePath = statement('let x: string & xyz & "foo" & void;')
178+
.get('declarations', 0)
179+
.get('id')
164180
.get('typeAnnotation')
165181
.get('typeAnnotation');
166182
expect(getTSType(typePath)).toEqual({
@@ -176,9 +192,11 @@ describe('getTSType', () => {
176192
});
177193

178194
it('detects function signature type', () => {
179-
const typePath = expression(
180-
'x: (p1: number, p2: string, ...rest: Array<string>) => boolean',
195+
const typePath = statement(
196+
'let x: (p1: number, p2: string, ...rest: Array<string>) => boolean;',
181197
)
198+
.get('declarations', 0)
199+
.get('id')
182200
.get('typeAnnotation')
183201
.get('typeAnnotation');
184202
expect(getTSType(typePath)).toEqual({
@@ -205,7 +223,9 @@ describe('getTSType', () => {
205223
});
206224

207225
it('detects function signature type with `this` parameter', () => {
208-
const typePath = expression('x: (this: Foo, p1: number) => boolean')
226+
const typePath = statement('let x: (this: Foo, p1: number) => boolean;')
227+
.get('declarations', 0)
228+
.get('id')
209229
.get('typeAnnotation')
210230
.get('typeAnnotation');
211231
expect(getTSType(typePath)).toEqual({
@@ -221,7 +241,11 @@ describe('getTSType', () => {
221241
});
222242

223243
it('detects callable signature type', () => {
224-
const typePath = expression('x: { (str: string): string, token: string }')
244+
const typePath = statement(
245+
'let x: { (str: string): string, token: string };',
246+
)
247+
.get('declarations', 0)
248+
.get('id')
225249
.get('typeAnnotation')
226250
.get('typeAnnotation');
227251
expect(getTSType(typePath)).toEqual({
@@ -246,9 +270,11 @@ describe('getTSType', () => {
246270
});
247271

248272
it('detects map signature', () => {
249-
const typePath = expression(
250-
'x: { [key: string]: number, [key: "xl"]: string, token: "a" | "b" }',
273+
const typePath = statement(
274+
'let x: { [key: string]: number, [key: "xl"]: string, token: "a" | "b" };',
251275
)
276+
.get('declarations', 0)
277+
.get('id')
252278
.get('typeAnnotation')
253279
.get('typeAnnotation');
254280
expect(getTSType(typePath)).toEqual({
@@ -283,7 +309,9 @@ describe('getTSType', () => {
283309
});
284310

285311
it('detects tuple signature', () => {
286-
const typePath = expression('x: [string, number]')
312+
const typePath = statement('let x: [string, number];')
313+
.get('declarations', 0)
314+
.get('id')
287315
.get('typeAnnotation')
288316
.get('typeAnnotation');
289317
expect(getTSType(typePath)).toEqual({
@@ -294,7 +322,9 @@ describe('getTSType', () => {
294322
});
295323

296324
it('detects tuple in union signature', () => {
297-
const typePath = expression('x: [string, number] | [number, string]')
325+
const typePath = statement('let x: [string, number] | [number, string];')
326+
.get('declarations', 0)
327+
.get('id')
298328
.get('typeAnnotation')
299329
.get('typeAnnotation');
300330
expect(getTSType(typePath)).toEqual({

0 commit comments

Comments
 (0)