Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Hermes parser optional #60

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change log

## [Unreleased]
### Added
* Make the Hermes parser optional and disabled by default.
It can now be activated by setting hte `parser` option
`[["@gandi/gandi", { "parser": "hermes" }]]`.

## 6.1.0 - 2024-07-29
### Changed
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
*/

module.exports = (context, options = {}) => {
let { parser = 'babel', ...envOptions } = options;

let envOpts = {
bugfixes: true,
...options,
...envOptions,
};

let reactOpts = {
Expand All @@ -53,7 +55,7 @@ module.exports = (context, options = {}) => {
];

let plugins = [
'babel-plugin-syntax-hermes-parser',
...(parser === 'hermes' ? ['babel-plugin-syntax-hermes-parser'] : []),
['@babel/plugin-transform-runtime', runtimeOpts],
];

Expand Down
12 changes: 12 additions & 0 deletions test/__file_snapshots__/babel-cjsm---ES--optional-chaining-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

let obj = {
foo: {
bar: {
baz: 42
}
}
};
let baz = obj?.foo?.bar?.baz; // 42

let safe = obj?.qux?.baz; // undefined
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/interopRequireWildcard"));
Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require( /* webpackChunkName: foo */'bar')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

/** @component */
function Foo() {}
10 changes: 10 additions & 0 deletions test/__file_snapshots__/babel-esm---ES--optional-chaining-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let obj = {
foo: {
bar: {
baz: 42
}
}
};
let baz = obj?.foo?.bar?.baz; // 42

let safe = obj?.qux?.baz; // undefined
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import( /* webpackChunkName: foo */'bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @component */
function Foo() {}
12 changes: 12 additions & 0 deletions test/__file_snapshots__/babel-node---ES--optional-chaining-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

let obj = {
foo: {
bar: {
baz: 42
}
}
};
let baz = obj?.foo?.bar?.baz; // 42

let safe = obj?.qux?.baz; // undefined
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/interopRequireWildcard"));
Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require( /* webpackChunkName: foo */'bar')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

/** @component */
function Foo() {}
2 changes: 0 additions & 2 deletions test/__file_snapshots__/esmodules--Flow-Conditional-Types-0

This file was deleted.

1 change: 0 additions & 1 deletion test/__file_snapshots__/esmodules--Flow-Type-Guards-0

This file was deleted.

9 changes: 0 additions & 9 deletions test/__file_snapshots__/esmodules--optional-chaining-0

This file was deleted.

3 changes: 3 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--Array.flatMap-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

[1, 2].flatMap(x => [x * 2]);
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--Object.entries-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

Object.entries({
a: 1
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

Promise.allSettled([Promise.resolve(1), Promise.resolve(2)]).then(rs => rs.forEach(r => console.log(r.status)));
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--Runtime-ponyfills-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

new Map();
new Set();
new Promise();
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--async-await-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

(async function () {
await foo();
})();
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--class-properties-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

class A {
a = () => 'hello';
}
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---ES--dynamic-imports-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/interopRequireWildcard"));
Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('./a')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

let obj = {};
let foo = obj.foo ?? 'default';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

let b = {
...a
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

class A {
static a = 'hello';
}
1 change: 1 addition & 0 deletions test/__file_snapshots__/hermes-cjsm---Flow--Mapped-Types-0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
7 changes: 7 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---Flow--Type-Casting-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

let val = value;
let obj = {
prop: value
};
let arr = [value, value];
3 changes: 3 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---Flow--Types-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

let a = 'hello';
23 changes: 23 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---React--class-component-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

var _react = require("react");
var _jsxRuntime = require("react/jsx-runtime");
class Button extends _react.Component {
handleClick = async evt => {
evt.preventDefault();
await fetch('/foo');
};
render() {
const {
type = 'button',
children,
...extraProps
} = this.props;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
type: type,
onClick: this.handleClick,
...extraProps,
children: children
});
}
}
14 changes: 14 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---React--function-component-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

var _jsxRuntime = require("react/jsx-runtime");
function Button({
type = 'button',
children,
...extraProps
}) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
type: type,
...extraProps,
children: children
});
}
6 changes: 6 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---React--jsx-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

var _jsxRuntime = require("react/jsx-runtime");
let A = () => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "hello"
});
8 changes: 8 additions & 0 deletions test/__file_snapshots__/hermes-cjsm---React--jsx-spread-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

var _jsxRuntime = require("react/jsx-runtime");
/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
a: true,
...b,
children: "hello"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

class C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/interopRequireWildcard"));
Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('bar')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

function Foo() {}
Empty file.
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-esm---Flow--Type-Casting-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let val = value;
let obj = {
prop: value
};
let arr = [value, value];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import('bar');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function Foo() {}
3 changes: 3 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--Array.flatMap-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

[1, 2].flatMap(x => [x * 2]);
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--Object.entries-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

Object.entries({
a: 1
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

Promise.allSettled([Promise.resolve(1), Promise.resolve(2)]).then(rs => rs.forEach(r => console.log(r.status)));
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--Runtime-ponyfills-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

new Map();
new Set();
new Promise();
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--async-await-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

(async function () {
await foo();
})();
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--class-properties-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

class A {
a = () => 'hello';
}
5 changes: 5 additions & 0 deletions test/__file_snapshots__/hermes-node---ES--dynamic-imports-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/interopRequireWildcard"));
Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('./a')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

let obj = {};
let foo = obj.foo ?? 'default';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

let b = {
...a
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

class A {
static a = 'hello';
}
1 change: 1 addition & 0 deletions test/__file_snapshots__/hermes-node---Flow--Mapped-Types-0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
7 changes: 7 additions & 0 deletions test/__file_snapshots__/hermes-node---Flow--Type-Casting-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

let val = value;
let obj = {
prop: value
};
let arr = [value, value];
3 changes: 3 additions & 0 deletions test/__file_snapshots__/hermes-node---Flow--Types-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

let a = 'hello';
Loading
Loading