Skip to content

Commit

Permalink
Merge pull request #929 from j-f1/patch-2
Browse files Browse the repository at this point in the history
Register TypeScript nodes as exports
  • Loading branch information
ljharb authored Jan 4, 2018
2 parents 34e4b95 + 7ae0233 commit 1c41350
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
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

0 comments on commit 1c41350

Please sign in to comment.