Skip to content

Fix imports for non-barrel files ending with index #19

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 2 commits into from
Sep 16, 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
2 changes: 1 addition & 1 deletion src/DeclarationIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class DeclarationIndex {
if (!index[declaration.name]) {
index[declaration.name] = [];
}
const from = key.replace(/[/]?index$/, '') || '/';
const from = key.replace(/\/index$/, '') || '/';
if (!index[declaration.name].some(
o => o.declaration.constructor === declaration.constructor && o.from === from,
)) {
Expand Down
1 change: 1 addition & 0 deletions test/_workspace/declaration-index/_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export let _index;
1 change: 1 addition & 0 deletions test/_workspace/declaration-index/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export let barrelExport;
16 changes: 13 additions & 3 deletions test/declaration-index/DeclarationIndex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('DeclarationIndex', () => {
join(rootPath, 'helper-functions.ts'),
join(rootPath, 'myReactTemplate.tsx'),
join(rootPath, 'prototype-funcs.ts'),
join(rootPath, 'index.ts'),
join(rootPath, '_index.ts'),
];

beforeEach(async () => {
Expand Down Expand Up @@ -84,6 +86,14 @@ describe('DeclarationIndex', () => {
expect(resource).toMatchSnapshot();
});

it('should properly index non-barrel files ending in `index`', () => {
const barrelExport = declarationIndex.index!['barrelExport'];
expect(barrelExport).toMatchSnapshot();

const _index = declarationIndex.index!['_index'];
expect(_index).toMatchSnapshot();
});

});

describe('reindexForChanges()', () => {
Expand Down Expand Up @@ -183,7 +193,7 @@ describe('DeclarationIndex', () => {
export class FancierLibraryClass {
public doSomethingAwesome(): void { }
}

export * from './foobar'`,
});

Expand Down Expand Up @@ -265,7 +275,7 @@ describe('DeclarationIndex', () => {
export class FancierLibraryClass {
public doSomethingAwesome(): void { }
}

export * from './foobar'`,
});

Expand All @@ -290,7 +300,7 @@ describe('DeclarationIndex', () => {
export class FancierLibraryClass {
public doSomethingAwesome(): void { }
}

export * from './foobar'`,
});

Expand Down
34 changes: 34 additions & 0 deletions test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Array [
"/helper-functions",
"/myReactTemplate",
"/prototype-funcs",
"/index",
"/_index",
]
`;

Expand Down Expand Up @@ -127,6 +129,38 @@ Array [
]
`;

exports[`DeclarationIndex buildIndex() should properly index non-barrel files ending in \`index\` 1`] = `
Array [
DeclarationInfo {
"declaration": VariableDeclaration {
"end": 24,
"isConst": false,
"isExported": true,
"name": "barrelExport",
"start": 0,
"type": undefined,
},
"from": "/",
},
]
`;

exports[`DeclarationIndex buildIndex() should properly index non-barrel files ending in \`index\` 2`] = `
Array [
DeclarationInfo {
"declaration": VariableDeclaration {
"end": 18,
"isConst": false,
"isExported": true,
"name": "_index",
"start": 0,
"type": undefined,
},
"from": "/_index",
},
]
`;

exports[`DeclarationIndex calculateIndexDelta() should calculate a newly added declaration 1`] = `
Object {
"added": Object {
Expand Down