Skip to content

Commit 5a528a0

Browse files
authored
Merge pull request #9 from TypeScript-Heroes/develop
2 parents ec54f69 + d43ca86 commit 5a528a0

File tree

10 files changed

+149
-13
lines changed

10 files changed

+149
-13
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
},
3232
"homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme",
3333
"devDependencies": {
34-
"@types/jest": "^20.0.1",
34+
"@types/jest": "^20.0.2",
3535
"@types/mock-fs": "^3.6.30",
36-
"@types/node": "^8.0.1",
37-
"del-cli": "^1.0.0",
36+
"@types/node": "^8.0.13",
37+
"del-cli": "^1.1.0",
3838
"jest": "^20.0.4",
3939
"mock-fs": "^4.4.1",
4040
"semantic-release": "^6.3.6",
41-
"ts-jest": "^20.0.6",
42-
"tslint": "^5.4.3",
43-
"tslint-config-airbnb": "^5.2.0",
44-
"tsutils": "^2.4.0",
41+
"ts-jest": "^20.0.7",
42+
"tslint": "^5.5.0",
43+
"tslint-config-airbnb": "^5.2.1",
44+
"tsutils": "^2.7.1",
4545
"typedoc": "^0.7.1"
4646
},
4747
"dependencies": {

src/imports/DefaultImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AliasedImport } from './Import';
1010
*/
1111
export class DefaultImport implements AliasedImport {
1212
public get isNew(): boolean {
13-
return this.start !== undefined && this.end !== undefined;
13+
return this.start === undefined || this.end === undefined;
1414
}
1515

1616
constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }

src/imports/ExternalModuleImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AliasedImport } from './Import';
1010
*/
1111
export class ExternalModuleImport implements AliasedImport {
1212
public get isNew(): boolean {
13-
return this.start !== undefined && this.end !== undefined;
13+
return this.start === undefined || this.end === undefined;
1414
}
1515

1616
constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }

src/imports/NamedImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class NamedImport implements Import {
1414
public specifiers: SymbolSpecifier[] = [];
1515

1616
public get isNew(): boolean {
17-
return this.start !== undefined && this.end !== undefined;
17+
return this.start === undefined || this.end === undefined;
1818
}
1919

2020
constructor(public libraryName: string, public start?: number, public end?: number) { }

src/imports/NamespaceImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { AliasedImport } from './Import';
99
*/
1010
export class NamespaceImport implements AliasedImport {
1111
public get isNew(): boolean {
12-
return this.start !== undefined && this.end !== undefined;
12+
return this.start === undefined || this.end === undefined;
1313
}
1414

1515
constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }

src/imports/StringImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Import } from './Import';
99
*/
1010
export class StringImport implements Import {
1111
public get isNew(): boolean {
12-
return this.start !== undefined && this.end !== undefined;
12+
return this.start === undefined || this.end === undefined;
1313
}
1414

1515
constructor(public libraryName: string, public start?: number, public end?: number) { }

test/TypescriptParser.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('TypescriptParser', () => {
3232

3333
it('should parse a source code string correctly', async () => {
3434
const parsed = await parser.parseSource(`import {foo} from 'bar'; class Foobar {}; const bar = new Foobar();`);
35-
35+
3636
expect(parsed).toMatchSnapshot();
3737
});
3838

@@ -544,4 +544,22 @@ describe('TypescriptParser', () => {
544544

545545
});
546546

547+
describe('TSX Usage parsing', () => {
548+
const file = getWorkspaceFile('typescript-parser/usagesOnly.tsx');
549+
let parsed: Resource;
550+
551+
beforeEach(async () => {
552+
parsed = await parser.parseFile(file, rootPath);
553+
});
554+
555+
it('should parse a tsx element usage', () => {
556+
const usages = parsed.usages;
557+
558+
expect(usages).toContain('myComponent');
559+
expect(usages).toContain('div');
560+
expect(usages).toContain('complexComp');
561+
expect(usages).toContain('SingleComp');
562+
});
563+
});
564+
547565
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { myComponent } from './myReactTemplate';
2+
3+
export default function foobar() {
4+
return (
5+
<myComponent></myComponent>
6+
);
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function foobar() {
2+
return (
3+
<myComponent>
4+
<div>
5+
<complexComp>
6+
<SingleComp />
7+
</complexComp>
8+
</div>
9+
</myComponent>
10+
);
11+
}

test/imports/Imports.spec.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { DefaultImport, ExternalModuleImport, NamedImport, NamespaceImport, StringImport } from '../../src/imports';
2+
3+
describe('Imports', () => {
4+
5+
describe('DefaultImport', () => {
6+
7+
it('should set isNew() when start is undefined', () => {
8+
const imp = new DefaultImport('lib', 'alias', undefined, 1337);
9+
expect(imp.isNew).toBeTruthy();
10+
});
11+
12+
it('should set isNew() when end is undefined', () => {
13+
const imp = new DefaultImport('lib', 'alias', 1337);
14+
expect(imp.isNew).toBeTruthy();
15+
});
16+
17+
it('should not set isNew() when start and end are defined', () => {
18+
const imp = new DefaultImport('lib', 'alias', 12, 1337);
19+
expect(imp.isNew).toBeFalsy();
20+
});
21+
22+
});
23+
24+
describe('ExternalModuleImport', () => {
25+
26+
it('should set isNew() when start is undefined', () => {
27+
const imp = new ExternalModuleImport('lib', 'alias', undefined, 1337);
28+
expect(imp.isNew).toBeTruthy();
29+
});
30+
31+
it('should set isNew() when end is undefined', () => {
32+
const imp = new ExternalModuleImport('lib', 'alias', 1337);
33+
expect(imp.isNew).toBeTruthy();
34+
});
35+
36+
it('should not set isNew() when start and end are defined', () => {
37+
const imp = new ExternalModuleImport('lib', 'alias', 12, 1337);
38+
expect(imp.isNew).toBeFalsy();
39+
});
40+
41+
});
42+
43+
describe('NamedImport', () => {
44+
45+
it('should set isNew() when start is undefined', () => {
46+
const imp = new NamedImport('lib', undefined, 1337);
47+
expect(imp.isNew).toBeTruthy();
48+
});
49+
50+
it('should set isNew() when end is undefined', () => {
51+
const imp = new NamedImport('lib', 1337);
52+
expect(imp.isNew).toBeTruthy();
53+
});
54+
55+
it('should not set isNew() when start and end are defined', () => {
56+
const imp = new NamedImport('lib', 12, 1337);
57+
expect(imp.isNew).toBeFalsy();
58+
});
59+
60+
});
61+
62+
describe('NamespaceImport', () => {
63+
64+
it('should set isNew() when start is undefined', () => {
65+
const imp = new NamespaceImport('lib', 'alias', undefined, 1337);
66+
expect(imp.isNew).toBeTruthy();
67+
});
68+
69+
it('should set isNew() when end is undefined', () => {
70+
const imp = new NamespaceImport('lib', 'alias', 1337);
71+
expect(imp.isNew).toBeTruthy();
72+
});
73+
74+
it('should not set isNew() when start and end are defined', () => {
75+
const imp = new NamespaceImport('lib', 'alias', 12, 1337);
76+
expect(imp.isNew).toBeFalsy();
77+
});
78+
79+
});
80+
81+
describe('StringImport', () => {
82+
83+
it('should set isNew() when start is undefined', () => {
84+
const imp = new StringImport('lib', undefined, 1337);
85+
expect(imp.isNew).toBeTruthy();
86+
});
87+
88+
it('should set isNew() when end is undefined', () => {
89+
const imp = new StringImport('lib', 1337);
90+
expect(imp.isNew).toBeTruthy();
91+
});
92+
93+
it('should not set isNew() when start and end are defined', () => {
94+
const imp = new StringImport('lib', 12, 1337);
95+
expect(imp.isNew).toBeFalsy();
96+
});
97+
98+
});
99+
100+
});

0 commit comments

Comments
 (0)