clanka 0.2.62 → 0.2.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -123,6 +123,31 @@ const findTemplateEnd = (
123
123
  return end
124
124
  }
125
125
 
126
+ const findStandaloneTemplateEnd = (
127
+ text: string,
128
+ start: number,
129
+ isTerminator: (char: string | undefined) => boolean,
130
+ ): number => {
131
+ for (let index = start + 1; index < text.length; index++) {
132
+ if (text[index] !== "`" || isEscaped(text, index)) {
133
+ continue
134
+ }
135
+
136
+ const next = skipWhitespace(text, index + 1)
137
+ if (!isTerminator(text[next])) {
138
+ continue
139
+ }
140
+
141
+ const lineStart = text.lastIndexOf("\n", index - 1) + 1
142
+ const prefix = text.slice(lineStart, index)
143
+ if (/^[ \t]*$/.test(prefix)) {
144
+ return index
145
+ }
146
+ }
147
+
148
+ return -1
149
+ }
150
+
126
151
  const findTemplateEndFirst = (
127
152
  text: string,
128
153
  start: number,
@@ -492,6 +517,17 @@ const findLiteralInterpolationEnd = (text: string, start: number): number => {
492
517
  const expressionEnd = skipWhitespace(text, literalEnd + 1)
493
518
  return text[expressionEnd] === "}" ? expressionEnd : -1
494
519
  }
520
+
521
+ const isAssignedTemplateTerminator = (char: string | undefined): boolean =>
522
+ char === undefined ||
523
+ char === "\n" ||
524
+ char === "\r" ||
525
+ char === ";" ||
526
+ char === "," ||
527
+ char === ")" ||
528
+ char === "}" ||
529
+ char === "]"
530
+
495
531
  const escapeTemplateLiteralContent = (text: string): string => {
496
532
  const patchNormalized = normalizePatchEscapedQuotes(text)
497
533
  const isPatchContent = patchNormalized.includes("*** Begin Patch")
@@ -1022,19 +1058,15 @@ const rewriteAssignedTemplate = (
1022
1058
  continue
1023
1059
  }
1024
1060
 
1025
- const templateEnd = findTemplateEnd(
1061
+ const standaloneTemplateEnd = findStandaloneTemplateEnd(
1026
1062
  text,
1027
1063
  templateStart,
1028
- (char) =>
1029
- char === undefined ||
1030
- char === "\n" ||
1031
- char === "\r" ||
1032
- char === ";" ||
1033
- char === "," ||
1034
- char === ")" ||
1035
- char === "}" ||
1036
- char === "]",
1064
+ isAssignedTemplateTerminator,
1037
1065
  )
1066
+ const templateEnd =
1067
+ standaloneTemplateEnd === -1
1068
+ ? findTemplateEnd(text, templateStart, isAssignedTemplateTerminator)
1069
+ : standaloneTemplateEnd
1038
1070
  if (templateEnd === -1) {
1039
1071
  cursor = templateStart + 1
1040
1072
  continue