From c781b12f87398d51a6ecf5dcb8b35afb08591c29 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 22 Mar 2022 16:27:35 -0500 Subject: [PATCH] fix: ensure private API is not enumerable (#2859) --- .changeset/modern-adults-dance.md | 5 +++++ packages/astro/components/Markdown.astro | 4 +--- packages/astro/src/core/render/result.ts | 14 +++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/modern-adults-dance.md diff --git a/.changeset/modern-adults-dance.md b/.changeset/modern-adults-dance.md new file mode 100644 index 000000000..ad98bbb68 --- /dev/null +++ b/.changeset/modern-adults-dance.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure private, internal APIs are not enumerable diff --git a/packages/astro/components/Markdown.astro b/packages/astro/components/Markdown.astro index 0dc214732..b7fbdf3cb 100644 --- a/packages/astro/components/Markdown.astro +++ b/packages/astro/components/Markdown.astro @@ -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, diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 9edef6bad..02b442610 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -88,7 +88,7 @@ export function createResult(args: CreateResultArgs): SSRResult { createAstro(astroGlobal: AstroGlobalPartial, props: Record, slots: Record | 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, // 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: {