Skip to content

Commit

Permalink
fix(ssr): non-empty text nodes adjacent with comments (#4965)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 26, 2024
1 parent 348130f commit c3db1c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export const expectedFailures = new Set([
'adjacent-text-nodes/with-comments/empty1/index.js',
'adjacent-text-nodes/with-comments/empty2/index.js',
'adjacent-text-nodes/with-comments/empty3/index.js',
'adjacent-text-nodes/with-comments/nonempty1/index.js',
'adjacent-text-nodes/with-comments/nonempty2/index.js',
'adjacent-text-nodes/with-comments/nonempty3/index.js',
'adjacent-text-nodes/with-comments/preserve-comments2/index.js',
'attribute-aria/dynamic/index.js',
'attribute-class/with-scoped-styles-only-in-child/dynamic/index.js',
Expand All @@ -25,10 +22,8 @@ export const expectedFailures = new Set([
'attribute-namespace/index.js',
'attribute-style/basic/index.js',
'attribute-style/dynamic/index.js',
'comments-text-preserve-off/index.js',
'dynamic-components/mixed/index.js',
'dynamic-slots/index.js',
'empty-text-with-comments-non-static-optimized/index.js',
'exports/component-as-default/index.js',
'if-conditional-slot-content/index.js',
'known-boolean-attributes/default-def-html-attributes/static-on-component/index.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
Expression as IrExpression,
Literal as IrLiteral,
Text as IrText,
Node as IrNode,
} from '@lwc/template-compiler';
import type { Transformer } from '../types';

Expand Down Expand Up @@ -44,10 +45,21 @@ export const Text: Transformer<IrText> = function Text(node, cxt): EsStatement[]
return [bYield(b.literal(node.value.value))];
}

const shouldIsolate = (node?: IrNode) => {
switch (node?.type) {
case 'Text':
return false;
case 'Comment':
return cxt.templateOptions.preserveComments;
default:
return true;
}
};

const isIsolatedTextNode = b.literal(
(!cxt.prevSibling || cxt.prevSibling.type !== 'Text') &&
(!cxt.nextSibling || cxt.nextSibling.type !== 'Text')
shouldIsolate(cxt.prevSibling) && shouldIsolate(cxt.nextSibling)
);

const valueToYield = expressionIrToEs(node.value, cxt);
const tempVariable = b.identifier(cxt.getUniqueVar());

Expand Down

0 comments on commit c3db1c7

Please sign in to comment.