Skip to content

chore: remove structuredClone workaround #5367

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions packages/@lwc/template-compiler/src/codegen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ import type {
import type { APIVersion } from '@lwc/shared';
import type { Node } from 'estree';

// structuredClone is only available in Node 17+
// https://developer.mozilla.org/en-US/docs/Web/API/structuredClone#browser_compatibility
const doStructuredClone =
typeof structuredClone === 'function'
? structuredClone
: (obj: any) => JSON.parse(JSON.stringify(obj));

type RenderPrimitive =
| 'iterator'
| 'flatten'
Expand Down Expand Up @@ -629,7 +622,7 @@ export default class CodeGen {
if (this.state.config.experimentalComplexExpressions) {
// Cloning here is necessary because `this.replace()` is destructive, and we might use the
// node later during static content optimization
expression = doStructuredClone(expression);
expression = structuredClone(expression);
return bindComplexExpression(expression as ComplexExpression, this);
}

Expand All @@ -639,7 +632,7 @@ export default class CodeGen {

// Cloning here is necessary because `this.replace()` is destructive, and we might use the
// node later during static content optimization
expression = doStructuredClone(expression);
expression = structuredClone(expression);
// TODO [#3370]: when the template expression flag is removed, the
// ComplexExpression type should be redefined as an ESTree Node. Doing
// so when the flag is still in place results in a cascade of required
Expand Down