hermes-parser 0.26.0 → 0.28.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.
@@ -118,6 +118,46 @@ function checkBindingKind(node, kind) {
118
118
  throw (0, _createSyntaxError.createSyntaxError)(node, `'var' bindings are not allowed. Use 'const' or 'let'.`);
119
119
  }
120
120
  }
121
+ /**
122
+ * Does an object property's pattern require a `prop-exists` condition added?
123
+ * If the pattern is a literal like `0`, then it's not required, since the `eq`
124
+ * condition implies the prop exists. However, if we could be doing an equality
125
+ * check against `undefined`, then it is required, since that will be true even
126
+ * if the property doesn't exist.
127
+ */
128
+
129
+
130
+ function needsPropExistsCond(pattern) {
131
+ switch (pattern.type) {
132
+ case 'MatchWildcardPattern':
133
+ case 'MatchBindingPattern':
134
+ case 'MatchIdentifierPattern':
135
+ case 'MatchMemberPattern':
136
+ return true;
137
+
138
+ case 'MatchLiteralPattern':
139
+ case 'MatchUnaryPattern':
140
+ case 'MatchObjectPattern':
141
+ case 'MatchArrayPattern':
142
+ return false;
143
+
144
+ case 'MatchAsPattern':
145
+ {
146
+ const {
147
+ pattern: asPattern
148
+ } = pattern;
149
+ return needsPropExistsCond(asPattern);
150
+ }
151
+
152
+ case 'MatchOrPattern':
153
+ {
154
+ const {
155
+ patterns
156
+ } = pattern;
157
+ return patterns.some(needsPropExistsCond);
158
+ }
159
+ }
160
+ }
121
161
  /**
122
162
  * Analyzes a match pattern, and produced both the conditions and bindings
123
163
  * produced by that pattern.
@@ -342,15 +382,12 @@ function analyzePattern(pattern, key, seenBindingNames) {
342
382
  seenNames.add(name);
343
383
  const propKey = key.concat(objKey);
344
384
 
345
- switch (propPattern.type) {
346
- case 'MatchWildcardPattern':
347
- case 'MatchBindingPattern':
348
- conditions.push({
349
- type: 'prop-exists',
350
- key,
351
- propName: name
352
- });
353
- break;
385
+ if (needsPropExistsCond(propPattern)) {
386
+ conditions.push({
387
+ type: 'prop-exists',
388
+ key,
389
+ propName: name
390
+ });
354
391
  }
355
392
 
356
393
  const {
@@ -175,6 +175,36 @@ function checkBindingKind(node: MatchPattern, kind: BindingKind): void {
175
175
  }
176
176
  }
177
177
 
178
+ /**
179
+ * Does an object property's pattern require a `prop-exists` condition added?
180
+ * If the pattern is a literal like `0`, then it's not required, since the `eq`
181
+ * condition implies the prop exists. However, if we could be doing an equality
182
+ * check against `undefined`, then it is required, since that will be true even
183
+ * if the property doesn't exist.
184
+ */
185
+ function needsPropExistsCond(pattern: MatchPattern): boolean {
186
+ switch (pattern.type) {
187
+ case 'MatchWildcardPattern':
188
+ case 'MatchBindingPattern':
189
+ case 'MatchIdentifierPattern':
190
+ case 'MatchMemberPattern':
191
+ return true;
192
+ case 'MatchLiteralPattern':
193
+ case 'MatchUnaryPattern':
194
+ case 'MatchObjectPattern':
195
+ case 'MatchArrayPattern':
196
+ return false;
197
+ case 'MatchAsPattern': {
198
+ const {pattern: asPattern} = pattern;
199
+ return needsPropExistsCond(asPattern);
200
+ }
201
+ case 'MatchOrPattern': {
202
+ const {patterns} = pattern;
203
+ return patterns.some(needsPropExistsCond);
204
+ }
205
+ }
206
+ }
207
+
178
208
  /**
179
209
  * Analyzes a match pattern, and produced both the conditions and bindings
180
210
  * produced by that pattern.
@@ -301,15 +331,12 @@ function analyzePattern(
301
331
  }
302
332
  seenNames.add(name);
303
333
  const propKey: Key = key.concat(objKey);
304
- switch (propPattern.type) {
305
- case 'MatchWildcardPattern':
306
- case 'MatchBindingPattern':
307
- conditions.push({
308
- type: 'prop-exists',
309
- key,
310
- propName: name,
311
- });
312
- break;
334
+ if (needsPropExistsCond(propPattern)) {
335
+ conditions.push({
336
+ type: 'prop-exists',
337
+ key,
338
+ propName: name,
339
+ });
313
340
  }
314
341
  const {conditions: childConditions, bindings: childBindings} =
315
342
  analyzePattern(propPattern, propKey, seenBindingNames);
package/dist/index.js CHANGED
@@ -120,6 +120,10 @@ function getOptions(options = { ...DEFAULTS
120
120
  options.enableExperimentalComponentSyntax = true; // Enable by default
121
121
  }
122
122
 
123
+ if (options.enableExperimentalFlowMatchSyntax == null) {
124
+ options.enableExperimentalFlowMatchSyntax = true; // Enable by default
125
+ }
126
+
123
127
  options.tokens = options.tokens === true;
124
128
  options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;
125
129
  return options;
@@ -53,6 +53,10 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) {
53
53
  options.enableExperimentalComponentSyntax = true; // Enable by default
54
54
  }
55
55
 
56
+ if (options.enableExperimentalFlowMatchSyntax == null) {
57
+ options.enableExperimentalFlowMatchSyntax = true; // Enable by default
58
+ }
59
+
56
60
  options.tokens = options.tokens === true;
57
61
  options.allowReturnOutsideFunction =
58
62
  options.allowReturnOutsideFunction === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-parser",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
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.26.0"
12
+ "hermes-estree": "0.28.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/parser": "7.7.4",