Skip to content

Commit be1ffe4

Browse files
authored
Merge pull request #6 from moznion/bind_parameter_on_immediately_invoked_function
Bind the argument of `dynamodbRecord()` to the transformed immediately invoked function's parameter
2 parents 4074468 + 5c6bcc9 commit be1ffe4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tests/transformer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ describe('dynamodb record transform', () => {
280280
['buz', 'qux'],
281281
]),
282282
});
283+
expect(record['id']).toEqual({ N: '12345' });
283284
expect(record['name']).toEqual({ S: 'John Doe' });
284285
expect(record['tags']).toEqual({ M: { foo: { S: 'bar' }, buz: { S: 'qux' } } });
285-
expect(record['id']).toEqual({ N: '12345' });
286286
expect(Object.keys(record)).toHaveLength(3);
287287
});
288288
});

transformer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ function visitNode(node: ts.Node, program: ts.Program): ts.Node | undefined {
246246
})
247247
.filter((c): c is ts.ObjectLiteralElementLike => !!c);
248248

249-
return ts.factory.createImmediatelyInvokedFunctionExpression([
250-
ts.factory.createVariableStatement([], [ts.factory.createVariableDeclaration(argVarNameIdent)]),
251-
ts.factory.createBinaryExpression(argVarNameIdent, ts.SyntaxKind.EqualsToken, node.arguments[0]),
252-
ts.factory.createReturnStatement(ts.factory.createObjectLiteralExpression(objectProps, true)),
253-
] as ts.Statement[]);
249+
return ts.factory.createImmediatelyInvokedFunctionExpression(
250+
[ts.factory.createReturnStatement(ts.factory.createObjectLiteralExpression(objectProps, true))] as ts.Statement[],
251+
ts.factory.createParameterDeclaration([], undefined, argVarNameIdent, undefined, node.typeArguments[0], undefined),
252+
node.arguments[0],
253+
);
254254
}
255255

256256
function extractKeyValueTypesFromKeyValuePairMapSyntax(nodes: ts.Node[]): [string, string] | undefined {

0 commit comments

Comments
 (0)