first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

21
node_modules/babel-plugin-syntax-hermes-parser/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,40 @@
# babel-plugin-syntax-hermes-parser
Hermes parser plugin for [Babel](https://babeljs.io/). This plugin switches Babel to use `hermes-parser` instead of the `@babel/parser`. Since Hermes parser uses C++ compiled to WASM it is significantly faster and provides full syntax support for Flow.
## Install
Using npm:
```sh
npm install --save-dev babel-plugin-syntax-hermes-parser
```
or using yarn:
```sh
yarn add babel-plugin-syntax-hermes-parser --dev
```
# Usage
The plugin can be enabled via:
```
// babel.config.json
{
"plugins": ["babel-plugin-syntax-hermes-parser"]
}
```
If parser options need to be provide you can do so via the `parserOpts` config:
```
// babel.config.json
{
"plugins": ["babel-plugin-syntax-hermes-parser"],
"parserOpts": {
"allowReturnOutsideFunction": true
}
}
```

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = BabelPluginSyntaxHermesParser;
var HermesParser = _interopRequireWildcard(require("hermes-parser"));
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); }
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; }
function BabelPluginSyntaxHermesParser( // $FlowExpectedError[unclear-type] We don't have types for this.
api, options) {
api.assertVersion('^7.0.0 || ^8.0.0-alpha.6');
const {
parseLangTypes = 'all'
} = options;
let curParserOpts = {};
let curFilename = null;
return {
name: 'syntax-hermes-parser',
manipulateOptions(opts) {
curParserOpts = opts.parserOpts;
curFilename = opts.filename;
},
// API suggested via https://babeljs.io/docs/babel-parser#will-the-babel-parser-support-a-plugin-system
parserOverride(code) {
const filename = curFilename;
if (filename != null && (filename.endsWith('.ts') || filename.endsWith('.tsx'))) {
return;
}
const parserOpts = {};
for (const [key, value] of Object.entries(curParserOpts)) {
if (HermesParser.ParserOptionsKeys.has(key)) {
// $FlowExpectedError[incompatible-type]
parserOpts[key] = value;
}
}
if (parseLangTypes === 'flow' && !/@flow/.test(code)) {
return;
}
return HermesParser.parse(code, { ...parserOpts,
babel: true
});
},
pre() {
curParserOpts = {};
}
};
}

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
import type {ParserOptions} from 'hermes-parser';
import * as HermesParser from 'hermes-parser';
type Options = {
/**
* When set to 'flow', will check files for a `@flow` annotation to apply
* this plugin, otherwise falling back to Babel's parser.
*
* This is independent of `parserOpts.flow`, which may customise 'detect'
* behaviour within hermes-parser (downstream from this plugin).
*
* Defaults to 'all'.
*/
parseLangTypes?: 'flow' | 'all',
};
export default function BabelPluginSyntaxHermesParser(
// $FlowExpectedError[unclear-type] We don't have types for this.
api: any,
options: Options,
): $ReadOnly<{...}> {
api.assertVersion('^7.0.0 || ^8.0.0-alpha.6');
const {parseLangTypes = 'all'} = options;
let curParserOpts: ParserOptions = {};
let curFilename: ?string = null;
return {
name: 'syntax-hermes-parser',
manipulateOptions(
opts: $ReadOnly<{parserOpts: ParserOptions, filename?: ?string}>,
) {
curParserOpts = opts.parserOpts;
curFilename = opts.filename;
},
// API suggested via https://babeljs.io/docs/babel-parser#will-the-babel-parser-support-a-plugin-system
parserOverride(code: string) {
const filename = curFilename;
if (
filename != null &&
(filename.endsWith('.ts') || filename.endsWith('.tsx'))
) {
return;
}
const parserOpts: ParserOptions = {};
for (const [key, value] of Object.entries(curParserOpts)) {
if (HermesParser.ParserOptionsKeys.has(key)) {
// $FlowExpectedError[incompatible-type]
parserOpts[key] = value;
}
}
if (parseLangTypes === 'flow' && !/@flow/.test(code)) {
return;
}
return HermesParser.parse(code, {...parserOpts, babel: true});
},
pre() {
curParserOpts = {};
},
};
}

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = BabelPluginSyntaxHermesParser;
var HermesParser = _interopRequireWildcard(require("hermes-parser"));
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); }
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; }
function BabelPluginSyntaxHermesParser( // $FlowExpectedError[unclear-type] We don't have types for this.
api, options) {
api.assertVersion('^7.0.0 || ^8.0.0-alpha.6');
const {
parseLangTypes = 'all'
} = options;
let curParserOpts = {};
let curFilename = null;
return {
name: 'syntax-hermes-parser',
manipulateOptions(opts) {
curParserOpts = opts.parserOpts;
curFilename = opts.filename;
},
// API suggested via https://babeljs.io/docs/babel-parser#will-the-babel-parser-support-a-plugin-system
parserOverride(code) {
const filename = curFilename;
if (filename != null && (filename.endsWith('.ts') || filename.endsWith('.tsx'))) {
return;
}
const parserOpts = {};
for (const [key, value] of Object.entries(curParserOpts)) {
if (HermesParser.ParserOptionsKeys.has(key)) {
// $FlowExpectedError[incompatible-type]
parserOpts[key] = value;
}
}
if (parseLangTypes === 'flow' && !/@flow/.test(code)) {
return;
}
return HermesParser.parse(code, { ...parserOpts,
babel: true
});
},
pre() {
curParserOpts = {};
}
};
}

View File

@@ -0,0 +1,22 @@
{
"name": "babel-plugin-syntax-hermes-parser",
"version": "0.32.0",
"description": "Babel plugin which switches Babel to use the Hermes parser.",
"main": "dist/index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:facebook/hermes.git"
},
"dependencies": {
"hermes-parser": "0.32.0"
},
"files": [
"dist",
"LICENCE",
"README.md"
],
"devDependencies": {
"@babel/core": "^7.22.5"
}
}