Skip to content
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

Register TypeScript nodes as exports #929

Merged
merged 4 commits into from
Jan 4, 2018
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-module-utils": "file:./utils",
"eslint-plugin-import": "2.x",
"eslint-plugin-typescript": "^0.8.1",
"gulp": "^3.9.0",
"gulp-babel": "6.1.2",
"istanbul": "^0.4.0",
Expand All @@ -71,7 +72,7 @@
"rimraf": "2.5.2",
"sinon": "^2.3.2",
"typescript": "^2.0.3",
"typescript-eslint-parser": "^2.1.0"
"typescript-eslint-parser": "^8.0.0"
},
"peerDependencies": {
"eslint": "2.x - 4.x"
Expand Down
3 changes: 3 additions & 0 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ ExportMap.parse = function (path, content, context) {
case 'ClassDeclaration':
case 'TypeAlias': // flowtype with babel-eslint parser
case 'InterfaceDeclaration':
case 'TSEnumDeclaration':
case 'TSInterfaceDeclaration':
case 'TSAbstractClassDeclaration':
m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n))
break
case 'VariableDeclaration':
Expand Down
22 changes: 20 additions & 2 deletions tests/files/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
type X = string
export type MyType = string
export enum MyEnum {
Foo,
Bar,
Baz
}
export interface Foo {
native: string | number
typedef: MyType
enum: MyEnum
}

export abstract class Bar {
abstract foo(): Foo

method() {
return "foo"
}
}

export function getFoo() : X {
export function getFoo() : MyType {
return "foo"
}
18 changes: 17 additions & 1 deletion tests/src/core/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,25 @@ describe('ExportMap', function () {
expect(imports).property('errors').to.be.empty
})

it('has export (getFoo)', function () {
it('has exported function', function () {
expect(imports.has('getFoo')).to.be.true
})

it('has exported typedef', function () {
expect(imports.has('MyType')).to.be.true
})

it('has exported enum', function () {
expect(imports.has('MyEnum')).to.be.true
})

it('has exported interface', function () {
expect(imports.has('Foo')).to.be.true
})

it('has exported abstract class', function () {
expect(imports.has('Bar')).to.be.true
})
})
})

Expand Down