Socket
Socket
Sign inDemoInstall

hermes-parser

Package Overview
Dependencies
Maintainers
3
Versions
41
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.12.1 to 0.13.0

dist/ParserOptions.js

2

dist/generated/ESTreeVisitorKeys.js

@@ -150,3 +150,3 @@ /**

Property: ['key', 'value'],
PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation', 'tsModifiers'],
PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation'],
QualifiedTypeIdentifier: ['qualification', 'id'],

@@ -153,0 +153,0 @@ QualifiedTypeofIdentifier: ['qualification', 'id'],

@@ -516,4 +516,3 @@ /**

variance: 'Node',
typeAnnotation: 'Node',
tsModifiers: 'Node'
typeAnnotation: 'Node'
},

@@ -520,0 +519,0 @@ QualifiedTypeIdentifier: {

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

*/
function createDefaultPosition() {
return {
line: 1,
column: 0
};
}
function createSyntaxError(node, err) {

@@ -122,4 +129,4 @@ const syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing]

case 'KeyofTypeAnnotation':
case 'ConditionalType':
case 'InferType':
case 'ConditionalTypeAnnotation':
case 'InferTypeAnnotation':
case 'TupleTypeLabeledElement':

@@ -611,17 +618,21 @@ case 'TupleTypeSpreadElement':

rendersType = {
type: 'GenericTypeAnnotation',
id: {
type: 'QualifiedTypeIdentifier',
qualification: {
type: 'Identifier',
name: 'React',
...createRendersTypeLoc()
type: 'TypeAnnotation',
typeAnnotation: {
type: 'GenericTypeAnnotation',
id: {
type: 'QualifiedTypeIdentifier',
qualification: {
type: 'Identifier',
name: 'React',
...createRendersTypeLoc()
},
id: {
type: 'Identifier',
name: 'Node',
...createRendersTypeLoc()
}
},
id: {
type: 'Identifier',
name: 'Node',
...createRendersTypeLoc()
}
typeParameters: null,
...createRendersTypeLoc()
},
typeParameters: null,
...createRendersTypeLoc()

@@ -644,84 +655,16 @@ };

const properties = nodeUnprocessed.params.map(param => {
switch (param.type) {
case 'RestElement':
{
delete param.typeAnnotation;
return param;
}
function createPropsTypeAnnotation(loc) {
// Create empty loc for type annotation nodes
const createParamsTypeLoc = () => ({
loc: {
start: loc.start != null ? { ...loc.start
} : createDefaultPosition(),
end: loc.end != null ? { ...loc.end
} : createDefaultPosition(),
rangeStart: loc.rangeStart,
rangeEnd: loc.rangeEnd
}
});
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',

@@ -752,5 +695,80 @@ typeAnnotation: {

...createParamsTypeLoc()
},
loc: paramsLoc
}];
};
}
const params = (() => {
if (nodeUnprocessed.params.length === 0) {
return [];
} // Optimize `component Foo(...props: Props) {}` to `function Foo(props: Props) {}
if (nodeUnprocessed.params.length === 1 && nodeUnprocessed.params[0].type === 'RestElement') {
const restElement = nodeUnprocessed.params[0];
return [{ ...restElement.argument,
typeAnnotation: createPropsTypeAnnotation(restElement.argument.typeAnnotation.loc)
}];
}
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 = {
start: properties[0].loc.start,
end: properties[properties.length - 1].loc.end,
rangeStart: properties[0].loc.rangeStart,
rangeEnd: properties[properties.length - 1].loc.rangeEnd
};
return [{
type: 'ObjectPattern',
properties,
typeAnnotation: createPropsTypeAnnotation({ ...paramsLoc,
start: paramsLoc.end,
rangeStart: paramsLoc.rangeEnd
}),
loc: paramsLoc
}];
})();
const functionComponent = {

@@ -757,0 +775,0 @@ type: 'FunctionDeclaration',

@@ -35,2 +35,11 @@ /**

var _ParserOptions = require("./ParserOptions");
Object.keys(_ParserOptions).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _ParserOptions[key]) return;
exports[key] = _ParserOptions[key];
});
var _SimpleTraverser = require("./traverse/SimpleTraverser");

@@ -37,0 +46,0 @@

@@ -106,4 +106,3 @@ /**

for (const key of (0, _getVisitorKeys.getVisitorKeys)(node)) {
if ((0, _getVisitorKeys.isNode)( // $FlowExpectedError[prop-missing]
node[key])) {
if ((0, _getVisitorKeys.isNode)(node[key])) {
node[key].parent = node;

@@ -142,3 +141,4 @@ } else if (Array.isArray(node[key])) {

// Check if this will actually result in a change, maintaining referential equality is important.
const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) => // $FlowExpectedError[prop-missing]
const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) => // $FlowExpectedError[incompatible-call]
// $FlowExpectedError[prop-missing]
Array.isArray(value) ? (0, _astArrayMutationHelpers.arrayIsEqual)(node[key], value) : node[key] === value);

@@ -145,0 +145,0 @@

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

for (const key of keys) {
// $FlowExpectedError[prop-missing]
const child = node[key];

@@ -86,0 +85,0 @@

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

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

"dependencies": {
"hermes-estree": "0.12.1"
"hermes-estree": "0.13.0"
},
"devDependencies": {
"@babel/parser": "7.7.4",
"@babel/generator": "7.7.4",
"@babel/types": "7.7.4",

@@ -18,0 +19,0 @@ "espree": "9.3.2"

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

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