Skip to content

Commit

Permalink
Warn with loose
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 12, 2020
1 parent aae050b commit acd82be
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/babel-helper-create-class-features-plugin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ export function createClassFeaturePlugin({
const setPublicClassFields = api.assumption("setPublicClassFields");
const privateFieldsAsProperties = api.assumption("privateFieldsAsProperties");

if (loose) {
const explicit = [];

if (setPublicClassFields !== undefined) {
explicit.push(`"setPublicClassFields"`);
}
if (privateFieldsAsProperties !== undefined) {
explicit.push(`"privateFieldsAsProperties"`);
}
if (explicit.length !== 0) {
console.warn(
`[${name}]: You are using the "loose: true" option and you are` +
` explicitly setting a value for the ${explicit.join(" and ")}` +
` assumption${explicit.length > 1 ? "s" : ""}. The "loose" option` +
` can cause incompatibilities with the other class features` +
` plugins, so it's recommended that you replace it with the` +
` following top-level option:\n` +
`\t"assumptions": {\n` +
`\t\t"setPublicClassFields": true,\n` +
`\t\t"privateFieldsAsProperties": true\n` +
`\t}`,
);
}
}

return {
name,
manipulateOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
foo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"validateLogs": true,
"plugins": [
["proposal-class-properties", { "loose": true }]
],
"assumptions": {
"setPublicClassFields": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class A {
constructor() {
this.foo = void 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[proposal-class-properties]: You are using the "loose: true" option and you are explicitly setting a value for the "setPublicClassFields" assumption. The "loose" option can cause incompatibilities with the other class features plugins, so it's recommended that you replace it with the following top-level option:
"assumptions": {
"setPublicClassFields": true,
"privateFieldsAsProperties": true
}

0 comments on commit acd82be

Please sign in to comment.