Skip to content

Commit

Permalink
chore: Upgrade babel dependencies and adjust tests for ne parser
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Feb 6, 2020
1 parent 2c42e8c commit cfe9f27
Show file tree
Hide file tree
Showing 4 changed files with 1,013 additions and 700 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/parse-test.js
Expand Up @@ -43,12 +43,12 @@ describe('parse', () => {
fs.writeFileSync(`${dir}/.babelrc`, '{}');

expect(() =>
parse('const chained = () => foo?.bar?.join?.()', () => {}, null, {
parse('const chained = () => a |> b', () => {}, null, {
cwd: dir,
filename: `${dir}/component.js`,
}),
).toThrowError(
/.*Support for the experimental syntax 'optionalChaining' isn't currently enabled.*/,
/.*Support for the experimental syntax 'pipelineOperator' isn't currently enabled.*/,
);
} finally {
fs.unlinkSync(`${dir}/.babelrc`);
Expand Down
18 changes: 0 additions & 18 deletions src/utils/__tests__/__snapshots__/getMembers-test.js.snap
Expand Up @@ -26,8 +26,6 @@ Array [
"callee": Node {
"computed": false,
"end": 8,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 8,
Expand All @@ -40,8 +38,6 @@ Array [
},
"object": Node {
"end": 4,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 4,
Expand All @@ -55,13 +51,10 @@ Array [
},
"name": "foo",
"start": 1,
"trailingComments": undefined,
"type": "Identifier",
},
"property": Node {
"end": 8,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 8,
Expand All @@ -75,16 +68,12 @@ Array [
},
"name": "bar",
"start": 5,
"trailingComments": undefined,
"type": "Identifier",
},
"start": 1,
"trailingComments": undefined,
"type": "MemberExpression",
},
"end": 13,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 13,
Expand All @@ -96,14 +85,11 @@ Array [
},
},
"start": 1,
"trailingComments": undefined,
"type": "CallExpression",
},
"computed": false,
"path": Node {
"end": 8,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 8,
Expand All @@ -117,7 +103,6 @@ Array [
},
"name": "bar",
"start": 5,
"trailingComments": undefined,
"type": "Identifier",
},
},
Expand All @@ -126,8 +111,6 @@ Array [
"computed": true,
"path": Node {
"end": 22,
"innerComments": undefined,
"leadingComments": undefined,
"loc": SourceLocation {
"end": Position {
"column": 22,
Expand All @@ -141,7 +124,6 @@ Array [
},
"name": "baz",
"start": 19,
"trailingComments": undefined,
"type": "Identifier",
},
},
Expand Down
82 changes: 56 additions & 26 deletions src/utils/__tests__/getTSType-test.js
Expand Up @@ -6,15 +6,9 @@
*
*/

import { expression as expr, statement as stmt } from '../../../tests/utils';
import { statement as stmt } from '../../../tests/utils';
import getTSType from '../getTSType';

function expression(code) {
return expr(code, {
filename: 'test.ts',
babelrc: false,
});
}
function statement(code) {
return stmt(code, {
filename: 'test.ts',
Expand Down Expand Up @@ -43,7 +37,9 @@ describe('getTSType', () => {
];

simplePropTypes.forEach(type => {
const typePath = expression('x: ' + type)
const typePath = statement(`let x: ${type};`)
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({ name: type });
Expand All @@ -54,7 +50,9 @@ describe('getTSType', () => {
const literalTypes = ['"foo"', 1234, true];

literalTypes.forEach(value => {
const typePath = expression(`x: ${value}`)
const typePath = statement(`let x: ${value};`)
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -65,14 +63,18 @@ describe('getTSType', () => {
});

it('detects external type', () => {
const typePath = expression('x: xyz')
const typePath = statement('let x: xyz;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({ name: 'xyz' });
});

it('detects array type shorthand', () => {
const typePath = expression('x: number[]')
const typePath = statement('let x: number[];')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -83,7 +85,9 @@ describe('getTSType', () => {
});

it('detects array type', () => {
const typePath = expression('x: Array<number>')
const typePath = statement('let x: Array<number>;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -94,7 +98,9 @@ describe('getTSType', () => {
});

it('detects array type with multiple types', () => {
const typePath = expression('x: Array<number, xyz>')
const typePath = statement('let x: Array<number, xyz>;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -105,7 +111,9 @@ describe('getTSType', () => {
});

it('detects class type', () => {
const typePath = expression('x: Class<Boolean>')
const typePath = statement('let x: Class<Boolean>;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -116,7 +124,9 @@ describe('getTSType', () => {
});

it('detects function type with subtype', () => {
const typePath = expression('x: Function<xyz>')
const typePath = statement('let x: Function<xyz>;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -127,7 +137,9 @@ describe('getTSType', () => {
});

it('detects object types', () => {
const typePath = expression('x: { a: string, b?: xyz }')
const typePath = statement('let x: { a: string, b?: xyz };')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -144,7 +156,9 @@ describe('getTSType', () => {
});

it('detects union type', () => {
const typePath = expression('x: string | xyz | "foo" | void')
const typePath = statement('let x: string | xyz | "foo" | void;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -160,7 +174,9 @@ describe('getTSType', () => {
});

it('detects intersection type', () => {
const typePath = expression('x: string & xyz & "foo" & void')
const typePath = statement('let x: string & xyz & "foo" & void;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -176,9 +192,11 @@ describe('getTSType', () => {
});

it('detects function signature type', () => {
const typePath = expression(
'x: (p1: number, p2: string, ...rest: Array<string>) => boolean',
const typePath = statement(
'let x: (p1: number, p2: string, ...rest: Array<string>) => boolean;',
)
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -205,7 +223,9 @@ describe('getTSType', () => {
});

it('detects function signature type with `this` parameter', () => {
const typePath = expression('x: (this: Foo, p1: number) => boolean')
const typePath = statement('let x: (this: Foo, p1: number) => boolean;')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -221,7 +241,11 @@ describe('getTSType', () => {
});

it('detects callable signature type', () => {
const typePath = expression('x: { (str: string): string, token: string }')
const typePath = statement(
'let x: { (str: string): string, token: string };',
)
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -246,9 +270,11 @@ describe('getTSType', () => {
});

it('detects map signature', () => {
const typePath = expression(
'x: { [key: string]: number, [key: "xl"]: string, token: "a" | "b" }',
const typePath = statement(
'let x: { [key: string]: number, [key: "xl"]: string, token: "a" | "b" };',
)
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand Down Expand Up @@ -283,7 +309,9 @@ describe('getTSType', () => {
});

it('detects tuple signature', () => {
const typePath = expression('x: [string, number]')
const typePath = statement('let x: [string, number];')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand All @@ -294,7 +322,9 @@ describe('getTSType', () => {
});

it('detects tuple in union signature', () => {
const typePath = expression('x: [string, number] | [number, string]')
const typePath = statement('let x: [string, number] | [number, string];')
.get('declarations', 0)
.get('id')
.get('typeAnnotation')
.get('typeAnnotation');
expect(getTSType(typePath)).toEqual({
Expand Down

0 comments on commit cfe9f27

Please sign in to comment.