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

A comments flag to keep all comments in the parse function #1853

Closed
elevatebart opened this issue Aug 14, 2020 · 3 comments · Fixed by #1858
Closed

A comments flag to keep all comments in the parse function #1853

elevatebart opened this issue Aug 14, 2020 · 3 comments · Fixed by #1858

Comments

@elevatebart
Copy link
Contributor

What problem does this feature solve?

When using @vue/component-core's parse() function while building an application for production, all html comments are lost.
In vue-docgen-api, I use the comments to determine information about the component. Even if I don't package the component entirely with its comments they are useful at build time when the NODE_ENV is set to 'production'.

What does the proposed API look like?

Add a comments option to the ParseOptions false by default in prod, useless (and considered true) in dev that would override line 231 or parse.ts

https://github.com/vuejs/vue-next/blob/ac81dcf0cc7f5fc722a0c14d1cc92ece5cc0db07/packages/compiler-core/src/parse.ts#L231-L235

Usage:

import { parse } from '@vue/compiler-core'
const ast = parse(source, {comments:true})

Without the perf cost of having the comments all the time, we would still be able to extract them optionally.

I could make a PR if need be.

@elevatebart
Copy link
Contributor Author

The condition would be replaced by

} else if (!__DEV__ && node.type === NodeTypes.COMMENT && !comments) {

@elevatebart
Copy link
Contributor Author

For reference here is the original issue.

vue-styleguidist/vue-styleguidist#942

@yyx990803
Copy link
Member

Yeah, open to a PR

@elevatebart elevatebart changed the title A comment flag for the parse function A comments flag to keep all comments in the parse function Aug 14, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants