Skip to content

Commit 5187331

Browse files
JordonPhillipssrchase
authored andcommitted
Avoid messing with prototypes
1 parent ed4d9c0 commit 5187331

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ final class SymbolVisitor implements SymbolProvider, ShapeVisitor<Symbol> {
9696
ReservedWords reservedWords = new ReservedWordsBuilder()
9797
.loadWords(TypeScriptCodegenPlugin.class.getResource("reserved-words.txt"))
9898
.build();
99+
ReservedWords memberReservedWords = new ReservedWordsBuilder()
100+
.loadWords(TypeScriptCodegenPlugin.class.getResource("reserved-words-members.txt"))
101+
.build();
99102

100103
escaper = ReservedWordSymbolProvider.builder()
101104
.nameReservedWords(reservedWords)
105+
.memberReservedWords(memberReservedWords)
102106
// Only escape words when the symbol has a definition file to
103107
// prevent escaping intentional references to built-in types.
104108
.escapePredicate((shape, symbol) -> !StringUtils.isEmpty(symbol.getDefinitionFile()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TypeScript reserved words for members.
2+
#
3+
# Smithy's rules around the names of types are already pretty strict and
4+
# mostly compatible with TypeScript's naming conventions. Furthermore, the
5+
# code generator will automatically uppercase every instance where a
6+
# TypeScript type is generated from a Smithy type. This makes the majority
7+
# of all of the reserved words in TypeScript something that will never be
8+
# encountered when generating code. However, it's possible that other
9+
# SymbolProvider implementations could be used that do emit reserved
10+
# words for identifiers, hence this code is useful as an extra layer of
11+
# protection.
12+
#
13+
# Adding new reserved words to this list could potentially result in a
14+
# breaking change to previously generated clients, so adding new reserved words
15+
# is discouraged. Ideally we could have just automatically added an alias for
16+
# built-in types that conflict with generated types, but, unfortunately, it's
17+
# not currently possible to alias a built-in TypeScript or JavaScript type.
18+
#
19+
# When a reserved word is encountered, this implementation will
20+
# continue to prefix the word with "_" until it's no longer considered
21+
# reserved.
22+
23+
# Prevent prototype pollution
24+
__proto__

0 commit comments

Comments
 (0)