-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add end position to ParserError #157
Draft
tscpp
wants to merge
1
commit into
meriyah:master
Choose a base branch
from
tscpp:tscpp/issue156
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−175
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { ParserState } from './common'; | ||
import { Location, Node, Position } from './estree'; | ||
import { Context, finishNode, ParserState } from './common'; | ||
|
||
export const enum Errors { | ||
Unexpected, | ||
|
@@ -352,26 +353,39 @@ export class ParseError extends SyntaxError { | |
line: ParseError['line']; | ||
column: ParseError['column']; | ||
}; | ||
public end?: Position; | ||
public index: number; | ||
public line: number; | ||
public column: number; | ||
public description: string; | ||
/*eslint-disable*/ | ||
constructor(startindex: number, line: number, column: number, type: Errors, ...params: string[]) { | ||
constructor(startindex: number, loc: { start: Position; end?: Position }, type: Errors, ...params: string[]) { | ||
const message = | ||
'[' + line + ':' + column + ']: ' + errorMessages[type].replace(/%(\d+)/g, (_: string, i: number) => params[i]); | ||
'[' + | ||
loc.start.line + | ||
':' + | ||
loc.start.column + | ||
']: ' + | ||
errorMessages[type].replace(/%(\d+)/g, (_: string, i: number) => params[i]); | ||
super(`${message}`); | ||
this.index = startindex; | ||
this.line = line; | ||
this.column = column; | ||
this.line = loc.start.line; | ||
this.column = loc.start.column; | ||
this.description = message; | ||
/* Acorn compat */ | ||
this.loc = { | ||
line, | ||
column | ||
} as any; | ||
line: this.line, | ||
column: this.line | ||
}; | ||
this.end = loc.end | ||
? { | ||
line: loc.end.line, | ||
column: loc.end.column | ||
} | ||
: undefined; | ||
} | ||
} | ||
|
||
/** | ||
* Throws an error | ||
* | ||
|
@@ -381,11 +395,22 @@ export class ParseError extends SyntaxError { | |
* @param {...string[]} params | ||
* @returns {never} | ||
*/ | ||
export function report(parser: ParserState, type: Errors, ...params: string[]): never { | ||
throw new ParseError(parser.index, parser.line, parser.column, type, ...params); | ||
export function report(parser: ParserState, context: Context, node: Node, type: Errors, ...params: string[]): never { | ||
const end = finishNode(parser, context, parser.index, parser.line, parser.column, node).loc?.end; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The finishNode mutates nothing on
Which you can directly get from |
||
|
||
throw new ParseError( | ||
parser.index, | ||
{ | ||
start: { line: parser.line, column: parser.column }, | ||
end: end ? ({ line: end.line, column: end.column } as Position) : undefined | ||
}, | ||
type, | ||
...params | ||
); | ||
} | ||
|
||
export function reportScopeError(scope: any): never { | ||
// warn me about this pls | ||
throw new ParseError(scope.index, scope.line, scope.column, scope.type, scope.params); | ||
} | ||
|
||
|
@@ -400,8 +425,8 @@ export function reportScopeError(scope: any): never { | |
* @param {Errors} type | ||
* @param {...string[]} params | ||
*/ | ||
export function reportMessageAt(index: number, line: number, column: number, type: Errors, ...params: string[]): never { | ||
throw new ParseError(index, line, column, type, ...params); | ||
export function reportMessageAt(index: number, loc: Location, type: Errors, ...params: string[]): never { | ||
throw new ParseError(index, loc, type, ...params); | ||
} | ||
|
||
/** | ||
|
@@ -414,6 +439,6 @@ export function reportMessageAt(index: number, line: number, column: number, typ | |
* @param {number} column | ||
* @param {Errors} type | ||
*/ | ||
export function reportScannerError(index: number, line: number, column: number, type: Errors): never { | ||
throw new ParseError(index, line, column, type); | ||
export function reportScannerError(index: number, loc: Location, type: Errors): never { | ||
throw new ParseError(index, loc, type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the semicolon in interface def?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an actual reason. I'm just used to don't use semis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But they are there for our other interface definitions. I suggest to put it back here for consistency.
I am surprised "prettier" does not have an opinion on this syntax, it accepted both. But there is
semi: true
in ourprettier.config.js
, a "prettier" bug?If you want to cleanup the type def to remove semicolon, pls create another PR to touch all of the interfaces, if @KFlash has no strong opinion on this syntax thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fisker should not
semi:true
inprettier.config.js
enforce the semicolon here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, why don't we run
prettier --check
on CI?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, we got these in
.prettierignore
. @KFlash why we ignored those source files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the style get fucked up with Prettier and not lined. Regarding unicode.ts it will be a long list (2000 lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@3cp Possible to use non-open source to replace Prettier? I got my own pretty printer we could use, but ain't going to open source that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be weird for open source project to depend on non-open project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point!