From 1ae3b91b1e2204da8552986a29455ab6b7ae0459 Mon Sep 17 00:00:00 2001 From: dpiercey Date: Fri, 19 Jan 2024 14:00:05 -0700 Subject: [PATCH] fix: non standard template literal escapes --- .changeset/heavy-squids-flow.md | 6 ++++++ .../src/migrate/non-standard-template-literals/parse.ts | 5 ++++- .../__snapshots__/auto-migrate.expected/template.marko | 3 +++ .../__snapshots__/dom.expected.md | 5 +++++ .../__snapshots__/dom.expected/template.js | 7 ++++++- .../__snapshots__/html.expected.md | 7 ++++++- .../__snapshots__/html.expected/template.js | 3 +++ .../__snapshots__/hydrate.expected.md | 5 +++++ .../__snapshots__/manual-migrate-0.expected/template.marko | 7 +++++-- .../__snapshots__/manual-migrate-1.expected/template.marko | 7 +++++-- .../non-standard-template-literals/template.marko | 5 +++-- tests/main.test.ts | 1 + 12 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 .changeset/heavy-squids-flow.md diff --git a/.changeset/heavy-squids-flow.md b/.changeset/heavy-squids-flow.md new file mode 100644 index 0000000..39f5357 --- /dev/null +++ b/.changeset/heavy-squids-flow.md @@ -0,0 +1,6 @@ +--- +"@marko/compat-v4": patch +"marko-widgets": patch +--- + +Improve handling of non standard template literals when there are escape sequences. diff --git a/packages/compat-v4/src/migrate/non-standard-template-literals/parse.ts b/packages/compat-v4/src/migrate/non-standard-template-literals/parse.ts index fb19c88..f9c9244 100644 --- a/packages/compat-v4/src/migrate/non-standard-template-literals/parse.ts +++ b/packages/compat-v4/src/migrate/non-standard-template-literals/parse.ts @@ -23,7 +23,10 @@ export function parseNonStandardTemplateLiteral( string: t.NodePath, ) { const { file } = string.hub; - const { value } = string.node; + const { extra } = string.node; + let value = extra?.raw as string | undefined; + if (typeof value !== "string") return; + value = value.slice(1, -1); const { length } = value; const valueStart = string.node.start == null ? null : string.node.start + 1; let elements: undefined | t.TemplateElement[]; diff --git a/tests/fixtures-class/non-standard-template-literals/__snapshots__/auto-migrate.expected/template.marko b/tests/fixtures-class/non-standard-template-literals/__snapshots__/auto-migrate.expected/template.marko index 2e85c10..e233622 100644 --- a/tests/fixtures-class/non-standard-template-literals/__snapshots__/auto-migrate.expected/template.marko +++ b/tests/fixtures-class/non-standard-template-literals/__snapshots__/auto-migrate.expected/template.marko @@ -36,5 +36,8 @@ $ const c = 3; x: 1 }.missing)}def`} +
+ ${'\${abc}'} +
$ const handler = console.log; +
${STATIC}
${SCRIPLET}
1
abc}
abc}
abc}
abcd}ef
abc3
abcdef
${abc}
# Render ```html @@ -52,5 +52,10 @@ > abcdef +
+ ${abc} +