hermes-parser 0.32.1 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HermesParser.js +2 -2
- package/dist/HermesParser.js.flow +2 -0
- package/dist/HermesParserNodeDeserializers.js +109 -5
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +11 -1
- package/dist/ParserOptions.js +1 -1
- package/dist/ParserOptions.js.flow +2 -0
- package/dist/babel/TransformESTreeToBabel.js +76 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +73 -2
- package/dist/estree/StripFlowTypes.js +1 -1
- package/dist/estree/StripFlowTypes.js.flow +1 -1
- package/dist/estree/TransformMatchSyntax.js +124 -56
- package/dist/estree/TransformMatchSyntax.js.flow +124 -46
- package/dist/estree/TransformRecordSyntax.js +294 -0
- package/dist/estree/TransformRecordSyntax.js.flow +308 -0
- package/dist/generated/ESTreeVisitorKeys.js +16 -4
- package/dist/generated/ParserVisitorKeys.js +45 -4
- package/dist/index.js +8 -1
- package/dist/index.js.flow +7 -0
- package/dist/src/HermesParser.js +2 -2
- package/dist/src/HermesParserNodeDeserializers.js +109 -5
- package/dist/src/ParserOptions.js +1 -1
- package/dist/src/babel/TransformESTreeToBabel.js +76 -3
- package/dist/src/estree/StripFlowTypes.js +1 -1
- package/dist/src/estree/TransformMatchSyntax.js +124 -56
- package/dist/src/estree/TransformRecordSyntax.js +294 -0
- package/dist/src/generated/ESTreeVisitorKeys.js +16 -4
- package/dist/src/generated/ParserVisitorKeys.js +45 -4
- package/dist/src/index.js +8 -1
- package/dist/src/utils/GenID.js +28 -23
- package/dist/src/utils/isReservedWord.js +62 -0
- package/dist/utils/GenID.js +28 -23
- package/dist/utils/GenID.js.flow +23 -22
- package/dist/utils/isReservedWord.js +62 -0
- package/dist/utils/isReservedWord.js.flow +57 -0
- package/package.json +2 -2
|
@@ -66,7 +66,6 @@ function deserializeArrowFunctionExpression() {
|
|
|
66
66
|
return {
|
|
67
67
|
type: 'ArrowFunctionExpression',
|
|
68
68
|
loc: this.addEmptyLoc(),
|
|
69
|
-
id: this.deserializeNode(),
|
|
70
69
|
params: this.deserializeNodeList(),
|
|
71
70
|
body: this.deserializeNode(),
|
|
72
71
|
typeParameters: this.deserializeNode(),
|
|
@@ -694,7 +693,7 @@ function deserializeClassDeclaration() {
|
|
|
694
693
|
id: this.deserializeNode(),
|
|
695
694
|
typeParameters: this.deserializeNode(),
|
|
696
695
|
superClass: this.deserializeNode(),
|
|
697
|
-
|
|
696
|
+
superTypeArguments: this.deserializeNode(),
|
|
698
697
|
implements: this.deserializeNodeList(),
|
|
699
698
|
decorators: this.deserializeNodeList(),
|
|
700
699
|
body: this.deserializeNode()
|
|
@@ -708,7 +707,7 @@ function deserializeClassExpression() {
|
|
|
708
707
|
id: this.deserializeNode(),
|
|
709
708
|
typeParameters: this.deserializeNode(),
|
|
710
709
|
superClass: this.deserializeNode(),
|
|
711
|
-
|
|
710
|
+
superTypeArguments: this.deserializeNode(),
|
|
712
711
|
implements: this.deserializeNodeList(),
|
|
713
712
|
decorators: this.deserializeNodeList(),
|
|
714
713
|
body: this.deserializeNode()
|
|
@@ -1022,6 +1021,15 @@ function deserializeMatchMemberPattern() {
|
|
|
1022
1021
|
};
|
|
1023
1022
|
}
|
|
1024
1023
|
|
|
1024
|
+
function deserializeMatchInstancePattern() {
|
|
1025
|
+
return {
|
|
1026
|
+
type: 'MatchInstancePattern',
|
|
1027
|
+
loc: this.addEmptyLoc(),
|
|
1028
|
+
targetConstructor: this.deserializeNode(),
|
|
1029
|
+
properties: this.deserializeNode()
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1025
1033
|
function deserializeMatchPatternLast() {
|
|
1026
1034
|
throw new Error('MatchPattern' + ' should not appear in program buffer');
|
|
1027
1035
|
}
|
|
@@ -1036,6 +1044,15 @@ function deserializeMatchObjectPatternProperty() {
|
|
|
1036
1044
|
};
|
|
1037
1045
|
}
|
|
1038
1046
|
|
|
1047
|
+
function deserializeMatchInstanceObjectPattern() {
|
|
1048
|
+
return {
|
|
1049
|
+
type: 'MatchInstanceObjectPattern',
|
|
1050
|
+
loc: this.addEmptyLoc(),
|
|
1051
|
+
properties: this.deserializeNodeList(),
|
|
1052
|
+
rest: this.deserializeNode()
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1039
1056
|
function deserializeMatchRestPattern() {
|
|
1040
1057
|
return {
|
|
1041
1058
|
type: 'MatchRestPattern',
|
|
@@ -1305,6 +1322,27 @@ function deserializeVoidTypeAnnotation() {
|
|
|
1305
1322
|
};
|
|
1306
1323
|
}
|
|
1307
1324
|
|
|
1325
|
+
function deserializeNeverTypeAnnotation() {
|
|
1326
|
+
return {
|
|
1327
|
+
type: 'NeverTypeAnnotation',
|
|
1328
|
+
loc: this.addEmptyLoc()
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
function deserializeUnknownTypeAnnotation() {
|
|
1333
|
+
return {
|
|
1334
|
+
type: 'UnknownTypeAnnotation',
|
|
1335
|
+
loc: this.addEmptyLoc()
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
function deserializeUndefinedTypeAnnotation() {
|
|
1340
|
+
return {
|
|
1341
|
+
type: 'UndefinedTypeAnnotation',
|
|
1342
|
+
loc: this.addEmptyLoc()
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1308
1346
|
function deserializeFunctionTypeAnnotation() {
|
|
1309
1347
|
return {
|
|
1310
1348
|
type: 'FunctionTypeAnnotation',
|
|
@@ -1415,7 +1453,7 @@ function deserializeTupleTypeAnnotation() {
|
|
|
1415
1453
|
return {
|
|
1416
1454
|
type: 'TupleTypeAnnotation',
|
|
1417
1455
|
loc: this.addEmptyLoc(),
|
|
1418
|
-
|
|
1456
|
+
elementTypes: this.deserializeNodeList(),
|
|
1419
1457
|
inexact: this.deserializeBoolean()
|
|
1420
1458
|
};
|
|
1421
1459
|
}
|
|
@@ -2000,6 +2038,72 @@ function deserializeComponentParameter() {
|
|
|
2000
2038
|
};
|
|
2001
2039
|
}
|
|
2002
2040
|
|
|
2041
|
+
function deserializeRecordDeclaration() {
|
|
2042
|
+
return {
|
|
2043
|
+
type: 'RecordDeclaration',
|
|
2044
|
+
loc: this.addEmptyLoc(),
|
|
2045
|
+
id: this.deserializeNode(),
|
|
2046
|
+
typeParameters: this.deserializeNode(),
|
|
2047
|
+
implements: this.deserializeNodeList(),
|
|
2048
|
+
body: this.deserializeNode()
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
function deserializeRecordDeclarationImplements() {
|
|
2053
|
+
return {
|
|
2054
|
+
type: 'RecordDeclarationImplements',
|
|
2055
|
+
loc: this.addEmptyLoc(),
|
|
2056
|
+
id: this.deserializeNode(),
|
|
2057
|
+
typeArguments: this.deserializeNode()
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
function deserializeRecordDeclarationBody() {
|
|
2062
|
+
return {
|
|
2063
|
+
type: 'RecordDeclarationBody',
|
|
2064
|
+
loc: this.addEmptyLoc(),
|
|
2065
|
+
elements: this.deserializeNodeList()
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
function deserializeRecordDeclarationProperty() {
|
|
2070
|
+
return {
|
|
2071
|
+
type: 'RecordDeclarationProperty',
|
|
2072
|
+
loc: this.addEmptyLoc(),
|
|
2073
|
+
key: this.deserializeNode(),
|
|
2074
|
+
typeAnnotation: this.deserializeNode(),
|
|
2075
|
+
defaultValue: this.deserializeNode()
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
function deserializeRecordDeclarationStaticProperty() {
|
|
2080
|
+
return {
|
|
2081
|
+
type: 'RecordDeclarationStaticProperty',
|
|
2082
|
+
loc: this.addEmptyLoc(),
|
|
2083
|
+
key: this.deserializeNode(),
|
|
2084
|
+
typeAnnotation: this.deserializeNode(),
|
|
2085
|
+
value: this.deserializeNode()
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
function deserializeRecordExpression() {
|
|
2090
|
+
return {
|
|
2091
|
+
type: 'RecordExpression',
|
|
2092
|
+
loc: this.addEmptyLoc(),
|
|
2093
|
+
recordConstructor: this.deserializeNode(),
|
|
2094
|
+
typeArguments: this.deserializeNode(),
|
|
2095
|
+
properties: this.deserializeNode()
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
function deserializeRecordExpressionProperties() {
|
|
2100
|
+
return {
|
|
2101
|
+
type: 'RecordExpressionProperties',
|
|
2102
|
+
loc: this.addEmptyLoc(),
|
|
2103
|
+
properties: this.deserializeNodeList()
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2003
2107
|
function deserializeFlowLast() {
|
|
2004
2108
|
throw new Error('Flow' + ' should not appear in program buffer');
|
|
2005
2109
|
}
|
|
@@ -2474,4 +2578,4 @@ function deserializeImplicitCheckedCast() {
|
|
|
2474
2578
|
};
|
|
2475
2579
|
}
|
|
2476
2580
|
|
|
2477
|
-
module.exports = [deserializeEmpty, deserializeMetadata, deserializeFunctionLikeFirst, deserializeProgram, deserializeFunctionExpression, deserializeArrowFunctionExpression, deserializeFunctionDeclaration, deserializeComponentDeclaration, deserializeHookDeclaration, deserializeFunctionLikeLast, deserializeStatementFirst, deserializeMatchStatement, deserializeLoopStatementFirst, deserializeWhileStatement, deserializeDoWhileStatement, deserializeForInStatement, deserializeForOfStatement, deserializeForStatement, deserializeLoopStatementLast, deserializeDebuggerStatement, deserializeEmptyStatement, deserializeBlockStatement, deserializeStaticBlock, deserializeBreakStatement, deserializeContinueStatement, deserializeThrowStatement, deserializeReturnStatement, deserializeWithStatement, deserializeSwitchStatement, deserializeLabeledStatement, deserializeExpressionStatement, deserializeTryStatement, deserializeIfStatement, deserializeStatementLast, deserializeNullLiteral, deserializeBooleanLiteral, deserializeStringLiteral, deserializeNumericLiteral, deserializeRegExpLiteral, deserializeBigIntLiteral, deserializeThisExpression, deserializeSuper, deserializeSequenceExpression, deserializeObjectExpression, deserializeArrayExpression, deserializeSpreadElement, deserializeNewExpression, deserializeYieldExpression, deserializeAwaitExpression, deserializeImportExpression, deserializeCallExpressionLikeFirst, deserializeCallExpression, deserializeOptionalCallExpression, deserializeCallExpressionLikeLast, deserializeAssignmentExpression, deserializeUnaryExpression, deserializeUpdateExpression, deserializeMemberExpressionLikeFirst, deserializeMemberExpression, deserializeOptionalMemberExpression, deserializeMemberExpressionLikeLast, deserializeLogicalExpression, deserializeConditionalExpression, deserializeBinaryExpression, deserializeDirective, deserializeDirectiveLiteral, deserializeIdentifier, deserializePrivateName, deserializeMetaProperty, deserializeSwitchCase, deserializeCatchClause, deserializeVariableDeclarator, deserializeVariableDeclaration, deserializeTemplateLiteral, deserializeTaggedTemplateExpression, deserializeTemplateElement, deserializeProperty, deserializeClassLikeFirst, deserializeClassDeclaration, deserializeClassExpression, deserializeClassLikeLast, deserializeClassBody, deserializeClassProperty, deserializeClassPrivateProperty, deserializeMethodDefinition, deserializeImportDeclaration, deserializeImportSpecifier, deserializeImportDefaultSpecifier, deserializeImportNamespaceSpecifier, deserializeImportAttribute, deserializeExportNamedDeclaration, deserializeExportSpecifier, deserializeExportNamespaceSpecifier, deserializeExportDefaultDeclaration, deserializeExportAllDeclaration, deserializePatternFirst, deserializeObjectPattern, deserializeArrayPattern, deserializeRestElement, deserializeAssignmentPattern, deserializePatternLast, deserializeMatchStatementCase, deserializeMatchExpression, deserializeMatchExpressionCase, deserializeMatchPatternFirst, deserializeMatchWildcardPattern, deserializeMatchLiteralPattern, deserializeMatchUnaryPattern, deserializeMatchIdentifierPattern, deserializeMatchBindingPattern, deserializeMatchObjectPattern, deserializeMatchArrayPattern, deserializeMatchOrPattern, deserializeMatchAsPattern, deserializeMatchMemberPattern, deserializeMatchPatternLast, deserializeMatchObjectPatternProperty, deserializeMatchRestPattern, deserializeJSXFirst, deserializeJSXIdentifier, deserializeJSXMemberExpression, deserializeJSXNamespacedName, deserializeJSXEmptyExpression, deserializeJSXExpressionContainer, deserializeJSXSpreadChild, deserializeJSXOpeningElement, deserializeJSXClosingElement, deserializeJSXAttribute, deserializeJSXSpreadAttribute, deserializeJSXStringLiteral, deserializeJSXText, deserializeJSXElement, deserializeJSXFragment, deserializeJSXOpeningFragment, deserializeJSXClosingFragment, deserializeJSXLast, deserializeFlowFirst, deserializeExistsTypeAnnotation, deserializeEmptyTypeAnnotation, deserializeStringTypeAnnotation, deserializeNumberTypeAnnotation, deserializeStringLiteralTypeAnnotation, deserializeNumberLiteralTypeAnnotation, deserializeBigIntLiteralTypeAnnotation, deserializeBooleanTypeAnnotation, deserializeBooleanLiteralTypeAnnotation, deserializeNullLiteralTypeAnnotation, deserializeSymbolTypeAnnotation, deserializeAnyTypeAnnotation, deserializeMixedTypeAnnotation, deserializeBigIntTypeAnnotation, deserializeVoidTypeAnnotation, deserializeFunctionTypeAnnotation, deserializeHookTypeAnnotation, deserializeFunctionTypeParam, deserializeComponentTypeAnnotation, deserializeComponentTypeParameter, deserializeNullableTypeAnnotation, deserializeQualifiedTypeIdentifier, deserializeTypeofTypeAnnotation, deserializeKeyofTypeAnnotation, deserializeTypeOperator, deserializeQualifiedTypeofIdentifier, deserializeTupleTypeAnnotation, deserializeTupleTypeSpreadElement, deserializeTupleTypeLabeledElement, deserializeArrayTypeAnnotation, deserializeInferTypeAnnotation, deserializeUnionTypeAnnotation, deserializeIntersectionTypeAnnotation, deserializeGenericTypeAnnotation, deserializeIndexedAccessType, deserializeOptionalIndexedAccessType, deserializeConditionalTypeAnnotation, deserializeTypePredicate, deserializeInterfaceTypeAnnotation, deserializeTypeAlias, deserializeOpaqueType, deserializeInterfaceDeclaration, deserializeDeclareTypeAlias, deserializeDeclareOpaqueType, deserializeDeclareInterface, deserializeDeclareClass, deserializeDeclareFunction, deserializeDeclareHook, deserializeDeclareComponent, deserializeDeclareVariable, deserializeDeclareEnum, deserializeDeclareExportDeclaration, deserializeDeclareExportAllDeclaration, deserializeDeclareModule, deserializeDeclareNamespace, deserializeDeclareModuleExports, deserializeInterfaceExtends, deserializeClassImplements, deserializeTypeAnnotation, deserializeObjectTypeAnnotation, deserializeObjectTypeProperty, deserializeObjectTypeSpreadProperty, deserializeObjectTypeInternalSlot, deserializeObjectTypeCallProperty, deserializeObjectTypeIndexer, deserializeObjectTypeMappedTypeProperty, deserializeVariance, deserializeTypeParameterDeclaration, deserializeTypeParameter, deserializeTypeParameterInstantiation, deserializeTypeCastExpression, deserializeAsExpression, deserializeAsConstExpression, deserializeInferredPredicate, deserializeDeclaredPredicate, deserializeEnumDeclaration, deserializeEnumStringBody, deserializeEnumNumberBody, deserializeEnumBigIntBody, deserializeEnumBooleanBody, deserializeEnumSymbolBody, deserializeEnumDefaultedMember, deserializeEnumStringMember, deserializeEnumNumberMember, deserializeEnumBigIntMember, deserializeEnumBooleanMember, deserializeComponentParameter, deserializeFlowLast, deserializeTSFirst, deserializeTSTypeAnnotation, deserializeTSAnyKeyword, deserializeTSNumberKeyword, deserializeTSBooleanKeyword, deserializeTSStringKeyword, deserializeTSSymbolKeyword, deserializeTSVoidKeyword, deserializeTSUndefinedKeyword, deserializeTSUnknownKeyword, deserializeTSNeverKeyword, deserializeTSBigIntKeyword, deserializeTSThisType, deserializeTSLiteralType, deserializeTSIndexedAccessType, deserializeTSArrayType, deserializeTSTypeReference, deserializeTSQualifiedName, deserializeTSFunctionType, deserializeTSConstructorType, deserializeTSTypePredicate, deserializeTSTupleType, deserializeTSTypeAssertion, deserializeTSAsExpression, deserializeTSParameterProperty, deserializeTSTypeAliasDeclaration, deserializeTSInterfaceDeclaration, deserializeTSInterfaceHeritage, deserializeTSInterfaceBody, deserializeTSEnumDeclaration, deserializeTSEnumMember, deserializeTSModuleDeclaration, deserializeTSModuleBlock, deserializeTSModuleMember, deserializeTSTypeParameterDeclaration, deserializeTSTypeParameter, deserializeTSTypeParameterInstantiation, deserializeTSUnionType, deserializeTSIntersectionType, deserializeTSTypeQuery, deserializeTSConditionalType, deserializeTSTypeLiteral, deserializeTSPropertySignature, deserializeTSMethodSignature, deserializeTSIndexSignature, deserializeTSCallSignatureDeclaration, deserializeTSModifiers, deserializeTSLast, deserializeCoverFirst, deserializeCoverEmptyArgs, deserializeCoverTrailingComma, deserializeCoverInitializer, deserializeCoverRestElement, deserializeCoverTypedIdentifier, deserializeCoverLast, deserializeSHBuiltin, deserializeImplicitCheckedCast];
|
|
2581
|
+
module.exports = [deserializeEmpty, deserializeMetadata, deserializeFunctionLikeFirst, deserializeProgram, deserializeFunctionExpression, deserializeArrowFunctionExpression, deserializeFunctionDeclaration, deserializeComponentDeclaration, deserializeHookDeclaration, deserializeFunctionLikeLast, deserializeStatementFirst, deserializeMatchStatement, deserializeLoopStatementFirst, deserializeWhileStatement, deserializeDoWhileStatement, deserializeForInStatement, deserializeForOfStatement, deserializeForStatement, deserializeLoopStatementLast, deserializeDebuggerStatement, deserializeEmptyStatement, deserializeBlockStatement, deserializeStaticBlock, deserializeBreakStatement, deserializeContinueStatement, deserializeThrowStatement, deserializeReturnStatement, deserializeWithStatement, deserializeSwitchStatement, deserializeLabeledStatement, deserializeExpressionStatement, deserializeTryStatement, deserializeIfStatement, deserializeStatementLast, deserializeNullLiteral, deserializeBooleanLiteral, deserializeStringLiteral, deserializeNumericLiteral, deserializeRegExpLiteral, deserializeBigIntLiteral, deserializeThisExpression, deserializeSuper, deserializeSequenceExpression, deserializeObjectExpression, deserializeArrayExpression, deserializeSpreadElement, deserializeNewExpression, deserializeYieldExpression, deserializeAwaitExpression, deserializeImportExpression, deserializeCallExpressionLikeFirst, deserializeCallExpression, deserializeOptionalCallExpression, deserializeCallExpressionLikeLast, deserializeAssignmentExpression, deserializeUnaryExpression, deserializeUpdateExpression, deserializeMemberExpressionLikeFirst, deserializeMemberExpression, deserializeOptionalMemberExpression, deserializeMemberExpressionLikeLast, deserializeLogicalExpression, deserializeConditionalExpression, deserializeBinaryExpression, deserializeDirective, deserializeDirectiveLiteral, deserializeIdentifier, deserializePrivateName, deserializeMetaProperty, deserializeSwitchCase, deserializeCatchClause, deserializeVariableDeclarator, deserializeVariableDeclaration, deserializeTemplateLiteral, deserializeTaggedTemplateExpression, deserializeTemplateElement, deserializeProperty, deserializeClassLikeFirst, deserializeClassDeclaration, deserializeClassExpression, deserializeClassLikeLast, deserializeClassBody, deserializeClassProperty, deserializeClassPrivateProperty, deserializeMethodDefinition, deserializeImportDeclaration, deserializeImportSpecifier, deserializeImportDefaultSpecifier, deserializeImportNamespaceSpecifier, deserializeImportAttribute, deserializeExportNamedDeclaration, deserializeExportSpecifier, deserializeExportNamespaceSpecifier, deserializeExportDefaultDeclaration, deserializeExportAllDeclaration, deserializePatternFirst, deserializeObjectPattern, deserializeArrayPattern, deserializeRestElement, deserializeAssignmentPattern, deserializePatternLast, deserializeMatchStatementCase, deserializeMatchExpression, deserializeMatchExpressionCase, deserializeMatchPatternFirst, deserializeMatchWildcardPattern, deserializeMatchLiteralPattern, deserializeMatchUnaryPattern, deserializeMatchIdentifierPattern, deserializeMatchBindingPattern, deserializeMatchObjectPattern, deserializeMatchArrayPattern, deserializeMatchOrPattern, deserializeMatchAsPattern, deserializeMatchMemberPattern, deserializeMatchInstancePattern, deserializeMatchPatternLast, deserializeMatchObjectPatternProperty, deserializeMatchInstanceObjectPattern, deserializeMatchRestPattern, deserializeJSXFirst, deserializeJSXIdentifier, deserializeJSXMemberExpression, deserializeJSXNamespacedName, deserializeJSXEmptyExpression, deserializeJSXExpressionContainer, deserializeJSXSpreadChild, deserializeJSXOpeningElement, deserializeJSXClosingElement, deserializeJSXAttribute, deserializeJSXSpreadAttribute, deserializeJSXStringLiteral, deserializeJSXText, deserializeJSXElement, deserializeJSXFragment, deserializeJSXOpeningFragment, deserializeJSXClosingFragment, deserializeJSXLast, deserializeFlowFirst, deserializeExistsTypeAnnotation, deserializeEmptyTypeAnnotation, deserializeStringTypeAnnotation, deserializeNumberTypeAnnotation, deserializeStringLiteralTypeAnnotation, deserializeNumberLiteralTypeAnnotation, deserializeBigIntLiteralTypeAnnotation, deserializeBooleanTypeAnnotation, deserializeBooleanLiteralTypeAnnotation, deserializeNullLiteralTypeAnnotation, deserializeSymbolTypeAnnotation, deserializeAnyTypeAnnotation, deserializeMixedTypeAnnotation, deserializeBigIntTypeAnnotation, deserializeVoidTypeAnnotation, deserializeNeverTypeAnnotation, deserializeUnknownTypeAnnotation, deserializeUndefinedTypeAnnotation, deserializeFunctionTypeAnnotation, deserializeHookTypeAnnotation, deserializeFunctionTypeParam, deserializeComponentTypeAnnotation, deserializeComponentTypeParameter, deserializeNullableTypeAnnotation, deserializeQualifiedTypeIdentifier, deserializeTypeofTypeAnnotation, deserializeKeyofTypeAnnotation, deserializeTypeOperator, deserializeQualifiedTypeofIdentifier, deserializeTupleTypeAnnotation, deserializeTupleTypeSpreadElement, deserializeTupleTypeLabeledElement, deserializeArrayTypeAnnotation, deserializeInferTypeAnnotation, deserializeUnionTypeAnnotation, deserializeIntersectionTypeAnnotation, deserializeGenericTypeAnnotation, deserializeIndexedAccessType, deserializeOptionalIndexedAccessType, deserializeConditionalTypeAnnotation, deserializeTypePredicate, deserializeInterfaceTypeAnnotation, deserializeTypeAlias, deserializeOpaqueType, deserializeInterfaceDeclaration, deserializeDeclareTypeAlias, deserializeDeclareOpaqueType, deserializeDeclareInterface, deserializeDeclareClass, deserializeDeclareFunction, deserializeDeclareHook, deserializeDeclareComponent, deserializeDeclareVariable, deserializeDeclareEnum, deserializeDeclareExportDeclaration, deserializeDeclareExportAllDeclaration, deserializeDeclareModule, deserializeDeclareNamespace, deserializeDeclareModuleExports, deserializeInterfaceExtends, deserializeClassImplements, deserializeTypeAnnotation, deserializeObjectTypeAnnotation, deserializeObjectTypeProperty, deserializeObjectTypeSpreadProperty, deserializeObjectTypeInternalSlot, deserializeObjectTypeCallProperty, deserializeObjectTypeIndexer, deserializeObjectTypeMappedTypeProperty, deserializeVariance, deserializeTypeParameterDeclaration, deserializeTypeParameter, deserializeTypeParameterInstantiation, deserializeTypeCastExpression, deserializeAsExpression, deserializeAsConstExpression, deserializeInferredPredicate, deserializeDeclaredPredicate, deserializeEnumDeclaration, deserializeEnumStringBody, deserializeEnumNumberBody, deserializeEnumBigIntBody, deserializeEnumBooleanBody, deserializeEnumSymbolBody, deserializeEnumDefaultedMember, deserializeEnumStringMember, deserializeEnumNumberMember, deserializeEnumBigIntMember, deserializeEnumBooleanMember, deserializeComponentParameter, deserializeRecordDeclaration, deserializeRecordDeclarationImplements, deserializeRecordDeclarationBody, deserializeRecordDeclarationProperty, deserializeRecordDeclarationStaticProperty, deserializeRecordExpression, deserializeRecordExpressionProperties, deserializeFlowLast, deserializeTSFirst, deserializeTSTypeAnnotation, deserializeTSAnyKeyword, deserializeTSNumberKeyword, deserializeTSBooleanKeyword, deserializeTSStringKeyword, deserializeTSSymbolKeyword, deserializeTSVoidKeyword, deserializeTSUndefinedKeyword, deserializeTSUnknownKeyword, deserializeTSNeverKeyword, deserializeTSBigIntKeyword, deserializeTSThisType, deserializeTSLiteralType, deserializeTSIndexedAccessType, deserializeTSArrayType, deserializeTSTypeReference, deserializeTSQualifiedName, deserializeTSFunctionType, deserializeTSConstructorType, deserializeTSTypePredicate, deserializeTSTupleType, deserializeTSTypeAssertion, deserializeTSAsExpression, deserializeTSParameterProperty, deserializeTSTypeAliasDeclaration, deserializeTSInterfaceDeclaration, deserializeTSInterfaceHeritage, deserializeTSInterfaceBody, deserializeTSEnumDeclaration, deserializeTSEnumMember, deserializeTSModuleDeclaration, deserializeTSModuleBlock, deserializeTSModuleMember, deserializeTSTypeParameterDeclaration, deserializeTSTypeParameter, deserializeTSTypeParameterInstantiation, deserializeTSUnionType, deserializeTSIntersectionType, deserializeTSTypeQuery, deserializeTSConditionalType, deserializeTSTypeLiteral, deserializeTSPropertySignature, deserializeTSMethodSignature, deserializeTSIndexSignature, deserializeTSCallSignatureDeclaration, deserializeTSModifiers, deserializeTSLast, deserializeCoverFirst, deserializeCoverEmptyArgs, deserializeCoverTrailingComma, deserializeCoverInitializer, deserializeCoverRestElement, deserializeCoverTypedIdentifier, deserializeCoverLast, deserializeSHBuiltin, deserializeImplicitCheckedCast];
|
|
@@ -14,5 +14,5 @@ exports.ParserOptionsKeys = void 0;
|
|
|
14
14
|
*
|
|
15
15
|
* @format
|
|
16
16
|
*/
|
|
17
|
-
const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
|
|
17
|
+
const ParserOptionsKeys = new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'enableExperimentalFlowRecordSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
|
|
18
18
|
exports.ParserOptionsKeys = ParserOptionsKeys;
|
|
@@ -30,6 +30,8 @@ const FlowESTreeAndBabelVisitorKeys = { ..._ESTreeVisitorKeys.default,
|
|
|
30
30
|
BigIntLiteral: [],
|
|
31
31
|
BlockStatement: ['directives', ..._ESTreeVisitorKeys.default.BlockStatement],
|
|
32
32
|
BooleanLiteral: [],
|
|
33
|
+
ClassExpression: ['superTypeParameters', ..._ESTreeVisitorKeys.default.ClassExpression],
|
|
34
|
+
ClassDeclaration: ['superTypeParameters', ..._ESTreeVisitorKeys.default.ClassDeclaration],
|
|
33
35
|
ClassMethod: ['key', 'params', 'body', 'returnType', 'typeParameters'],
|
|
34
36
|
ClassPrivateMethod: ['key', 'params', 'body', 'returnType', 'typeParameters'],
|
|
35
37
|
ClassProperty: ['key', 'value', 'typeAnnotation', 'variance'],
|
|
@@ -50,6 +52,7 @@ const FlowESTreeAndBabelVisitorKeys = { ..._ESTreeVisitorKeys.default,
|
|
|
50
52
|
RegExpLiteral: [],
|
|
51
53
|
RestElement: [..._ESTreeVisitorKeys.default.RestElement, 'typeAnnotation'],
|
|
52
54
|
StringLiteral: [],
|
|
55
|
+
TupleTypeAnnotation: ['types'],
|
|
53
56
|
CommentBlock: [],
|
|
54
57
|
CommentLine: []
|
|
55
58
|
};
|
|
@@ -821,10 +824,74 @@ function transformNode(node) {
|
|
|
821
824
|
case 'TupleTypeAnnotation':
|
|
822
825
|
{
|
|
823
826
|
// $FlowExpectedError[cannot-write]
|
|
824
|
-
delete node.inexact;
|
|
827
|
+
delete node.inexact; // $FlowExpectedError[prop-missing]
|
|
828
|
+
|
|
829
|
+
node.types = node.elementTypes; // $FlowExpectedError[cannot-write]
|
|
830
|
+
|
|
831
|
+
delete node.elementTypes;
|
|
825
832
|
return node;
|
|
826
833
|
}
|
|
827
834
|
|
|
835
|
+
case 'UnknownTypeAnnotation':
|
|
836
|
+
{
|
|
837
|
+
return {
|
|
838
|
+
type: 'GenericTypeAnnotation',
|
|
839
|
+
id: {
|
|
840
|
+
type: 'Identifier',
|
|
841
|
+
name: 'unknown',
|
|
842
|
+
optional: false,
|
|
843
|
+
typeAnnotation: null,
|
|
844
|
+
loc: node.loc,
|
|
845
|
+
range: node.range,
|
|
846
|
+
parent: EMPTY_PARENT
|
|
847
|
+
},
|
|
848
|
+
typeParameters: null,
|
|
849
|
+
loc: node.loc,
|
|
850
|
+
range: node.range,
|
|
851
|
+
parent: EMPTY_PARENT
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
case 'NeverTypeAnnotation':
|
|
856
|
+
{
|
|
857
|
+
return {
|
|
858
|
+
type: 'GenericTypeAnnotation',
|
|
859
|
+
id: {
|
|
860
|
+
type: 'Identifier',
|
|
861
|
+
name: 'never',
|
|
862
|
+
optional: false,
|
|
863
|
+
typeAnnotation: null,
|
|
864
|
+
loc: node.loc,
|
|
865
|
+
range: node.range,
|
|
866
|
+
parent: EMPTY_PARENT
|
|
867
|
+
},
|
|
868
|
+
typeParameters: null,
|
|
869
|
+
loc: node.loc,
|
|
870
|
+
range: node.range,
|
|
871
|
+
parent: EMPTY_PARENT
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
case 'UndefinedTypeAnnotation':
|
|
876
|
+
{
|
|
877
|
+
return {
|
|
878
|
+
type: 'GenericTypeAnnotation',
|
|
879
|
+
id: {
|
|
880
|
+
type: 'Identifier',
|
|
881
|
+
name: 'undefined',
|
|
882
|
+
optional: false,
|
|
883
|
+
typeAnnotation: null,
|
|
884
|
+
loc: node.loc,
|
|
885
|
+
range: node.range,
|
|
886
|
+
parent: EMPTY_PARENT
|
|
887
|
+
},
|
|
888
|
+
typeParameters: null,
|
|
889
|
+
loc: node.loc,
|
|
890
|
+
range: node.range,
|
|
891
|
+
parent: EMPTY_PARENT
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
|
|
828
895
|
case 'JSXText':
|
|
829
896
|
{
|
|
830
897
|
// $FlowExpectedError[prop-missing]
|
|
@@ -987,9 +1054,15 @@ function transformNode(node) {
|
|
|
987
1054
|
delete node.implements;
|
|
988
1055
|
}
|
|
989
1056
|
|
|
990
|
-
if (node.
|
|
1057
|
+
if (node.superTypeArguments == null) {
|
|
1058
|
+
// $FlowExpectedError[cannot-write]
|
|
1059
|
+
delete node.superTypeArguments;
|
|
1060
|
+
} else {
|
|
991
1061
|
// $FlowExpectedError[cannot-write]
|
|
992
|
-
|
|
1062
|
+
// $FlowExpectedError[prop-missing]
|
|
1063
|
+
node.superTypeParameters = node.superTypeArguments; // $FlowExpectedError[cannot-write]
|
|
1064
|
+
|
|
1065
|
+
delete node.superTypeArguments;
|
|
993
1066
|
}
|
|
994
1067
|
|
|
995
1068
|
if (node.typeParameters == null) {
|
|
@@ -25,20 +25,22 @@ var _createSyntaxError = require("../utils/createSyntaxError");
|
|
|
25
25
|
|
|
26
26
|
var _Builders = require("../utils/Builders");
|
|
27
27
|
|
|
28
|
-
var _GenID = require("../utils/GenID");
|
|
28
|
+
var _GenID = _interopRequireDefault(require("../utils/GenID"));
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* Generated identifiers.
|
|
32
34
|
* `GenID` is initialized in the transform.
|
|
33
35
|
*/
|
|
34
|
-
let
|
|
36
|
+
let genID = null;
|
|
35
37
|
|
|
36
38
|
function genIdent() {
|
|
37
|
-
if (
|
|
39
|
+
if (genID == null) {
|
|
38
40
|
throw Error('GenID must be initialized at the start of the transform.');
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
return (0, _Builders.ident)(
|
|
43
|
+
return (0, _Builders.ident)(genID.id());
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* A series of properties.
|
|
@@ -138,6 +140,7 @@ function needsPropExistsCond(pattern) {
|
|
|
138
140
|
case 'MatchLiteralPattern':
|
|
139
141
|
case 'MatchUnaryPattern':
|
|
140
142
|
case 'MatchObjectPattern':
|
|
143
|
+
case 'MatchInstancePattern':
|
|
141
144
|
case 'MatchArrayPattern':
|
|
142
145
|
return false;
|
|
143
146
|
|
|
@@ -158,6 +161,78 @@ function needsPropExistsCond(pattern) {
|
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Analyzes properties of both object patterns and instance patterns.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
170
|
+
const conditions = [];
|
|
171
|
+
const bindings = [];
|
|
172
|
+
const objKeys = [];
|
|
173
|
+
const seenNames = new Set();
|
|
174
|
+
properties.forEach(prop => {
|
|
175
|
+
const {
|
|
176
|
+
key: objKey,
|
|
177
|
+
pattern: propPattern
|
|
178
|
+
} = prop;
|
|
179
|
+
objKeys.push(objKey);
|
|
180
|
+
const name = objKeyToString(objKey);
|
|
181
|
+
|
|
182
|
+
if (seenNames.has(name)) {
|
|
183
|
+
throw (0, _createSyntaxError.createSyntaxError)(propPattern, `Duplicate property name '${name}' in match object pattern.`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
seenNames.add(name);
|
|
187
|
+
const propKey = key.concat(objKey);
|
|
188
|
+
|
|
189
|
+
if (needsPropExistsCond(propPattern)) {
|
|
190
|
+
conditions.push({
|
|
191
|
+
type: 'prop-exists',
|
|
192
|
+
key,
|
|
193
|
+
propName: name
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const {
|
|
198
|
+
conditions: childConditions,
|
|
199
|
+
bindings: childBindings
|
|
200
|
+
} = analyzePattern(propPattern, propKey, seenBindingNames);
|
|
201
|
+
conditions.push(...childConditions);
|
|
202
|
+
bindings.push(...childBindings);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (rest != null && rest.argument != null) {
|
|
206
|
+
const {
|
|
207
|
+
id,
|
|
208
|
+
kind
|
|
209
|
+
} = rest.argument;
|
|
210
|
+
checkDuplicateBindingName(seenBindingNames, rest.argument, id.name);
|
|
211
|
+
checkBindingKind(pattern, kind);
|
|
212
|
+
bindings.push({
|
|
213
|
+
type: 'object-rest',
|
|
214
|
+
key,
|
|
215
|
+
exclude: objKeys,
|
|
216
|
+
kind,
|
|
217
|
+
id
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
conditions,
|
|
223
|
+
bindings
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function constructorExpression(constructor) {
|
|
228
|
+
switch (constructor.type) {
|
|
229
|
+
case 'MatchIdentifierPattern':
|
|
230
|
+
return constructor.id;
|
|
231
|
+
|
|
232
|
+
case 'MatchMemberPattern':
|
|
233
|
+
return convertMemberPattern(constructor);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
161
236
|
/**
|
|
162
237
|
* Analyzes a match pattern, and produced both the conditions and bindings
|
|
163
238
|
* produced by that pattern.
|
|
@@ -360,60 +435,38 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
360
435
|
properties,
|
|
361
436
|
rest
|
|
362
437
|
} = pattern;
|
|
438
|
+
const {
|
|
439
|
+
conditions: propertyConditions,
|
|
440
|
+
bindings
|
|
441
|
+
} = analyzeProperties(key, pattern, seenBindingNames, properties, rest);
|
|
363
442
|
const conditions = [{
|
|
364
443
|
type: 'object',
|
|
365
444
|
key
|
|
366
|
-
}];
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
key: objKey,
|
|
373
|
-
pattern: propPattern
|
|
374
|
-
} = prop;
|
|
375
|
-
objKeys.push(objKey);
|
|
376
|
-
const name = objKeyToString(objKey);
|
|
377
|
-
|
|
378
|
-
if (seenNames.has(name)) {
|
|
379
|
-
throw (0, _createSyntaxError.createSyntaxError)(propPattern, `Duplicate property name '${name}' in match object pattern.`);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
seenNames.add(name);
|
|
383
|
-
const propKey = key.concat(objKey);
|
|
445
|
+
}, ...propertyConditions];
|
|
446
|
+
return {
|
|
447
|
+
conditions,
|
|
448
|
+
bindings
|
|
449
|
+
};
|
|
450
|
+
}
|
|
384
451
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
452
|
+
case 'MatchInstancePattern':
|
|
453
|
+
{
|
|
454
|
+
const {
|
|
455
|
+
targetConstructor,
|
|
456
|
+
properties: {
|
|
457
|
+
properties,
|
|
458
|
+
rest
|
|
391
459
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const {
|
|
403
|
-
id,
|
|
404
|
-
kind
|
|
405
|
-
} = rest.argument;
|
|
406
|
-
checkDuplicateBindingName(seenBindingNames, rest.argument, id.name);
|
|
407
|
-
checkBindingKind(pattern, kind);
|
|
408
|
-
bindings.push({
|
|
409
|
-
type: 'object-rest',
|
|
410
|
-
key,
|
|
411
|
-
exclude: objKeys,
|
|
412
|
-
kind,
|
|
413
|
-
id
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
|
|
460
|
+
} = pattern;
|
|
461
|
+
const {
|
|
462
|
+
conditions: propertyConditions,
|
|
463
|
+
bindings
|
|
464
|
+
} = analyzeProperties(key, pattern, seenBindingNames, properties, rest);
|
|
465
|
+
const conditions = [{
|
|
466
|
+
type: 'instanceof',
|
|
467
|
+
key,
|
|
468
|
+
constructor: constructorExpression(targetConstructor)
|
|
469
|
+
}, ...propertyConditions];
|
|
417
470
|
return {
|
|
418
471
|
conditions,
|
|
419
472
|
bindings
|
|
@@ -567,6 +620,21 @@ function testsOfCondition(root, condition) {
|
|
|
567
620
|
return [(0, _Builders.disjunction)([(0, _Builders.conjunction)([typeofObject, notNull]), typeofFunction])];
|
|
568
621
|
}
|
|
569
622
|
|
|
623
|
+
case 'instanceof':
|
|
624
|
+
{
|
|
625
|
+
const {
|
|
626
|
+
key,
|
|
627
|
+
constructor
|
|
628
|
+
} = condition;
|
|
629
|
+
return [{
|
|
630
|
+
type: 'BinaryExpression',
|
|
631
|
+
left: expressionOfKey(root, key),
|
|
632
|
+
right: constructor,
|
|
633
|
+
operator: 'instanceof',
|
|
634
|
+
...(0, _Builders.etc)()
|
|
635
|
+
}];
|
|
636
|
+
}
|
|
637
|
+
|
|
570
638
|
case 'prop-exists':
|
|
571
639
|
{
|
|
572
640
|
// <propName> in <x>
|
|
@@ -968,7 +1036,7 @@ function mapMatchStatement(node) {
|
|
|
968
1036
|
function transformProgram(program, _options) {
|
|
969
1037
|
// Initialize so each file transformed starts freshly incrementing the
|
|
970
1038
|
// variable name counter, and has its own usage tracking.
|
|
971
|
-
|
|
1039
|
+
genID = new _GenID.default('m');
|
|
972
1040
|
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
973
1041
|
transform(node) {
|
|
974
1042
|
switch (node.type) {
|
|
@@ -987,11 +1055,11 @@ function transformProgram(program, _options) {
|
|
|
987
1055
|
// A rudimentary check to avoid some collisions with our generated
|
|
988
1056
|
// variable names. Ideally, we would have access a scope analyzer
|
|
989
1057
|
// inside the transform instead.
|
|
990
|
-
if (
|
|
1058
|
+
if (genID == null) {
|
|
991
1059
|
throw Error('GenID must be initialized at the start of the transform.');
|
|
992
1060
|
}
|
|
993
1061
|
|
|
994
|
-
|
|
1062
|
+
genID.addUsage(node.name);
|
|
995
1063
|
return node;
|
|
996
1064
|
}
|
|
997
1065
|
|