Skip to content

fix: isNew in imports does return correct value #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
},
"homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme",
"devDependencies": {
"@types/jest": "^20.0.1",
"@types/jest": "^20.0.2",
"@types/mock-fs": "^3.6.30",
"@types/node": "^8.0.1",
"del-cli": "^1.0.0",
"@types/node": "^8.0.13",
"del-cli": "^1.1.0",
"jest": "^20.0.4",
"mock-fs": "^4.4.1",
"semantic-release": "^6.3.6",
"ts-jest": "^20.0.6",
"tslint": "^5.4.3",
"tslint-config-airbnb": "^5.2.0",
"tsutils": "^2.4.0",
"ts-jest": "^20.0.7",
"tslint": "^5.5.0",
"tslint-config-airbnb": "^5.2.1",
"tsutils": "^2.7.1",
"typedoc": "^0.7.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/imports/DefaultImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AliasedImport } from './Import';
*/
export class DefaultImport implements AliasedImport {
public get isNew(): boolean {
return this.start !== undefined && this.end !== undefined;
return this.start === undefined || this.end === undefined;
}

constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }
Expand Down
2 changes: 1 addition & 1 deletion src/imports/ExternalModuleImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AliasedImport } from './Import';
*/
export class ExternalModuleImport implements AliasedImport {
public get isNew(): boolean {
return this.start !== undefined && this.end !== undefined;
return this.start === undefined || this.end === undefined;
}

constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }
Expand Down
2 changes: 1 addition & 1 deletion src/imports/NamedImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class NamedImport implements Import {
public specifiers: SymbolSpecifier[] = [];

public get isNew(): boolean {
return this.start !== undefined && this.end !== undefined;
return this.start === undefined || this.end === undefined;
}

constructor(public libraryName: string, public start?: number, public end?: number) { }
Expand Down
2 changes: 1 addition & 1 deletion src/imports/NamespaceImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AliasedImport } from './Import';
*/
export class NamespaceImport implements AliasedImport {
public get isNew(): boolean {
return this.start !== undefined && this.end !== undefined;
return this.start === undefined || this.end === undefined;
}

constructor(public libraryName: string, public alias: string, public start?: number, public end?: number) { }
Expand Down
2 changes: 1 addition & 1 deletion src/imports/StringImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Import } from './Import';
*/
export class StringImport implements Import {
public get isNew(): boolean {
return this.start !== undefined && this.end !== undefined;
return this.start === undefined || this.end === undefined;
}

constructor(public libraryName: string, public start?: number, public end?: number) { }
Expand Down
100 changes: 100 additions & 0 deletions test/imports/Imports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { DefaultImport, ExternalModuleImport, NamedImport, NamespaceImport, StringImport } from '../../src/imports';

describe('Imports', () => {

describe('DefaultImport', () => {

it('should set isNew() when start is undefined', () => {
const imp = new DefaultImport('lib', 'alias', undefined, 1337);
expect(imp.isNew).toBeTruthy();
});

it('should set isNew() when end is undefined', () => {
const imp = new DefaultImport('lib', 'alias', 1337);
expect(imp.isNew).toBeTruthy();
});

it('should not set isNew() when start and end are defined', () => {
const imp = new DefaultImport('lib', 'alias', 12, 1337);
expect(imp.isNew).toBeFalsy();
});

});

describe('ExternalModuleImport', () => {

it('should set isNew() when start is undefined', () => {
const imp = new ExternalModuleImport('lib', 'alias', undefined, 1337);
expect(imp.isNew).toBeTruthy();
});

it('should set isNew() when end is undefined', () => {
const imp = new ExternalModuleImport('lib', 'alias', 1337);
expect(imp.isNew).toBeTruthy();
});

it('should not set isNew() when start and end are defined', () => {
const imp = new ExternalModuleImport('lib', 'alias', 12, 1337);
expect(imp.isNew).toBeFalsy();
});

});

describe('NamedImport', () => {

it('should set isNew() when start is undefined', () => {
const imp = new NamedImport('lib', undefined, 1337);
expect(imp.isNew).toBeTruthy();
});

it('should set isNew() when end is undefined', () => {
const imp = new NamedImport('lib', 1337);
expect(imp.isNew).toBeTruthy();
});

it('should not set isNew() when start and end are defined', () => {
const imp = new NamedImport('lib', 12, 1337);
expect(imp.isNew).toBeFalsy();
});

});

describe('NamespaceImport', () => {

it('should set isNew() when start is undefined', () => {
const imp = new NamespaceImport('lib', 'alias', undefined, 1337);
expect(imp.isNew).toBeTruthy();
});

it('should set isNew() when end is undefined', () => {
const imp = new NamespaceImport('lib', 'alias', 1337);
expect(imp.isNew).toBeTruthy();
});

it('should not set isNew() when start and end are defined', () => {
const imp = new NamespaceImport('lib', 'alias', 12, 1337);
expect(imp.isNew).toBeFalsy();
});

});

describe('StringImport', () => {

it('should set isNew() when start is undefined', () => {
const imp = new StringImport('lib', undefined, 1337);
expect(imp.isNew).toBeTruthy();
});

it('should set isNew() when end is undefined', () => {
const imp = new StringImport('lib', 1337);
expect(imp.isNew).toBeTruthy();
});

it('should not set isNew() when start and end are defined', () => {
const imp = new StringImport('lib', 12, 1337);
expect(imp.isNew).toBeFalsy();
});

});

});