Skip to content

Commit 0023a14

Browse files
committed
deployment status 2
1 parent ed7c15c commit 0023a14

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/utils/arduino/generate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export function generateArduinoSketch(opts: GenerateOpts): string {
4141
for (const c of ast.commands) {
4242
switch (c.type) {
4343
case 'STRING':
44-
lines.push(` typeString(${JSON.stringify(c.args[0])});\n`);
44+
lines.push(` typeString(${JSON.stringify(c.args[0] ?? '')});\n`);
4545
break;
4646
case 'DELAY':
47-
lines.push(` delay(${c.args[0]});\n`);
47+
lines.push(` delay(${c.args[0] ?? '0'});\n`);
4848
break;
4949
case 'MOD': {
50-
const keys = c.args.filter(Boolean);
51-
const last = keys[keys.length - 1];
50+
const keys = (c.args || []).filter(Boolean);
51+
const last = keys[keys.length - 1] ?? '';
5252
const mods = keys.slice(0, -1).map(k => mapMod(k)).filter(Boolean);
5353
for (const m of mods) lines.push(` Keyboard.press(${m});\n`);
5454
lines.push(` Keyboard.press(${mapKey(last)});\n delay(5);\n Keyboard.releaseAll();\n`);

src/utils/ducky/parse.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,37 @@ export function parseDuckyScript(input: string): DuckyAst {
1212

1313
for (let i = 0; i < lines.length; i++) {
1414
const raw = lines[i];
15+
if (raw == null) continue;
1516
const line = raw.trim();
1617
if (!line || line.startsWith('REM')) continue;
1718

1819
const [cmd, ...rest] = line.split(/\s+/);
20+
if (!cmd) continue;
1921
const upper = cmd.toUpperCase();
2022

2123
if (upper === 'STRING') {
22-
const args = [raw.slice(raw.toUpperCase().indexOf('STRING') + 6).trimStart()];
24+
const idx = raw.toUpperCase().indexOf('STRING');
25+
const args = [idx >= 0 ? raw.slice(idx + 6).trimStart() : ''];
2326
commands.push({ type: 'STRING', args });
2427
continue;
2528
}
2629

2730
if (upper === 'DELAY') {
31+
if (!rest[0]) {
32+
errors.push(`Line ${i + 1}: DELAY requires a number`);
33+
continue;
34+
}
2835
const ms = parseInt(rest[0], 10);
2936
if (Number.isFinite(ms)) commands.push({ type: 'DELAY', args: [String(ms)] });
3037
else errors.push(`Line ${i + 1}: DELAY requires a number`);
3138
continue;
3239
}
3340

3441
if (upper === 'REPEAT') {
42+
if (!rest[0]) {
43+
errors.push(`Line ${i + 1}: REPEAT requires positive number`);
44+
continue;
45+
}
3546
const n = parseInt(rest[0], 10);
3647
if (!Number.isFinite(n) || n < 1) {
3748
errors.push(`Line ${i + 1}: REPEAT requires positive number`);
@@ -42,7 +53,7 @@ export function parseDuckyScript(input: string): DuckyAst {
4253
continue;
4354
}
4455
const last = commands[commands.length - 1];
45-
for (let j = 0; j < n; j++) commands.push({ ...last });
56+
for (let j = 0; j < n; j++) commands.push({ type: last.type, args: [...last.args] });
4657
continue;
4758
}
4859

0 commit comments

Comments
 (0)