-
Notifications
You must be signed in to change notification settings - Fork 405
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
fix(ssr-compiler): harmonize some wire errors #5062
Changes from all commits
3a2ff79
72cacbe
5c28b5f
b2ab326
65f7945
a786420
2951316
03df628
3d73c71
7801f45
84e7f9c
79cc491
7e85287
617b3ef
56aa004
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,4 +218,4 @@ export const DecoratorErrors = { | |
level: DiagnosticLevel.Error, | ||
url: '', | ||
}, | ||
}; | ||
} as const; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,4 @@ export const expectedFailures = new Set([ | |
'superclass/render-in-superclass/unused-default-in-superclass/index.js', | ||
'wire/errors/throws-on-computed-key/index.js', | ||
'wire/errors/throws-when-colliding-prop-then-method/index.js', | ||
Comment on lines
35
to
36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems there are some open questions regarding these two, which is discussed in several open issues such as:
Among others... So I don't think this PR will address these. |
||
'wire/errors/throws-when-computed-prop-is-expression/index.js', | ||
'wire/errors/throws-when-computed-prop-is-let-variable/index.js', | ||
'wire/errors/throws-when-computed-prop-is-regexp-literal/index.js', | ||
'wire/errors/throws-when-computed-prop-is-template-literal/index.js', | ||
'wire/errors/throws-when-using-2-wired-decorators/index.js', | ||
'wire/errors/throws-when-wired-method-is-combined-with-@api/index.js', | ||
'wire/errors/throws-when-wired-property-is-combined-with-@api/index.js', | ||
'wire/errors/throws-when-wired-property-is-combined-with-@track/index.js', | ||
]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { generateErrorMessage, type LWCErrorInfo } from '@lwc/errors'; | ||
|
||
// This type extracts the arguments in a string. Example: "Error {0} {1}" -> [string, string] | ||
type ExtractArguments< | ||
T extends string, | ||
Numbers extends number = never, | ||
Args extends string[] = [], | ||
> = T extends `${string}{${infer N extends number}}${infer R}` | ||
? N extends Numbers // Is `N` in the union of seen numbers? | ||
? ExtractArguments<R, Numbers, Args> // new `N`, add an argument | ||
: ExtractArguments<R, N | Numbers, [string, ...Args]> // `N` already accounted for | ||
: Args; // No `N` found, nothing more to check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! I think in a post-PR fixup, we could potentially move this into |
||
|
||
export function generateError<const T extends LWCErrorInfo>( | ||
error: T, | ||
...args: ExtractArguments<T['message']> | ||
): Error { | ||
return new Error(generateErrorMessage(error, args)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows typing the message placeholders (as described in the comment above). Hopefully this is ok.