hermes-parser 0.17.0 → 0.17.1

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.
@@ -195,16 +195,7 @@ function mapComponentParameters(params) {
195
195
  let ref = null;
196
196
 
197
197
  if (refParam != null) {
198
- const refType = refParam.local;
199
- ref = {
200
- type: 'Identifier',
201
- name: 'ref',
202
- optional: false,
203
- typeAnnotation: refType.type === 'AssignmentPattern' ? refType.left.typeAnnotation : refType.typeAnnotation,
204
- loc: refParam.loc,
205
- range: refParam.range,
206
- parent: EMPTY_PARENT
207
- };
198
+ ref = refParam.local;
208
199
  }
209
200
 
210
201
  return {
@@ -228,10 +219,6 @@ function mapComponentParameter(param) {
228
219
 
229
220
  case 'ComponentParameter':
230
221
  {
231
- if (getComponentParameterName(param.name) === 'ref') {
232
- throw (0, _createSyntaxError.createSyntaxError)(param, 'Component parameters named "ref" are currently not supported');
233
- }
234
-
235
222
  let value;
236
223
 
237
224
  if (param.local.type === 'AssignmentPattern') {
@@ -38,6 +38,8 @@ import type {
38
38
  VariableDeclaration,
39
39
  ModuleDeclaration,
40
40
  Statement,
41
+ AssignmentPattern,
42
+ BindingName,
41
43
  } from 'hermes-estree';
42
44
 
43
45
  import {SimpleTransform} from '../transform/SimpleTransform';
@@ -148,7 +150,7 @@ function mapComponentParameters(
148
150
  params: $ReadOnlyArray<ComponentParameter | RestElement>,
149
151
  ): $ReadOnly<{
150
152
  props: ?(ObjectPattern | Identifier),
151
- ref: ?Identifier,
153
+ ref: ?(BindingName | AssignmentPattern),
152
154
  }> {
153
155
  if (params.length === 0) {
154
156
  return {props: null, ref: null};
@@ -237,19 +239,7 @@ function mapComponentParameters(
237
239
 
238
240
  let ref = null;
239
241
  if (refParam != null) {
240
- const refType = refParam.local;
241
- ref = {
242
- type: 'Identifier',
243
- name: 'ref',
244
- optional: false,
245
- typeAnnotation:
246
- refType.type === 'AssignmentPattern'
247
- ? refType.left.typeAnnotation
248
- : refType.typeAnnotation,
249
- loc: refParam.loc,
250
- range: refParam.range,
251
- parent: EMPTY_PARENT,
252
- };
242
+ ref = refParam.local;
253
243
  }
254
244
 
255
245
  return {
@@ -270,13 +260,6 @@ function mapComponentParameter(
270
260
  return a;
271
261
  }
272
262
  case 'ComponentParameter': {
273
- if (getComponentParameterName(param.name) === 'ref') {
274
- throw createSyntaxError(
275
- param,
276
- 'Component parameters named "ref" are currently not supported',
277
- );
278
- }
279
-
280
263
  let value;
281
264
  if (param.local.type === 'AssignmentPattern') {
282
265
  value = nodeWith(param.local, {
@@ -17,7 +17,17 @@ exports.default = mutate;
17
17
  var _SimpleTransform = require("../transform/SimpleTransform");
18
18
 
19
19
  // https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
20
- function transformChainExpression(node) {
20
+ function transformChainExpression(node, comments) {
21
+ if (comments != null) {
22
+ var _node$comments;
23
+
24
+ // $FlowExpectedError[prop-missing]
25
+ const joinedComments = comments.concat((_node$comments = node.comments) != null ? _node$comments : []); // $FlowExpectedError[prop-missing]
26
+ // $FlowFixMe[cannot-write]
27
+
28
+ node.comments = joinedComments;
29
+ }
30
+
21
31
  switch (node.type) {
22
32
  case 'CallExpression':
23
33
  // $FlowExpectedError[cannot-spread-interface]
@@ -56,7 +66,8 @@ function mutate(rootNode, visitorKeys) {
56
66
 
57
67
 
58
68
  if (node.type === 'ChainExpression') {
59
- return transformChainExpression(node.expression);
69
+ // $FlowFixMe[prop-missing]
70
+ return transformChainExpression(node.expression, node == null ? void 0 : node.comments);
60
71
  } // Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
61
72
  // `ObjectTypeProperty` is a method or not (instead of using the `node.method` boolean). To correctly print
62
73
  // the node when its not a method we need the start position to be different from the `node.value`s start
@@ -10,12 +10,22 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type {ESNode, Program} from 'hermes-estree';
13
+ import type {ESNode, Program, Comment} from 'hermes-estree';
14
14
  import type {VisitorKeysType} from '../traverse/getVisitorKeys';
15
15
  import {SimpleTransform} from '../transform/SimpleTransform';
16
16
 
17
17
  // https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
18
- function transformChainExpression(node: ESNode): ESNode {
18
+ function transformChainExpression(
19
+ node: ESNode,
20
+ comments: ?$ReadOnlyArray<Comment>,
21
+ ): ESNode {
22
+ if (comments != null) {
23
+ // $FlowExpectedError[prop-missing]
24
+ const joinedComments = comments.concat(node.comments ?? []);
25
+ // $FlowExpectedError[prop-missing]
26
+ // $FlowFixMe[cannot-write]
27
+ node.comments = joinedComments;
28
+ }
19
29
  switch (node.type) {
20
30
  case 'CallExpression':
21
31
  // $FlowExpectedError[cannot-spread-interface]
@@ -59,7 +69,8 @@ export default function mutate(
59
69
  // so we have to apply their transform to our AST so it can actually format it.
60
70
  // Note: Only needed for prettier V2, this is supported in V3
61
71
  if (node.type === 'ChainExpression') {
62
- return transformChainExpression(node.expression);
72
+ // $FlowFixMe[prop-missing]
73
+ return transformChainExpression(node.expression, node?.comments);
63
74
  }
64
75
 
65
76
  // Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-parser",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "A JavaScript parser built from the Hermes engine",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "url": "git@github.com:facebook/hermes.git"
10
10
  },
11
11
  "dependencies": {
12
- "hermes-estree": "0.17.0"
12
+ "hermes-estree": "0.17.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/parser": "7.7.4",