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