@@ -5,13 +5,15 @@ use crate::prelude::*;
5
5
use crate :: state:: { EnterType , SignatureFlags } ;
6
6
use crate :: syntax:: expr:: {
7
7
is_at_binary_operator, is_at_expression, is_at_identifier, is_nth_at_identifier,
8
- is_nth_at_identifier_or_keyword, parse_big_int_literal_expression, parse_identifier,
9
- parse_literal_expression, parse_name, parse_number_literal_expression,
10
- parse_reference_identifier, parse_template_elements, ExpressionContext ,
8
+ is_nth_at_identifier_or_keyword, parse_assignment_expression_or_higher,
9
+ parse_big_int_literal_expression, parse_identifier, parse_literal_expression, parse_name,
10
+ parse_number_literal_expression, parse_reference_identifier, parse_template_elements,
11
+ ExpressionContext ,
11
12
} ;
12
13
use crate :: syntax:: function:: {
13
14
parse_formal_parameter, parse_parameter_list, skip_parameter_start, ParameterContext ,
14
15
} ;
16
+ use crate :: syntax:: js_parse_error;
15
17
use crate :: syntax:: js_parse_error:: {
16
18
decorators_not_allowed, expected_identifier, expected_object_member_name, expected_parameter,
17
19
expected_parameters, expected_property_or_signature, modifier_already_seen,
@@ -29,6 +31,7 @@ use crate::syntax::typescript::ts_parse_error::{
29
31
ts_in_out_modifier_cannot_appear_on_a_type_parameter,
30
32
} ;
31
33
use biome_parser:: parse_lists:: { ParseNodeList , ParseSeparatedList } ;
34
+ use biome_parser:: ParserProgress ;
32
35
use enumflags2:: { bitflags, make_bitflags, BitFlags } ;
33
36
use smallvec:: SmallVec ;
34
37
@@ -1150,6 +1153,11 @@ fn parse_ts_mapped_type_optional_modifier_clause(p: &mut JsParser) -> ParsedSynt
1150
1153
// type C = typeof import("test").a.b.c.d.e.f;
1151
1154
// type D = import("test")<string>;
1152
1155
// type E = import("test").C<string>;
1156
+ // type F = typeof import("test", { with: { "resolution-mode": "import" } });
1157
+ // type G = import("test", { with: { "resolution-mode": "import" } }).TypeFromImport;
1158
+ // type H = import("test", { with: { "resolution-mode": "import" } })<string>;
1159
+ // type I = import("test", { with: { "resolution-mode": "require" } }).C<string>;
1160
+ // type J = typeof import("test", { with: { "resolution-mode": "require" } }).a.b.c.d.e.f;
1153
1161
fn parse_ts_import_type ( p : & mut JsParser , context : TypeContext ) -> ParsedSyntax {
1154
1162
if !p. at ( T ! [ typeof] ) && !p. at ( T ! [ import] ) {
1155
1163
return Absent ;
@@ -1158,9 +1166,42 @@ fn parse_ts_import_type(p: &mut JsParser, context: TypeContext) -> ParsedSyntax
1158
1166
let m = p. start ( ) ;
1159
1167
p. eat ( T ! [ typeof] ) ;
1160
1168
p. expect ( T ! [ import] ) ;
1169
+ let args = p. start ( ) ;
1161
1170
p. expect ( T ! [ '(' ] ) ;
1162
- p. expect ( JS_STRING_LITERAL ) ;
1171
+ let args_list = p. start ( ) ;
1172
+
1173
+ let mut progress = ParserProgress :: default ( ) ;
1174
+ let mut error_range_start = p. cur_range ( ) . start ( ) ;
1175
+ let mut args_count = 0 ;
1176
+
1177
+ while !p. at ( EOF ) && !p. at ( T ! [ ')' ] ) {
1178
+ progress. assert_progressing ( p) ;
1179
+ args_count += 1 ;
1180
+
1181
+ if args_count == 3 {
1182
+ error_range_start = p. cur_range ( ) . start ( ) ;
1183
+ }
1184
+
1185
+ parse_assignment_expression_or_higher ( p, ExpressionContext :: default ( ) )
1186
+ . or_add_diagnostic ( p, js_parse_error:: expected_expression_assignment) ;
1187
+
1188
+ if p. at ( T ! [ , ] ) {
1189
+ p. bump_any ( ) ;
1190
+ } else {
1191
+ break ;
1192
+ }
1193
+ }
1194
+ args_list. complete ( p, JS_CALL_ARGUMENT_LIST ) ;
1195
+
1196
+ if args_count == 0 || args_count > 2 {
1197
+ let err = p. err_builder (
1198
+ "`typeof import()` requires exactly one or two arguments. " ,
1199
+ error_range_start..p. cur_range ( ) . end ( ) ,
1200
+ ) ;
1201
+ p. error ( err) ;
1202
+ }
1163
1203
p. expect ( T ! [ ')' ] ) ;
1204
+ args. complete ( p, JS_CALL_ARGUMENTS ) ;
1164
1205
1165
1206
if p. at ( T ! [ . ] ) {
1166
1207
let qualifier = p. start ( ) ;
0 commit comments