|
1 | 1 | // @flow |
2 | 2 | /* eslint sort-keys: "error" */ |
3 | | -import { getLineInfo, type Position } from "../util/location"; |
4 | | -import CommentsParser from "./comments"; |
5 | | - |
6 | | -// This function is used to raise exceptions on parse errors. It |
7 | | -// takes an offset integer (into the current `input`) to indicate |
8 | | -// the location of the error, attaches the position to the end |
9 | | -// of the error message, and then raises a `SyntaxError` with that |
10 | | -// message. |
11 | | - |
12 | | -type ErrorContext = { |
13 | | - pos: number, |
14 | | - loc: Position, |
15 | | - missingPlugin?: Array<string>, |
16 | | - code?: string, |
17 | | -}; |
18 | 3 |
|
19 | 4 | // The Errors key follows https://cs.chromium.org/chromium/src/v8/src/common/message-template.h unless it does not exist |
20 | | -export const Errors = Object.freeze({ |
| 5 | +export const ErrorMessages = Object.freeze({ |
21 | 6 | ArgumentsDisallowedInInitializer: |
22 | 7 | "'arguments' is not allowed in class field initializer", |
23 | 8 | AsyncFunctionInSingleStatementContext: |
@@ -205,53 +190,3 @@ export const Errors = Object.freeze({ |
205 | 190 | ZeroDigitNumericSeparator: |
206 | 191 | "Numeric separator can not be used after leading 0", |
207 | 192 | }); |
208 | | - |
209 | | -export default class LocationParser extends CommentsParser { |
210 | | - // Forward-declaration: defined in tokenizer/index.js |
211 | | - /*:: |
212 | | - +isLookahead: boolean; |
213 | | - */ |
214 | | - |
215 | | - getLocationForPosition(pos: number): Position { |
216 | | - let loc; |
217 | | - if (pos === this.state.start) loc = this.state.startLoc; |
218 | | - else if (pos === this.state.lastTokStart) loc = this.state.lastTokStartLoc; |
219 | | - else if (pos === this.state.end) loc = this.state.endLoc; |
220 | | - else if (pos === this.state.lastTokEnd) loc = this.state.lastTokEndLoc; |
221 | | - else loc = getLineInfo(this.input, pos); |
222 | | - |
223 | | - return loc; |
224 | | - } |
225 | | - |
226 | | - raise(pos: number, errorTemplate: string, ...params: any): Error | empty { |
227 | | - return this.raiseWithData(pos, undefined, errorTemplate, ...params); |
228 | | - } |
229 | | - |
230 | | - raiseWithData( |
231 | | - pos: number, |
232 | | - data?: { |
233 | | - missingPlugin?: Array<string>, |
234 | | - code?: string, |
235 | | - }, |
236 | | - errorTemplate: string, |
237 | | - ...params: any |
238 | | - ): Error | empty { |
239 | | - const loc = this.getLocationForPosition(pos); |
240 | | - const message = |
241 | | - errorTemplate.replace(/%(\d+)/g, (_, i: number) => params[i]) + |
242 | | - ` (${loc.line}:${loc.column})`; |
243 | | - return this._raise(Object.assign(({ loc, pos }: Object), data), message); |
244 | | - } |
245 | | - |
246 | | - _raise(errorContext: ErrorContext, message: string): Error | empty { |
247 | | - // $FlowIgnore |
248 | | - const err: SyntaxError & ErrorContext = new SyntaxError(message); |
249 | | - Object.assign(err, errorContext); |
250 | | - if (this.options.errorRecovery) { |
251 | | - if (!this.isLookahead) this.state.errors.push(err); |
252 | | - return err; |
253 | | - } else { |
254 | | - throw err; |
255 | | - } |
256 | | - } |
257 | | -} |
0 commit comments