-
Notifications
You must be signed in to change notification settings - Fork 235
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
[Experimental] First attempt at replacing AST traversal with Maybe<T> #180
Conversation
Looks hot, happy to see your suggestion in action! Will take a look at it in the next a couple of days and give you feedback. Thanks! |
Had some more thoughts about refactor experience so far. Can codelyzer develop against a different TS than the runtime TS? I have a feeling you can, but if not, it harder to write compatible type-friendly code as a lot of useful features like 'control flow based type analysis' and 'dot name type guards' landed only in TS 2.0 More refactoring can be done in Also there may be a few minor bugs, I'll highlight them below. |
} | ||
|
||
export function isSimpleTemplateString(expr: ts.Expression): expr is (ts.StringLiteral | ts.NoSubstitutionTemplateLiteral) { | ||
return expr && expr.kind === kinds.StringLiteral || expr.kind === kinds.NoSubstitutionTemplateLiteral; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe https://github.com/mgechev/codelyzer/blob/master/src/util/utils.ts#L29 should use kinds.NoSubstitutionTemplateLiteral
instead.
I was using astExplorer and find it odd that it maps to FirstTemplateToken
as well.
return url; | ||
}; | ||
const code = ` | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to wrap with try/finally or the spy would leak when a test fails.
const metadata = this.readDirectiveMetadata(d, dec); | ||
const result = new ComponentMetadata(); | ||
result.selector = metadata.selector; | ||
result.controller = metadata.controller; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that decorator
is not copied to result. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an issue.
Added Walker builder (a builder approach and a functional approach) in attempt to make Rule definition easier. |
|
||
read(d: ts.ClassDeclaration): DirectiveMetadata { | ||
let componentMetadata = unwrapFirst( | ||
(d.decorators || ([] as ts.Decorator[])).map((dec: ts.Decorator) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks beautiful!
const inlineStyles_M = getInlineStyle(dec) | ||
.fmap(inlineStyles => { | ||
return inlineStyles.elements.map((inlineStyle: ts.Expression) => { | ||
if (isSimpleTemplateString(inlineStyle)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can first apply filter
and after that map it, so we can drop the ugly if condition?
} | ||
|
||
export function all<T>(...preds: F1<T, boolean>[]): F1<T, boolean> { | ||
return (t: T) => !preds.find(p => !p(t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some
can do the trick since it returns boolean anyway.
return (t: T) => !preds.find(p => !p(t)); | ||
} | ||
export function any<T>(...preds: F1<T, boolean>[]): F1<T, boolean> { | ||
return (t: T) => !!preds.find(p => p(t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some
can do the trick since it returns boolean anyway.
I left some comments. In general I like the direction that you took! The build is failing:
|
7e88123
to
ba0f67f
Compare
Nothing new yet, just fixed the above error resulted from merging master. |
Awesome! I just published beta.4, we can introduce this new AST traversal mechanism in beta.5. |
Prototyping of Maybe monad in AST traversal
This is intended to further discuss whether/how Maybe monad would be a good fit in
src/angular/metadataReader.ts seems to be a good target to start. Most of the work goes into extracting AST traversal code into
astQuery
andngQuery
.A few realizations so far
decoratorArgument
)callExpression
)