mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +03:00
Fix remaining compile errors.
This commit is contained in:
parent
266885899e
commit
5e16fe457b
@ -266,6 +266,7 @@ const emptyOpts: Transforms = {
|
||||
unusedValues: false,
|
||||
replaceListFunctions: false,
|
||||
replaceStringFunctions: false,
|
||||
recordUpdates: false,
|
||||
v8Analysis: false,
|
||||
replacements: null
|
||||
};
|
||||
|
@ -30,6 +30,7 @@ const defaultOptions: Transforms = {
|
||||
unusedValues: false,
|
||||
replaceListFunctions: true,
|
||||
replaceStringFunctions: true,
|
||||
recordUpdates: false,
|
||||
v8Analysis: true,
|
||||
replacements: null
|
||||
};
|
||||
|
@ -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],
|
||||
]);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user