From 6759da2093800bed234f45114519822d3223fcb3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 31 Oct 2020 12:01:40 +0100 Subject: [PATCH] feat: add suppotr for TLA on node 14.3 and newer --- .github/workflows/nodejs.yml | 2 +- package.json | 3 ++- src/index.js | 7 ++++++- test/fixtures.json | 3 ++- yarn.lock | 20 ++++++++++++++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index e9b9ddb..6b295ea 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [10.19, 12.4, 12.8, 13.11, 14] + node-version: [10.19, 12.4, 12.8, 13.11, 14.3, 14, 15] steps: - uses: actions/checkout@v2 diff --git a/package.json b/package.json index 1916b1c..6a0d526 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "@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-optional-chaining": "^7.8.3", + "@babel/plugin-syntax-top-level-await": "^7.8.3" }, "peerDependencies": { "@babel/core": "^7.0.0" diff --git a/src/index.js b/src/index.js index 03b8f89..e0243bd 100644 --- a/src/index.js +++ b/src/index.js @@ -45,8 +45,13 @@ for (const [name, cases] of Object.entries(tests)) { // 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)) { +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 }); diff --git a/test/fixtures.json b/test/fixtures.json index 18af007..aaf4199 100644 --- a/test/fixtures.json +++ b/test/fixtures.json @@ -10,5 +10,6 @@ "numeric separators": [12.7, "1_2"], "optional chaining": [14.0, "a?.b"], "nullish coalescing": [14.0, "a ?? b"], - "import.meta": [10.4, "import.meta"] + "import.meta": [10.4, "import.meta"], + "top level await": [14.3, "await Promise.resolve()"] } diff --git a/yarn.lock b/yarn.lock index ec4c832..584c2b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -68,10 +68,10 @@ __metadata: languageName: node linkType: hard -"@babel/helper-plugin-utils@npm:^7.8.0, @babel/helper-plugin-utils@npm:^7.8.3": - version: 7.8.3 - resolution: "@babel/helper-plugin-utils@npm:7.8.3" - checksum: 56f09626f24511aadd36a96aacd8658274ededc2e94f5e85bb6e51c9e6ad72eb1dd9f9a28a4ee5a8691de7601cf2a8e63ce235db01dda8964779940281f2787f +"@babel/helper-plugin-utils@npm:^7.10.4, @babel/helper-plugin-utils@npm:^7.8.0, @babel/helper-plugin-utils@npm:^7.8.3": + version: 7.10.4 + resolution: "@babel/helper-plugin-utils@npm:7.10.4" + checksum: 9f617e619a3557cb5fae8885e91cd94ba4ee16fb345e0360de0d7dc037efb10cc604939ecc1038ccdb71aa37e7e78f20133d7bbbebecb8f6dcdb557650366d92 languageName: node linkType: hard @@ -243,6 +243,17 @@ __metadata: languageName: node linkType: hard +"@babel/plugin-syntax-top-level-await@npm:^7.8.3": + version: 7.12.1 + resolution: "@babel/plugin-syntax-top-level-await@npm:7.12.1" + dependencies: + "@babel/helper-plugin-utils": ^7.10.4 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 9767e46ddc1add9133a21f5d6c4452e9a62f891fe1db5d8291f62f9036f9e697bc118adad43109a8740ac15769e9489d68d134b17cfe9f3bdf06d2c50c9c6dce + languageName: node + linkType: hard + "@babel/template@npm:^7.0.0, @babel/template@npm:^7.8.3": version: 7.8.6 resolution: "@babel/template@npm:7.8.6" @@ -307,6 +318,7 @@ __metadata: "@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 languageName: unknown