@marko/language-tools 2.5.1 → 2.5.3
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/dist/extractors/script/util/is-text-only-script.d.ts +7 -0
- package/dist/index.js +39 -24
- package/dist/index.mjs +36 -21
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1055,6 +1055,21 @@ var import_relative_import_path = require("relative-import-path");
|
|
|
1055
1055
|
|
|
1056
1056
|
// src/extractors/script/util/attach-scopes.ts
|
|
1057
1057
|
var t = __toESM(require("@babel/types"));
|
|
1058
|
+
|
|
1059
|
+
// src/extractors/script/util/is-text-only-script.ts
|
|
1060
|
+
function isTextOnlyScript(tag) {
|
|
1061
|
+
if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
for (const child of tag.body) {
|
|
1065
|
+
if (child.type !== 17 /* Text */) {
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return true;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// src/extractors/script/util/attach-scopes.ts
|
|
1058
1073
|
var ATTR_UNAMED = "value";
|
|
1059
1074
|
var Scopes = /* @__PURE__ */ new WeakMap();
|
|
1060
1075
|
var BoundAttrMemberExpressionStartOffsets = /* @__PURE__ */ new WeakMap();
|
|
@@ -1185,12 +1200,12 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1185
1200
|
}
|
|
1186
1201
|
}
|
|
1187
1202
|
}
|
|
1188
|
-
if (child
|
|
1203
|
+
if (isTextOnlyScript(child)) {
|
|
1189
1204
|
checkForMutations(
|
|
1190
1205
|
parentScope,
|
|
1191
1206
|
scriptParser.expressionAt(
|
|
1192
|
-
child.body[0].start - "()=>{\n".length,
|
|
1193
|
-
`()=>{
|
|
1207
|
+
child.body[0].start - "async ()=>{\n".length,
|
|
1208
|
+
`async ()=>{
|
|
1194
1209
|
${read({
|
|
1195
1210
|
start: child.body[0].start,
|
|
1196
1211
|
end: child.body[child.body.length - 1].end
|
|
@@ -1743,7 +1758,7 @@ function getRuntimeOverrides(runtimeTypes, generics, applyGenerics) {
|
|
|
1743
1758
|
}
|
|
1744
1759
|
|
|
1745
1760
|
// src/extractors/script/util/script-parser.ts
|
|
1746
|
-
var
|
|
1761
|
+
var import_parser6 = require("@babel/parser");
|
|
1747
1762
|
var plugins = [
|
|
1748
1763
|
"exportDefaultFrom",
|
|
1749
1764
|
"importAssertions",
|
|
@@ -1757,7 +1772,7 @@ var ScriptParser = class {
|
|
|
1757
1772
|
statementAt(startIndex, src) {
|
|
1758
1773
|
const pos = this.#parsed.positionAt(startIndex);
|
|
1759
1774
|
try {
|
|
1760
|
-
return (0,
|
|
1775
|
+
return (0, import_parser6.parse)(src, {
|
|
1761
1776
|
plugins,
|
|
1762
1777
|
startIndex,
|
|
1763
1778
|
startLine: pos.line + 1,
|
|
@@ -1778,7 +1793,7 @@ var ScriptParser = class {
|
|
|
1778
1793
|
expressionAt(startIndex, src) {
|
|
1779
1794
|
const pos = this.#parsed.positionAt(startIndex);
|
|
1780
1795
|
try {
|
|
1781
|
-
return (0,
|
|
1796
|
+
return (0, import_parser6.parseExpression)(src, {
|
|
1782
1797
|
plugins,
|
|
1783
1798
|
startIndex,
|
|
1784
1799
|
startLine: pos.line + 1,
|
|
@@ -2673,17 +2688,25 @@ const attrTags = ${varShared(
|
|
|
2673
2688
|
if (this.#writeAttrs(tag)) {
|
|
2674
2689
|
hasInput = true;
|
|
2675
2690
|
}
|
|
2676
|
-
const isScript = tag
|
|
2677
|
-
const body = !isScript ? this.#processBody(tag) : void 0;
|
|
2691
|
+
const isScript = isTextOnlyScript(tag);
|
|
2678
2692
|
let hasRenderBody = false;
|
|
2693
|
+
let body;
|
|
2679
2694
|
if (isScript) {
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2695
|
+
this.#extractor.write("async value(){");
|
|
2696
|
+
this.#copyWithMutationsReplaced({
|
|
2697
|
+
start: tag.body[0].start,
|
|
2698
|
+
end: tag.body[tag.body.length - 1].end
|
|
2699
|
+
});
|
|
2700
|
+
this.#extractor.write(`}${SEP_COMMA_NEW_LINE}`);
|
|
2701
|
+
} else {
|
|
2702
|
+
body = this.#processBody(tag);
|
|
2703
|
+
if (body) {
|
|
2704
|
+
hasInput = true;
|
|
2705
|
+
this.#writeAttrTags(body, false, nestedTagType);
|
|
2706
|
+
hasRenderBody = body.renderBody !== void 0;
|
|
2707
|
+
} else if (tag.close) {
|
|
2708
|
+
hasRenderBody = true;
|
|
2709
|
+
}
|
|
2687
2710
|
}
|
|
2688
2711
|
if (tag.params || hasRenderBody) {
|
|
2689
2712
|
this.#extractor.write('["renderBody"');
|
|
@@ -2700,15 +2723,7 @@ const attrTags = ${varShared(
|
|
|
2700
2723
|
`);
|
|
2701
2724
|
}
|
|
2702
2725
|
let didReturn = false;
|
|
2703
|
-
if (
|
|
2704
|
-
if (tag.body) {
|
|
2705
|
-
this.#copyWithMutationsReplaced({
|
|
2706
|
-
start: tag.body[0].start,
|
|
2707
|
-
end: tag.body[tag.body.length - 1].end
|
|
2708
|
-
});
|
|
2709
|
-
didReturn = this.#writeChildren(tag, []);
|
|
2710
|
-
}
|
|
2711
|
-
} else if (body == null ? void 0 : body.renderBody) {
|
|
2726
|
+
if (body == null ? void 0 : body.renderBody) {
|
|
2712
2727
|
didReturn = this.#writeChildren(tag, body.renderBody);
|
|
2713
2728
|
}
|
|
2714
2729
|
if (!tag.params) {
|
package/dist/index.mjs
CHANGED
|
@@ -1016,6 +1016,21 @@ import { relativeImportPath } from "relative-import-path";
|
|
|
1016
1016
|
|
|
1017
1017
|
// src/extractors/script/util/attach-scopes.ts
|
|
1018
1018
|
import * as t from "@babel/types";
|
|
1019
|
+
|
|
1020
|
+
// src/extractors/script/util/is-text-only-script.ts
|
|
1021
|
+
function isTextOnlyScript(tag) {
|
|
1022
|
+
if (tag.nameText !== "script" || tag.args || tag.attrs || !tag.body) {
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
for (const child of tag.body) {
|
|
1026
|
+
if (child.type !== 17 /* Text */) {
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// src/extractors/script/util/attach-scopes.ts
|
|
1019
1034
|
var ATTR_UNAMED = "value";
|
|
1020
1035
|
var Scopes = /* @__PURE__ */ new WeakMap();
|
|
1021
1036
|
var BoundAttrMemberExpressionStartOffsets = /* @__PURE__ */ new WeakMap();
|
|
@@ -1146,12 +1161,12 @@ function crawlProgramScope(parsed, scriptParser) {
|
|
|
1146
1161
|
}
|
|
1147
1162
|
}
|
|
1148
1163
|
}
|
|
1149
|
-
if (child
|
|
1164
|
+
if (isTextOnlyScript(child)) {
|
|
1150
1165
|
checkForMutations(
|
|
1151
1166
|
parentScope,
|
|
1152
1167
|
scriptParser.expressionAt(
|
|
1153
|
-
child.body[0].start - "()=>{\n".length,
|
|
1154
|
-
`()=>{
|
|
1168
|
+
child.body[0].start - "async ()=>{\n".length,
|
|
1169
|
+
`async ()=>{
|
|
1155
1170
|
${read({
|
|
1156
1171
|
start: child.body[0].start,
|
|
1157
1172
|
end: child.body[child.body.length - 1].end
|
|
@@ -2637,17 +2652,25 @@ const attrTags = ${varShared(
|
|
|
2637
2652
|
if (this.#writeAttrs(tag)) {
|
|
2638
2653
|
hasInput = true;
|
|
2639
2654
|
}
|
|
2640
|
-
const isScript = tag
|
|
2641
|
-
const body = !isScript ? this.#processBody(tag) : void 0;
|
|
2655
|
+
const isScript = isTextOnlyScript(tag);
|
|
2642
2656
|
let hasRenderBody = false;
|
|
2657
|
+
let body;
|
|
2643
2658
|
if (isScript) {
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2659
|
+
this.#extractor.write("async value(){");
|
|
2660
|
+
this.#copyWithMutationsReplaced({
|
|
2661
|
+
start: tag.body[0].start,
|
|
2662
|
+
end: tag.body[tag.body.length - 1].end
|
|
2663
|
+
});
|
|
2664
|
+
this.#extractor.write(`}${SEP_COMMA_NEW_LINE}`);
|
|
2665
|
+
} else {
|
|
2666
|
+
body = this.#processBody(tag);
|
|
2667
|
+
if (body) {
|
|
2668
|
+
hasInput = true;
|
|
2669
|
+
this.#writeAttrTags(body, false, nestedTagType);
|
|
2670
|
+
hasRenderBody = body.renderBody !== void 0;
|
|
2671
|
+
} else if (tag.close) {
|
|
2672
|
+
hasRenderBody = true;
|
|
2673
|
+
}
|
|
2651
2674
|
}
|
|
2652
2675
|
if (tag.params || hasRenderBody) {
|
|
2653
2676
|
this.#extractor.write('["renderBody"');
|
|
@@ -2664,15 +2687,7 @@ const attrTags = ${varShared(
|
|
|
2664
2687
|
`);
|
|
2665
2688
|
}
|
|
2666
2689
|
let didReturn = false;
|
|
2667
|
-
if (
|
|
2668
|
-
if (tag.body) {
|
|
2669
|
-
this.#copyWithMutationsReplaced({
|
|
2670
|
-
start: tag.body[0].start,
|
|
2671
|
-
end: tag.body[tag.body.length - 1].end
|
|
2672
|
-
});
|
|
2673
|
-
didReturn = this.#writeChildren(tag, []);
|
|
2674
|
-
}
|
|
2675
|
-
} else if (body == null ? void 0 : body.renderBody) {
|
|
2690
|
+
if (body == null ? void 0 : body.renderBody) {
|
|
2676
2691
|
didReturn = this.#writeChildren(tag, body.renderBody);
|
|
2677
2692
|
}
|
|
2678
2693
|
if (!tag.params) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/language-tools",
|
|
3
3
|
"description": "Marko Language Tools",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.3",
|
|
5
5
|
"bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@marko/compiler": "^5.28.4"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@babel/code-frame": "^7.26.2",
|
|
17
|
-
"@marko/compiler": "^5.38.
|
|
17
|
+
"@marko/compiler": "^5.38.4",
|
|
18
18
|
"@marko/translator-default": "^6.1.2",
|
|
19
19
|
"@types/babel__code-frame": "^7.0.6",
|
|
20
20
|
"@typescript/vfs": "^1.6.0",
|