-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ab455b
commit 36c2e11
Showing
3 changed files
with
50 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/@lwc/ssr-compiler/src/compile-template/transformers/text.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, 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 { builders as b, is } from 'estree-toolkit'; | ||
import { esTemplateWithYield } from '../../estemplate'; | ||
import { expressionIrToEs } from '../expression'; | ||
import { isLiteral } from '../shared'; | ||
|
||
import type { Statement as EsStatement, BlockStatement as EsBlockStatement } from 'estree'; | ||
import type { Text as IrText } from '@lwc/template-compiler'; | ||
import type { Transformer } from '../types'; | ||
|
||
const bYieldTextContent = esTemplateWithYield` | ||
{ | ||
const text = massageTextContent(${/* string value */ is.expression}); | ||
yield text === '' ? '\u200D' : htmlEscape(text); | ||
}`<EsBlockStatement>; | ||
|
||
export const Text: Transformer<IrText> = function Text(node, cxt): EsStatement[] { | ||
cxt.import(['htmlEscape', 'massageTextContent']); | ||
|
||
const valueToYield = isLiteral(node.value) | ||
? b.literal(node.value.value) | ||
: expressionIrToEs(node.value, cxt); | ||
|
||
return [bYieldTextContent(valueToYield)]; | ||
}; |