diff --git a/package.json b/package.json index cd7e643..b45dbb1 100644 --- a/package.json +++ b/package.json @@ -31,22 +31,22 @@ }, "homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme", "devDependencies": { - "@types/jest": "^21.1.0", + "@types/jest": "^21.1.8", "@types/mock-fs": "^3.6.30", - "@types/node": "^8.0.31", + "@types/node": "^8.0.57", "del-cli": "^1.1.0", - "jest": "^21.2.0", - "mock-fs": "^4.4.1", + "jest": "^21.2.1", + "mock-fs": "^4.4.2", "semantic-release": "^9.0.0", - "ts-jest": "^21.0.0", - "tslint": "^5.5.0", - "tslint-config-airbnb": "^5.2.1", - "tsutils": "^2.9.0", - "typedoc": "^0.8.0" + "ts-jest": "^21.2.4", + "tslint": "^5.8.0", + "tslint-config-airbnb": "^5.4.2", + "tsutils": "^2.13.0", + "typedoc": "^0.9.0" }, "dependencies": { "lodash": "^4.17.4", - "tslib": "^1.7.1", - "typescript": "^2.5.3" + "tslib": "^1.8.1", + "typescript": "^2.6.2" } } diff --git a/src/code-generators/typescript-generators/namedImport.ts b/src/code-generators/typescript-generators/namedImport.ts index ca9c8d8..155a240 100644 --- a/src/code-generators/typescript-generators/namedImport.ts +++ b/src/code-generators/typescript-generators/namedImport.ts @@ -23,7 +23,8 @@ function specifierSort(i1: SymbolSpecifier, i2: SymbolSpecifier): number { if (strA < strB) { return -1; - } else if (strA > strB) { + } + if (strA > strB) { return 1; } return 0; diff --git a/src/resources/Module.ts b/src/resources/Module.ts index 2f84dcd..7b2c115 100644 --- a/src/resources/Module.ts +++ b/src/resources/Module.ts @@ -7,7 +7,7 @@ import { Resource } from './Resource'; /** * TypeScript resource. Declaration of a typescript module (i.e. declare module "foobar"). - * + * * @export * @class Module * @implements {Resource} @@ -39,9 +39,9 @@ export class Module implements Resource, Node { /** * Function that calculates the alias name of a namespace. * Removes all underlines and dashes and camelcases the name. - * + * * @returns {string} - * + * * @memberof Module */ public getNamespaceAlias(): string { @@ -49,9 +49,8 @@ export class Module implements Resource, Node { (all, cur, idx) => { if (idx === 0) { return all + cur.toLowerCase(); - } else { - return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase(); } + return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase(); }, '', ); diff --git a/src/resources/Namespace.ts b/src/resources/Namespace.ts index d304e21..6061d60 100644 --- a/src/resources/Namespace.ts +++ b/src/resources/Namespace.ts @@ -7,7 +7,7 @@ import { Resource } from './Resource'; /** * TypeScript resource. Declaration of a typescript namespace (i.e. declare foobar). - * + * * @export * @class Namespace * @implements {Resource} @@ -39,9 +39,9 @@ export class Namespace implements Resource, Node { /** * Function that calculates the alias name of a namespace. * Removes all underlines and dashes and camelcases the name. - * + * * @returns {string} - * + * * @memberof Namespace */ public getNamespaceAlias(): string { @@ -49,9 +49,8 @@ export class Namespace implements Resource, Node { (all, cur, idx) => { if (idx === 0) { return all + cur.toLowerCase(); - } else { - return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase(); } + return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase(); }, '', ); diff --git a/test/SpecificUsageCases.spec.ts b/test/SpecificUsageCases.spec.ts new file mode 100644 index 0000000..ed06def --- /dev/null +++ b/test/SpecificUsageCases.spec.ts @@ -0,0 +1,23 @@ +import { TypescriptParser } from '../src'; +import { getWorkspaceFile, rootPath } from './testUtilities'; + +describe('Specific usage cases', () => { + const parser = new TypescriptParser(); + + describe('i18next with and without destructure', () => { + + it('should contain i18next reference in not destructured way', async () => { + const file = getWorkspaceFile('specific-usage-cases/i18next-destructure/import-my-component.tsx'); + const parsed = await parser.parseFile(file, rootPath); + expect(parsed.usages).toMatchSnapshot(); + }); + + it('should contain t reference in destructured way', async () => { + const file = getWorkspaceFile('specific-usage-cases/i18next-destructure/destructure-my-component.tsx'); + const parsed = await parser.parseFile(file, rootPath); + expect(parsed.usages).toMatchSnapshot(); + }); + + }); + +}); diff --git a/test/__snapshots__/SpecificUsageCases.spec.ts.snap b/test/__snapshots__/SpecificUsageCases.spec.ts.snap new file mode 100644 index 0000000..b805af7 --- /dev/null +++ b/test/__snapshots__/SpecificUsageCases.spec.ts.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Specific usage cases i18next with and without destructure should contain i18next reference in not destructured way 1`] = ` +Array [ + "MyComponent", + "p", + "i18next", +] +`; + +exports[`Specific usage cases i18next with and without destructure should contain t reference in destructured way 1`] = ` +Array [ + "MyComponent", + "p", + "t", +] +`; diff --git a/test/_workspace/specific-usage-cases/i18next-destructure/destructure-my-component.tsx b/test/_workspace/specific-usage-cases/i18next-destructure/destructure-my-component.tsx new file mode 100644 index 0000000..cffd37a --- /dev/null +++ b/test/_workspace/specific-usage-cases/i18next-destructure/destructure-my-component.tsx @@ -0,0 +1,6 @@ +import * as React from 'react'; +import { t } from 'i18next'; + +export const MyComponent = () => ( +
{t('foo')}
+); diff --git a/test/_workspace/specific-usage-cases/i18next-destructure/import-my-component.tsx b/test/_workspace/specific-usage-cases/i18next-destructure/import-my-component.tsx new file mode 100644 index 0000000..ee5c639 --- /dev/null +++ b/test/_workspace/specific-usage-cases/i18next-destructure/import-my-component.tsx @@ -0,0 +1,4 @@ +import * as i18next from 'i18next'; +import * as React from 'react'; + +export const MyComponent = () =>{i18next.t('foo')}
;