From a49e0d71077f2acf80e33037ef7f34a425262e1c Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 19 Jun 2020 12:51:45 -0400 Subject: [PATCH 1/8] Account for ConfigItem being generated by another copy of Babel --- packages/babel-core/src/config/item.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index d1f548ffe0fa..906fe7badf25 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -40,7 +40,7 @@ export function createConfigItem( } export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { - if (item instanceof ConfigItem) { + if (item instanceof ConfigItem || item._isConfigItem === true) { return item._descriptor; } @@ -64,6 +64,11 @@ class ConfigItem { */ _descriptor: UnloadedDescriptor; + /** + * Used to detect ConfigItem instances from other Babel instances. + */ + _isConfigItem: true; + /** * The resolved value of the item itself. */ @@ -105,6 +110,9 @@ class ConfigItem { this._descriptor = descriptor; Object.defineProperty(this, "_descriptor", { enumerable: false }); + this._isConfigItem = true; + Object.defineProperty(this, "_isConfigItem", { enumerable: false }); + this.value = this._descriptor.value; this.options = this._descriptor.options; this.dirname = this._descriptor.dirname; From c75a6f29830feb1b563129d1ce455cac6a4b008c Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 23 Jun 2020 12:16:54 -0400 Subject: [PATCH 2/8] Use a symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- packages/babel-core/src/config/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index 906fe7badf25..b6e58193d36e 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -67,7 +67,7 @@ class ConfigItem { /** * Used to detect ConfigItem instances from other Babel instances. */ - _isConfigItem: true; + [Symbol.for("@babel/core@7 - ConfigItem")] = true; /** * The resolved value of the item itself. From 96f4fe656b84dae67ffeb76e2989350bc9c295f1 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 23 Jun 2020 12:17:37 -0400 Subject: [PATCH 3/8] Use a symbol --- packages/babel-core/src/config/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index b6e58193d36e..abe992f2db86 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -40,7 +40,7 @@ export function createConfigItem( } export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { - if (item instanceof ConfigItem || item._isConfigItem === true) { + if (item && item[Symbol.for("@babel/core@7 - ConfigItem")] === true) { return item._descriptor; } From 04dc69450ff7f933c66cc0f6537508151da91f37 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 23 Jun 2020 12:18:31 -0400 Subject: [PATCH 4/8] Update item.js --- packages/babel-core/src/config/item.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index abe992f2db86..b1d19ccda79d 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -49,6 +49,8 @@ export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { export type { ConfigItem }; +const CONFIG_ITEM_BRAND = Symbol.for("@babel/core@7 - ConfigItem"); + /** * A public representation of a plugin/preset that will _eventually_ be load. * Users can use this to interact with the results of a loaded Babel @@ -67,7 +69,7 @@ class ConfigItem { /** * Used to detect ConfigItem instances from other Babel instances. */ - [Symbol.for("@babel/core@7 - ConfigItem")] = true; + [CONFIG_ITEM_BRAND] = true; /** * The resolved value of the item itself. @@ -110,8 +112,7 @@ class ConfigItem { this._descriptor = descriptor; Object.defineProperty(this, "_descriptor", { enumerable: false }); - this._isConfigItem = true; - Object.defineProperty(this, "_isConfigItem", { enumerable: false }); + Object.defineProperty(this, CONFIG_ITEM_BRAND, { enumerable: false }); this.value = this._descriptor.value; this.options = this._descriptor.options; From 25508fca702008532af5e325c38b96ecf9dd74d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 9 Nov 2020 23:58:47 +0100 Subject: [PATCH 5/8] Update packages/babel-core/src/config/item.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- packages/babel-core/src/config/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index b1d19ccda79d..c86da2be8dbc 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -40,7 +40,7 @@ export function createConfigItem( } export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { - if (item && item[Symbol.for("@babel/core@7 - ConfigItem")] === true) { + if (item?.[Symbol.for("@babel/core@7 - ConfigItem")] === true) { return item._descriptor; } From c280263a3a4ffe00f5be4f5ca0126e1baed29381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 10 Nov 2020 00:00:14 +0100 Subject: [PATCH 6/8] Update packages/babel-core/src/config/item.js --- packages/babel-core/src/config/item.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index c86da2be8dbc..42c08cc88186 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -66,6 +66,7 @@ class ConfigItem { */ _descriptor: UnloadedDescriptor; + // TODO(Babel 8): Check if this symbol needs to be updated /** * Used to detect ConfigItem instances from other Babel instances. */ From 93ca9c81215488bec02096e2d4f3f2d6a39cb332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 10 Nov 2020 00:04:28 +0100 Subject: [PATCH 7/8] Update --- packages/babel-core/src/config/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index 42c08cc88186..d9c1a3941e3a 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -40,7 +40,7 @@ export function createConfigItem( } export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { - if (item?.[Symbol.for("@babel/core@7 - ConfigItem")] === true) { + if (item?.[CONFIG_ITEM_BRAND]) { return item._descriptor; } From a00bf9e3bb5a6e2baf3b4509edf9a32ac6f40452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 10 Nov 2020 13:39:19 +0100 Subject: [PATCH 8/8] Fix flow --- packages/babel-core/src/config/item.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/babel-core/src/config/item.js b/packages/babel-core/src/config/item.js index d9c1a3941e3a..e344732454f5 100644 --- a/packages/babel-core/src/config/item.js +++ b/packages/babel-core/src/config/item.js @@ -1,5 +1,7 @@ // @flow +/*:: declare var invariant; */ + import type { PluginTarget, PluginOptions } from "./validation/options"; import path from "path"; @@ -40,7 +42,8 @@ export function createConfigItem( } export function getItemDescriptor(item: mixed): UnloadedDescriptor | void { - if (item?.[CONFIG_ITEM_BRAND]) { + if ((item: any)?.[CONFIG_ITEM_BRAND]) { + /*:: invariant(item instanceof ConfigItem) */ return item._descriptor; } @@ -70,6 +73,7 @@ class ConfigItem { /** * Used to detect ConfigItem instances from other Babel instances. */ + // $FlowIgnore [CONFIG_ITEM_BRAND] = true; /**