Skip to content

Commit

Permalink
chore: remove unnecessary block statements (#4888)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhsf authored Nov 19, 2024
1 parent 3f0e444 commit e677e5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
8 changes: 3 additions & 5 deletions packages/@lwc/ssr-compiler/src/compile-js/generate-markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { bImportDeclaration } from '../estree/builders';
import { bWireAdaptersPlumbing } from './wire';

import type {
BlockStatement,
ExportNamedDeclaration,
Program,
SimpleCallExpression,
Identifier,
MemberExpression,
Statement,
ExpressionStatement,
} from 'estree';
import type { ComponentMetaState } from './types';

Expand Down Expand Up @@ -68,10 +68,8 @@ const bGenerateMarkup = esTemplate`
`<ExportNamedDeclaration>;

const bAssignGenerateMarkupToComponentClass = esTemplate`
{
${/* lwcClassName */ is.identifier}[__SYMBOL__GENERATE_MARKUP] = generateMarkup;
}
`<BlockStatement>;
${/* lwcClassName */ is.identifier}[__SYMBOL__GENERATE_MARKUP] = generateMarkup;
`<ExpressionStatement>;

/**
* This builds a generator function `generateMarkup` and adds it to the component JS's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { is } from 'estree-toolkit';
import { generateScopeTokens } from '@lwc/template-compiler';
import { builders as b } from 'estree-toolkit/dist/builders';
import { esTemplate } from '../estemplate';
import type { BlockStatement, Program, VariableDeclaration } from 'estree';
import type { ExpressionStatement, Program, VariableDeclaration } from 'estree';

const bStylesheetTokenDeclaration = esTemplate`
const stylesheetScopeToken = '${is.literal}';
Expand All @@ -23,11 +23,9 @@ const bHasScopedStylesheetsDeclaration = esTemplate`
// We also need to keep track of whether the template has any scoped styles or not so that we can render (or not) the
// scope token.
const tmplAssignmentBlock = esTemplate`
{
${/* template */ is.identifier}.hasScopedStylesheets = hasScopedStylesheets;
${/* template */ 0}.stylesheetScopeToken = stylesheetScopeToken;
}
`<BlockStatement>;
${/* template */ is.identifier}.hasScopedStylesheets = hasScopedStylesheets;
${/* template */ 0}.stylesheetScopeToken = stylesheetScopeToken;
`<ExpressionStatement[]>;

export function addScopeTokenDeclarations(
program: Program,
Expand All @@ -42,5 +40,5 @@ export function addScopeTokenDeclarations(
bHasScopedStylesheetsDeclaration()
);

program.body.push(tmplAssignmentBlock(b.identifier('tmpl')));
program.body.push(...tmplAssignmentBlock(b.identifier('tmpl')));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
BlockStatement as EsBlockStatement,
Expression as EsExpression,
Statement as EsStatement,
IfStatement as EsIfStatement,
} from 'estree';
import type { Transformer, TransformerContext } from '../types';

Expand Down Expand Up @@ -89,13 +90,10 @@ const bStringLiteralYield = esTemplateWithYield`
`<EsBlockStatement>;

const bConditionallyYieldScopeTokenClass = esTemplateWithYield`
{
const shouldRenderScopeToken = hasScopedStylesheets || hasScopedStaticStylesheets(Cmp);
if (shouldRenderScopeToken) {
yield \` class="\${stylesheetScopeToken}"\`;
}
if (hasScopedStylesheets || hasScopedStaticStylesheets(Cmp)) {
yield \` class="\${stylesheetScopeToken}"\`;
}
`<EsBlockStatement>;
`<EsIfStatement>;

const bYieldSanitizedHtml = esTemplateWithYield`
yield sanitizeHtmlContent(${/* lwc:inner-html content */ is.expression})
Expand Down

0 comments on commit e677e5c

Please sign in to comment.