Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions crates/rome_js_parser/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ impl ParserState {
.contains(ParsingContextFlags::BREAK_ALLOWED)
}

pub fn allow_conditional_type(&self) -> bool {
!self
.parsing_context
.contains(ParsingContextFlags::DISALLOW_CONDITIONAL_TYPE)
}

pub fn strict(&self) -> Option<&StrictMode> {
self.strict.as_ref()
}
Expand Down Expand Up @@ -403,8 +397,6 @@ bitflags! {
/// Whatever the parser is in a TypeScript ambient context
const AMBIENT_CONTEXT = 1 << 7;

const DISALLOW_CONDITIONAL_TYPE = 1 << 8;

const LOOP = Self::BREAK_ALLOWED.bits | Self::CONTINUE_ALLOWED.bits;

/// Bitmask of all the flags that must be reset (shouldn't be inherited) when the parser enters a function
Expand Down Expand Up @@ -588,27 +580,6 @@ impl ChangeParserStateFlags for EnterType {
}
}

pub(crate) struct EnterConditionalTypes(bool);

impl EnterConditionalTypes {
pub(crate) const fn allow() -> Self {
Self(true)
}
pub(crate) const fn disallow() -> Self {
Self(false)
}
}

impl ChangeParserStateFlags for EnterConditionalTypes {
fn compute_new_flags(&self, existing: ParsingContextFlags) -> ParsingContextFlags {
if self.0 {
existing - ParsingContextFlags::DISALLOW_CONDITIONAL_TYPE
} else {
existing | ParsingContextFlags::DISALLOW_CONDITIONAL_TYPE
}
}
}

#[derive(Default)]
pub(crate) struct EnterAmbientContextSnapshot {
flags: ParsingContextFlags,
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/syntax/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ fn parse_binary_or_logical_expression_recursive(
// as;
// let precedence = "hello" as const + 3 as number as number;
if op == T![as] {
parse_ts_type(p).or_add_diagnostic(p, expected_ts_type);
parse_ts_type(p, TypeContext::default()).or_add_diagnostic(p, expected_ts_type);
let mut as_expression = m.complete(p, TS_AS_EXPRESSION);

if TypeScript.is_unsupported(p) {
Expand Down Expand Up @@ -612,7 +612,7 @@ fn parse_binary_or_logical_expression_recursive(
// test_err ts_satisfies_expression
// let x = "hello" satisfies string;
if op == T![satisfies] {
parse_ts_type(p).or_add_diagnostic(p, expected_ts_type);
parse_ts_type(p, TypeContext::default()).or_add_diagnostic(p, expected_ts_type);
let mut satisfies_expression = m.complete(p, TS_SATISFIES_EXPRESSION);

if TypeScript.is_unsupported(p) {
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_parser/src/syntax/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ fn parse_catch_declaration(p: &mut JsParser) -> ParsedSyntax {
let annotation = p.start();
p.bump(T![:]);

if let Some(ty) = parse_ts_type(p).or_add_diagnostic(p, expected_ts_type) {
if let Some(ty) = parse_ts_type(p, TypeContext::default()).or_add_diagnostic(p, expected_ts_type) {
if !matches!(ty.kind(p), TS_ANY_TYPE | TS_UNKNOWN_TYPE) {
p.error(
p
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_parser/src/syntax/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn parse_ts_type_assertion_expression(

let m = p.start();
p.bump(T![<]);
parse_ts_type(p).or_add_diagnostic(p, expected_ts_type);
parse_ts_type(p, TypeContext::default()).or_add_diagnostic(p, expected_ts_type);
p.expect(T![>]);
parse_unary_expr(p, context).or_add_diagnostic(p, expected_expression);
Present(m.complete(p, TS_TYPE_ASSERTION_EXPRESSION))
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_js_parser/src/syntax/typescript/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::syntax::class::parse_initializer_clause;
use crate::syntax::expr::{is_nth_at_identifier, parse_name, ExpressionContext};

use super::ts_parse_error::expected_ts_enum_member;
use super::TypeContext;
use crate::state::EnterAmbientContext;
use crate::syntax::auxiliary::{is_nth_at_declaration_clause, parse_declaration_clause};
use crate::syntax::js_parse_error::{expected_identifier, expected_module_source};
Expand Down Expand Up @@ -209,7 +210,7 @@ pub(crate) fn parse_ts_type_alias_declaration(p: &mut JsParser) -> ParsedSyntax
.or_add_diagnostic(p, expected_identifier);
parse_ts_type_parameters(p).ok();
p.expect(T![=]);
parse_ts_type(p).or_add_diagnostic(p, expected_ts_type);
parse_ts_type(p, TypeContext::default()).or_add_diagnostic(p, expected_ts_type);

semi(p, TextRange::new(start, p.cur_range().end()));

Expand Down
Loading