Skip to content

Commit

Permalink
Account for ConfigItem being generated by another copy of Babel (#11734)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
3 people committed Nov 10, 2020
1 parent 4b1b961 commit ddd868f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 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";
Expand Down Expand Up @@ -40,7 +42,8 @@ export function createConfigItem(
}

export function getItemDescriptor(item: mixed): UnloadedDescriptor | void {
if (item instanceof ConfigItem) {
if ((item: any)?.[CONFIG_ITEM_BRAND]) {
/*:: invariant(item instanceof ConfigItem) */
return item._descriptor;
}

Expand All @@ -49,6 +52,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
Expand All @@ -64,6 +69,13 @@ class ConfigItem {
*/
_descriptor: UnloadedDescriptor;

// TODO(Babel 8): Check if this symbol needs to be updated
/**
* Used to detect ConfigItem instances from other Babel instances.
*/
// $FlowIgnore
[CONFIG_ITEM_BRAND] = true;

/**
* The resolved value of the item itself.
*/
Expand Down Expand Up @@ -105,6 +117,8 @@ class ConfigItem {
this._descriptor = descriptor;
Object.defineProperty(this, "_descriptor", { enumerable: false });

Object.defineProperty(this, CONFIG_ITEM_BRAND, { enumerable: false });

this.value = this._descriptor.value;
this.options = this._descriptor.options;
this.dirname = this._descriptor.dirname;
Expand Down

0 comments on commit ddd868f

Please sign in to comment.