Skip to content

Commit b9ce151

Browse files
committed
handle reserved words in abi
1 parent 4914d79 commit b9ce151

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

packages/cli/src/codegen/util.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export function disambiguateNames<T>({
99
}) {
1010
const collisionCounter = new Map();
1111
return values.map((value, index) => {
12-
const name = getName(value, index);
12+
let name = getName(value, index);
13+
name = handleReservedWord(name);
1314
const counter = collisionCounter.get(name);
1415
if (counter === undefined) {
1516
collisionCounter.set(name, 1);
@@ -20,6 +21,61 @@ export function disambiguateNames<T>({
2021
});
2122
}
2223

24+
// List of JavaScript reserved words that need to be handled
25+
const RESERVED_WORDS = new Set([
26+
'await',
27+
'break',
28+
'case',
29+
'catch',
30+
'class',
31+
'const',
32+
'continue',
33+
'debugger',
34+
'default',
35+
'delete',
36+
'do',
37+
'else',
38+
'enum',
39+
'export',
40+
'extends',
41+
'false',
42+
'finally',
43+
'for',
44+
'function',
45+
'if',
46+
'implements',
47+
'import',
48+
'in',
49+
'instanceof',
50+
'interface',
51+
'let',
52+
'new',
53+
'null',
54+
'package',
55+
'private',
56+
'protected',
57+
'public',
58+
'return',
59+
'super',
60+
'switch',
61+
'static',
62+
'this',
63+
'throw',
64+
'true',
65+
'try',
66+
'typeof',
67+
'var',
68+
'void',
69+
'while',
70+
'with',
71+
'yield'
72+
]);
73+
74+
// Function to handle JavaScript reserved words by appending an underscore
75+
export function handleReservedWord(name: string): string {
76+
return RESERVED_WORDS.has(name) ? `${name}_` : name;
77+
}
78+
2379
export function isTupleType(t: string) {
2480
return t === 'tuple';
2581
}

0 commit comments

Comments
 (0)