Skip to content

Commit

Permalink
JS error should use JS-char-offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Dec 19, 2023
1 parent e67aaa1 commit 6944873
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,25 @@ export class Preprocessor {
*/
parse(src: string, filename?: string): Parsed[];
}

export interface ParseError {
source_code: string;
source_code_color: string;

/**
* 0-indexed starting line of the error
*/
start_line: number;
/**
* 0-indexed starting character-based column of the error
*/
start_column: number;
/**
* 0-indexed ending line of the error
*/
end_line: number;
/**
* 0-indexed ending character-based column of the error
*/
end_column: number;
}
8 changes: 4 additions & 4 deletions test/node-api-esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ export default template(\`Hi\`, {
const Foo = <template>{{foo}}</template>
<template>
<Foo />
🥳🥳🥳🥳<Foo />
`);
} catch (err) {
parseError = err;
}

// Unexpected eof
// column 10 is the EOF
// column 14 is the EOF
expect(parseError.start_line).to.equal(6, "start_line");
expect(parseError.start_column).to.equal(10, "start_column");
expect(parseError.start_column).to.equal(14, "start_column");
expect(parseError.end_line).to.equal(6, "end_line");
expect(parseError.end_column).to.equal(10, "end_column");
expect(parseError.end_column).to.equal(14, "end_column");
});
});

0 comments on commit 6944873

Please sign in to comment.