Skip to content

Commit

Permalink
Fix TypeStrong#1667 multiline function arguments support in REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
d9k committed Mar 4, 2022
1 parent 20cbbf5 commit ea6d318
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/repl.ts
Expand Up @@ -680,6 +680,8 @@ const RECOVERY_CODES: Set<number> = new Set([
1160, // "Unterminated template literal."
1161, // "Unterminated regular expression literal."
2355, // "A function whose declared type is neither 'void' nor 'any' must return a value."
2391, // "Function implementation is missing or not immediately following the declaration."
7010, // "Function, which lacks return-type annotation, implicitly has an 'any' return type."
]);

/**
Expand Down
26 changes: 26 additions & 0 deletions src/test/repl/repl.spec.ts
Expand Up @@ -424,6 +424,32 @@ test.suite(
expect(stdout).toContain(":1:1'\n");
}
);

// Serial because it's timing-sensitive
test.serial(
'multiline function args declaration is supported',
async (t) => {
const script = `function myFn(
a: string,
b: string
) {
return a + ' ' + b
}
myFn('test', '!')
`;

// If first line of input ends in a semicolon, should not add a second semicolon.
// That will cause an extra blank line in the compiled output which will
// offset the stack line number.
const { stdout, stderr } = await t.context.executeInRepl(script, {
registerHooks: true,
startInternalOptions: { useGlobal: false },
waitPattern: 'done!',
});
expect(stderr).toBe('');
expect(stdout).toContain(`'test !'`);
}
);
}
);

Expand Down

0 comments on commit ea6d318

Please sign in to comment.