fix: ensure private API is not enumerable (#2859)
This commit is contained in:
parent
5869e015d4
commit
c781b12f87
3 changed files with 17 additions and 6 deletions
5
.changeset/modern-adults-dance.md
Normal file
5
.changeset/modern-adults-dance.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ensure private, internal APIs are not enumerable
|
|
@ -24,8 +24,6 @@ let { content, class: className } = Astro.props as InternalProps;
|
||||||
let html = null;
|
let html = null;
|
||||||
let htmlContent = '';
|
let htmlContent = '';
|
||||||
|
|
||||||
const { privateRenderMarkdownDoNotUse: renderMarkdown } = Astro as any;
|
|
||||||
|
|
||||||
// If no content prop provided, use the slot.
|
// If no content prop provided, use the slot.
|
||||||
if (!content) {
|
if (!content) {
|
||||||
content = await Astro.slots.render('default');
|
content = await Astro.slots.render('default');
|
||||||
|
@ -35,7 +33,7 @@ if (!content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
htmlContent = await renderMarkdown(content, {
|
htmlContent = await (Astro as any).__renderMarkdown(content, {
|
||||||
mode: 'md',
|
mode: 'md',
|
||||||
$: {
|
$: {
|
||||||
scopedClassName: className,
|
scopedClassName: className,
|
||||||
|
|
|
@ -88,7 +88,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
|
||||||
createAstro(astroGlobal: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null) {
|
createAstro(astroGlobal: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null) {
|
||||||
const astroSlots = new Slots(result, slots);
|
const astroSlots = new Slots(result, slots);
|
||||||
|
|
||||||
return {
|
const Astro = {
|
||||||
__proto__: astroGlobal,
|
__proto__: astroGlobal,
|
||||||
props,
|
props,
|
||||||
request,
|
request,
|
||||||
|
@ -138,8 +138,14 @@ ${extra}`
|
||||||
return astroGlobal.resolve(path);
|
return astroGlobal.resolve(path);
|
||||||
},
|
},
|
||||||
slots: astroSlots,
|
slots: astroSlots,
|
||||||
|
} as unknown as AstroGlobal;
|
||||||
|
|
||||||
|
Object.defineProperty(Astro, '__renderMarkdown', {
|
||||||
|
// Ensure this API is not exposed to users
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
// <Markdown> also needs the same `astroConfig.markdownOptions.render` as `.md` pages
|
// <Markdown> also needs the same `astroConfig.markdownOptions.render` as `.md` pages
|
||||||
async privateRenderMarkdownDoNotUse(content: string, opts: any) {
|
value: async function(content: string, opts: any) {
|
||||||
let [mdRender, renderOpts] = markdownRender;
|
let [mdRender, renderOpts] = markdownRender;
|
||||||
let parser: MarkdownParser | null = null;
|
let parser: MarkdownParser | null = null;
|
||||||
//let renderOpts = {};
|
//let renderOpts = {};
|
||||||
|
@ -164,7 +170,9 @@ ${extra}`
|
||||||
const { code } = await parser(content, { ...renderOpts, ...(opts ?? {}) });
|
const { code } = await parser(content, { ...renderOpts, ...(opts ?? {}) });
|
||||||
return code;
|
return code;
|
||||||
},
|
},
|
||||||
} as unknown as AstroGlobal;
|
});
|
||||||
|
|
||||||
|
return Astro;
|
||||||
},
|
},
|
||||||
resolve,
|
resolve,
|
||||||
_metadata: {
|
_metadata: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue