Skip to content

feat: Support uri fragment in transformed require #22

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

Merged
merged 20 commits into from
Sep 18, 2018
Merged

feat: Support uri fragment in transformed require #22

merged 20 commits into from
Sep 18, 2018

Conversation

joma74
Copy link
Contributor

@joma74 joma74 commented Jun 17, 2018

My case for this PR is a svg within a html based vue component, where i deployed vue-template-loader for this usage. In this html i put a svg element as in

<svg>
    <use href="~@svg/menu.svg#menu"></use>
</svg>

Root cause is that the whole href is generated by component-compiler-utils and as-is is required by webpack; this must fail because the whole href - including the uri fragment #menu - is not part of any mapped physical file location of such an svg.

@joma74
Copy link
Contributor Author

joma74 commented Jun 17, 2018

Just for the records: originally requested on ktsn/vue-template-loader#49

if(urlString){
// A TypeError is thrown if urlString is not a string
// @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
if('string' === typeof urlString){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urlString is of type string. Is this really required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was assuming pure JS library user, so no tsc validation. Defensive.

If not really required, should there be a catch block? Or what's the expected upper error handling concept? Anyone upper expected to log that error?

export function urlToRequire (url: string): string {
let returnValue = `"${url}"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


const uriParts = parseUriParts(url)

!uriParts.hash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if block and return early. Avoid using mutable variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok on if instead of ternary and return early;
not totally sure what is meant with mutable variables; pls comment on next commit

function parseUriParts(urlString: string): UrlWithStringQuery{
// initialize return value
const returnValue : UrlWithStringQuery = uriParse("");
if(urlString){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the code style is not consistent with the existing code. It seems that we should add a linting tool here. @znck

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced double quotes with single quotes, if that is all you have meant

@znck znck requested a review from yyx990803 June 27, 2018 17:12
@yyx990803
Copy link
Member

Please make sure to follow existing code style:

  • 2 spaces indentation
  • no semicolons
  • spaces between if conditions / braces

@joma74
Copy link
Contributor Author

joma74 commented Aug 17, 2018

Sorry for the merge foxtrot - please squash.

@znck znck merged commit f8cb88b into vuejs:master Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants