hermes-parser 0.19.0 → 0.19.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.
@@ -66,6 +66,7 @@ function transformProgram(program, _options) {
66
66
  case 'DeclareInterface':
67
67
  case 'DeclareModule':
68
68
  case 'DeclareModuleExports':
69
+ case 'DeclareNamespace':
69
70
  case 'DeclareOpaqueType':
70
71
  case 'DeclareTypeAlias':
71
72
  case 'DeclareVariable':
@@ -59,6 +59,7 @@ export function transformProgram(
59
59
  case 'DeclareInterface':
60
60
  case 'DeclareModule':
61
61
  case 'DeclareModuleExports':
62
+ case 'DeclareNamespace':
62
63
  case 'DeclareOpaqueType':
63
64
  case 'DeclareTypeAlias':
64
65
  case 'DeclareVariable':
@@ -80,6 +80,29 @@ function mapDeclareEnum(node) {
80
80
  parent: node.parent
81
81
  };
82
82
  }
83
+ /**
84
+ * Convert DeclareNamespace nodes to DeclareVariable
85
+ */
86
+
87
+
88
+ function mapDeclareNamespace(node) {
89
+ return {
90
+ type: 'DeclareVariable',
91
+ kind: 'const',
92
+ id: nodeWith(node.id, {
93
+ typeAnnotation: {
94
+ type: 'TypeAnnotation',
95
+ typeAnnotation: createAnyTypeAnnotation(node.body),
96
+ loc: node.body.loc,
97
+ range: node.body.range,
98
+ parent: EMPTY_PARENT
99
+ }
100
+ }),
101
+ loc: node.loc,
102
+ range: node.range,
103
+ parent: node.parent
104
+ };
105
+ }
83
106
  /**
84
107
  * Remove `this` param from functions.
85
108
  */
@@ -170,6 +193,11 @@ function transformProgram(program, _options) {
170
193
  return mapDeclareEnum(node);
171
194
  }
172
195
 
196
+ case 'DeclareNamespace':
197
+ {
198
+ return mapDeclareNamespace(node);
199
+ }
200
+
173
201
  case 'FunctionDeclaration':
174
202
  case 'FunctionExpression':
175
203
  {
@@ -23,6 +23,7 @@ import type {
23
23
  Program,
24
24
  ESNode,
25
25
  DeclareEnum,
26
+ DeclareNamespace,
26
27
  DeclareVariable,
27
28
  AnyTypeAnnotation,
28
29
  GenericTypeAnnotation,
@@ -92,6 +93,28 @@ function mapDeclareEnum(node: DeclareEnum): DeclareVariable {
92
93
  };
93
94
  }
94
95
 
96
+ /**
97
+ * Convert DeclareNamespace nodes to DeclareVariable
98
+ */
99
+ function mapDeclareNamespace(node: DeclareNamespace): DeclareVariable {
100
+ return {
101
+ type: 'DeclareVariable',
102
+ kind: 'const',
103
+ id: nodeWith(node.id, {
104
+ typeAnnotation: {
105
+ type: 'TypeAnnotation',
106
+ typeAnnotation: createAnyTypeAnnotation(node.body),
107
+ loc: node.body.loc,
108
+ range: node.body.range,
109
+ parent: EMPTY_PARENT,
110
+ },
111
+ }),
112
+ loc: node.loc,
113
+ range: node.range,
114
+ parent: node.parent,
115
+ };
116
+ }
117
+
95
118
  /**
96
119
  * Remove `this` param from functions.
97
120
  */
@@ -177,6 +200,9 @@ export function transformProgram(
177
200
  case 'DeclareEnum': {
178
201
  return mapDeclareEnum(node);
179
202
  }
203
+ case 'DeclareNamespace': {
204
+ return mapDeclareNamespace(node);
205
+ }
180
206
  case 'FunctionDeclaration':
181
207
  case 'FunctionExpression': {
182
208
  return mapFunction(node);
@@ -64,6 +64,7 @@ module.exports = {
64
64
  DeclareInterface: ['id', 'typeParameters', 'extends', 'body'],
65
65
  DeclareModule: ['id', 'body'],
66
66
  DeclareModuleExports: ['typeAnnotation'],
67
+ DeclareNamespace: ['id', 'body'],
67
68
  DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
68
69
  DeclareTypeAlias: ['id', 'typeParameters', 'right'],
69
70
  DeclareVariable: ['id'],
@@ -203,6 +203,10 @@ const HERMES_AST_VISITOR_KEYS = {
203
203
  DeclareModuleExports: {
204
204
  typeAnnotation: 'Node'
205
205
  },
206
+ DeclareNamespace: {
207
+ id: 'Node',
208
+ body: 'Node'
209
+ },
206
210
  DeclareOpaqueType: {
207
211
  id: 'Node',
208
212
  typeParameters: 'Node',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-parser",
3
- "version": "0.19.0",
3
+ "version": "0.19.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.19.0"
12
+ "hermes-estree": "0.19.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/parser": "7.7.4",