fix: ensure private API is not enumerable (#2859)

This commit is contained in:
Nate Moore 2022-03-22 16:27:35 -05:00 committed by GitHub
parent 5869e015d4
commit c781b12f87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Ensure private, internal APIs are not enumerable

View file

@ -24,8 +24,6 @@ let { content, class: className } = Astro.props as InternalProps;
let html = null;
let htmlContent = '';
const { privateRenderMarkdownDoNotUse: renderMarkdown } = Astro as any;
// If no content prop provided, use the slot.
if (!content) {
content = await Astro.slots.render('default');
@ -35,7 +33,7 @@ if (!content) {
}
if (content) {
htmlContent = await renderMarkdown(content, {
htmlContent = await (Astro as any).__renderMarkdown(content, {
mode: 'md',
$: {
scopedClassName: className,

View file

@ -88,7 +88,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
createAstro(astroGlobal: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null) {
const astroSlots = new Slots(result, slots);
return {
const Astro = {
__proto__: astroGlobal,
props,
request,
@ -138,8 +138,14 @@ ${extra}`
return astroGlobal.resolve(path);
},
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
async privateRenderMarkdownDoNotUse(content: string, opts: any) {
value: async function(content: string, opts: any) {
let [mdRender, renderOpts] = markdownRender;
let parser: MarkdownParser | null = null;
//let renderOpts = {};
@ -164,7 +170,9 @@ ${extra}`
const { code } = await parser(content, { ...renderOpts, ...(opts ?? {}) });
return code;
},
} as unknown as AstroGlobal;
});
return Astro;
},
resolve,
_metadata: {