Skip to content

Commit

Permalink
fix: ensure private API is not enumerable (#2859)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Mar 22, 2022
1 parent 5869e01 commit c781b12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-adults-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Ensure private, internal APIs are not enumerable
4 changes: 1 addition & 3 deletions packages/astro/components/Markdown.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -35,7 +33,7 @@ if (!content) {
}
if (content) {
htmlContent = await renderMarkdown(content, {
htmlContent = await (Astro as any).__renderMarkdown(content, {
mode: 'md',
$: {
scopedClassName: className,
Expand Down
14 changes: 11 additions & 3 deletions packages/astro/src/core/render/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};
Expand All @@ -164,7 +170,9 @@ ${extra}`
const { code } = await parser(content, { ...renderOpts, ...(opts ?? {}) });
return code;
},
} as unknown as AstroGlobal;
});

return Astro;
},
resolve,
_metadata: {
Expand Down

0 comments on commit c781b12

Please sign in to comment.