Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure private API is not enumerable #2859

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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