fix: add tokens when tokens: true is passed to parseExpression (#12939)
This commit is contained in:
parent
9844eeee84
commit
efdca01409
@ -148,7 +148,7 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
|
||||
// Convenience method to parse an Expression only
|
||||
getExpression(): N.Expression {
|
||||
getExpression(): N.Expression & N.ParserOutput {
|
||||
let paramFlags = PARAM;
|
||||
if (this.hasPlugin("topLevelAwait") && this.inModule) {
|
||||
paramFlags |= PARAM_AWAIT;
|
||||
@ -162,6 +162,9 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
expr.comments = this.state.comments;
|
||||
expr.errors = this.state.errors;
|
||||
if (this.options.tokens) {
|
||||
expr.tokens = this.tokens;
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import type { SourceType } from "./options";
|
||||
import type { Token } from "./tokenizer";
|
||||
import type { SourceLocation } from "./util/location";
|
||||
import type { PlaceholderTypes } from "./plugins/placeholders";
|
||||
import type { ParsingError } from "./parser/error";
|
||||
|
||||
/*
|
||||
* If making any changes to the AST, update:
|
||||
@ -129,6 +130,11 @@ export type BigIntLiteral = NodeBase & {
|
||||
value: number,
|
||||
};
|
||||
|
||||
export type ParserOutput = {
|
||||
comments: $ReadOnlyArray<Comment>,
|
||||
errors: Array<ParsingError>,
|
||||
tokens?: $ReadOnlyArray<Token | Comment>,
|
||||
};
|
||||
// Programs
|
||||
|
||||
export type BlockStatementLike = Program | BlockStatement;
|
||||
@ -136,9 +142,7 @@ export type BlockStatementLike = Program | BlockStatement;
|
||||
export type File = NodeBase & {
|
||||
type: "File",
|
||||
program: Program,
|
||||
comments: $ReadOnlyArray<Comment>,
|
||||
tokens: $ReadOnlyArray<Token | Comment>,
|
||||
};
|
||||
} & ParserOutput;
|
||||
|
||||
export type Program = NodeBase & {
|
||||
type: "Program",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user