Skip to content

Commit 3cc7822

Browse files
authored
fix: isNew in imports does return correct value (#8)
1 parent 06fc66a commit 3cc7822

File tree

7 files changed

+112
-12
lines changed

7 files changed

+112
-12
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/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)