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): transform of empty text strings #4963

Merged
merged 7 commits into from
Nov 26, 2024

Conversation

jhefferman-sfdc
Copy link
Collaborator

Details

Aligns transformation of empty text strings with original implementation

Does this pull request introduce a breaking change?

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

Does this pull request introduce an observable change?

  • 🔬 Yes, it does include an observable change.

GUS work item

W-17094045

@jhefferman-sfdc jhefferman-sfdc requested a review from a team as a code owner November 26, 2024 21:34

cxt.import('htmlEscape');
return bYieldEscapedString(tempVariable, valueToYield, isIsolatedTextNode);
return [bYieldEscapedString(valueToYield, isIsolatedTextNode)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return [bYieldEscapedString(valueToYield, isIsolatedTextNode)];
return [bYieldEscapedString(valueToYield)];

Looks like tests are failing because we don't need the extra variable any more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we can change the return type of this function to EsBlockStatement[] to be a bit more precise.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The variable is declared as export const Text: Transformer<IrText>, so the return type on the function doesn't actually matter. The return type defined by Transformer<IrText> is what will ultimately be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you

Copy link
Contributor

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

Looking good so far!

For future reference, we are adding new failing tests because the new code is smaller, more concise, and more similar to the pre-existing api.ts code, even if we're introducing new test failures which are still due to adjacent text node collapsing not being implemented.

'dynamic-imports/basic/index.js',
'context-no-provider/index.js',
'attribute-global-html/as-component-prop/with-@api/index.js',
'adjacent-text-nodes/nonempty/index.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's alphabetize these

yield ${0} ? htmlEscape(${0}.toString()) : ${2} ? '\\u200D' : '';
{
const value = ${/* string value */ is.expression};
const massagedValue = value == null ? '' : String(value);
Copy link
Contributor

@nolanlawson nolanlawson Nov 26, 2024

Choose a reason for hiding this comment

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

Let's add a comment with a link to the code in api.ts to make it clear why we're doing this particular logic:

return value == null ? '' : String(value);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@nolanlawson for the suggestion about function return type: EsBlockStatement might be too specific as it can also return an IRLiteral[]

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, missed that. OK no problem.


cxt.import('htmlEscape');
return bYieldEscapedString(tempVariable, valueToYield, isIsolatedTextNode);
return [bYieldEscapedString(valueToYield, isIsolatedTextNode)];
Copy link
Contributor

Choose a reason for hiding this comment

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

Also we can change the return type of this function to EsBlockStatement[] to be a bit more precise.

@nolanlawson
Copy link
Contributor

Fixed merge conflicts with #4965. We still have 3 new failures but that's fine; the new code is more succinct and we have more work to do to fix adjacent text nodes anyway.

@nolanlawson
Copy link
Contributor

nolanlawson commented Nov 26, 2024

Actually I'm wrong – I just had a bug in my merge commit. No new test failures, and smaller code. Hooray!

@nolanlawson nolanlawson merged commit 33b7737 into master Nov 26, 2024
11 checks passed
@nolanlawson nolanlawson deleted the jhefferman/ssr/adjacent-text-fix branch November 26, 2024 23:44
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.

4 participants