@thyn/core 0.0.353 → 0.0.354
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.
- package/README.md +1 -1
- package/dist/plugin/index.js +1 -1
- package/dist/plugin/utils.js +11 -7
- package/docs/package-lock.json +4 -4
- package/docs/package.json +1 -1
- package/docs/src/pages/Home.thyn +1 -5
- package/package.json +1 -1
- package/src/plugin/index.ts +1 -1
- package/src/plugin/utils.ts +11 -7
- package/tests/CodeSnippet.test.ts +11 -0
package/README.md
CHANGED
package/dist/plugin/index.js
CHANGED
|
@@ -879,7 +879,7 @@ export async function transformSFC(source, id) {
|
|
|
879
879
|
s.append([
|
|
880
880
|
"",
|
|
881
881
|
`export default function ${name}($props) {`,
|
|
882
|
-
...body.map((l) => " " + l),
|
|
882
|
+
...body.map((l) => (l.shouldIndent ? " " + l.text : l.text)),
|
|
883
883
|
removeUnusedThynVars(` ${transformed} return ${root};`),
|
|
884
884
|
`}`,
|
|
885
885
|
].join("\n"));
|
package/dist/plugin/utils.js
CHANGED
|
@@ -268,7 +268,7 @@ export function splitScript(script) {
|
|
|
268
268
|
currentImport.push(line);
|
|
269
269
|
}
|
|
270
270
|
else {
|
|
271
|
-
body.push(line);
|
|
271
|
+
body.push({ text: line, shouldIndent: true });
|
|
272
272
|
}
|
|
273
273
|
// Check for end of multi-line comment, tracking strings
|
|
274
274
|
for (let j = 0; j < line.length; j++) {
|
|
@@ -303,7 +303,7 @@ export function splitScript(script) {
|
|
|
303
303
|
currentImport.push(line);
|
|
304
304
|
}
|
|
305
305
|
else {
|
|
306
|
-
body.push(line);
|
|
306
|
+
body.push({ text: line, shouldIndent: !inString });
|
|
307
307
|
}
|
|
308
308
|
// Check if comment ends on same line
|
|
309
309
|
for (let j = 0; j < line.length; j++) {
|
|
@@ -336,12 +336,12 @@ export function splitScript(script) {
|
|
|
336
336
|
}
|
|
337
337
|
// Skip single-line comments when not in import (only if not in string)
|
|
338
338
|
if (!inString && !inImport && trimmed.startsWith("//")) {
|
|
339
|
-
body.push(line);
|
|
339
|
+
body.push({ text: line, shouldIndent: true });
|
|
340
340
|
continue;
|
|
341
341
|
}
|
|
342
342
|
// Skip empty lines when not in import
|
|
343
343
|
if (!trimmed && !inImport) {
|
|
344
|
-
body.push(line);
|
|
344
|
+
body.push({ text: line, shouldIndent: true });
|
|
345
345
|
continue;
|
|
346
346
|
}
|
|
347
347
|
// Process the line character by character to maintain string state
|
|
@@ -405,7 +405,7 @@ export function splitScript(script) {
|
|
|
405
405
|
}
|
|
406
406
|
} // Regular body content
|
|
407
407
|
else {
|
|
408
|
-
body.push(line);
|
|
408
|
+
body.push({ text: line, shouldIndent: !inString });
|
|
409
409
|
// Update global string state
|
|
410
410
|
inString = lineInString;
|
|
411
411
|
stringChar = lineStringChar;
|
|
@@ -419,11 +419,15 @@ export function splitScript(script) {
|
|
|
419
419
|
}
|
|
420
420
|
else {
|
|
421
421
|
// Still in string or incomplete, treat as body
|
|
422
|
-
|
|
422
|
+
// We can't know for sure about indentation here, but if it was part of an import or string,
|
|
423
|
+
// it likely follows previous logic. For safety, if we are in string, don't indent.
|
|
424
|
+
for (const l of currentImport) {
|
|
425
|
+
body.push({ text: l, shouldIndent: !inString });
|
|
426
|
+
}
|
|
423
427
|
}
|
|
424
428
|
}
|
|
425
429
|
return {
|
|
426
430
|
imports: imports.filter((imp) => imp.trim()),
|
|
427
|
-
body: body.length > 0 ? body : [""],
|
|
431
|
+
body: body.length > 0 ? body : [{ text: "", shouldIndent: true }],
|
|
428
432
|
};
|
|
429
433
|
}
|
package/docs/package-lock.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"name": "thyn-app",
|
|
9
9
|
"version": "0.0.0",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@thyn/core": "^0.0.
|
|
11
|
+
"@thyn/core": "^0.0.353",
|
|
12
12
|
"vite": "^6.3.5"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -742,9 +742,9 @@
|
|
|
742
742
|
]
|
|
743
743
|
},
|
|
744
744
|
"node_modules/@thyn/core": {
|
|
745
|
-
"version": "0.0.
|
|
746
|
-
"resolved": "https://registry.npmjs.org/@thyn/core/-/core-0.0.
|
|
747
|
-
"integrity": "sha512-
|
|
745
|
+
"version": "0.0.353",
|
|
746
|
+
"resolved": "https://registry.npmjs.org/@thyn/core/-/core-0.0.353.tgz",
|
|
747
|
+
"integrity": "sha512-vg8X99bz1H+cCJtwPY8chIRBiRA+R26uI5XOOqXxL+jW2qWzZd7PID0EzkYi3zbfbCX0I3u5A+kfjbBJucFYAw==",
|
|
748
748
|
"dev": true,
|
|
749
749
|
"license": "MIT",
|
|
750
750
|
"dependencies": {
|
package/docs/package.json
CHANGED
package/docs/src/pages/Home.thyn
CHANGED
|
@@ -49,11 +49,7 @@ mount(App, document.body);`;
|
|
|
49
49
|
<div class="compiled-wrapper">
|
|
50
50
|
<div>
|
|
51
51
|
<h4>source</h4>
|
|
52
|
-
<pre>
|
|
53
|
-
<code class="code language-javascript">
|
|
54
|
-
{{ codeSnippet }}
|
|
55
|
-
</code>
|
|
56
|
-
</pre>
|
|
52
|
+
<pre><code class="code language-javascript">{{ codeSnippet }}</code></pre>
|
|
57
53
|
</div>
|
|
58
54
|
<div>
|
|
59
55
|
<h4>compiled</h4>
|
package/package.json
CHANGED
package/src/plugin/index.ts
CHANGED
|
@@ -977,7 +977,7 @@ export async function transformSFC(source: string, id: string) {
|
|
|
977
977
|
s.append([
|
|
978
978
|
"",
|
|
979
979
|
`export default function ${name}($props) {`,
|
|
980
|
-
...body.map((l) => " " + l),
|
|
980
|
+
...body.map((l: any) => (l.shouldIndent ? " " + l.text : l.text)),
|
|
981
981
|
removeUnusedThynVars(` ${transformed} return ${root};`),
|
|
982
982
|
`}`,
|
|
983
983
|
].join("\n"));
|
package/src/plugin/utils.ts
CHANGED
|
@@ -304,7 +304,7 @@ export function splitScript(script: string) {
|
|
|
304
304
|
if (inImport) {
|
|
305
305
|
currentImport.push(line);
|
|
306
306
|
} else {
|
|
307
|
-
body.push(line);
|
|
307
|
+
body.push({ text: line, shouldIndent: true });
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
// Check for end of multi-line comment, tracking strings
|
|
@@ -338,7 +338,7 @@ export function splitScript(script: string) {
|
|
|
338
338
|
if (inImport) {
|
|
339
339
|
currentImport.push(line);
|
|
340
340
|
} else {
|
|
341
|
-
body.push(line);
|
|
341
|
+
body.push({ text: line, shouldIndent: !inString });
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
// Check if comment ends on same line
|
|
@@ -372,13 +372,13 @@ export function splitScript(script: string) {
|
|
|
372
372
|
|
|
373
373
|
// Skip single-line comments when not in import (only if not in string)
|
|
374
374
|
if (!inString && !inImport && trimmed.startsWith("//")) {
|
|
375
|
-
body.push(line);
|
|
375
|
+
body.push({ text: line, shouldIndent: true });
|
|
376
376
|
continue;
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
// Skip empty lines when not in import
|
|
380
380
|
if (!trimmed && !inImport) {
|
|
381
|
-
body.push(line);
|
|
381
|
+
body.push({ text: line, shouldIndent: true });
|
|
382
382
|
continue;
|
|
383
383
|
}
|
|
384
384
|
|
|
@@ -451,7 +451,7 @@ export function splitScript(script: string) {
|
|
|
451
451
|
}
|
|
452
452
|
} // Regular body content
|
|
453
453
|
else {
|
|
454
|
-
body.push(line);
|
|
454
|
+
body.push({ text: line, shouldIndent: !inString });
|
|
455
455
|
// Update global string state
|
|
456
456
|
inString = lineInString;
|
|
457
457
|
stringChar = lineStringChar;
|
|
@@ -465,12 +465,16 @@ export function splitScript(script: string) {
|
|
|
465
465
|
imports.push(currentImport.join("\n"));
|
|
466
466
|
} else {
|
|
467
467
|
// Still in string or incomplete, treat as body
|
|
468
|
-
|
|
468
|
+
// We can't know for sure about indentation here, but if it was part of an import or string,
|
|
469
|
+
// it likely follows previous logic. For safety, if we are in string, don't indent.
|
|
470
|
+
for(const l of currentImport) {
|
|
471
|
+
body.push({ text: l, shouldIndent: !inString });
|
|
472
|
+
}
|
|
469
473
|
}
|
|
470
474
|
}
|
|
471
475
|
|
|
472
476
|
return {
|
|
473
477
|
imports: imports.filter((imp) => imp.trim()),
|
|
474
|
-
body: body.length > 0 ? body : [""],
|
|
478
|
+
body: body.length > 0 ? body : [{ text: "", shouldIndent: true }],
|
|
475
479
|
};
|
|
476
480
|
}
|
|
@@ -16,6 +16,17 @@ describe("CodeSnippet component", () => {
|
|
|
16
16
|
expect(display.textContent).toContain("button {");
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
it("should not add extra indentation to template literals", () => {
|
|
20
|
+
const root = CodeSnippet();
|
|
21
|
+
const display = root.querySelector('.display');
|
|
22
|
+
const text = display.textContent;
|
|
23
|
+
|
|
24
|
+
// Check that <script> is at the start of the line (no extra indentation)
|
|
25
|
+
expect(text).toContain("\n<script>");
|
|
26
|
+
// Check that const count has exactly 2 spaces (as in source), not 4
|
|
27
|
+
expect(text).toContain("\n const count");
|
|
28
|
+
});
|
|
29
|
+
|
|
19
30
|
it("should apply the component's actual style, not style from codeSnippet", () => {
|
|
20
31
|
const root = CodeSnippet();
|
|
21
32
|
const display = root.querySelector('.display');
|