Skip to content

Commit

Permalink
Merge pull request #24 from NASA-AMMOS/fix/unterminated-string-litera…
Browse files Browse the repository at this point in the history
…l-regression

[FIX] Unterminated String Literal Regression
  • Loading branch information
Dylan Stewart authored Aug 30, 2022
2 parents 1284a84 + f6e591c commit b76f051
Show file tree
Hide file tree
Showing 3 changed files with 898 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/UserCodeRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export abstract class UserCodeError {
return nodeList;
}

protected static getDescendentAtLocation(node: ts.Node, start: number, end: number): ts.Node | null {
protected static getDescendentAtLocation(node: ts.Node, start: number, end: number): ts.Node {
if (node.getStart() === start && node.getEnd() === end) {
return node;
}
Expand All @@ -273,7 +273,7 @@ export abstract class UserCodeError {
return UserCodeError.getDescendentAtLocation(child1, start, end);
}
}
return null;
return node;
}

public toJSON(): {
Expand Down
52 changes: 52 additions & 0 deletions test/UserCodeRunner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,55 @@ test('Aerie incorrect stack frame assumption regression test', async () => {
column: 56,
});
});

test('Unterminated string literal regression', async () => {
const userCode =
`export default () =>
Sequence.new({
seqId: 'seq0',
metadata: {},
commands: [
A('2020-001T00:00:00').ECHO("BDS_DIAG_SVC_CMD_CHANGE_MODE),
],
});`.trimTemplate();

const runner = new UserCodeRunner();
const [commandTypes, temporalPolyfill] = await Promise.all([
fs.promises.readFile(new URL('./inputs/command-types.ts', import.meta.url).pathname, 'utf8'),
fs.promises.readFile(new URL('./inputs/TemporalPolyfillTypes.ts', import.meta.url).pathname, 'utf8'),
]);

const result = await runner.executeUserCode(
userCode,
[],
'Sequence',
[],
1000,
[
ts.createSourceFile('command-types.ts', commandTypes, ts.ScriptTarget.ESNext),
ts.createSourceFile('TemporalPolyfillTypes.ts', temporalPolyfill, ts.ScriptTarget.ESNext),
],
vm.createContext({
Temporal,
}),
);

expect(result.isErr()).toBeTruthy();
expect(result.unwrapErr().length).toBe(2);
expect(result.unwrapErr()[0].message).toBe(`TypeError: TS1002 Unterminated string literal.`);
expect(result.unwrapErr()[0].stack).toBe(`
at (6:70)
`.trimTemplate())
expect(result.unwrapErr()[0].location).toMatchObject({
line: 6,
column: 70,
});
expect(result.unwrapErr()[1].message).toBe(`TypeError: TS1005 ',' expected.`);
expect(result.unwrapErr()[1].stack).toBe(`
at (7:9)
`.trimTemplate())
expect(result.unwrapErr()[1].location).toMatchObject({
line: 7,
column: 9,
});
});
Loading

0 comments on commit b76f051

Please sign in to comment.