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);