babel-plugin-syntax-hermes-parser 0.28.1 → 0.29.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 (2) hide show
  1. package/dist/src/index.js +70 -0
  2. package/package.json +2 -2
@@ -0,0 +1,70 @@
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.default = BabelPluginSyntaxHermesParser;
16
+
17
+ var HermesParser = _interopRequireWildcard(require("hermes-parser"));
18
+
19
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
+
21
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+
23
+ function BabelPluginSyntaxHermesParser( // $FlowExpectedError[unclear-type] We don't have types for this.
24
+ api, options) {
25
+ api.assertVersion('^7.0.0 || ^8.0.0-alpha.6');
26
+ const {
27
+ parseLangTypes = 'all'
28
+ } = options;
29
+ let curParserOpts = {};
30
+ let curFilename = null;
31
+ return {
32
+ name: 'syntax-hermes-parser',
33
+
34
+ manipulateOptions(opts) {
35
+ curParserOpts = opts.parserOpts;
36
+ curFilename = opts.filename;
37
+ },
38
+
39
+ // API suggested via https://babeljs.io/docs/babel-parser#will-the-babel-parser-support-a-plugin-system
40
+ parserOverride(code) {
41
+ const filename = curFilename;
42
+
43
+ if (filename != null && (filename.endsWith('.ts') || filename.endsWith('.tsx'))) {
44
+ return;
45
+ }
46
+
47
+ const parserOpts = {};
48
+
49
+ for (const [key, value] of Object.entries(curParserOpts)) {
50
+ if (HermesParser.ParserOptionsKeys.has(key)) {
51
+ // $FlowExpectedError[incompatible-type]
52
+ parserOpts[key] = value;
53
+ }
54
+ }
55
+
56
+ if (parseLangTypes === 'flow' && !/@flow/.test(code)) {
57
+ return;
58
+ }
59
+
60
+ return HermesParser.parse(code, { ...parserOpts,
61
+ babel: true
62
+ });
63
+ },
64
+
65
+ pre() {
66
+ curParserOpts = {};
67
+ }
68
+
69
+ };
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-syntax-hermes-parser",
3
- "version": "0.28.1",
3
+ "version": "0.29.1",
4
4
  "description": "Babel plugin which switches Babel to use the Hermes parser.",
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-parser": "0.28.1"
12
+ "hermes-parser": "0.29.1"
13
13
  },
14
14
  "files": [
15
15
  "dist",