From 507127809990baadece1f7dc6dc98d32b145c6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 11 Dec 2020 22:37:12 +0100 Subject: [PATCH] Implement `setComputedProperties` assumption (#12490) --- packages/babel-core/src/config/validation/options.js | 1 + .../src/index.js | 6 ++++-- .../accessors/input.js | 0 .../accessors/output.js | 0 .../argument/input.js | 0 .../argument/output.js | 0 .../assignment/input.js | 0 .../assignment/output.js | 0 .../coerce/input.js | 0 .../coerce/output.js | 0 .../method/input.js | 0 .../method/output.js | 0 .../mixed/input.js | 0 .../mixed/output.js | 0 .../multiple/input.js | 0 .../multiple/output.js | 0 .../assumption-setComputedProperties/options.json | 9 +++++++++ .../single/input.js | 0 .../single/output.js | 0 .../symbol/exec.js | 0 .../symbol/input.js | 0 .../symbol/output.js | 0 .../this/input.js | 0 .../this/output.js | 0 .../two/input.js | 0 .../two/output.js | 0 .../variable/input.js | 0 .../variable/output.js | 0 .../test/fixtures/loose/setComputedProperties/input.js | 4 ++++ .../test/fixtures/loose/setComputedProperties/output.js | 3 +++ 30 files changed, 21 insertions(+), 2 deletions(-) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/accessors/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/accessors/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/argument/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/argument/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/assignment/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/assignment/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/coerce/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/coerce/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/method/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/method/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/mixed/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/mixed/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/multiple/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/multiple/output.js (100%) create mode 100644 packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/options.json rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/single/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/single/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/symbol/exec.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/symbol/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/symbol/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/this/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/this/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/two/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/two/output.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/variable/input.js (100%) rename packages/babel-plugin-transform-computed-properties/test/fixtures/{loose => assumption-setComputedProperties}/variable/output.js (100%) create mode 100644 packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/input.js create mode 100644 packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/output.js diff --git a/packages/babel-core/src/config/validation/options.js b/packages/babel-core/src/config/validation/options.js index 81724f7f97d1..b48ad22a941b 100644 --- a/packages/babel-core/src/config/validation/options.js +++ b/packages/babel-core/src/config/validation/options.js @@ -335,6 +335,7 @@ export const assumptionsNames = new Set([ "ignoreToPrimitiveHint", "mutableTemplateObject", "setClassMethods", + "setComputedProperties", "setPublicClassFields", ]); diff --git a/packages/babel-plugin-transform-computed-properties/src/index.js b/packages/babel-plugin-transform-computed-properties/src/index.js index dc34b5b5b061..4f33dd8cf726 100644 --- a/packages/babel-plugin-transform-computed-properties/src/index.js +++ b/packages/babel-plugin-transform-computed-properties/src/index.js @@ -4,8 +4,10 @@ import { template, types as t } from "@babel/core"; export default declare((api, options) => { api.assertVersion(7); - const { loose } = options; - const pushComputedProps = loose + const setComputedProperties = + api.assumption("setComputedProperties") ?? options.loose; + + const pushComputedProps = setComputedProperties ? pushComputedPropsLoose : pushComputedPropsSpec; diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/accessors/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/accessors/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/accessors/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/accessors/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/accessors/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/accessors/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/accessors/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/accessors/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/argument/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/argument/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/argument/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/argument/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/argument/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/argument/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/argument/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/argument/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/assignment/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/assignment/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/assignment/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/assignment/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/assignment/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/assignment/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/assignment/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/assignment/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/coerce/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/coerce/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/coerce/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/coerce/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/coerce/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/coerce/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/coerce/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/coerce/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/method/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/method/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/method/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/method/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/method/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/method/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/method/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/method/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/mixed/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/mixed/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/mixed/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/mixed/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/mixed/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/mixed/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/mixed/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/mixed/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/multiple/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/multiple/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/multiple/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/multiple/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/multiple/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/multiple/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/multiple/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/multiple/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/options.json b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/options.json new file mode 100644 index 000000000000..2a2f114c2a9e --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/options.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + "external-helpers", + "transform-computed-properties" + ], + "assumptions": { + "setComputedProperties": true + } +} diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/single/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/single/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/single/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/single/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/single/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/single/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/single/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/single/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/exec.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/exec.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/exec.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/exec.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/symbol/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/this/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/this/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/this/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/this/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/this/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/this/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/this/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/this/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/two/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/two/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/two/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/two/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/two/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/two/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/two/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/two/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/variable/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/variable/input.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/variable/input.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/variable/input.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/variable/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/variable/output.js similarity index 100% rename from packages/babel-plugin-transform-computed-properties/test/fixtures/loose/variable/output.js rename to packages/babel-plugin-transform-computed-properties/test/fixtures/assumption-setComputedProperties/variable/output.js diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/input.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/input.js new file mode 100644 index 000000000000..02d4195fa78d --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/input.js @@ -0,0 +1,4 @@ +var obj = { + ["x" + foo]: "heh", + ["y" + bar]: "noo" +}; diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/output.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/output.js new file mode 100644 index 000000000000..13145e4a26f8 --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/loose/setComputedProperties/output.js @@ -0,0 +1,3 @@ +var _obj; + +var obj = (_obj = {}, _obj["x" + foo] = "heh", _obj["y" + bar] = "noo", _obj);