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

WIP: Grouped types #60

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

WIP: Grouped types #60

wants to merge 6 commits into from

Conversation

bodia-uz
Copy link
Collaborator

No description provided.

@bodia-uz bodia-uz changed the title Grouped types WIP: Grouped types Oct 29, 2018
const relativePath = path.node.source.value;
// convert relative path to absolute
const absolutePath = resolveDependencyPath({ dependency: relativePath, entryAST: fileAST, entryPath: filePath });
const specifiers = [
Copy link
Collaborator Author

@bodia-uz bodia-uz Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb add some NOTE with sens like "there could be some other specifiers in file with the same import path"?

const dependencies = resolveDependencies({ entryAST: fileAST });

// TBD: which identifier should we use in case path is missing?
storage.set('__source', { dependencies, fileAST });
Copy link
Collaborator Author

@bodia-uz bodia-uz Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__source seems OK. But mb move to constants

entries.forEach(entry => {
const filePath = path.resolve(entry);

if (!storage.has(filePath)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mb use early return? (some descussion of why it could be better -https://softwareengineering.stackexchange.com/q/18454/11854)

Suggested change
if (!storage.has(filePath)) {
if (storage.has(filePath)) {
return;
}

const interfaceFile = state.dependenciesTree.get(absoluteFilePath);

if (interfaceFile) {
const importName = t.isImportDefaultSpecifier(importSpecifier) ?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this logic could be moved to the place where specifiers are extracted.
Not sure if we need some other info here except specifier name in this file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an idea in mind that buildDependenciesTree is responsible for building the tree itself, without knowing which content might be used in future for markdown generation process.

But maybe it's possible to put interfaceVisitor logic inside createApiClassMethod / createApiClassProperty / createApiFunction methods?

// NOTE: it might be the case when more than 1 import exists.
// Example:
// import { MyType } from './types';
// import { MyType } from './another-type';
Copy link
Collaborator Author

@bodia-uz bodia-uz Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not it invalid code if there are two imports with the same specifier name?

Copy link

@sdoomz sdoomz Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I was thinking such sort of validation have to be done inside eslint / tslint tools.
But it's not true - typescript is throwing an error in such cases TS2300: Duplicate identifier 'Type'.

But in the other hand next code should be valid:

// @ts-ignore
import { Type } from './type1.ts';
// @ts-ignore
import { Type } from './type2.ts';

createApiClassDeclaration(path.node, path, options),
);
traverseInterfaces(path, state);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb better to traverse a node, returned by createApi[ClassDeclaration|ClassMethod|..]?

...createApiVisitor((path, options) => {
};

const traverseInterfaces = (path, state) => path.traverse(interfaceVisitor, state);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for me traverseInterfaces name is too abstract.
Mb something like traversNodeTypes?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for me traversNodeTypes even more abstract, anyways it's already changed to
path.traverse(interfaceVisitor, { filePath });

// NOTE: it might be the case when more than 1 import exists.
// Example:
// import { MyType } from './types';
// import { MyType } from './another-type';
Copy link

@sdoomz sdoomz Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I was thinking such sort of validation have to be done inside eslint / tslint tools.
But it's not true - typescript is throwing an error in such cases TS2300: Duplicate identifier 'Type'.

But in the other hand next code should be valid:

// @ts-ignore
import { Type } from './type1.ts';
// @ts-ignore
import { Type } from './type2.ts';

const visitors = {
enter: (path, state) => {
//store filePath locally in order to be able
filePath = state.filePath;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF?

Looking for better solution

...createApiVisitor((path, options) => {
};

const traverseInterfaces = (path, state) => path.traverse(interfaceVisitor, state);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for me traversNodeTypes even more abstract, anyways it's already changed to
path.traverse(interfaceVisitor, { filePath });

},
// In order to implement CommonJS support can use https:/dependents/node-detective-cjs
ImportDeclaration: path => {
// TODO: prevent traverse for files without filePath in more efficient and elegant way
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixme, boy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants