first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import type { types, template } from '@babel/core';
export declare const defaultWrapHelper: ({ statement }: typeof template, name: string) => types.Statement;
export declare const namespaceWrapHelper: ({ statement }: typeof template, name: string) => types.Statement;
export declare const liveExportAllHelper: ({ statement }: typeof template, id: string) => types.Statement;
export declare const liveExportHelper: (t: typeof types, exportName: string, expr: types.Expression) => types.Statement;
export declare const assignExportHelper: (t: typeof types, exportName: string, expr: types.Expression) => types.Statement;
export declare const varDeclaratorHelper: (t: typeof types, name: string, expr: types.Expression) => types.Statement;
/** `var %id% = require("%source%");` */
export declare const requireCall: (t: typeof types, id: string, source: types.StringLiteral) => types.VariableDeclaration;
/** `require("%source%");` */
export declare const sideEffectRequireCall: (t: typeof types, source: types.StringLiteral) => types.Statement;
/** `var %id% = %fnName%(%source%);` */
export declare const varDeclaratorCallHelper: (t: typeof types, id: string, fn: string, arg: string) => types.Statement;
export declare const esModuleExportTemplate: ({ statement }: typeof template) => types.Statement;
export declare const nullBoundExpression: (t: typeof types, expr: types.Expression) => types.ParenthesizedExpression;
declare function withLocation<TNode extends types.Node>(node: TNode, loc: types.SourceLocation | null | undefined): TNode;
declare function withLocation<TNode extends types.Node>(nodeArray: readonly TNode[], loc: types.SourceLocation | null | undefined): TNode[];
export { withLocation };

View File

@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nullBoundExpression = exports.esModuleExportTemplate = exports.varDeclaratorCallHelper = exports.sideEffectRequireCall = exports.requireCall = exports.varDeclaratorHelper = exports.assignExportHelper = exports.liveExportHelper = exports.liveExportAllHelper = exports.namespaceWrapHelper = exports.defaultWrapHelper = void 0;
exports.withLocation = withLocation;
const defaultWrapHelper = ({ statement }, name) => statement(`
function %%name%%(e) {
return e && e.__esModule ? e : { default: e };
}
`)({ name });
exports.defaultWrapHelper = defaultWrapHelper;
const namespaceWrapHelper = ({ statement }, name) => {
// NOTE(@kitten): A looser option than the above that matches Metro's legacy behaviour
return statement(`
function %%name%%(e) {
if (e && e.__esModule) return e;
var n = {};
if (e) Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
});
n.default = e;
return n;
}
`)({ name });
};
exports.namespaceWrapHelper = namespaceWrapHelper;
const liveExportAllHelper = ({ statement }, id) => {
return statement(`
Object.keys(%%id%%).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) {
Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return %%id%%[k]; }
});
}
});
`)({ id });
};
exports.liveExportAllHelper = liveExportAllHelper;
const liveExportHelper = (t, exportName, expr) => {
return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('defineProperty')), [
t.identifier('exports'),
t.stringLiteral(exportName),
t.objectExpression([
t.objectProperty(t.identifier('enumerable'), t.booleanLiteral(true)),
t.objectProperty(t.identifier('get'), t.functionExpression(null, [], t.blockStatement([t.returnStatement(expr)]))),
]),
]));
};
exports.liveExportHelper = liveExportHelper;
const assignExportHelper = (t, exportName, expr) => {
if (exportName === '__proto__') {
// NOTE(@kitten): `exports` is instantiated as `{}` instead of `Object.create(null)`, so the __proto__
// assignment still carries its special meaning. We switch to the live export helper implicitly here
// to avoid this
return (0, exports.liveExportHelper)(t, exportName, expr);
}
const member = t.isValidIdentifier(exportName)
? t.identifier(exportName)
: t.stringLiteral(exportName);
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), member), expr));
};
exports.assignExportHelper = assignExportHelper;
const varDeclaratorHelper = (t, name, expr) => t.variableDeclaration('var', [t.variableDeclarator(t.identifier(name), expr)]);
exports.varDeclaratorHelper = varDeclaratorHelper;
/** `var %id% = require("%source%");` */
const requireCall = (t, id, source) => t.variableDeclaration('var', [
t.variableDeclarator(t.identifier(id), t.callExpression(t.identifier('require'), [source])),
]);
exports.requireCall = requireCall;
/** `require("%source%");` */
const sideEffectRequireCall = (t, source) => t.expressionStatement(t.callExpression(t.identifier('require'), [source]));
exports.sideEffectRequireCall = sideEffectRequireCall;
/** `var %id% = %fnName%(%source%);` */
const varDeclaratorCallHelper = (t, id, fn, arg) => t.variableDeclaration('var', [
t.variableDeclarator(t.identifier(id), t.callExpression(t.identifier(fn), [t.identifier(arg)])),
]);
exports.varDeclaratorCallHelper = varDeclaratorCallHelper;
// Needs to be kept in 1:1 compatibility with Babel.
const esModuleExportTemplate = ({ statement }) => {
return statement(`
Object.defineProperty(exports, '__esModule', {value: true});
`)();
};
exports.esModuleExportTemplate = esModuleExportTemplate;
const nullBoundExpression = (t, expr) => t.parenthesizedExpression(t.sequenceExpression([t.numericLiteral(0), expr]));
exports.nullBoundExpression = nullBoundExpression;
function withLocation(nodeOrArray, loc) {
if (Array.isArray(nodeOrArray)) {
return nodeOrArray.map((n) => withLocation(n, loc));
}
const node = nodeOrArray;
if (!node.loc) {
node.loc = loc;
}
return node;
}
//# sourceMappingURL=helpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/transform-plugins/helpers.ts"],"names":[],"mappings":";;;AA6JS,oCAAY;AA3Jd,MAAM,iBAAiB,GAAG,CAAC,EAAE,SAAS,EAAmB,EAAE,IAAY,EAAmB,EAAE,CACjG,SAAS,CAAC;;;;GAIT,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AALF,QAAA,iBAAiB,qBAKf;AAER,MAAM,mBAAmB,GAAG,CACjC,EAAE,SAAS,EAAmB,EAC9B,IAAY,EACK,EAAE;IACnB,sFAAsF;IACtF,OAAO,SAAS,CAAC;;;;;;;;;;;;;;GAchB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AACf,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B;AAEK,MAAM,mBAAmB,GAAG,CACjC,E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ConfigAPI, PluginObj, types as t } from '@babel/core';
export interface Options {
readonly performConstantFolding?: boolean;
readonly resolve: boolean;
readonly out?: {
isESModule: boolean;
};
}
type ModuleRequest = t.StringLiteral;
type ModuleSource = string;
type ID = string;
declare const enum ImportDeclarationKind {
REQUIRE = "REQUIRE",
IMPORT_DEFAULT = "DEFAULT",
IMPORT_NAMESPACE = "NAMESPACE"
}
/** Record of specifiers (arbitrary name, default, or namespace import, to local IDs) */
interface ModuleSpecifiers {
[ImportDeclarationKind.REQUIRE]?: ID;
[ImportDeclarationKind.IMPORT_DEFAULT]?: ID;
[ImportDeclarationKind.IMPORT_NAMESPACE]?: ID;
/** Marks that the require call should be kept due to a side-effect */
sideEffect?: boolean;
}
/** Instruction for how to replace an expression when inlining */
interface InlineRef {
/** ID to access (MemberExpression.object) */
parentId: ID;
/** Specifier property to access (undefined for direct namespace access) */
member: 'default' | (string & {}) | undefined;
}
interface ImportDeclaration {
kind: ImportDeclarationKind;
source: ModuleRequest;
local: ID | undefined;
loc: t.SourceLocation | null | undefined;
}
interface ExportDeclaration {
statement: t.Statement;
local: ID | undefined;
}
interface State {
readonly opts: Options;
importSpecifiers: Map<ModuleSource, ModuleSpecifiers>;
/** Identifiers referencing import specifiers that should be rewritten (ID/key will be replaced) */
inlineBodyRefs: Map<ID, InlineRef>;
/** Identifiers by name that are referenced in the output */
referencedLocals: Set<ID>;
/** Cached untransformed export statements */
exportStatements: t.ExportNamedDeclaration[];
/** Transformed exports to add to the body, while referencing ID */
exportDeclarations: ExportDeclaration[];
/** Transformed export namespaces to add to the body, while referencing ID */
exportAll: Map<ID, t.Statement>;
/** Transformed imports to add to the body, if IDs referenced */
importDeclarations: ImportDeclaration[];
}
export declare function importExportLiveBindingsPlugin({ template, types: t, }: ConfigAPI & typeof import('@babel/core')): PluginObj<State>;
export {};

View File

@@ -0,0 +1,429 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.importExportLiveBindingsPlugin = importExportLiveBindingsPlugin;
const helpers_1 = require("./helpers");
function importExportLiveBindingsPlugin({ template, types: t, }) {
const addModuleSpecifiers = (state, source) => {
let moduleSpecifiers = state.importSpecifiers.get(source.value);
if (!moduleSpecifiers) {
moduleSpecifiers = Object.create(null);
state.importSpecifiers.set(source.value, moduleSpecifiers);
}
return moduleSpecifiers;
};
const addImport = (path, state, source, sideEffect = false) => {
const moduleSpecifiers = addModuleSpecifiers(state, source);
if (sideEffect || !state.opts.performConstantFolding) {
moduleSpecifiers.sideEffect = true;
}
let id = moduleSpecifiers["REQUIRE" /* ImportDeclarationKind.REQUIRE */];
if (!id) {
id = path.scope.generateUid(source.value);
moduleSpecifiers["REQUIRE" /* ImportDeclarationKind.REQUIRE */] = id;
state.importDeclarations.push({
kind: "REQUIRE" /* ImportDeclarationKind.REQUIRE */,
local: undefined,
source,
loc: path.node.loc,
});
}
return id;
};
const addDefaultImport = (path, state, source, name) => {
const moduleSpecifiers = addModuleSpecifiers(state, source);
let id = moduleSpecifiers["DEFAULT" /* ImportDeclarationKind.IMPORT_DEFAULT */];
if (!id) {
// Use the given name, if possible, or generate one. If no initial name is given,
// we'll create one based on the parent import
const parentImportLocal = addImport(path, state, source);
id =
!name || !t.isValidIdentifier(name)
? path.scope.generateUid(name ?? parentImportLocal)
: name;
moduleSpecifiers["DEFAULT" /* ImportDeclarationKind.IMPORT_DEFAULT */] = id;
state.importDeclarations.push({
kind: "DEFAULT" /* ImportDeclarationKind.IMPORT_DEFAULT */,
local: parentImportLocal,
source,
loc: path.node.loc,
});
}
return id;
};
const addNamespaceImport = (path, state, source, name) => {
const moduleSpecifiers = addModuleSpecifiers(state, source);
let id = moduleSpecifiers["NAMESPACE" /* ImportDeclarationKind.IMPORT_NAMESPACE */];
if (!id) {
// Use the given name, if possible, or generate one. If no initial name is given,
// we'll create one based on the parent import
const parentImportLocal = addImport(path, state, source);
id =
!name || !t.isValidIdentifier(name)
? path.scope.generateUid(name ?? parentImportLocal)
: name;
moduleSpecifiers["NAMESPACE" /* ImportDeclarationKind.IMPORT_NAMESPACE */] = id;
state.importDeclarations.push({
kind: "NAMESPACE" /* ImportDeclarationKind.IMPORT_NAMESPACE */,
local: parentImportLocal,
source,
loc: path.node.loc,
});
}
return id;
};
return {
visitor: {
// (1): Scan imports and prepare require calls
ImportDeclaration(path, state) {
if (path.node.importKind && path.node.importKind !== 'value') {
path.remove();
return;
}
const source = path.node.source;
if (!path.node.specifiers.length) {
addImport(path, state, source, true);
path.remove();
return;
}
for (const specifier of path.node.specifiers) {
const localId = specifier.local.name;
let importId;
let member;
switch (specifier.type) {
case 'ImportNamespaceSpecifier':
// The `namespaceWrapHelper` ensures a namespace object, but namespaces are accessed directly
member = undefined;
importId = addNamespaceImport(path, state, source, localId);
break;
case 'ImportSpecifier':
if (specifier.importKind && specifier.importKind !== 'value') {
continue;
}
member = t.isIdentifier(specifier.imported)
? specifier.imported.name
: specifier.imported.value;
// An imported default specifier is the same as an ImportDefaultSpecifier
importId =
member === 'default'
? addDefaultImport(path, state, source, localId)
: addImport(path, state, source);
break;
case 'ImportDefaultSpecifier':
// The `defaultWrapHelper` works by wrapping CommonJS modules in a fake module wrapper
member = 'default';
importId = addDefaultImport(path, state, source, localId);
break;
}
state.inlineBodyRefs.set(localId, {
parentId: importId,
member,
});
}
path.remove();
},
// (2.1): Declare live exports for ExportAllDeclarations immediately (References the import)
ExportAllDeclaration(path, state) {
if (path.node.exportKind && path.node.exportKind !== 'value') {
path.remove();
return;
}
const loc = path.node.loc;
const source = path.node.source;
const importId = addImport(path, state, source);
if (!state.exportAll.has(importId)) {
state.referencedLocals.add(importId);
state.exportAll.set(importId, (0, helpers_1.withLocation)((0, helpers_1.liveExportAllHelper)(template, importId), loc));
}
path.remove();
},
// (2.2): Store ExportDefaultDeclaration for later, for processing after all imports are evaluated
ExportDefaultDeclaration(path, state) {
if (path.node.exportKind && path.node.exportKind !== 'value') {
path.remove();
return;
}
let localId;
// We purposefully don't check for `Identifier` or `MemberExpression` here
// `export default` values are assigne at the point they're declared. We don't want them to be mutated
if (t.isDeclaration(path.node.declaration)) {
if (!path.node.declaration.id) {
path.node.declaration.id = path.scope.generateUidIdentifierBasedOnNode(path.node.declaration);
}
localId = path.node.declaration.id.name;
path.replaceWith(path.node.declaration);
}
else {
localId = path.scope.generateUid('_default');
path.replaceWith((0, helpers_1.withLocation)((0, helpers_1.varDeclaratorHelper)(t, localId, path.node.declaration), path.node.loc));
}
state.exportDeclarations.push({
statement: (0, helpers_1.withLocation)((0, helpers_1.liveExportHelper)(t, 'default', t.identifier(localId)), path.node.loc),
local: undefined,
});
},
// (2.3): Store ExportNamedDeclaration for later (if it has a local declaration), for processing after all imports are evaluated
// - If we have a source, create live bindings immediately for specifiers (References the import)
ExportNamedDeclaration(path, state) {
if (path.node.exportKind && path.node.exportKind !== 'value') {
path.remove();
return;
}
else if (path.node.declaration || !path.node.source) {
state.exportStatements.push(path.node);
if (path.node.declaration) {
// If we have a declaration, we'll replace the export with it
// In (3.1), we can then refer to the declarations by their local ids
path.replaceWith(path.node.declaration);
path.skip();
if (!path.node.source) {
return;
}
}
else if (!path.node.source) {
path.remove();
return;
}
}
const source = path.node.source;
if (!path.node.specifiers.length) {
addImport(path, state, source, true);
path.remove();
return;
}
for (const specifier of path.node.specifiers) {
let importId;
let specifierLocal;
let exportExpression;
switch (specifier.type) {
case 'ExportNamespaceSpecifier':
// The `namespaceWrapHelper` ensures a namespace object, but namespaces are accessed directly
specifierLocal = undefined;
importId = addNamespaceImport(path, state, source);
exportExpression = t.identifier(importId);
break;
case 'ExportSpecifier':
if (specifier.exportKind && specifier.exportKind !== 'value') {
continue;
}
specifierLocal = specifier.local.name;
// An imported default specifier is the same as an ImportDefaultSpecifier
importId =
specifierLocal === 'default'
? addDefaultImport(path, state, source)
: addImport(path, state, source);
exportExpression = t.memberExpression(t.identifier(importId), t.identifier(specifierLocal));
break;
case 'ExportDefaultSpecifier':
// The `defaultWrapHelper` works by wrapping CommonJS modules in a fake module wrapper
specifierLocal = 'default';
importId = addDefaultImport(path, state, source);
exportExpression = t.memberExpression(t.identifier(importId), t.identifier(specifierLocal));
break;
}
const exportName = t.isIdentifier(specifier.exported)
? specifier.exported.name
: specifier.exported.value;
state.referencedLocals.add(importId);
state.exportDeclarations.push({
statement: (0, helpers_1.withLocation)((0, helpers_1.liveExportHelper)(t, exportName, exportExpression), path.node.loc),
local: importId,
});
}
path.remove();
},
Program: {
// (0): Initialize all state
enter(path, state) {
state.importSpecifiers = new Map();
state.inlineBodyRefs = new Map();
state.referencedLocals = new Set();
state.exportStatements = [];
state.exportDeclarations = [];
state.exportAll = new Map();
state.importDeclarations = [];
// Ensure the iife "globals" don't have conflicting variables in the module.
['global', 'require', 'module', 'exports'].forEach((name) => {
path.scope.rename(name, path.scope.generateUidIdentifier(name).name);
});
},
exit(path, state) {
function getInlineRefExpression(node, localId) {
const inlineRef = state.inlineBodyRefs.get(localId);
if (!inlineRef)
return undefined;
// Reference count the target ID to ensure its import will be added,
// then replace this ID with the InlineRef
state.referencedLocals.add(inlineRef.parentId);
node.name = inlineRef.parentId;
let refNode;
if (inlineRef.member == null) {
refNode = node;
}
else if (node.type !== 'JSXIdentifier') {
refNode = t.memberExpression(node, t.identifier(inlineRef.member));
}
else {
refNode = t.jsxMemberExpression(t.jsxIdentifier(inlineRef.parentId), t.jsxIdentifier(inlineRef.member));
}
return refNode;
}
// (3): Process all "deferred" export declarations in `state.exportDeclarations`
for (const exportStatement of state.exportStatements) {
// (3.1): Convert all local exports into export declarations, while making sure
// to reference imports if necessary
if (!exportStatement.source && exportStatement.specifiers) {
for (const specifier of exportStatement.specifiers) {
if (specifier.type !== 'ExportSpecifier') {
continue; // NOTE: This is not a legal AST type without `source`
}
else if (specifier.exportKind && specifier.exportKind !== 'value') {
continue;
}
const exportName = t.isIdentifier(specifier.exported)
? specifier.exported.name
: specifier.exported.value;
const exportExpression = getInlineRefExpression(specifier.local, specifier.local.name) ?? specifier.local;
state.exportDeclarations.push({
statement: (0, helpers_1.withLocation)((0, helpers_1.liveExportHelper)(t, exportName, exportExpression), exportStatement.loc),
local: undefined,
});
}
}
// (3.2): Process all locally exported declarations
const declaration = exportStatement.declaration;
if (declaration) {
// Live bindings are used for variables, since they can be reassigned and may not be declared until later on
const exportHelper = declaration.type === 'VariableDeclaration' ||
declaration.type !== 'FunctionDeclaration'
? helpers_1.liveExportHelper
: helpers_1.assignExportHelper;
const exportBindings = t.getBindingIdentifiers(declaration, false, true);
for (const exportName in exportBindings) {
state.exportDeclarations.push({
statement: (0, helpers_1.withLocation)(exportHelper(t, exportName, t.identifier(exportBindings[exportName].name)), exportStatement.loc),
local: undefined,
});
}
}
}
// (4): Traverse reference identifiers and replace as needed with `state.inlineBodyRefs`'
// synthetic IDs, while marking the IDs that are referenced in `state.syntheticRefs`
path.traverse({
ReferencedIdentifier(path, state) {
if (path.parent.type === 'ExportSpecifier') {
return;
}
const localId = path.node.name;
// We skip this identifier if it's not a program binding, since
// that means it was declared in a child scope
const localBinding = path.scope.getBinding(localId);
const rootBinding = state.programScope.getBinding(localId);
if (rootBinding !== localBinding)
return;
// Replace the local ID with the inlined reference, if there is one
let inlineRefExpression = getInlineRefExpression(path.node, localId);
if (inlineRefExpression) {
// NOTE(@kitten): Ensure that calls after this member access aren't implicitly bound
// to the object they're called on
if (path.parent.type === 'CallExpression' &&
path.parent.callee === path.node &&
inlineRefExpression.type !== 'JSXMemberExpression') {
inlineRefExpression = (0, helpers_1.nullBoundExpression)(t, inlineRefExpression);
}
path.replaceWith(inlineRefExpression);
path.skip();
}
},
}, {
referencedLocals: state.referencedLocals,
inlineBodyRefs: state.inlineBodyRefs,
programScope: path.scope,
});
const preambleStatements = [];
const esmStatements = [];
let _defaultWrapName;
const wrapDefault = (localId, sourceId) => {
if (!_defaultWrapName) {
_defaultWrapName = '_interopDefault';
preambleStatements.push((0, helpers_1.defaultWrapHelper)(template, _defaultWrapName));
}
return (0, helpers_1.varDeclaratorCallHelper)(t, localId, _defaultWrapName, sourceId);
};
let _namespaceWrapName;
const wrapNamespace = (localId, sourceId) => {
if (!_namespaceWrapName) {
_namespaceWrapName = '_interopNamespace';
preambleStatements.push((0, helpers_1.namespaceWrapHelper)(template, _namespaceWrapName));
}
return (0, helpers_1.varDeclaratorCallHelper)(t, localId, _namespaceWrapName, sourceId);
};
// Add `__esModule` marker if we have any exports
if (state.exportDeclarations.length || state.exportAll.size) {
preambleStatements.push((0, helpers_1.esModuleExportTemplate)(template));
}
// (5): Add all exports, and all referenced imports
for (const exportDeclaration of state.exportDeclarations) {
esmStatements.push(exportDeclaration.statement);
if (exportDeclaration.local) {
state.referencedLocals.add(exportDeclaration.local);
}
}
// Reference locals that are referenced by import declarations
for (const importDeclaration of state.importDeclarations) {
// NOTE(@kitten): The first check removes default/namespace import wrappers when they're unused.
// This diverges from the previous implementation a lot, and is basically unused local elimination
// If we don't want this, this can safely be removed
const source = importDeclaration.source;
const local = addModuleSpecifiers(state, source)[importDeclaration.kind];
if (!local || !state.referencedLocals.has(local)) {
continue;
}
else if (importDeclaration.local) {
state.referencedLocals.add(importDeclaration.local);
}
}
// Insert imports, if they're referenced
for (const importDeclaration of state.importDeclarations) {
const source = importDeclaration.source;
const moduleSpecifiers = addModuleSpecifiers(state, source);
const local = moduleSpecifiers[importDeclaration.kind];
if (!local || !state.referencedLocals.has(local)) {
// Don't add imports that aren't referenced, unless they're required for a side-effect
// We check for REQUIRE, to make sure we only ever add a single side-effect require
if (importDeclaration.kind === "REQUIRE" /* ImportDeclarationKind.REQUIRE */ &&
moduleSpecifiers.sideEffect) {
esmStatements.push((0, helpers_1.withLocation)((0, helpers_1.sideEffectRequireCall)(t, source), importDeclaration.loc));
}
continue;
}
let importStatement;
switch (importDeclaration.kind) {
case "REQUIRE" /* ImportDeclarationKind.REQUIRE */:
importStatement = (0, helpers_1.requireCall)(t, local, source);
break;
case "DEFAULT" /* ImportDeclarationKind.IMPORT_DEFAULT */:
importStatement = wrapDefault(local, importDeclaration.local);
break;
case "NAMESPACE" /* ImportDeclarationKind.IMPORT_NAMESPACE */:
importStatement = wrapNamespace(local, importDeclaration.local);
break;
}
importStatement = (0, helpers_1.withLocation)(importStatement, importDeclaration.loc);
esmStatements.push(importStatement);
const exportAllStatement = state.exportAll.get(local);
if (exportAllStatement != null) {
esmStatements.push(exportAllStatement);
}
}
// WARN(@kitten): This isn't only dependent on exports! If we set this to `false` but
// added any imports, then those imports will accidentally be shifted back to CJS-mode
if (esmStatements.length && state.opts.out) {
state.opts.out.isESModule = true;
}
path.node.body = [...preambleStatements, ...esmStatements, ...path.node.body];
},
},
},
};
}
//# sourceMappingURL=importExportLiveBindings.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,63 @@
/**
* Copyright (c) 650 Industries (Expo). All rights reserved.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { ConfigAPI, PluginObj, types as t } from '@babel/core';
export type Options = Readonly<{
importDefault: string;
importAll: string;
resolve: boolean;
out?: {
isESModule: boolean;
[key: string]: unknown;
};
}>;
type State = {
importDefault: t.Node;
importAll: t.Node;
opts: Options;
originalImportOrder: Map<string, t.StringLiteral>;
exportAllFrom: Map<string, {
loc: t.SourceLocation | null | undefined;
}>;
importAllFromAs: Map<string, {
loc: t.SourceLocation | null | undefined;
as: string;
}[]>;
exportAllFromAs: Map<string, {
loc: t.SourceLocation | null | undefined;
as: string;
}[]>;
importDefaultFromAs: Map<string, {
loc: t.SourceLocation | null | undefined;
as: t.Identifier;
}[]>;
exportDefault: {
loc: t.SourceLocation | null | undefined;
name: string;
}[];
exportNamedFrom: Map<string, {
loc: t.SourceLocation | null | undefined;
name: string;
as: string;
}[]>;
importNamedFrom: Map<string, {
loc: t.SourceLocation | null | undefined;
name: string;
as: string;
}[]>;
exportNamed: {
loc: t.SourceLocation | null | undefined;
name: string;
as: string;
}[];
importSideEffect: Map<string, {
loc: t.SourceLocation | null | undefined;
}>;
[key: string]: unknown;
};
export declare function importExportPlugin({ types: t, }: ConfigAPI & typeof import('@babel/core')): PluginObj<State>;
export {};

View File

@@ -0,0 +1,462 @@
"use strict";
/**
* Copyright (c) 650 Industries (Expo). All rights reserved.
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// A fork of the upstream metro-babel-transform-plugin/import-export-plugin that uses Expo-specific features
// and adds support for export-namespace-from
// https://github.com/facebook/metro/blob/8e48aa823378962beccbe37d85f1aff2c34b28b1/packages/metro-transform-plugins/src/import-export-plugin.js
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importExportPlugin = importExportPlugin;
const core_1 = require("@babel/core");
const node_assert_1 = __importDefault(require("node:assert"));
const helpers_1 = require("./helpers");
const debug = require('debug')('expo:metro-config:import-export-plugin');
function nullthrows(x, message) {
(0, node_assert_1.default)(x != null, message);
return x;
}
function getArray(map, key) {
if (!map.has(key)) {
map.set(key, []);
}
return nullthrows(map.get(key));
}
function setFirst(map, key, value) {
if (!map.has(key)) {
map.set(key, value);
}
}
const importTemplate = core_1.template.statement(`
var %%asId%% = %%importHelperId%%(%%moduleStr%%);
`);
const requireNameTemplate = core_1.template.statement(`
var %%asId%% = require(%%moduleStr%%).%%nameId%%;
`);
const requireSideEffectTemplate = core_1.template.statement(`
require(%%moduleStr%%);
`);
// NOTE(@krystofwoldrich): Export all template doesn't have to check for export existence
// because it always runs before default and named exports which overwrite the exports object.
// NOTE(@krystofwoldrich): This also re-exports `default` and `__esModule` properties
// we might want to remove that in the future to align with the spec.
const staticExportAllTemplate = core_1.template.statements(`
var %%namespaceId%% = require(%%moduleStr%%);
for (var %%keyId%% in %%namespaceId%%) {
exports[%%keyId%%] = %%namespaceId%%[%%keyId%%];
}
`);
const staticExportTemplate = core_1.template.statement(`
exports.%%asId%% = %%nameId%%;
`);
// Needs to be kept in 1:1 compatibility with Babel.
const esModuleExportTemplate = core_1.template.statement(`
Object.defineProperty(exports, '__esModule', {value: true});
`);
const resolveTemplate = core_1.template.expression(`
require.resolve(NODE)
`);
/**
* Enforces the resolution of a path to a fully-qualified one, if set.
*/
function resolvePath(node, resolve) {
if (!resolve) {
return node;
}
return resolveTemplate({
NODE: node,
});
}
function importExportPlugin({ types: t, }) {
const { isDeclaration, isVariableDeclaration } = t;
return {
visitor: {
ExportAllDeclaration(path, state) {
setFirst(state.originalImportOrder, path.node.source.value, path.node.source);
state.exportAllFrom.set(path.node.source.value, {
loc: path.node.loc,
});
path.remove();
},
ExportDefaultDeclaration(path, state) {
const declaration = path.node.declaration;
const id = ('id' in declaration && declaration.id) || path.scope.generateUidIdentifier('default');
declaration.id = id;
const loc = path.node.loc;
if (isDeclaration(declaration)) {
path.insertBefore((0, helpers_1.withLocation)(declaration, loc));
}
else {
path.insertBefore((0, helpers_1.withLocation)(t.variableDeclaration('var', [t.variableDeclarator(id, declaration)]), loc));
}
state.exportDefault.push({
name: id.name,
loc,
});
path.remove();
},
ExportNamedDeclaration(path, state) {
if (path.node.exportKind && path.node.exportKind !== 'value') {
return;
}
const loc = path.node.loc;
const declaration = path.node.declaration;
if (declaration) {
if (isVariableDeclaration(declaration)) {
declaration.declarations.forEach((d) => {
switch (d.id.type) {
case 'ObjectPattern':
{
const properties = d.id.properties;
properties.forEach((p) => {
const nameCandidate = p.type === 'ObjectProperty' ? p.value : p.argument;
const name = 'name' in nameCandidate ? nameCandidate.name : undefined;
if (name) {
state.exportNamed.push({
name,
as: name,
loc,
});
}
else {
debug('Unexpected export named declaration with object pattern without name.', p.toString());
}
});
}
break;
case 'ArrayPattern':
{
const elements = d.id.elements;
elements.forEach((e) => {
if (!e) {
return;
}
const nameCandidate = 'argument' in e ? e.argument : e;
const name = 'name' in nameCandidate ? nameCandidate.name : undefined;
if (name) {
state.exportNamed.push({
name,
as: name,
loc,
});
}
else {
debug('Unexpected export named declaration with array pattern without name.', e?.toString());
}
});
}
break;
default:
{
const id = d.id;
const name = 'name' in id ? id.name : undefined;
if (name) {
state.exportNamed.push({
name,
as: name,
loc,
});
}
else {
debug('Unexpected export named declaration with identifier without name.', id.toString());
}
}
break;
}
});
}
else {
if ('id' in declaration) {
const id = declaration.id || path.scope.generateUidIdentifier();
const name = id.type === 'StringLiteral' ? id.value : id.name;
declaration.id = id;
state.exportNamed.push({
name,
as: name,
loc,
});
}
else {
debug('Unexpected export named declaration without id.', declaration.toString());
}
}
path.insertBefore(declaration);
}
const specifiers = path.node.specifiers;
if (specifiers && specifiers.length) {
const source = path.node.source;
if (source)
setFirst(state.originalImportOrder, source.value, source);
specifiers.forEach((s) => {
if (s.exported.type === 'StringLiteral') {
// https://babeljs.io/docs/en/babel-plugin-syntax-module-string-names
throw path.buildCodeFrameError('Module string names are not supported');
}
switch (s.type) {
case 'ExportSpecifier':
(source ? getArray(state.exportNamedFrom, source.value) : state.exportNamed).push({
name: s.local.name,
as: s.exported.name,
loc: path.node.loc,
});
break;
case 'ExportDefaultSpecifier':
state.exportDefault.push({
name: s.exported.name,
loc: path.node.loc,
});
break;
case 'ExportNamespaceSpecifier':
// export * as b from 'a'
getArray(state.exportAllFromAs, nullthrows(source?.value)).push({
as: s.exported.name,
loc: path.node.loc,
});
break;
default:
debug('Unexpected export named declaration specifier type.', s.toString());
break;
}
});
}
path.remove();
},
ImportDeclaration(path, state) {
if (path.node.importKind && path.node.importKind !== 'value') {
return;
}
const file = path.node.source;
const specifiers = path.node.specifiers;
const loc = path.node.loc;
setFirst(state.originalImportOrder, file.value, file);
if (!specifiers.length) {
state.importSideEffect.set(file.value, { loc });
}
else {
specifiers.forEach((s) => {
switch (s.type) {
case 'ImportNamespaceSpecifier':
getArray(state.importAllFromAs, file.value).push({
as: s.local.name,
loc: path.node.loc,
});
break;
case 'ImportDefaultSpecifier':
getArray(state.importDefaultFromAs, file.value).push({
as: s.local,
loc: path.node.loc,
});
break;
case 'ImportSpecifier': {
const importedName = s.imported.type === 'StringLiteral' ? s.imported.value : s.imported.name;
if (importedName === 'default') {
getArray(state.importDefaultFromAs, file.value).push({
as: s.local,
loc: path.node.loc,
});
}
else {
getArray(state.importNamedFrom, file.value).push({
name: importedName,
as: s.local.name,
loc: path.node.loc,
});
}
break;
}
default:
throw new TypeError('Unknown import type: ' + s.type);
}
});
}
path.remove();
},
Program: {
enter(path, state) {
state.exportAll = [];
state.exportDefault = [];
state.exportNamed = [];
state.imports = [];
state.importAll = t.identifier(state.opts.importAll);
state.importDefault = t.identifier(state.opts.importDefault);
state.originalImportOrder = new Map();
state.exportAllFrom = new Map();
state.importAllFromAs = new Map();
state.exportAllFromAs = new Map();
state.importDefaultFromAs = new Map();
state.exportDefault = [];
state.exportNamedFrom = new Map();
state.importNamedFrom = new Map();
state.exportNamed = [];
state.importSideEffect = new Map();
// Rename declarations at module scope that might otherwise conflict
// with arguments we inject into the module factory.
// Note that it isn't necessary to rename importAll/importDefault
// because Metro already uses generateUid to generate unused names.
['module', 'global', 'exports', 'require'].forEach((name) => path.scope.rename(name));
},
exit(path, state) {
const body = path.node.body;
const hasESExports = state.exportDefault.length ||
state.exportAllFrom.size ||
state.exportNamed.length ||
state.exportAllFromAs.size ||
state.exportNamedFrom.size;
const hasESImports = state.importAllFromAs.size ||
state.importDefaultFromAs.size ||
state.importNamedFrom.size ||
state.importSideEffect.size;
const imports = [];
const exportAll = [];
const staticExports = [];
const defaultStaticExports = [];
for (const [, module] of state.originalImportOrder) {
const resolved = resolvePath(module, state.opts.resolve);
const exportAllFrom = state.exportAllFrom.get(module.value);
if (exportAllFrom) {
// export * from 'module'
exportAll.push(...(0, helpers_1.withLocation)(staticExportAllTemplate({
keyId: path.scope.generateUidIdentifier('key'),
moduleStr: t.cloneNode(resolved),
namespaceId: path.scope.generateUidIdentifier(module.value),
}), exportAllFrom.loc));
}
for (const { as, loc } of getArray(state.exportAllFromAs, module.value)) {
// export * as name from 'module' -> var _name = _$$_IMPORT_ALL('module'); exports.name = _name;
const ns = path.scope.generateUidIdentifier(as);
imports.push((0, helpers_1.withLocation)(importTemplate({
importHelperId: t.cloneNode(state.importAll),
moduleStr: t.cloneNode(resolved),
asId: t.cloneNode(ns),
}), loc));
// NOTE: To move all defaults to bottom of the program, we should check as === 'default' here
// but the original plugin doesn't do that.
staticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.cloneNode(ns),
asId: t.identifier(as),
}), loc));
}
for (const { name, as, loc } of getArray(state.exportNamedFrom, module.value)) {
if (name === 'default' && as === 'default') {
// export { default } from 'module' -> exports.default = requireDefault('module');
const tmp = path.scope.generateUidIdentifier(name);
imports.push((0, helpers_1.withLocation)(importTemplate({
importHelperId: t.cloneNode(state.importDefault),
moduleStr: t.cloneNode(resolved),
asId: t.cloneNode(tmp),
}), loc));
defaultStaticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.cloneNode(tmp),
asId: t.identifier(as),
}), loc));
}
else if (name === 'default') {
// export { default as name } from 'module' -> var _default = requireDefault('module'); exports.name = _default;
const tmp = path.scope.generateUidIdentifier(name);
imports.push((0, helpers_1.withLocation)(importTemplate({
importHelperId: t.cloneNode(state.importDefault),
moduleStr: t.cloneNode(resolved),
asId: t.cloneNode(tmp),
}), loc));
staticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.cloneNode(tmp),
asId: t.identifier(as),
}), loc));
}
else {
// export { one as two } from 'module' -> var _one = require('module').one; exports.two = _one;
const tmp = path.scope.generateUidIdentifier(name);
imports.push((0, helpers_1.withLocation)(requireNameTemplate({
moduleStr: t.cloneNode(resolved),
nameId: t.identifier(name),
asId: t.cloneNode(tmp),
}), loc));
staticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.cloneNode(tmp),
asId: t.identifier(as),
}), loc));
}
}
let sharedModuleVariableDeclaration = null;
if (getArray(state.importNamedFrom, module.value).length === 1) {
// import { one as two } from 'module' -> var two = require('module').one;
const importNamed = getArray(state.importNamedFrom, module.value)[0];
imports.push((0, helpers_1.withLocation)(requireNameTemplate({
moduleStr: t.cloneNode(resolved),
nameId: t.identifier(importNamed.name),
asId: t.identifier(importNamed.as),
}), getArray(state.importNamedFrom, module.value)[0].loc));
}
else {
// import { one as two, three as four } from 'module'
// -> var _module = require('module'), two = _module.one, four = _module.four;
let sharedModuleImport = null;
for (const { name, as, loc } of getArray(state.importNamedFrom, module.value)) {
if (!sharedModuleVariableDeclaration) {
sharedModuleImport = path.scope.generateUidIdentifierBasedOnNode(module);
sharedModuleVariableDeclaration = (0, helpers_1.withLocation)(t.variableDeclaration('var', [
t.variableDeclarator(t.cloneNode(sharedModuleImport), t.callExpression(t.identifier('require'), [t.cloneNode(resolved)])),
]), loc);
imports.push(sharedModuleVariableDeclaration);
}
sharedModuleVariableDeclaration.declarations.push((0, helpers_1.withLocation)(t.variableDeclarator(t.identifier(as), t.memberExpression(t.cloneNode(nullthrows(sharedModuleImport)), t.identifier(name))), loc));
}
}
if (!sharedModuleVariableDeclaration && state.importSideEffect.has(module.value)) {
// import 'module' -> require('module')
imports.push((0, helpers_1.withLocation)(requireSideEffectTemplate({
moduleStr: t.cloneNode(resolved),
}), state.importSideEffect.get(module.value)?.loc));
}
for (const { as, loc } of getArray(state.importAllFromAs, module.value)) {
// import * as name from 'module'
imports.push((0, helpers_1.withLocation)(importTemplate({
importHelperId: t.cloneNode(state.importAll),
moduleStr: t.cloneNode(resolved),
asId: t.identifier(as),
}), loc));
}
for (const { as, loc } of getArray(state.importDefaultFromAs, module.value)) {
// import name from 'module'
imports.push((0, helpers_1.withLocation)(importTemplate({
importHelperId: t.cloneNode(state.importDefault),
moduleStr: t.cloneNode(resolved),
asId: as,
}), loc));
}
}
for (const { name, as, loc } of state.exportNamed) {
staticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.identifier(name),
asId: t.identifier(as),
}), loc));
}
for (const { name, loc } of state.exportDefault) {
defaultStaticExports.push((0, helpers_1.withLocation)(staticExportTemplate({
nameId: t.identifier(name),
asId: t.identifier('default'),
}), loc));
}
body.unshift(...imports);
body.push(...exportAll);
body.push(...staticExports);
body.push(...defaultStaticExports);
if (hasESExports) {
body.unshift(esModuleExportTemplate());
}
if (state.opts.out && (hasESExports || hasESImports)) {
state.opts.out.isESModule = true;
}
},
},
},
};
}
//# sourceMappingURL=importExportStatic.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { importExportLiveBindingsPlugin } from './importExportLiveBindings';
export { importExportPlugin } from './importExportStatic';

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.importExportPlugin = exports.importExportLiveBindingsPlugin = void 0;
var importExportLiveBindings_1 = require("./importExportLiveBindings");
Object.defineProperty(exports, "importExportLiveBindingsPlugin", { enumerable: true, get: function () { return importExportLiveBindings_1.importExportLiveBindingsPlugin; } });
var importExportStatic_1 = require("./importExportStatic");
Object.defineProperty(exports, "importExportPlugin", { enumerable: true, get: function () { return importExportStatic_1.importExportPlugin; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transform-plugins/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4E;AAAnE,0IAAA,8BAA8B,OAAA;AACvC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA"}