Skip to content

Commit cd17ae4

Browse files
committed
Add route prefix to reserved js keyword route names
1 parent 747731a commit cd17ae4

File tree

3 files changed

+47
-39
lines changed

3 files changed

+47
-39
lines changed

src/GenerateCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ private function writeNamedFile(Collection $routes, string $namespace): void
207207
fn ($s) => $s->camel()
208208
)->toString();
209209

210+
if (in_array($base, TypeScript::RESERVED_KEYWORDS)) {
211+
$base = $base.'Route';
212+
}
213+
214+
if (is_numeric($base)) {
215+
$base = 'route'.$base;
216+
}
217+
210218
if ($base !== $imports) {
211219
$this->appendContent($path, "const {$base} = { {$imports} }\n");
212220
}

src/Route.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -165,45 +165,7 @@ public function controllerMethodLineNumber(): int
165165

166166
private function finalJsMethod(string $method): string
167167
{
168-
$reserved = [
169-
'break',
170-
'case',
171-
'catch',
172-
'class',
173-
'const',
174-
'continue',
175-
'debugger',
176-
'default',
177-
'delete',
178-
'do',
179-
'else',
180-
'export',
181-
'extends',
182-
'false',
183-
'finally',
184-
'for',
185-
'function',
186-
'if',
187-
'import',
188-
'in',
189-
'instanceof',
190-
'new',
191-
'null',
192-
'return',
193-
'super',
194-
'switch',
195-
'this',
196-
'throw',
197-
'true',
198-
'try',
199-
'typeof',
200-
'var',
201-
'void',
202-
'while',
203-
'with',
204-
];
205-
206-
$method = in_array($method, $reserved) ? $method.'Method' : $method;
168+
$method = in_array($method, TypeScript::RESERVED_KEYWORDS) ? $method.'Method' : $method;
207169

208170
if (is_numeric($method)) {
209171
return 'method'.$method;

src/TypeScript.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@
66

77
class TypeScript
88
{
9+
public const RESERVED_KEYWORDS = [
10+
'break',
11+
'case',
12+
'catch',
13+
'class',
14+
'const',
15+
'continue',
16+
'debugger',
17+
'default',
18+
'delete',
19+
'do',
20+
'else',
21+
'export',
22+
'extends',
23+
'false',
24+
'finally',
25+
'for',
26+
'function',
27+
'if',
28+
'import',
29+
'in',
30+
'instanceof',
31+
'new',
32+
'null',
33+
'return',
34+
'super',
35+
'switch',
36+
'this',
37+
'throw',
38+
'true',
39+
'try',
40+
'typeof',
41+
'var',
42+
'void',
43+
'while',
44+
'with',
45+
];
46+
947
public static function cleanUp(string $view): string
1048
{
1149
$replacements = [

0 commit comments

Comments
 (0)