@mintlify/common 1.0.1219 → 1.0.1221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mdx/snippets/findAndRemoveImports.js +4 -3
- package/dist/mdx/snippets/getExportMap.js +2 -1
- package/dist/mdx/snippets/importedExportName.d.ts +4 -0
- package/dist/mdx/snippets/importedExportName.js +3 -0
- package/dist/mdx/snippets/resolveImport/findExport.js +30 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -12,6 +12,7 @@ import { remove } from 'unist-util-remove';
|
|
|
12
12
|
import { removePosition } from 'unist-util-remove-position';
|
|
13
13
|
import { MdxImportSpecifier } from '../../types/mdx/index.js';
|
|
14
14
|
import { isMdxJsEsm, estreeIsProgram, isImportDeclaration } from '../utils.js';
|
|
15
|
+
import { importedExportName } from './importedExportName.js';
|
|
15
16
|
/**
|
|
16
17
|
An import like "import {Chart} from './chart.mdx'" looks like this in the AST:
|
|
17
18
|
{
|
|
@@ -52,11 +53,11 @@ export const findAndRemoveImports = (tree) => __awaiter(void 0, void 0, void 0,
|
|
|
52
53
|
const importDeclaration = {
|
|
53
54
|
source: bodyChild.source.value,
|
|
54
55
|
specifiers: bodyChild.specifiers.map((specifier) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
56
|
+
const imported = specifier.type === 'ImportSpecifier' ? importedExportName(specifier) : undefined;
|
|
57
|
+
const isRenamedImportSpecifier = imported !== undefined && imported != specifier.local.name;
|
|
57
58
|
return Object.assign({ type: isRenamedImportSpecifier
|
|
58
59
|
? MdxImportSpecifier.RenamedImportSpecifier
|
|
59
|
-
: specifier.type, name: isRenamedImportSpecifier ?
|
|
60
|
+
: specifier.type, name: isRenamedImportSpecifier ? imported : specifier.local.name }, (isRenamedImportSpecifier && {
|
|
60
61
|
renamedName: specifier.local.name,
|
|
61
62
|
}));
|
|
62
63
|
}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, toJs } from 'estree-util-to-js';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { moduleExportName } from './importedExportName.js';
|
|
3
4
|
import { nodeIncludesExport } from './nodeIncludesExport.js';
|
|
4
5
|
import { addExportPrefix } from './resolveImport/addExportPrefix.js';
|
|
5
6
|
/**
|
|
@@ -37,7 +38,7 @@ export const getExportMapFromTree = (tree) => {
|
|
|
37
38
|
if (bodyChild.type === 'ExportNamedDeclaration' && bodyChild.specifiers.length > 0) {
|
|
38
39
|
for (const specifier of bodyChild.specifiers) {
|
|
39
40
|
const localName = specifier.local.name;
|
|
40
|
-
const exportedName = specifier.exported
|
|
41
|
+
const exportedName = moduleExportName(specifier.exported);
|
|
41
42
|
// Find the original declaration
|
|
42
43
|
const originalDeclaration = findDeclarationInTree(localName, node);
|
|
43
44
|
if (originalDeclaration) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Identifier, ImportSpecifier, Literal } from 'estree-jsx';
|
|
2
|
+
export declare const moduleExportName: (node: Identifier | Literal) => string;
|
|
3
|
+
export declare const isIdentifierName: (name: string) => boolean;
|
|
4
|
+
export declare const importedExportName: (specifier: ImportSpecifier) => string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const moduleExportName = (node) => node.type === 'Identifier' ? node.name : String(node.value);
|
|
2
|
+
export const isIdentifierName = (name) => /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u.test(name);
|
|
3
|
+
export const importedExportName = (specifier) => moduleExportName(specifier.imported);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { jsx, toJs } from 'estree-util-to-js';
|
|
2
|
+
import { walk } from 'estree-walker';
|
|
2
3
|
import { visit, EXIT } from 'unist-util-visit';
|
|
4
|
+
import { isIdentifierName, moduleExportName } from '../importedExportName.js';
|
|
3
5
|
import { nodeIncludesExport } from '../nodeIncludesExport.js';
|
|
4
6
|
import { addExportPrefix } from './addExportPrefix.js';
|
|
5
7
|
/**
|
|
@@ -29,13 +31,17 @@ export const findExport = (exportName, tree, renamedExportName) => {
|
|
|
29
31
|
// handle `export { name }`
|
|
30
32
|
if (bodyChild.type === 'ExportNamedDeclaration' && bodyChild.specifiers.length > 0) {
|
|
31
33
|
for (const specifier of bodyChild.specifiers) {
|
|
32
|
-
if (specifier.exported
|
|
34
|
+
if (moduleExportName(specifier.exported) === exportName) {
|
|
33
35
|
const localName = specifier.local.name;
|
|
34
36
|
const originalDeclaration = findDeclarationInTree(localName, node);
|
|
35
37
|
if (originalDeclaration) {
|
|
36
38
|
const isolatedExport = structuredClone(originalDeclaration);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const declaredName = renamedExportName !== null && renamedExportName !== void 0 ? renamedExportName : (isIdentifierName(exportName) &&
|
|
40
|
+
isSafeToRename(isolatedExport, localName, exportName)
|
|
41
|
+
? exportName
|
|
42
|
+
: localName);
|
|
43
|
+
if (declaredName !== localName) {
|
|
44
|
+
renameInDeclaration(isolatedExport, localName, declaredName);
|
|
39
45
|
}
|
|
40
46
|
const wrappedNode = structuredClone(node);
|
|
41
47
|
wrappedNode.data.estree.body = [isolatedExport];
|
|
@@ -120,3 +126,24 @@ function renameInDeclaration(declaration, oldName, newName) {
|
|
|
120
126
|
declaration.id.name = newName;
|
|
121
127
|
}
|
|
122
128
|
}
|
|
129
|
+
// Renaming only the declared id is safe only when nothing else in the statement mentions either name.
|
|
130
|
+
function isSafeToRename(declaration, from, to) {
|
|
131
|
+
var _a;
|
|
132
|
+
if (declaration.type === 'VariableDeclaration' &&
|
|
133
|
+
(declaration.declarations.length !== 1 || ((_a = declaration.declarations[0]) === null || _a === void 0 ? void 0 : _a.id.type) !== 'Identifier')) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
let fromCount = 0;
|
|
137
|
+
let toCount = 0;
|
|
138
|
+
walk(declaration, {
|
|
139
|
+
enter(node) {
|
|
140
|
+
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
|
|
141
|
+
if (node.name === from)
|
|
142
|
+
fromCount += 1;
|
|
143
|
+
if (node.name === to)
|
|
144
|
+
toCount += 1;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return fromCount === 1 && toCount === 0;
|
|
149
|
+
}
|