@@ -342,6 +342,10 @@ private Node convertNodeUntyped(JsonObject node, String defaultKind) throws Pars
342
342
return convertArrowFunction (node , loc );
343
343
case "AsExpression" :
344
344
return convertTypeAssertionExpression (node , loc );
345
+ case "AssertClause" :
346
+ return convertAssertClause (node , loc );
347
+ case "AssertEntry" :
348
+ return convertAssertEntry (node , loc );
345
349
case "SatisfiesExpression" :
346
350
return convertSatisfiesExpression (node , loc );
347
351
case "AwaitExpression" :
@@ -887,8 +891,8 @@ private Node convertBreakStatement(JsonObject node, SourceLocation loc) throws P
887
891
888
892
private Node convertCallExpression (JsonObject node , SourceLocation loc ) throws ParseError {
889
893
List <Expression > arguments = convertChildren (node , "arguments" );
890
- if (arguments .size () = = 1 && hasKind (node .get ("expression" ), "ImportKeyword" )) {
891
- return new DynamicImport (loc , arguments .get (0 ), null ); // TODO: preserve import attributes
894
+ if (arguments .size () > = 1 && hasKind (node .get ("expression" ), "ImportKeyword" )) {
895
+ return new DynamicImport (loc , arguments .get (0 ), arguments . size () > 1 ? arguments . get ( 1 ) : null );
892
896
}
893
897
Expression callee = convertChild (node , "expression" );
894
898
List <ITypeExpression > typeArguments = convertChildrenAsTypes (node , "typeArguments" );
@@ -1193,15 +1197,16 @@ private Node convertExportAssignment(JsonObject node, SourceLocation loc) throws
1193
1197
1194
1198
private Node convertExportDeclaration (JsonObject node , SourceLocation loc ) throws ParseError {
1195
1199
Literal source = tryConvertChild (node , "moduleSpecifier" , Literal .class );
1200
+ Expression assertion = convertChild (node , "assertClause" );
1196
1201
if (hasChild (node , "exportClause" )) {
1197
1202
boolean hasTypeKeyword = node .get ("isTypeOnly" ).getAsBoolean ();
1198
1203
List <ExportSpecifier > specifiers =
1199
1204
hasKind (node .get ("exportClause" ), "NamespaceExport" )
1200
1205
? Collections .singletonList (convertChild (node , "exportClause" ))
1201
1206
: convertChildren (node .get ("exportClause" ).getAsJsonObject (), "elements" );
1202
- return new ExportNamedDeclaration (loc , null , specifiers , source , null , hasTypeKeyword ); // TODO: preserve import assertions
1207
+ return new ExportNamedDeclaration (loc , null , specifiers , source , assertion , hasTypeKeyword );
1203
1208
} else {
1204
- return new ExportAllDeclaration (loc , source , null ); // TODO: preserve import assertions
1209
+ return new ExportAllDeclaration (loc , source , assertion );
1205
1210
}
1206
1211
}
1207
1212
@@ -1383,6 +1388,7 @@ private Node convertImportClause(JsonObject node, SourceLocation loc) throws Par
1383
1388
1384
1389
private Node convertImportDeclaration (JsonObject node , SourceLocation loc ) throws ParseError {
1385
1390
Literal src = tryConvertChild (node , "moduleSpecifier" , Literal .class );
1391
+ Expression assertion = convertChild (node , "assertClause" );
1386
1392
List <ImportSpecifier > specifiers = new ArrayList <>();
1387
1393
boolean hasTypeKeyword = false ;
1388
1394
if (hasChild (node , "importClause" )) {
@@ -1400,7 +1406,7 @@ private Node convertImportDeclaration(JsonObject node, SourceLocation loc) throw
1400
1406
}
1401
1407
hasTypeKeyword = importClause .get ("isTypeOnly" ).getAsBoolean ();
1402
1408
}
1403
- ImportDeclaration importDecl = new ImportDeclaration (loc , specifiers , src , null , hasTypeKeyword ); // TODO: preserve import assertions
1409
+ ImportDeclaration importDecl = new ImportDeclaration (loc , specifiers , src , assertion , hasTypeKeyword );
1404
1410
attachSymbolInformation (importDecl , node );
1405
1411
return importDecl ;
1406
1412
}
@@ -1746,7 +1752,7 @@ private Node convertNamespaceDeclaration(JsonObject node, SourceLocation loc) th
1746
1752
if (hasFlag (node , "NestedNamespace" )) {
1747
1753
// In a nested namespace declaration `namespace A.B`, the nested namespace `B`
1748
1754
// is implicitly exported.
1749
- return new ExportNamedDeclaration (loc , decl , new ArrayList <>(), null , null ); // TODO: preserve import assertion
1755
+ return new ExportNamedDeclaration (loc , decl , new ArrayList <>(), null , null );
1750
1756
} else {
1751
1757
return fixExports (loc , decl );
1752
1758
}
@@ -2276,6 +2282,24 @@ private Node convertTypeAssertionExpression(JsonObject node, SourceLocation loc)
2276
2282
return new TypeAssertion (loc , convertChild (node , "expression" ), type , false );
2277
2283
}
2278
2284
2285
+ private Node convertAssertClause (JsonObject node , SourceLocation loc ) throws ParseError {
2286
+ List <Property > properties = new ArrayList <>();
2287
+ for (INode child : convertChildren (node , "elements" )) {
2288
+ properties .add ((Property )child );
2289
+ }
2290
+ return new ObjectExpression (loc , properties );
2291
+ }
2292
+
2293
+ private Node convertAssertEntry (JsonObject node , SourceLocation loc ) throws ParseError {
2294
+ return new Property (
2295
+ loc ,
2296
+ convertChild (node , "key" ),
2297
+ convertChild (node , "value" ),
2298
+ "init" ,
2299
+ false ,
2300
+ false );
2301
+ }
2302
+
2279
2303
private Node convertSatisfiesExpression (JsonObject node , SourceLocation loc ) throws ParseError {
2280
2304
ITypeExpression type = convertChildAsType (node , "type" );
2281
2305
return new SatisfiesExpr (loc , convertChild (node , "expression" ), type );
@@ -2455,7 +2479,7 @@ private Node fixExports(SourceLocation loc, Node decl) {
2455
2479
advance (loc , skipped );
2456
2480
// capture group 1 is `default`, if present
2457
2481
if (m .group (1 ) == null )
2458
- return new ExportNamedDeclaration (outerLoc , (Statement ) decl , new ArrayList <>(), null , null ); // TODO: preserve import assertions
2482
+ return new ExportNamedDeclaration (outerLoc , (Statement ) decl , new ArrayList <>(), null , null );
2459
2483
return new ExportDefaultDeclaration (outerLoc , decl );
2460
2484
}
2461
2485
return decl ;
0 commit comments