Skip to content

Commit

Permalink
fix: always use trimmedText
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Dec 11, 2023
1 parent 8fc7c6a commit dfb01a9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/embedded/css/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: "scss",
});
Expand Down
7 changes: 6 additions & 1 deletion src/embedded/es/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: options.embeddedEsParser ?? "babel",
});
Expand Down
7 changes: 6 additions & 1 deletion src/embedded/html/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: "html",
});
Expand Down
7 changes: 6 additions & 1 deletion src/embedded/markdown/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: "markdown",
__inJsTemplate: true,
Expand Down
7 changes: 6 additions & 1 deletion src/embedded/sql/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: "sql",
});
Expand Down
7 changes: 6 additions & 1 deletion src/embedded/ts/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ export const embedder: Embedder<Options> = async (
const leadingWhitespaces = text.match(/^\s+/)?.[0] ?? "";
const trailingWhitespaces = text.match(/\s+$/)?.[0] ?? "";

const trimmedText = text.slice(
leadingWhitespaces.length,
-trailingWhitespaces.length || undefined,
);

const expressionDocs = printTemplateExpressions(path, print);

const doc = await textToDoc(text, {
const doc = await textToDoc(trimmedText, {
...options,
parser: options.embeddedTsParser ?? "typescript",
// set filepath to undefined to enable jsx auto detection:
Expand Down

0 comments on commit dfb01a9

Please sign in to comment.