Move purify transforms#81
Conversation
|
/cc @IgorMinar |
|
|
||
|
|
||
| export const wrapEnumsRegexes = [ | ||
| // tslint:disable:max-line-length |
There was a problem hiding this comment.
Seriously consider making those regexes as parser functions. There are many backreferences and those are really slow. I wouldn't be surprised if this is O(n^4), considering you're going to 4 backrefs. Considering you run this on really long strings I think you'd see some improvements. We can chat about it later.
|
|
||
|
|
||
| export const prefixClassRegexes = [ | ||
| // tslint:disable-next-line:max-line-length |
| // expressions: `(function() {}())` Their start pos doesn't include the opening paren | ||
| // and must be adjusted. | ||
| if (isIIFE(node) | ||
| if ( |
There was a problem hiding this comment.
First line goes with the if, last parenthesis with the last line, with 4 spaces of indentation:
if (isIIFE(node)
&& previousNode.kind === ts.SyntaxKind.ParenthesizedExpression
&& node.parent
&& !hasPureComment(node.parent)) {
topLEvelFunctions.push(node.parent);
} else if ((node.kind === ts.SyntaxKind.CallExpression || node.kind === ts.SyntaxKind.NewExpression)
&& !hasPureComment(node)) {
topLevelFunctions.push(node);
}There was a problem hiding this comment.
Done, but the else if still has to be split because of line length.
|
|
||
|
|
||
| export const scrubFileRegexes = [ | ||
| /decorators/, |
There was a problem hiding this comment.
indexOf() is 10x faster than regexes. For static strings like those I'd use indexOf. Reference: https://jsperf.com/regex-vs-strings
| enumStatements.push(...findTs2_3EnumStatements(maybeName, nextStatement)); | ||
| enumDropNodes.push(nextStatement); | ||
| } else if ( | ||
| varDecl.initializer |
There was a problem hiding this comment.
See my comment about if and alignment.
| const exprStmt = innerStmt as ts.ExpressionStatement; | ||
|
|
||
| if (!( | ||
| innerBinExpr.operatorToken.kind === ts.SyntaxKind.FirstAssignment |
| const leftExpr = binExpr.left as ts.PropertyAccessExpression | ts.ElementAccessExpression; | ||
|
|
||
| if (!( | ||
| leftExpr.expression.kind === ts.SyntaxKind.Identifier |
| return ts.visitEachChild(node, visitor, context); | ||
| }; | ||
|
|
||
| return ts.visitNode(sf, visitor); |
There was a problem hiding this comment.
ts.visitEachChild would be slightly more efficient here. The source file node can't be a down leveled class so no need to check it.
| const enums = findEnumDeclarations(sf); | ||
| const dropNodes = enums.reduce((acc: ts.Node[], curr) => acc.concat(curr.dropNodes), []); | ||
|
|
||
| const visitor: ts.Visitor = (node: ts.Node): ts.Node => { |
There was a problem hiding this comment.
Return type of ts.Node | undefined to remove the any usage below?
There was a problem hiding this comment.
TypeScript has wrong typing here (ts.Visitor), so we can't easily :(
There was a problem hiding this comment.
Yup, noticed that. The return type of ts.Visitor (ts.VisitResult<Node>) is the issue. It should be defined as T | T[] | undefined.
There was a problem hiding this comment.
I did a PR for that, should be in one of the newer versions microsoft/TypeScript#17044
|
Please rebase. This looks good to me, just want to run the latest lint and tests. |
No description provided.