Fix remaining compile errors.

This commit is contained in:
Robin Heggelund Hansen 2021-07-14 12:16:26 +02:00
parent 266885899e
commit 5e16fe457b
4 changed files with 20 additions and 14 deletions

View File

@ -266,6 +266,7 @@ const emptyOpts: Transforms = {
unusedValues: false,
replaceListFunctions: false,
replaceStringFunctions: false,
recordUpdates: false,
v8Analysis: false,
replacements: null
};

View File

@ -30,6 +30,7 @@ const defaultOptions: Transforms = {
unusedValues: false,
replaceListFunctions: true,
replaceStringFunctions: true,
recordUpdates: false,
v8Analysis: true,
replacements: null
};

View File

@ -117,7 +117,7 @@ export const transform = async (
[transforms.arrowFns, convertFunctionExpressionsToArrowFuncs],
[transforms.shorthandObjectLiterals, convertToObjectShorthandLiterals],
[transforms.unusedValues, createRemoveUnusedLocalsTransform()],
[transforms.recordUpdate, recordUpdate()],
[transforms.recordUpdates, recordUpdate()],
[transforms.v8Analysis, reportFunctionStatusInBenchmarks],
]);

View File

@ -4,25 +4,29 @@ export const recordUpdate = (): ts.TransformerFactory<ts.SourceFile> =>
(context) => (sourceFile) => {
console.log('record update');
const registry = new RecordRegistry();
ts.visitNode(sourceFile, removeApplicativeFuncVisitor(registry, context));
ts.visitNode(sourceFile, replaceObjectLiterals(registry, context));
return sourceFile;
}
function RecordRegistry() {
this.counter = 0;
this.map = new Map();
class RecordRegistry {
counter: number;
map: Map<String, String>;
constructor() {
this.counter = 0;
this.map = new Map();
}
register(recordAst: ts.Node) {
console.log(recordAst);
}
}
RecordRegistry.prototype.register = function(recordAst) {
console.log(recordAst);
}
function unwrapVisitor(recordRegistry, context) {
function replaceObjectLiterals(_registry: RecordRegistry, _ctx: ts.TransformationContext) {
const visitorHelp = (node: ts.Node): ts.VisitResult<ts.Node> => {
if (isRecordLiteral(visitedNode)) {
return visitedNode.arguments[0];
if (isRecordLiteral(node)) {
return node;
}
return node;
@ -32,5 +36,5 @@ function unwrapVisitor(recordRegistry, context) {
}
function isRecordLiteral(node: ts.Node): boolean {
return ts.isObjectLiteral(node);
return ts.isObjectLiteralExpression(node);
}