Skip to content

Commit

Permalink
chore: add go reserved words (#2300)
Browse files Browse the repository at this point in the history
Fixes #2299



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
SoManyHs authored Dec 4, 2020
1 parent f29c5f6 commit 2ef46d6
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 47 deletions.
94 changes: 47 additions & 47 deletions docs/typescript-restrictions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,53 @@ element (which will cause a compilation failure if `--fail-on-warnings` is set).
The list of reserved words (which are not also reserved in **TypeScript**),
derived from [`jsii/lib/reserved-words.ts`] is:

**C#** | **Java** | **Python**
---------------|----------------|---------------
`abstract` | `abstract` | `False`
`base` | `assert` | `None`
`bool` | `boolean` | `True`
`byte` | `byte` | `and`
`char` | `char` | `assert`
`checked` | `double` | `def`
`decimal` | `final` | `del`
`delegate` | `float` | `elif`
`double` | `goto` | `except`
`event` | `int` | `from`
`explicit` | `long` | `global`
`extern` | `native` | `is`
`fixed` | `short` | `lambda`
`float` | `strictfp` | `nonlocal`
`foreach` | `synchronized` | `not`
`goto` | `throws` | `or`
`implicit` | `transient` | `pass`
`int` | `volatile` | `raise`
`internal` | |
`is` | |
`lock` | |
`long` | |
`namespace` | |
`object` | |
`operator` | |
`out` | |
`override` | |
`params` | |
`readonly` | |
`ref` | |
`sbyte` | |
`sealed` | |
`short` | |
`sizeof` | |
`stackalloc` | |
`string` | |
`struct` | |
`uint` | |
`ulong` | |
`unchecked` | |
`unsafe` | |
`ushort` | |
`using` | |
`virtual` | |
`volatile` | |
**C#** | **Java** | **Python** | **Go**
---------------|----------------|--------------|-------------
`abstract` | `abstract` | `False` | `break`
`base` | `assert` | `None` | `case`
`bool` | `boolean` | `True` | `chan`
`byte` | `byte` | `and` | `const`
`char` | `char` | `assert` | `continue`
`checked` | `double` | `def` | `default`
`decimal` | `final` | `del` | `defer`
`delegate` | `float` | `elif` | `else`
`double` | `goto` | `except` | `fallthrough`
`event` | `int` | `from` | `for`
`explicit` | `long` | `global` | `func`
`extern` | `native` | `is` | `go`
`fixed` | `short` | `lambda` | `goto`
`float` | `strictfp` | `nonlocal` | `if`
`foreach` | `synchronized` | `not` | `import`
`goto` | `throws` | `or` | `interface`
`implicit` | `transient` | `pass` | `map`
`int` | `volatile` | `raise` | `package`
`internal` | | | `range`
`is` | | | `return`
`lock` | | | `select`
`long` | | | `struct`
`namespace` | | | `switch`
`object` | | | `type`
`operator` | | | `var`
`out` | | |
`override` | | |
`params` | | |
`readonly` | | |
`ref` | | |
`sbyte` | | |
`sealed` | | |
`short` | | |
`sizeof` | | |
`stackalloc` | | |
`string` | | |
`struct` | | |
`uint` | | |
`ulong` | | |
`unchecked` | | |
`unsafe` | | |
`ushort` | | |
`using` | | |
`virtual` | | |
`volatile` | | |

Code generators from `jsii-pacmak` will try to work around those reserved words
when they are encountered, but may resort to using names that could clash with
Expand Down
72 changes: 72 additions & 0 deletions packages/jsii/lib/reserved-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function isReservedName(name: string): string[] | undefined {
if (PYTHON_RESERVED.has(name)) {
reserved.push('Python');
}

if (GO_RESERVED.has(name)) {
reserved.push('Go');
}
return reserved.length > 0 ? reserved : undefined;
}

Expand Down Expand Up @@ -184,3 +188,71 @@ export const PYTHON_RESERVED = new Set([
'raise',
'self',
]);

export const GO_RESERVED = new Set([
'break',
'case',
'chan',
'const',
'continue',
'default',
'defer',
'else',
'fallthrough',
'for',
'func',
'go',
'goto',
'if',
'import',
'interface',
'map',
'package',
'range',
'return',
'select',
'struct',
'switch',
'type',
'var',
// constants
'true',
'false',
'iota',
'nil',
// types
'int',
'int8',
'int16',
'int32',
'int64',
'uint',
'uint8',
'uint16',
'uint32',
'uint64',
'uintptr',
'float32',
'float64',
'complex128',
'complex64',
'bool',
'rune',
'byte',
'string',
'error',
// functions
'make',
'len',
'cap',
'new',
'append',
'copy',
'close',
'delete',
'complex',
'real',
'imag',
'panic',
'recover',
]);

0 comments on commit 2ef46d6

Please sign in to comment.