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

fix(ssr-compiler): harmonize some wire errors #5062

Merged
merged 15 commits into from
Dec 19, 2024

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Dec 19, 2024

Details

Partially addresses #5032

Fixes 8 expected failures.

  • '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',

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

@cardoso cardoso requested a review from a team as a code owner December 19, 2024 03:02
Copy link
Contributor Author

@cardoso cardoso left a comment

Choose a reason for hiding this comment

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

I kept the todos which don't seem to be covered by tests. I could add tests for those and fix them, but it might be better to do in a follow-up PR.

Comment on lines 35 to 36
'wire/errors/throws-on-computed-key/index.js',
'wire/errors/throws-when-colliding-prop-then-method/index.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines 1 to 19
/*
* 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> = T extends `${string}{${number}}${infer R}`
? [string, ...ExtractArguments<R>]
: [];

export function generateError<const T extends LWCErrorInfo>(
error: T,
...args: ExtractArguments<T['message']>
): Error {
return new Error(generateErrorMessage(error, args));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sure placeholders in the error messages become required arguments so it's a type error if you miss any or provide extras.

Comment on lines 220 to +221
},
};
} as const;
Copy link
Contributor Author

@cardoso cardoso Dec 19, 2024

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.

}

const hasTrack = decorators.some(({ expression }) =>
is.identifier(expression, { name: 'track' })
Copy link
Collaborator

Choose a reason for hiding this comment

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

{ name: 'track' }

You can do that?! 🤯

packages/@lwc/ssr-compiler/src/compile-js/index.ts Outdated Show resolved Hide resolved
packages/@lwc/ssr-compiler/src/compile-js/index.ts Outdated Show resolved Hide resolved
packages/@lwc/ssr-compiler/src/compile-js/index.ts Outdated Show resolved Hide resolved
packages/@lwc/ssr-compiler/src/compile-js/errors.ts Outdated Show resolved Hide resolved
? 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 @lwc/errors itself, since other packages could benefit from better typing here (e.g. @lwc/babel-plugin-component).

@nolanlawson
Copy link
Contributor

/nucleus test

@nolanlawson nolanlawson merged commit 141ac4d into salesforce:master Dec 19, 2024
11 checks passed
wjhsf added a commit that referenced this pull request Dec 20, 2024
* test(ssr): add tests for nested elements in slots (#5048)

* fix(compiler): log warning for missing name/namespace (#4825)

* test(karma): remove unnecessary IE11-related code (#5054)

* fix: replace barrel exports from `lwc` with `@lwc/ssr-runtime` (#5034)

* fix: replace barrel from `lwc` package with '@lwc/ssr-runtime'

* fix: handle * barrel case and corresponding tests

* fix: function naming

* fix: barrel import test parity

* fix: include optional exported alias for export all declaration replacement, tests

* chore: explain function name massaging in test

* fix: deep clone objects and optimize tests

* fix: remove unused shared file

* test(karma): add test for for:each issue #4889 (#5053)

* fix(ssr): missing bookends for slotted lwc:if not at the top-level (#5027)

Co-authored-by: Nolan Lawson <[email protected]>

* fix(ssr): fix HTML comment bookends for if blocks (#5055)

Co-authored-by: Will Harney <[email protected]>

* fix(ssr-compiler): namespace and name should be optional in ComponentTransformOptions (#5058)

* test(ssr): test `if` with adjacent text (#5056)

* test(karma): reduce #4889 even further (#5060)

* fix(ssr): fix `style` attribute rendering (#5061)

* fix(ssr-compiler): harmonize some wire errors (#5062)

Co-authored-by: Will Harney <[email protected]>

* fix: only call callback when needed @W-17420330 (#5064)

* fix: only call callback when needed @W-17420330

* chore: simplify test

* fix: use correct class check

* fix(ssr): render from superclass (#5063)

Co-authored-by: Nolan Lawson <[email protected]>

* test(ssr): add more superclass tests (#5065)

* fix: use correct shadow root @W-17441501 (#5070)

* fix: use correct shadow root @W-17441501

* chore: yagni i guess

* chore: 🛩️📦

* If you read this, tell me so!

* fix(ssr): align csr and ssr reflective behavior (#5050)

* chore: release v8.12.2 @W-17485572 (#5075)

---------

Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: jhefferman-sfdc <[email protected]>
Co-authored-by: Matheus Cardoso <[email protected]>
Co-authored-by: Nolan Lawson <[email protected]>
Co-authored-by: Eugene Kashida <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants