aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babel-preset-current-node-syntax
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babel-preset-current-node-syntax')
-rw-r--r--node_modules/babel-preset-current-node-syntax/LICENSE22
-rw-r--r--node_modules/babel-preset-current-node-syntax/README.md30
-rw-r--r--node_modules/babel-preset-current-node-syntax/package.json41
-rw-r--r--node_modules/babel-preset-current-node-syntax/scripts/check-yarn-bug.sh5
-rw-r--r--node_modules/babel-preset-current-node-syntax/src/index.js57
5 files changed, 155 insertions, 0 deletions
diff --git a/node_modules/babel-preset-current-node-syntax/LICENSE b/node_modules/babel-preset-current-node-syntax/LICENSE
new file mode 100644
index 0000000..7f09add
--- /dev/null
+++ b/node_modules/babel-preset-current-node-syntax/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2020 Nicolò Ribaudo and other contributors
+
+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.
diff --git a/node_modules/babel-preset-current-node-syntax/README.md b/node_modules/babel-preset-current-node-syntax/README.md
new file mode 100644
index 0000000..d6b42a0
--- /dev/null
+++ b/node_modules/babel-preset-current-node-syntax/README.md
@@ -0,0 +1,30 @@
+# `babel-preset-current-node-syntax`
+
+> A Babel preset that enables parsing of proposals supported by the current Node.js version.
+
+## Installation
+
+If you are using yarn:
+```
+yarn add --dev babel-preset-current-node-syntax
+```
+
+If you are using npm:
+```
+npm install --save-dev babel-preset-current-node-syntax
+```
+
+## Contributing
+
+PRs are welcome! The codebase is so small that I didn't setup a linter, but try
+to match the style of the existing code.
+
+You can run tests with the following command:
+```
+yarn node test/index.js
+```
+
+The `test/fixtures.json` file contains a bunch of syntax tests, alongside with
+the minimum supported node version for each of them. Babel should throw on
+older versions, without support for that given syntax.
+All the tests are run using `@babel/parser@7.0.0`.
diff --git a/node_modules/babel-preset-current-node-syntax/package.json b/node_modules/babel-preset-current-node-syntax/package.json
new file mode 100644
index 0000000..af07533
--- /dev/null
+++ b/node_modules/babel-preset-current-node-syntax/package.json
@@ -0,0 +1,41 @@
+{
+ "name": "babel-preset-current-node-syntax",
+ "version": "1.0.1",
+ "description": "A Babel preset that enables parsing of proposals supported by the current Node.js version.",
+ "main": "src/index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/nicolo-ribaudo/babel-preset-current-node-syntax.git"
+ },
+ "author": {
+ "name": "Nicolò Ribaudo",
+ "url": "https://github.com/nicolo-ribaudo"
+ },
+ "scripts": {
+ "test": "node ./test/index.js",
+ "prepublish": "./scripts/check-yarn-bug.sh"
+ },
+ "dependencies": {
+ "@babel/plugin-syntax-async-generators": "^7.8.4",
+ "@babel/plugin-syntax-bigint": "^7.8.3",
+ "@babel/plugin-syntax-class-properties": "^7.8.3",
+ "@babel/plugin-syntax-import-meta": "^7.8.3",
+ "@babel/plugin-syntax-json-strings": "^7.8.3",
+ "@babel/plugin-syntax-logical-assignment-operators": "^7.8.3",
+ "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
+ "@babel/plugin-syntax-numeric-separator": "^7.8.3",
+ "@babel/plugin-syntax-object-rest-spread": "^7.8.3",
+ "@babel/plugin-syntax-optional-catch-binding": "^7.8.3",
+ "@babel/plugin-syntax-optional-chaining": "^7.8.3",
+ "@babel/plugin-syntax-top-level-await": "^7.8.3"
+ },
+ "peerDependencies": {
+ "@babel/core": "^7.0.0"
+ },
+ "devDependencies": {
+ "@babel/core": "7.0.0",
+ "@babel/parser-7.0.0": "npm:@babel/parser@7.0.0",
+ "@babel/parser-7.9.0": "npm:@babel/parser@7.9.0"
+ },
+ "license": "MIT"
+} \ No newline at end of file
diff --git a/node_modules/babel-preset-current-node-syntax/scripts/check-yarn-bug.sh b/node_modules/babel-preset-current-node-syntax/scripts/check-yarn-bug.sh
new file mode 100644
index 0000000..3deb69f
--- /dev/null
+++ b/node_modules/babel-preset-current-node-syntax/scripts/check-yarn-bug.sh
@@ -0,0 +1,5 @@
+if grep 3155328e5 .yarn/releases/yarn-*.cjs -c; then
+ echo "Your version of yarn is affected by https://github.com/yarnpkg/berry/issues/1882"
+ echo "Please run \`sed -i -e \"s/3155328e5/4567890e5/g\" .yarn/releases/yarn-*.cjs\`"
+ exit 1
+fi
diff --git a/node_modules/babel-preset-current-node-syntax/src/index.js b/node_modules/babel-preset-current-node-syntax/src/index.js
new file mode 100644
index 0000000..e0243bd
--- /dev/null
+++ b/node_modules/babel-preset-current-node-syntax/src/index.js
@@ -0,0 +1,57 @@
+const tests = {
+ // ECMAScript 2018
+ "object-rest-spread": ["({ ...{} })", "({ ...x } = {})"], // Babel 7.2.0
+ "async-generators": ["async function* f() {}"], // Babel 7.2.0
+
+ // ECMAScript 2019
+ "optional-catch-binding": ["try {} catch {}"], // Babel 7.2.0
+ "json-strings": ["'\\u2028'"], // Babel 7.2.0
+
+ // ECMAScript 2020
+ "bigint": ["1n"], // Babel 7.8.0
+ "optional-chaining": ["a?.b"], // Babel 7.9.0
+ "nullish-coalescing-operator": ["a ?? b"], // Babel 7.9.0
+ // import.meta is handled manually
+
+ // Stage 3
+ "numeric-separator": ["1_2"],
+ "class-properties": [
+ "(class { x = 1 })",
+ "(class { #x = 1 })",
+ "(class { #x() {} })",
+ ],
+ "logical-assignment-operators": ["a ||= b", "a &&= b", "a ??= c"],
+};
+
+const plugins = [];
+const works = (test) => {
+ try {
+ // Wrap the test in a function to only test the syntax, without executing it
+ (0, eval)(`(() => { ${test} })`);
+ return true;
+ } catch (_error) {
+ return false;
+ }
+};
+
+for (const [name, cases] of Object.entries(tests)) {
+ if (cases.some(works)) {
+ plugins.push(require.resolve(`@babel/plugin-syntax-${name}`));
+ }
+}
+
+// import.meta is only allowed in modules, and modules can only be evaluated
+// synchronously. For this reason, we cannot detect import.meta support at
+// runtime. It is supported starting from 10.4, so we can check the version.
+const major = parseInt(process.versions.node, 10);
+const minor = parseInt(process.versions.node.match(/^\d+\.(\d+)/)[1], 10);
+if (major > 10 || (major === 10 && minor >= 4)) {
+ plugins.push(require.resolve("@babel/plugin-syntax-import-meta"));
+}
+// Same for top level await - it is only supported in modules. It is supported
+// from 14.3.0
+if (major > 14 || (major === 14 && minor >= 3)) {
+ plugins.push(require.resolve("@babel/plugin-syntax-top-level-await"));
+}
+
+module.exports = () => ({ plugins });