Skip to content
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

fix(rosetta): use of keyword 'lambda' produces invalid Python code #1850

Merged
merged 3 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/jsii-rosetta/lib/languages/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export class PythonVisitor extends DefaultVisitor<PythonLanguageContext> {
const originalIdentifier = node.text;

const explodedParameter = context.currentContext.explodedParameter;
// eslint-disable-next-line max-len
if (
context.currentContext.tailPositionArgument &&
explodedParameter &&
Expand Down Expand Up @@ -815,10 +814,11 @@ function mangleIdentifier(originalIdentifier: string) {
return originalIdentifier;
}
// Turn into snake-case
return originalIdentifier.replace(
const cased = originalIdentifier.replace(
/[^A-Z][A-Z]/g,
(m) => `${m[0].substr(0, 1)}_${m.substr(1).toLowerCase()}`,
);
return IDENTIFIER_KEYWORDS.includes(cased) ? `${cased}_` : cased;
}

const BUILTIN_FUNCTIONS: { [key: string]: string } = {
Expand All @@ -833,6 +833,8 @@ const TOKEN_REWRITES: { [key: string]: string } = {
false: 'False',
};

const IDENTIFIER_KEYWORDS: string[] = ['lambda'];

function last<A>(xs: readonly A[]): A {
return xs[xs.length - 1];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Scope.Aws.Lambda;
new ClassFromLambda(new Struct {
Key = "lambda.amazonaws.com"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scope.aws.lambda.*;
ClassFromLambda.Builder.create()
.key("lambda.amazonaws.com")
.build();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scope.aws_lambda as lambda_
lambda_.ClassFromLambda(
key="lambda.amazonaws.com"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as lambda from '@scope/aws-lambda';
new lambda.ClassFromLambda({
key: 'lambda.amazonaws.com'
});