Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for ConfigItem being generated by another copy of Babel #11734

Merged
merged 8 commits into from Nov 10, 2020
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/babel-core/src/config/item.js
Expand Up @@ -40,7 +40,7 @@ export function createConfigItem(
}

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

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

// TODO(Babel 8): Check if this symbol needs to be updated
/**
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved
* Used to detect ConfigItem instances from other Babel instances.
*/
[CONFIG_ITEM_BRAND] = true;

/**
* The resolved value of the item itself.
*/
Expand Down Expand Up @@ -105,6 +113,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