hermes-estree 0.9.0 → 0.10.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.
Files changed (41) hide show
  1. package/dist/HermesAST.js.flow +57 -0
  2. package/dist/HermesASTAdapter.js +186 -0
  3. package/dist/HermesASTAdapter.js.flow +183 -0
  4. package/dist/HermesParser.js +83 -0
  5. package/dist/HermesParser.js.flow +123 -0
  6. package/dist/HermesParserDecodeUTF8String.js +68 -0
  7. package/dist/HermesParserDecodeUTF8String.js.flow +65 -0
  8. package/dist/HermesParserDeserializer.js +243 -0
  9. package/dist/HermesParserDeserializer.js.flow +261 -0
  10. package/dist/HermesParserNodeDeserializers.js +2008 -0
  11. package/dist/HermesParserNodeDeserializers.js.flow +16 -0
  12. package/dist/HermesParserWASM.js +6 -0
  13. package/dist/HermesParserWASM.js.flow +75 -0
  14. package/dist/HermesToBabelAdapter.js +514 -0
  15. package/dist/HermesToBabelAdapter.js.flow +490 -0
  16. package/dist/HermesToESTreeAdapter.js +439 -0
  17. package/dist/HermesToESTreeAdapter.js.flow +422 -0
  18. package/dist/ParserOptions.js.flow +18 -0
  19. package/dist/generated/ESTreeVisitorKeys.js +180 -0
  20. package/dist/generated/ESTreeVisitorKeys.js.flow +15 -0
  21. package/dist/generated/HermesESTreeSelectorTypes.js.flow +20 -1
  22. package/dist/generated/ParserVisitorKeys.js +622 -0
  23. package/dist/generated/ParserVisitorKeys.js.flow +17 -0
  24. package/dist/generated/predicates.js +24 -12
  25. package/dist/generated/predicates.js.flow +34 -23
  26. package/dist/getModuleDocblock.js +112 -0
  27. package/dist/getModuleDocblock.js.flow +118 -0
  28. package/dist/predicates.js +13 -1
  29. package/dist/predicates.js.flow +125 -2
  30. package/dist/transform/SimpleTransform.js +92 -0
  31. package/dist/transform/SimpleTransform.js.flow +104 -0
  32. package/dist/transform/astArrayMutationHelpers.js +62 -0
  33. package/dist/transform/astArrayMutationHelpers.js.flow +71 -0
  34. package/dist/transform/astNodeMutationHelpers.js +186 -0
  35. package/dist/transform/astNodeMutationHelpers.js.flow +205 -0
  36. package/dist/traverse/SimpleTraverser.js +138 -0
  37. package/dist/traverse/SimpleTraverser.js.flow +132 -0
  38. package/dist/traverse/getVisitorKeys.js +35 -0
  39. package/dist/traverse/getVisitorKeys.js.flow +36 -0
  40. package/dist/types.js.flow +128 -30
  41. package/package.json +1 -1
@@ -6,12 +6,19 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @generated
10
+ */
11
+
12
+ /*
13
+ * !!! GENERATED FILE !!!
14
+ *
15
+ * Any manual changes to this file will be overwritten. To regenerate run `yarn build`.
9
16
  */
10
17
  // lint directives to let us do some basic validation of generated files
11
18
 
12
19
  /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
13
20
 
14
- /* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
21
+ /* global $NonMaybeType, Partial, $ReadOnly, $ReadOnlyArray */
15
22
  'use strict';
16
23
 
17
24
  Object.defineProperty(exports, "__esModule", {
@@ -30,6 +37,7 @@ exports.isAsyncKeyword = isAsyncKeyword;
30
37
  exports.isAwaitExpression = isAwaitExpression;
31
38
  exports.isAwaitKeyword = isAwaitKeyword;
32
39
  exports.isBigIntLiteralTypeAnnotation = isBigIntLiteralTypeAnnotation;
40
+ exports.isBigIntTypeAnnotation = isBigIntTypeAnnotation;
33
41
  exports.isBinaryExpression = isBinaryExpression;
34
42
  exports.isBitwiseANDEqualToken = isBitwiseANDEqualToken;
35
43
  exports.isBitwiseANDToken = isBitwiseANDToken;
@@ -313,6 +321,10 @@ function isBigIntLiteralTypeAnnotation(node) {
313
321
  return node.type === 'BigIntLiteralTypeAnnotation';
314
322
  }
315
323
 
324
+ function isBigIntTypeAnnotation(node) {
325
+ return node.type === 'BigIntTypeAnnotation';
326
+ }
327
+
316
328
  function isBinaryExpression(node) {
317
329
  return node.type === 'BinaryExpression';
318
330
  }
@@ -1218,47 +1230,47 @@ function isYieldToken(node) {
1218
1230
  }
1219
1231
 
1220
1232
  function isAsKeyword(node) {
1221
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'as';
1233
+ return node.type === 'Identifier' && node.name === 'as' || node.type === 'Keyword' && node.value === 'as';
1222
1234
  }
1223
1235
 
1224
1236
  function isAsyncKeyword(node) {
1225
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'async';
1237
+ return node.type === 'Identifier' && node.name === 'async' || node.type === 'Keyword' && node.value === 'async';
1226
1238
  }
1227
1239
 
1228
1240
  function isAwaitKeyword(node) {
1229
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'await';
1241
+ return node.type === 'Identifier' && node.name === 'await' || node.type === 'Keyword' && node.value === 'await';
1230
1242
  }
1231
1243
 
1232
1244
  function isDeclareKeyword(node) {
1233
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'declare';
1245
+ return node.type === 'Identifier' && node.name === 'declare' || node.type === 'Keyword' && node.value === 'declare';
1234
1246
  }
1235
1247
 
1236
1248
  function isFromKeyword(node) {
1237
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'from';
1249
+ return node.type === 'Identifier' && node.name === 'from' || node.type === 'Keyword' && node.value === 'from';
1238
1250
  }
1239
1251
 
1240
1252
  function isGetKeyword(node) {
1241
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'get';
1253
+ return node.type === 'Identifier' && node.name === 'get' || node.type === 'Keyword' && node.value === 'get';
1242
1254
  }
1243
1255
 
1244
1256
  function isLetKeyword(node) {
1245
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'let';
1257
+ return node.type === 'Identifier' && node.name === 'let' || node.type === 'Keyword' && node.value === 'let';
1246
1258
  }
1247
1259
 
1248
1260
  function isModuleKeyword(node) {
1249
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'module';
1261
+ return node.type === 'Identifier' && node.name === 'module' || node.type === 'Keyword' && node.value === 'module';
1250
1262
  }
1251
1263
 
1252
1264
  function isOfKeyword(node) {
1253
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'of';
1265
+ return node.type === 'Identifier' && node.name === 'of' || node.type === 'Keyword' && node.value === 'of';
1254
1266
  }
1255
1267
 
1256
1268
  function isSetKeyword(node) {
1257
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'set';
1269
+ return node.type === 'Identifier' && node.name === 'set' || node.type === 'Keyword' && node.value === 'set';
1258
1270
  }
1259
1271
 
1260
1272
  function isTypeKeyword(node) {
1261
- return (node.type === 'Identifier' || node.type === 'Keyword') && node.value === 'type';
1273
+ return node.type === 'Identifier' && node.name === 'type' || node.type === 'Keyword' && node.value === 'type';
1262
1274
  }
1263
1275
 
1264
1276
  function isCommaToken(node) {
@@ -6,11 +6,18 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
+ * @generated
10
+ */
11
+
12
+ /*
13
+ * !!! GENERATED FILE !!!
14
+ *
15
+ * Any manual changes to this file will be overwritten. To regenerate run `yarn build`.
9
16
  */
10
17
 
11
18
  // lint directives to let us do some basic validation of generated files
12
19
  /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
13
- /* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
20
+ /* global $NonMaybeType, Partial, $ReadOnly, $ReadOnlyArray */
14
21
 
15
22
  'use strict';
16
23
 
@@ -56,6 +63,10 @@ export function isBigIntLiteralTypeAnnotation(
56
63
  return node.type === 'BigIntLiteralTypeAnnotation';
57
64
  }
58
65
 
66
+ export function isBigIntTypeAnnotation(node: ESNode | Token): boolean %checks {
67
+ return node.type === 'BigIntTypeAnnotation';
68
+ }
69
+
59
70
  export function isBinaryExpression(node: ESNode | Token): boolean %checks {
60
71
  return node.type === 'BinaryExpression';
61
72
  }
@@ -1024,78 +1035,78 @@ export function isYieldToken(node: ESNode | Token): boolean %checks {
1024
1035
 
1025
1036
  export function isAsKeyword(node: ESNode | Token): boolean %checks {
1026
1037
  return (
1027
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1028
- node.value === 'as'
1038
+ (node.type === 'Identifier' && node.name === 'as') ||
1039
+ (node.type === 'Keyword' && node.value === 'as')
1029
1040
  );
1030
1041
  }
1031
1042
 
1032
1043
  export function isAsyncKeyword(node: ESNode | Token): boolean %checks {
1033
1044
  return (
1034
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1035
- node.value === 'async'
1045
+ (node.type === 'Identifier' && node.name === 'async') ||
1046
+ (node.type === 'Keyword' && node.value === 'async')
1036
1047
  );
1037
1048
  }
1038
1049
 
1039
1050
  export function isAwaitKeyword(node: ESNode | Token): boolean %checks {
1040
1051
  return (
1041
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1042
- node.value === 'await'
1052
+ (node.type === 'Identifier' && node.name === 'await') ||
1053
+ (node.type === 'Keyword' && node.value === 'await')
1043
1054
  );
1044
1055
  }
1045
1056
 
1046
1057
  export function isDeclareKeyword(node: ESNode | Token): boolean %checks {
1047
1058
  return (
1048
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1049
- node.value === 'declare'
1059
+ (node.type === 'Identifier' && node.name === 'declare') ||
1060
+ (node.type === 'Keyword' && node.value === 'declare')
1050
1061
  );
1051
1062
  }
1052
1063
 
1053
1064
  export function isFromKeyword(node: ESNode | Token): boolean %checks {
1054
1065
  return (
1055
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1056
- node.value === 'from'
1066
+ (node.type === 'Identifier' && node.name === 'from') ||
1067
+ (node.type === 'Keyword' && node.value === 'from')
1057
1068
  );
1058
1069
  }
1059
1070
 
1060
1071
  export function isGetKeyword(node: ESNode | Token): boolean %checks {
1061
1072
  return (
1062
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1063
- node.value === 'get'
1073
+ (node.type === 'Identifier' && node.name === 'get') ||
1074
+ (node.type === 'Keyword' && node.value === 'get')
1064
1075
  );
1065
1076
  }
1066
1077
 
1067
1078
  export function isLetKeyword(node: ESNode | Token): boolean %checks {
1068
1079
  return (
1069
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1070
- node.value === 'let'
1080
+ (node.type === 'Identifier' && node.name === 'let') ||
1081
+ (node.type === 'Keyword' && node.value === 'let')
1071
1082
  );
1072
1083
  }
1073
1084
 
1074
1085
  export function isModuleKeyword(node: ESNode | Token): boolean %checks {
1075
1086
  return (
1076
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1077
- node.value === 'module'
1087
+ (node.type === 'Identifier' && node.name === 'module') ||
1088
+ (node.type === 'Keyword' && node.value === 'module')
1078
1089
  );
1079
1090
  }
1080
1091
 
1081
1092
  export function isOfKeyword(node: ESNode | Token): boolean %checks {
1082
1093
  return (
1083
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1084
- node.value === 'of'
1094
+ (node.type === 'Identifier' && node.name === 'of') ||
1095
+ (node.type === 'Keyword' && node.value === 'of')
1085
1096
  );
1086
1097
  }
1087
1098
 
1088
1099
  export function isSetKeyword(node: ESNode | Token): boolean %checks {
1089
1100
  return (
1090
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1091
- node.value === 'set'
1101
+ (node.type === 'Identifier' && node.name === 'set') ||
1102
+ (node.type === 'Keyword' && node.value === 'set')
1092
1103
  );
1093
1104
  }
1094
1105
 
1095
1106
  export function isTypeKeyword(node: ESNode | Token): boolean %checks {
1096
1107
  return (
1097
- (node.type === 'Identifier' || node.type === 'Keyword') &&
1098
- node.value === 'type'
1108
+ (node.type === 'Identifier' && node.name === 'type') ||
1109
+ (node.type === 'Keyword' && node.value === 'type')
1099
1110
  );
1100
1111
  }
1101
1112
 
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ exports.getModuleDocblock = getModuleDocblock;
16
+ exports.parseDocblockString = parseDocblockString;
17
+ const DIRECTIVE_REGEX = /^\s*@([a-zA-Z0-9_-]+)( +.+)?$/;
18
+
19
+ function parseDocblockString(docblock) {
20
+ const directiveLines = docblock.split('\n') // remove the leading " *" from each line
21
+ .map(line => line.trimStart().replace(/^\* ?/, '').trim()).filter(line => line.startsWith('@'));
22
+ const directives = // $FlowExpectedError[incompatible-type] - flow types this return as {...}
23
+ Object.create(null);
24
+
25
+ for (const line of directiveLines) {
26
+ var _match$;
27
+
28
+ const match = DIRECTIVE_REGEX.exec(line);
29
+
30
+ if (match == null) {
31
+ continue;
32
+ }
33
+
34
+ const name = match[1]; // explicitly use an empty string if there's no value
35
+ // this way the array length tracks how many instances of the directive there was
36
+
37
+ const value = ((_match$ = match[2]) != null ? _match$ : '').trim();
38
+
39
+ if (directives[name]) {
40
+ directives[name].push(value);
41
+ } else {
42
+ directives[name] = [value];
43
+ }
44
+ }
45
+
46
+ return directives;
47
+ }
48
+
49
+ function getModuleDocblock(hermesProgram) {
50
+ const docblockNode = (() => {
51
+ if (hermesProgram.type !== 'Program') {
52
+ return null;
53
+ } // $FlowExpectedError[incompatible-type] - escape out of the unsafe hermes types
54
+
55
+
56
+ const program = hermesProgram;
57
+
58
+ if (program.comments.length === 0) {
59
+ return null;
60
+ }
61
+
62
+ const firstComment = (() => {
63
+ const first = program.comments[0];
64
+
65
+ if (first.type === 'Block') {
66
+ return first;
67
+ }
68
+
69
+ if (program.comments.length === 1) {
70
+ return null;
71
+ } // ESLint will always strip out the shebang comment from the code before passing it to the parser
72
+ // https://github.com/eslint/eslint/blob/21d647904dc30f9484b22acdd9243a6d0ecfba38/lib/linter/linter.js#L779
73
+ // this means that we're forced to parse it as a line comment :(
74
+ // this hacks around it by selecting the second comment in this case
75
+
76
+
77
+ const second = program.comments[1];
78
+
79
+ if (first.type === 'Line' && first.range[0] === 0 && second.type === 'Block') {
80
+ return second;
81
+ }
82
+
83
+ return null;
84
+ })();
85
+
86
+ if (firstComment == null) {
87
+ return null;
88
+ }
89
+ /*
90
+ Handle cases like this where the comment isn't actually the first thing in the code:
91
+ ```
92
+ const x = 1; /* docblock *./
93
+ ```
94
+ */
95
+
96
+
97
+ if (program.body.length > 0 && program.body[0].range[0] < firstComment.range[0]) {
98
+ return null;
99
+ }
100
+
101
+ return firstComment;
102
+ })();
103
+
104
+ if (docblockNode == null) {
105
+ return null;
106
+ }
107
+
108
+ return {
109
+ directives: parseDocblockString(docblockNode.value),
110
+ comment: docblockNode
111
+ };
112
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ import type {HermesNode} from './HermesAST';
14
+ import type {DocblockDirectives, Program} from 'hermes-estree';
15
+
16
+ const DIRECTIVE_REGEX = /^\s*@([a-zA-Z0-9_-]+)( +.+)?$/;
17
+
18
+ export function parseDocblockString(docblock: string): DocblockDirectives {
19
+ const directiveLines = docblock
20
+ .split('\n')
21
+ // remove the leading " *" from each line
22
+ .map(line => line.trimStart().replace(/^\* ?/, '').trim())
23
+ .filter(line => line.startsWith('@'));
24
+
25
+ const directives: {
26
+ [string]: Array<string>,
27
+ } =
28
+ // $FlowExpectedError[incompatible-type] - flow types this return as {...}
29
+ Object.create(null);
30
+
31
+ for (const line of directiveLines) {
32
+ const match = DIRECTIVE_REGEX.exec(line);
33
+ if (match == null) {
34
+ continue;
35
+ }
36
+ const name = match[1];
37
+ // explicitly use an empty string if there's no value
38
+ // this way the array length tracks how many instances of the directive there was
39
+ const value = (match[2] ?? '').trim();
40
+ if (directives[name]) {
41
+ directives[name].push(value);
42
+ } else {
43
+ directives[name] = [value];
44
+ }
45
+ }
46
+
47
+ return directives;
48
+ }
49
+
50
+ export function getModuleDocblock(
51
+ hermesProgram: HermesNode,
52
+ ): Program['docblock'] {
53
+ const docblockNode = (() => {
54
+ if (hermesProgram.type !== 'Program') {
55
+ return null;
56
+ }
57
+
58
+ // $FlowExpectedError[incompatible-type] - escape out of the unsafe hermes types
59
+ const program: Program = hermesProgram;
60
+
61
+ if (program.comments.length === 0) {
62
+ return null;
63
+ }
64
+
65
+ const firstComment = (() => {
66
+ const first = program.comments[0];
67
+ if (first.type === 'Block') {
68
+ return first;
69
+ }
70
+
71
+ if (program.comments.length === 1) {
72
+ return null;
73
+ }
74
+
75
+ // ESLint will always strip out the shebang comment from the code before passing it to the parser
76
+ // https://github.com/eslint/eslint/blob/21d647904dc30f9484b22acdd9243a6d0ecfba38/lib/linter/linter.js#L779
77
+ // this means that we're forced to parse it as a line comment :(
78
+ // this hacks around it by selecting the second comment in this case
79
+ const second = program.comments[1];
80
+ if (
81
+ first.type === 'Line' &&
82
+ first.range[0] === 0 &&
83
+ second.type === 'Block'
84
+ ) {
85
+ return second;
86
+ }
87
+
88
+ return null;
89
+ })();
90
+ if (firstComment == null) {
91
+ return null;
92
+ }
93
+
94
+ /*
95
+ Handle cases like this where the comment isn't actually the first thing in the code:
96
+ ```
97
+ const x = 1; /* docblock *./
98
+ ```
99
+ */
100
+ if (
101
+ program.body.length > 0 &&
102
+ program.body[0].range[0] < firstComment.range[0]
103
+ ) {
104
+ return null;
105
+ }
106
+
107
+ return firstComment;
108
+ })();
109
+
110
+ if (docblockNode == null) {
111
+ return null;
112
+ }
113
+
114
+ return {
115
+ directives: parseDocblockString(docblockNode.value),
116
+ comment: docblockNode,
117
+ };
118
+ }
@@ -29,7 +29,9 @@ var _exportNames = {
29
29
  isNullLiteral: true,
30
30
  isNumericLiteral: true,
31
31
  isRegExpLiteral: true,
32
- isStringLiteral: true
32
+ isStringLiteral: true,
33
+ isExpression: true,
34
+ isStatement: true
33
35
  };
34
36
  exports.isBigIntLiteral = isBigIntLiteral;
35
37
  exports.isBooleanLiteral = isBooleanLiteral;
@@ -37,6 +39,7 @@ exports.isClass = isClass;
37
39
  exports.isClassMember = isClassMember;
38
40
  exports.isClassMemberWithNonComputedName = isClassMemberWithNonComputedName;
39
41
  exports.isComment = isComment;
42
+ exports.isExpression = isExpression;
40
43
  exports.isFunction = isFunction;
41
44
  exports.isMemberExpressionWithNonComputedProperty = isMemberExpressionWithNonComputedProperty;
42
45
  exports.isMethodDefinitionWithNonComputedName = isMethodDefinitionWithNonComputedName;
@@ -47,6 +50,7 @@ exports.isObjectPropertyWithShorthand = isObjectPropertyWithShorthand;
47
50
  exports.isOptionalMemberExpressionWithNonComputedProperty = isOptionalMemberExpressionWithNonComputedProperty;
48
51
  exports.isPropertyDefinitionWithNonComputedName = isPropertyDefinitionWithNonComputedName;
49
52
  exports.isRegExpLiteral = isRegExpLiteral;
53
+ exports.isStatement = isStatement;
50
54
  exports.isStringLiteral = isStringLiteral;
51
55
 
52
56
  var _predicates = require("./generated/predicates");
@@ -124,4 +128,12 @@ function isRegExpLiteral(node) {
124
128
 
125
129
  function isStringLiteral(node) {
126
130
  return (0, _predicates.isLiteral)(node) && node.literalType === 'string';
131
+ }
132
+
133
+ function isExpression(node) {
134
+ return (0, _predicates.isThisExpression)(node) || (0, _predicates.isArrayExpression)(node) || (0, _predicates.isObjectExpression)(node) || (0, _predicates.isFunctionExpression)(node) || (0, _predicates.isArrowFunctionExpression)(node) || (0, _predicates.isYieldExpression)(node) || (0, _predicates.isLiteral)(node) || (0, _predicates.isUnaryExpression)(node) || (0, _predicates.isUpdateExpression)(node) || (0, _predicates.isBinaryExpression)(node) || (0, _predicates.isAssignmentExpression)(node) || (0, _predicates.isLogicalExpression)(node) || (0, _predicates.isMemberExpression)(node) || (0, _predicates.isConditionalExpression)(node) || (0, _predicates.isCallExpression)(node) || (0, _predicates.isNewExpression)(node) || (0, _predicates.isSequenceExpression)(node) || (0, _predicates.isTemplateLiteral)(node) || (0, _predicates.isTaggedTemplateExpression)(node) || (0, _predicates.isClassExpression)(node) || (0, _predicates.isMetaProperty)(node) || (0, _predicates.isIdentifier)(node) || (0, _predicates.isAwaitExpression)(node) || (0, _predicates.isImportExpression)(node) || (0, _predicates.isChainExpression)(node) || (0, _predicates.isTypeCastExpression)(node) || (0, _predicates.isJSXFragment)(node) || (0, _predicates.isJSXElement)(node);
135
+ }
136
+
137
+ function isStatement(node) {
138
+ return (0, _predicates.isBlockStatement)(node) || (0, _predicates.isBreakStatement)(node) || (0, _predicates.isClassDeclaration)(node) || (0, _predicates.isContinueStatement)(node) || (0, _predicates.isDebuggerStatement)(node) || (0, _predicates.isDeclareClass)(node) || (0, _predicates.isDeclareVariable)(node) || (0, _predicates.isDeclareFunction)(node) || (0, _predicates.isDeclareInterface)(node) || (0, _predicates.isDeclareModule)(node) || (0, _predicates.isDeclareOpaqueType)(node) || (0, _predicates.isDeclareTypeAlias)(node) || (0, _predicates.isDoWhileStatement)(node) || (0, _predicates.isEmptyStatement)(node) || (0, _predicates.isEnumDeclaration)(node) || (0, _predicates.isExpressionStatement)(node) || (0, _predicates.isForInStatement)(node) || (0, _predicates.isForOfStatement)(node) || (0, _predicates.isForStatement)(node) || (0, _predicates.isFunctionDeclaration)(node) || (0, _predicates.isIfStatement)(node) || (0, _predicates.isInterfaceDeclaration)(node) || (0, _predicates.isLabeledStatement)(node) || (0, _predicates.isOpaqueType)(node) || (0, _predicates.isReturnStatement)(node) || (0, _predicates.isSwitchStatement)(node) || (0, _predicates.isThrowStatement)(node) || (0, _predicates.isTryStatement)(node) || (0, _predicates.isTypeAlias)(node) || (0, _predicates.isVariableDeclaration)(node) || (0, _predicates.isWhileStatement)(node) || (0, _predicates.isWithStatement)(node);
127
139
  }
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @flow strict
7
+ * @flow strict-local
8
8
  * @format
9
9
  */
10
10
 
@@ -13,18 +13,71 @@
13
13
  import type {ESNode, Token} from './types';
14
14
 
15
15
  import {
16
+ isArrayExpression,
16
17
  isArrowFunctionExpression,
18
+ isAssignmentExpression,
19
+ isAwaitExpression,
20
+ isBinaryExpression,
17
21
  isBlockComment,
22
+ isBlockStatement,
23
+ isBreakStatement,
24
+ isCallExpression,
25
+ isChainExpression,
18
26
  isClassDeclaration,
19
27
  isClassExpression,
28
+ isConditionalExpression,
29
+ isContinueStatement,
30
+ isDebuggerStatement,
31
+ isDeclareClass,
32
+ isDeclareFunction,
33
+ isDeclareInterface,
34
+ isDeclareModule,
35
+ isDeclareOpaqueType,
36
+ isDeclareTypeAlias,
37
+ isDeclareVariable,
38
+ isDoWhileStatement,
39
+ isEmptyStatement,
40
+ isEnumDeclaration,
41
+ isExpressionStatement,
42
+ isForInStatement,
43
+ isForOfStatement,
44
+ isForStatement,
20
45
  isFunctionDeclaration,
21
46
  isFunctionExpression,
47
+ isIdentifier,
48
+ isIfStatement,
49
+ isImportExpression,
50
+ isInterfaceDeclaration,
51
+ isJSXElement,
52
+ isJSXFragment,
53
+ isLabeledStatement,
22
54
  isLineComment,
23
55
  isLiteral,
56
+ isLogicalExpression,
24
57
  isMemberExpression,
58
+ isMetaProperty,
25
59
  isMethodDefinition,
26
- isPropertyDefinition,
60
+ isNewExpression,
61
+ isObjectExpression,
62
+ isOpaqueType,
27
63
  isProperty,
64
+ isPropertyDefinition,
65
+ isReturnStatement,
66
+ isSequenceExpression,
67
+ isSwitchStatement,
68
+ isTaggedTemplateExpression,
69
+ isTemplateLiteral,
70
+ isThisExpression,
71
+ isThrowStatement,
72
+ isTryStatement,
73
+ isTypeAlias,
74
+ isTypeCastExpression,
75
+ isUnaryExpression,
76
+ isUpdateExpression,
77
+ isVariableDeclaration,
78
+ isWhileStatement,
79
+ isWithStatement,
80
+ isYieldExpression,
28
81
  } from './generated/predicates';
29
82
 
30
83
  export * from './generated/predicates';
@@ -112,3 +165,73 @@ export function isRegExpLiteral(node: ESNode): boolean %checks {
112
165
  export function isStringLiteral(node: ESNode): boolean %checks {
113
166
  return isLiteral(node) && node.literalType === 'string';
114
167
  }
168
+
169
+ export function isExpression(node: ESNode): boolean %checks {
170
+ return (
171
+ isThisExpression(node) ||
172
+ isArrayExpression(node) ||
173
+ isObjectExpression(node) ||
174
+ isFunctionExpression(node) ||
175
+ isArrowFunctionExpression(node) ||
176
+ isYieldExpression(node) ||
177
+ isLiteral(node) ||
178
+ isUnaryExpression(node) ||
179
+ isUpdateExpression(node) ||
180
+ isBinaryExpression(node) ||
181
+ isAssignmentExpression(node) ||
182
+ isLogicalExpression(node) ||
183
+ isMemberExpression(node) ||
184
+ isConditionalExpression(node) ||
185
+ isCallExpression(node) ||
186
+ isNewExpression(node) ||
187
+ isSequenceExpression(node) ||
188
+ isTemplateLiteral(node) ||
189
+ isTaggedTemplateExpression(node) ||
190
+ isClassExpression(node) ||
191
+ isMetaProperty(node) ||
192
+ isIdentifier(node) ||
193
+ isAwaitExpression(node) ||
194
+ isImportExpression(node) ||
195
+ isChainExpression(node) ||
196
+ isTypeCastExpression(node) ||
197
+ isJSXFragment(node) ||
198
+ isJSXElement(node)
199
+ );
200
+ }
201
+
202
+ export function isStatement(node: ESNode): boolean %checks {
203
+ return (
204
+ isBlockStatement(node) ||
205
+ isBreakStatement(node) ||
206
+ isClassDeclaration(node) ||
207
+ isContinueStatement(node) ||
208
+ isDebuggerStatement(node) ||
209
+ isDeclareClass(node) ||
210
+ isDeclareVariable(node) ||
211
+ isDeclareFunction(node) ||
212
+ isDeclareInterface(node) ||
213
+ isDeclareModule(node) ||
214
+ isDeclareOpaqueType(node) ||
215
+ isDeclareTypeAlias(node) ||
216
+ isDoWhileStatement(node) ||
217
+ isEmptyStatement(node) ||
218
+ isEnumDeclaration(node) ||
219
+ isExpressionStatement(node) ||
220
+ isForInStatement(node) ||
221
+ isForOfStatement(node) ||
222
+ isForStatement(node) ||
223
+ isFunctionDeclaration(node) ||
224
+ isIfStatement(node) ||
225
+ isInterfaceDeclaration(node) ||
226
+ isLabeledStatement(node) ||
227
+ isOpaqueType(node) ||
228
+ isReturnStatement(node) ||
229
+ isSwitchStatement(node) ||
230
+ isThrowStatement(node) ||
231
+ isTryStatement(node) ||
232
+ isTypeAlias(node) ||
233
+ isVariableDeclaration(node) ||
234
+ isWhileStatement(node) ||
235
+ isWithStatement(node)
236
+ );
237
+ }