Skip to content

Commit

Permalink
fix(go): arguments named "_" result in invalid code
Browse files Browse the repository at this point in the history
It is common in TypeScript to use `_` as an argument name if the argument is not used. This is an invalid name in Go, so replace it with `_arg`.

Fixes #2530
  • Loading branch information
Elad Ben-Israel committed Mar 15, 2021
1 parent 99b3b71 commit 2796962
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 113 deletions.
1 change: 1 addition & 0 deletions packages/jsii-calc/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * as nodirect from './no-direct-types';
export * as module2647 from './module2647';
export * as module2689 from './module2689';
export * as module2692 from './module2692';
export * as module2530 from './module2530';
17 changes: 17 additions & 0 deletions packages/jsii-calc/lib/module2530/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Verifies a method with parameters "_" can be generated.
* @see https://github.com/aws/jsii/issues/2530
*/
export class MyClass {
public static bar(_: boolean) {
return;
}

public constructor(_: number) {
return;
}

public foo(_: string) {
return;
}
}
80 changes: 79 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@
"line": 142
}
},
"jsii-calc.module2530": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 17
}
},
"jsii-calc.module2647": {
"locationInModule": {
"filename": "lib/index.ts",
Expand Down Expand Up @@ -14173,6 +14179,78 @@
"name": "CompositionStringStyle",
"namespace": "composition.CompositeOperation"
},
"jsii-calc.module2530.MyClass": {
"assembly": "jsii-calc",
"docs": {
"see": "https://github.com/aws/jsii/issues/2530",
"stability": "stable",
"summary": "Verifies a method with parameters \"_\" can be generated."
},
"fqn": "jsii-calc.module2530.MyClass",
"initializer": {
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2530/index.ts",
"line": 10
},
"parameters": [
{
"name": "_",
"type": {
"primitive": "number"
}
}
]
},
"kind": "class",
"locationInModule": {
"filename": "lib/module2530/index.ts",
"line": 5
},
"methods": [
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2530/index.ts",
"line": 6
},
"name": "bar",
"parameters": [
{
"name": "_",
"type": {
"primitive": "boolean"
}
}
],
"static": true
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2530/index.ts",
"line": 14
},
"name": "foo",
"parameters": [
{
"name": "_",
"type": {
"primitive": "string"
}
}
]
}
],
"name": "MyClass",
"namespace": "module2530"
},
"jsii-calc.module2647.ExtendAndImplement": {
"assembly": "jsii-calc",
"base": "@scope/jsii-calc-lib.BaseFor2647",
Expand Down Expand Up @@ -15344,5 +15422,5 @@
}
},
"version": "3.20.120",
"fingerprint": "zzayVZr0GAzkOZJ5SHHy3UvRxdZ1DZAPChbY/MkerHU="
"fingerprint": "hBZRskNm0XPeSO9U+PMqKKVZ2faqmKnE9eVN2tY1Wik="
}
1 change: 1 addition & 0 deletions packages/jsii-pacmak/lib/targets/go/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const RESERVED_WORDS: { [word: string]: string } = {
import: 'import_',
return: 'return_',
var: 'var_',
_: '_arg',
};

/*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2796962

Please sign in to comment.