Account for ConfigItem being generated by another copy of Babel (#11734)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This commit is contained in:
parent
4b1b961bd1
commit
ddd868f838
@ -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 instanceof ConfigItem) {
|
||||
if ((item: any)?.[CONFIG_ITEM_BRAND]) {
|
||||
/*:: invariant(item instanceof ConfigItem) */
|
||||
return item._descriptor;
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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.
|
||||
*/
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user