Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hermes-parser

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hermes-parser - npm Package Compare versions

Comparing version 0.11.1 to 0.12.0

dist/utils/mutateESTreeASTForPrettier.js

6

dist/generated/ESTreeVisitorKeys.js

@@ -47,5 +47,5 @@ /**

ClassImplements: ['id', 'typeParameters'],
ComponentDeclaration: ['id', 'params', 'body', 'typeParameters', 'returnType'],
ComponentDeclaration: ['id', 'params', 'body', 'typeParameters', 'rendersType'],
ComponentParameter: ['name', 'local'],
ComponentTypeAnnotation: ['params', 'rest', 'typeParameters', 'returnType'],
ComponentTypeAnnotation: ['params', 'rest', 'typeParameters', 'rendersType'],
ComponentTypeParameter: ['name', 'typeAnnotation'],

@@ -57,3 +57,3 @@ ConditionalExpression: ['test', 'consequent', 'alternate'],

DeclareClass: ['id', 'typeParameters', 'extends', 'implements', 'mixins', 'body'],
DeclareComponent: ['id', 'params', 'rest', 'typeParameters', 'returnType'],
DeclareComponent: ['id', 'params', 'rest', 'typeParameters', 'rendersType'],
DeclaredPredicate: ['value'],

@@ -60,0 +60,0 @@ DeclareEnum: ['id', 'body'],

@@ -121,3 +121,3 @@ /**

typeParameters: 'Node',
returnType: 'Node'
rendersType: 'Node'
},

@@ -132,3 +132,3 @@ ComponentParameter: {

typeParameters: 'Node',
returnType: 'Node'
rendersType: 'Node'
},

@@ -167,3 +167,3 @@ ComponentTypeParameter: {

typeParameters: 'Node',
returnType: 'Node'
rendersType: 'Node'
},

@@ -170,0 +170,0 @@ DeclaredPredicate: {

@@ -23,30 +23,55 @@ /**

const hermesParse = _HermesParserWASM.default.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
let HermesParserWASM;
let hermesParse;
let hermesParseResult_free;
let hermesParseResult_getError;
let hermesParseResult_getErrorLine;
let hermesParseResult_getErrorColumn;
let hermesParseResult_getProgramBuffer;
let hermesParseResult_getPositionBuffer;
let hermesParseResult_getPositionBufferSize;
/**
* Init the WASM wrapper code generated by `emscripten` to preparse the
* HermesParser WASM code.
*/
const hermesParseResult_free = _HermesParserWASM.default.cwrap('hermesParseResult_free', 'void', ['number']);
function initHermesParserWASM() {
if (HermesParserWASM != null) {
return;
}
const hermesParseResult_getError = _HermesParserWASM.default.cwrap('hermesParseResult_getError', 'string', ['number']);
HermesParserWASM = (0, _HermesParserWASM.default)({
/**
* The emscripten version of `quit` unconditionally assigns the `status` to
* `process.exitCode` which overrides any pre-existing code that has been
* set, even if it is non zero. For our use case we never want an
* `exitCode` to be set so this override removes that functionality.
*/
quit(_status, toThrow) {
throw toThrow;
}
const hermesParseResult_getErrorLine = _HermesParserWASM.default.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
});
hermesParse = HermesParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number', 'number']);
hermesParseResult_free = HermesParserWASM.cwrap('hermesParseResult_free', 'void', ['number']);
hermesParseResult_getError = HermesParserWASM.cwrap('hermesParseResult_getError', 'string', ['number']);
hermesParseResult_getErrorLine = HermesParserWASM.cwrap('hermesParseResult_getErrorLine', 'number', ['number']);
hermesParseResult_getErrorColumn = HermesParserWASM.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']);
hermesParseResult_getProgramBuffer = HermesParserWASM.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']);
hermesParseResult_getPositionBuffer = HermesParserWASM.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']);
hermesParseResult_getPositionBufferSize = HermesParserWASM.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']);
} // Copy a string into the WASM heap and null-terminate
const hermesParseResult_getErrorColumn = _HermesParserWASM.default.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']);
const hermesParseResult_getProgramBuffer = _HermesParserWASM.default.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']);
const hermesParseResult_getPositionBuffer = _HermesParserWASM.default.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']);
const hermesParseResult_getPositionBufferSize = _HermesParserWASM.default.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']); // Copy a string into the WASM heap and null-terminate
function copyToHeap(buffer, addr) {
_HermesParserWASM.default.HEAP8.set(buffer, addr);
_HermesParserWASM.default.HEAP8[addr + buffer.length] = 0;
HermesParserWASM.HEAP8.set(buffer, addr);
HermesParserWASM.HEAP8[addr + buffer.length] = 0;
}
function parse(source, options) {
// Allocate space on heap for source text
initHermesParserWASM(); // Allocate space on heap for source text
const sourceBuffer = Buffer.from(source, 'utf8');
const sourceAddr = _HermesParserWASM.default._malloc(sourceBuffer.length + 1);
const sourceAddr = HermesParserWASM._malloc(sourceBuffer.length + 1);

@@ -76,3 +101,3 @@ if (!sourceAddr) {

const deserializer = new _HermesParserDeserializer.default(hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), _HermesParserWASM.default, options);
const deserializer = new _HermesParserDeserializer.default(hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), HermesParserWASM, options);
return deserializer.deserialize();

@@ -83,4 +108,4 @@ } finally {

} finally {
_HermesParserWASM.default._free(sourceAddr);
HermesParserWASM._free(sourceAddr);
}
}

@@ -95,2 +95,14 @@ /**

function deserializeComponentDeclaration() {
return {
type: 'ComponentDeclaration',
loc: this.addEmptyLoc(),
id: this.deserializeNode(),
params: this.deserializeNodeList(),
body: this.deserializeNode(),
typeParameters: this.deserializeNode(),
rendersType: this.deserializeNode()
};
}
function deserializeFunctionLikeLast() {

@@ -1136,3 +1148,3 @@ throw new Error('FunctionLike' + ' should not appear in program buffer');

typeParameters: this.deserializeNode(),
returnType: this.deserializeNode()
rendersType: this.deserializeNode()
};

@@ -1405,3 +1417,3 @@ }

typeParameters: this.deserializeNode(),
returnType: this.deserializeNode()
rendersType: this.deserializeNode()
};

@@ -1595,3 +1607,4 @@ }

variance: this.deserializeNode(),
default: this.deserializeNode()
default: this.deserializeNode(),
usesExtendsBound: this.deserializeBoolean()
};

@@ -1715,14 +1728,2 @@ }

function deserializeComponentDeclaration() {
return {
type: 'ComponentDeclaration',
loc: this.addEmptyLoc(),
id: this.deserializeNode(),
params: this.deserializeNodeList(),
body: this.deserializeNode(),
typeParameters: this.deserializeNode(),
returnType: this.deserializeNode()
};
}
function deserializeComponentParameter() {

@@ -2157,2 +2158,2 @@ return {

module.exports = [deserializeEmpty, deserializeMetadata, deserializeFunctionLikeFirst, deserializeProgram, deserializeFunctionExpression, deserializeArrowFunctionExpression, deserializeFunctionDeclaration, deserializeFunctionLikeLast, deserializeStatementFirst, deserializeLoopStatementFirst, deserializeWhileStatement, deserializeDoWhileStatement, deserializeForInStatement, deserializeForOfStatement, deserializeForStatement, deserializeLoopStatementLast, deserializeDebuggerStatement, deserializeEmptyStatement, deserializeBlockStatement, 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, deserializeClassDeclaration, deserializeClassExpression, deserializeClassBody, deserializeClassProperty, deserializeClassPrivateProperty, deserializeMethodDefinition, deserializeImportDeclaration, deserializeImportSpecifier, deserializeImportDefaultSpecifier, deserializeImportNamespaceSpecifier, deserializeImportAttribute, deserializeExportNamedDeclaration, deserializeExportSpecifier, deserializeExportNamespaceSpecifier, deserializeExportDefaultDeclaration, deserializeExportAllDeclaration, deserializePatternFirst, deserializeObjectPattern, deserializeArrayPattern, deserializeRestElement, deserializeAssignmentPattern, deserializePatternLast, deserializeJSXIdentifier, deserializeJSXMemberExpression, deserializeJSXNamespacedName, deserializeJSXEmptyExpression, deserializeJSXExpressionContainer, deserializeJSXSpreadChild, deserializeJSXOpeningElement, deserializeJSXClosingElement, deserializeJSXAttribute, deserializeJSXSpreadAttribute, deserializeJSXStringLiteral, deserializeJSXText, deserializeJSXElement, deserializeJSXFragment, deserializeJSXOpeningFragment, deserializeJSXClosingFragment, deserializeExistsTypeAnnotation, deserializeEmptyTypeAnnotation, deserializeStringTypeAnnotation, deserializeNumberTypeAnnotation, deserializeStringLiteralTypeAnnotation, deserializeNumberLiteralTypeAnnotation, deserializeBigIntLiteralTypeAnnotation, deserializeBooleanTypeAnnotation, deserializeBooleanLiteralTypeAnnotation, deserializeNullLiteralTypeAnnotation, deserializeSymbolTypeAnnotation, deserializeAnyTypeAnnotation, deserializeMixedTypeAnnotation, deserializeBigIntTypeAnnotation, deserializeVoidTypeAnnotation, deserializeFunctionTypeAnnotation, deserializeFunctionTypeParam, deserializeComponentTypeAnnotation, deserializeComponentTypeParameter, deserializeNullableTypeAnnotation, deserializeQualifiedTypeIdentifier, deserializeTypeofTypeAnnotation, deserializeKeyofTypeAnnotation, deserializeQualifiedTypeofIdentifier, deserializeTupleTypeAnnotation, deserializeTupleTypeSpreadElement, deserializeTupleTypeLabeledElement, deserializeArrayTypeAnnotation, deserializeInferTypeAnnotation, deserializeUnionTypeAnnotation, deserializeIntersectionTypeAnnotation, deserializeGenericTypeAnnotation, deserializeIndexedAccessType, deserializeOptionalIndexedAccessType, deserializeConditionalTypeAnnotation, deserializeTypePredicate, deserializeInterfaceTypeAnnotation, deserializeTypeAlias, deserializeOpaqueType, deserializeInterfaceDeclaration, deserializeDeclareTypeAlias, deserializeDeclareOpaqueType, deserializeDeclareInterface, deserializeDeclareClass, deserializeDeclareFunction, deserializeDeclareComponent, deserializeDeclareVariable, deserializeDeclareEnum, deserializeDeclareExportDeclaration, deserializeDeclareExportAllDeclaration, deserializeDeclareModule, deserializeDeclareModuleExports, deserializeInterfaceExtends, deserializeClassImplements, deserializeTypeAnnotation, deserializeObjectTypeAnnotation, deserializeObjectTypeProperty, deserializeObjectTypeSpreadProperty, deserializeObjectTypeInternalSlot, deserializeObjectTypeCallProperty, deserializeObjectTypeIndexer, deserializeObjectTypeMappedTypeProperty, deserializeVariance, deserializeTypeParameterDeclaration, deserializeTypeParameter, deserializeTypeParameterInstantiation, deserializeTypeCastExpression, deserializeInferredPredicate, deserializeDeclaredPredicate, deserializeEnumDeclaration, deserializeEnumStringBody, deserializeEnumNumberBody, deserializeEnumBooleanBody, deserializeEnumSymbolBody, deserializeEnumDefaultedMember, deserializeEnumStringMember, deserializeEnumNumberMember, deserializeEnumBooleanMember, deserializeComponentDeclaration, deserializeComponentParameter, deserializeTSTypeAnnotation, deserializeTSAnyKeyword, deserializeTSNumberKeyword, deserializeTSBooleanKeyword, deserializeTSStringKeyword, deserializeTSSymbolKeyword, deserializeTSVoidKeyword, 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, deserializeCoverFirst, deserializeCoverEmptyArgs, deserializeCoverTrailingComma, deserializeCoverInitializer, deserializeCoverRestElement, deserializeCoverTypedIdentifier, deserializeCoverLast];
module.exports = [deserializeEmpty, deserializeMetadata, deserializeFunctionLikeFirst, deserializeProgram, deserializeFunctionExpression, deserializeArrowFunctionExpression, deserializeFunctionDeclaration, deserializeComponentDeclaration, deserializeFunctionLikeLast, deserializeStatementFirst, deserializeLoopStatementFirst, deserializeWhileStatement, deserializeDoWhileStatement, deserializeForInStatement, deserializeForOfStatement, deserializeForStatement, deserializeLoopStatementLast, deserializeDebuggerStatement, deserializeEmptyStatement, deserializeBlockStatement, 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, deserializeClassDeclaration, deserializeClassExpression, deserializeClassBody, deserializeClassProperty, deserializeClassPrivateProperty, deserializeMethodDefinition, deserializeImportDeclaration, deserializeImportSpecifier, deserializeImportDefaultSpecifier, deserializeImportNamespaceSpecifier, deserializeImportAttribute, deserializeExportNamedDeclaration, deserializeExportSpecifier, deserializeExportNamespaceSpecifier, deserializeExportDefaultDeclaration, deserializeExportAllDeclaration, deserializePatternFirst, deserializeObjectPattern, deserializeArrayPattern, deserializeRestElement, deserializeAssignmentPattern, deserializePatternLast, deserializeJSXIdentifier, deserializeJSXMemberExpression, deserializeJSXNamespacedName, deserializeJSXEmptyExpression, deserializeJSXExpressionContainer, deserializeJSXSpreadChild, deserializeJSXOpeningElement, deserializeJSXClosingElement, deserializeJSXAttribute, deserializeJSXSpreadAttribute, deserializeJSXStringLiteral, deserializeJSXText, deserializeJSXElement, deserializeJSXFragment, deserializeJSXOpeningFragment, deserializeJSXClosingFragment, deserializeExistsTypeAnnotation, deserializeEmptyTypeAnnotation, deserializeStringTypeAnnotation, deserializeNumberTypeAnnotation, deserializeStringLiteralTypeAnnotation, deserializeNumberLiteralTypeAnnotation, deserializeBigIntLiteralTypeAnnotation, deserializeBooleanTypeAnnotation, deserializeBooleanLiteralTypeAnnotation, deserializeNullLiteralTypeAnnotation, deserializeSymbolTypeAnnotation, deserializeAnyTypeAnnotation, deserializeMixedTypeAnnotation, deserializeBigIntTypeAnnotation, deserializeVoidTypeAnnotation, deserializeFunctionTypeAnnotation, deserializeFunctionTypeParam, deserializeComponentTypeAnnotation, deserializeComponentTypeParameter, deserializeNullableTypeAnnotation, deserializeQualifiedTypeIdentifier, deserializeTypeofTypeAnnotation, deserializeKeyofTypeAnnotation, deserializeQualifiedTypeofIdentifier, deserializeTupleTypeAnnotation, deserializeTupleTypeSpreadElement, deserializeTupleTypeLabeledElement, deserializeArrayTypeAnnotation, deserializeInferTypeAnnotation, deserializeUnionTypeAnnotation, deserializeIntersectionTypeAnnotation, deserializeGenericTypeAnnotation, deserializeIndexedAccessType, deserializeOptionalIndexedAccessType, deserializeConditionalTypeAnnotation, deserializeTypePredicate, deserializeInterfaceTypeAnnotation, deserializeTypeAlias, deserializeOpaqueType, deserializeInterfaceDeclaration, deserializeDeclareTypeAlias, deserializeDeclareOpaqueType, deserializeDeclareInterface, deserializeDeclareClass, deserializeDeclareFunction, deserializeDeclareComponent, deserializeDeclareVariable, deserializeDeclareEnum, deserializeDeclareExportDeclaration, deserializeDeclareExportAllDeclaration, deserializeDeclareModule, deserializeDeclareModuleExports, deserializeInterfaceExtends, deserializeClassImplements, deserializeTypeAnnotation, deserializeObjectTypeAnnotation, deserializeObjectTypeProperty, deserializeObjectTypeSpreadProperty, deserializeObjectTypeInternalSlot, deserializeObjectTypeCallProperty, deserializeObjectTypeIndexer, deserializeObjectTypeMappedTypeProperty, deserializeVariance, deserializeTypeParameterDeclaration, deserializeTypeParameter, deserializeTypeParameterInstantiation, deserializeTypeCastExpression, deserializeInferredPredicate, deserializeDeclaredPredicate, deserializeEnumDeclaration, deserializeEnumStringBody, deserializeEnumNumberBody, deserializeEnumBooleanBody, deserializeEnumSymbolBody, deserializeEnumDefaultedMember, deserializeEnumStringMember, deserializeEnumNumberMember, deserializeEnumBooleanMember, deserializeComponentParameter, deserializeTSTypeAnnotation, deserializeTSAnyKeyword, deserializeTSNumberKeyword, deserializeTSBooleanKeyword, deserializeTSStringKeyword, deserializeTSSymbolKeyword, deserializeTSVoidKeyword, 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, deserializeCoverFirst, deserializeCoverEmptyArgs, deserializeCoverTrailingComma, deserializeCoverInitializer, deserializeCoverRestElement, deserializeCoverTypedIdentifier, deserializeCoverLast];

@@ -21,2 +21,12 @@ "use strict";

*/
function createSyntaxError(node, err) {
const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]
syntaxError.loc = {
line: node.loc.start.line,
column: node.loc.start.column
};
return syntaxError;
}
class HermesToBabelAdapter extends _HermesASTAdapter.default {

@@ -117,2 +127,3 @@ fixSourceLocation(node) {

case 'ObjectTypeMappedTypeProperty':
case 'ComponentTypeAnnotation':
return this.mapUnsupportedTypeAnnotation(node);

@@ -141,5 +152,11 @@

case 'DeclareComponent':
return this.mapDeclareComponent(node);
case 'JSXElement':
return this.mapJSXElement(node);
case 'ComponentDeclaration':
return this.mapComponentDeclaration(node);
default:

@@ -563,2 +580,12 @@ return this.mapNodeDefault(node);

mapDeclareComponent(nodeUnprocessed) {
nodeUnprocessed.id.typeAnnotation = this.mapUnsupportedTypeAnnotation(nodeUnprocessed);
delete nodeUnprocessed.params;
delete nodeUnprocessed.rest;
delete nodeUnprocessed.typeParameters;
delete nodeUnprocessed.rendersType;
nodeUnprocessed.type = 'DeclareVariable';
return this.mapDeclareVariable(nodeUnprocessed);
}
mapJSXElement(nodeUnprocessed) {

@@ -569,4 +596,178 @@ delete nodeUnprocessed.openingElement.typeArguments;

mapComponentDeclaration(nodeUnprocessed) {
let rendersType = nodeUnprocessed.rendersType;
if (rendersType == null) {
// Create empty loc for return type annotation nodes
const createRendersTypeLoc = () => ({
loc: {
start: { ...nodeUnprocessed.body.loc.end
},
end: { ...nodeUnprocessed.body.loc.end
},
rangeStart: nodeUnprocessed.body.loc.rangeStart,
rangeEnd: nodeUnprocessed.body.loc.rangeEnd
}
});
rendersType = {
type: 'GenericTypeAnnotation',
id: {
type: 'QualifiedTypeIdentifier',
qualification: {
type: 'Identifier',
name: 'React',
...createRendersTypeLoc()
},
id: {
type: 'Identifier',
name: 'Node',
...createRendersTypeLoc()
}
},
typeParameters: null,
...createRendersTypeLoc()
};
}
function getParamName(paramName) {
switch (paramName.type) {
case 'Identifier':
return paramName.name;
case 'StringLiteral':
return paramName.value;
default:
throw createSyntaxError(paramName, `Unknown Component parameter name type of "${paramName.type}"`);
}
}
const properties = nodeUnprocessed.params.map(param => {
switch (param.type) {
case 'RestElement':
{
delete param.typeAnnotation;
return param;
}
case 'ComponentParameter':
{
if (getParamName(param.name) === 'ref') {
throw createSyntaxError(param, 'Component parameters named "ref" are currently not supported');
}
if (param.name.type === 'Identifier') {
delete param.name.typeAnnotation;
}
if (param.local.type === 'AssignmentPattern') {
delete param.local.left.typeAnnotation;
delete param.local.left.optional;
} else {
delete param.local.typeAnnotation;
delete param.local.optional;
}
return {
type: 'ObjectProperty',
key: param.name,
value: param.local,
method: false,
shorthand: param.shorthand,
computed: false,
loc: param.loc,
start: param.start,
end: param.end
};
}
default:
{
throw createSyntaxError(param, `Unknown Component parameter type of "${param.type}"`);
}
}
});
const paramsLoc = (() => {
if (properties.length === 0) {
// No props, approximate range via existing nodes.
const startLoc = nodeUnprocessed.typeParameters != null ? nodeUnprocessed.typeParameters.loc : nodeUnprocessed.id.loc;
return {
start: startLoc.end,
end: rendersType.loc.start,
startRange: startLoc.endRange,
endRange: rendersType.loc.startRange
};
}
return {
start: properties[0].loc.start,
end: properties[properties.length - 1].loc.end,
startRange: properties[0].loc.startRange,
endRange: properties[properties.length - 1].loc.endRange
};
})(); // Create empty loc for type annotation nodes
const createParamsTypeLoc = () => ({
loc: {
start: { ...paramsLoc.end
},
end: { ...paramsLoc.end
},
startRange: paramsLoc.endRange,
endRange: paramsLoc.endRange
}
});
const params = [{
type: 'ObjectPattern',
properties,
typeAnnotation: {
type: 'TypeAnnotation',
typeAnnotation: {
type: 'GenericTypeAnnotation',
id: {
type: 'Identifier',
name: '$ReadOnly',
...createParamsTypeLoc()
},
typeParameters: {
type: 'TypeParameterInstantiation',
params: [{
type: 'ObjectTypeAnnotation',
callProperties: [],
properties: [],
indexers: [],
internalSlots: [],
exact: false,
inexact: true,
...createParamsTypeLoc()
}],
...createParamsTypeLoc()
},
...createParamsTypeLoc()
},
...createParamsTypeLoc()
},
loc: paramsLoc
}];
const functionComponent = {
type: 'FunctionDeclaration',
id: nodeUnprocessed.id,
typeParameters: nodeUnprocessed.typeParameters,
params,
returnType: rendersType,
body: nodeUnprocessed.body,
async: false,
generator: false,
predicate: null,
loc: nodeUnprocessed.loc
};
return this.mapNodeDefault(functionComponent);
}
}
exports.default = HermesToBabelAdapter;

@@ -17,2 +17,3 @@ /**

parse: true,
mutateESTreeASTForPrettier: true,
FlowVisitorKeys: true,

@@ -22,3 +23,3 @@ astArrayMutationHelpers: true,

};
exports.astNodeMutationHelpers = exports.astArrayMutationHelpers = void 0;
exports.mutateESTreeASTForPrettier = exports.astNodeMutationHelpers = exports.astArrayMutationHelpers = void 0;
exports.parse = parse;

@@ -71,2 +72,6 @@

var _mutateESTreeASTForPrettier = _interopRequireDefault(require("./utils/mutateESTreeASTForPrettier"));
exports.mutateESTreeASTForPrettier = _mutateESTreeASTForPrettier.default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -73,0 +78,0 @@

@@ -57,4 +57,5 @@ /**

leave(_node) {}
leave(_node) {},
visitorKeys: options.visitorKeys
});

@@ -61,0 +62,0 @@

{
"name": "hermes-parser",
"version": "0.11.1",
"version": "0.12.0",
"description": "A JavaScript parser built from the Hermes engine",

@@ -12,3 +12,3 @@ "main": "dist/index.js",

"dependencies": {
"hermes-estree": "0.11.1"
"hermes-estree": "0.12.0"
},

@@ -15,0 +15,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc