@marko/language-tools 2.5.12 → 2.5.14

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.
@@ -9,11 +9,13 @@ export interface ProgramScope {
9
9
  parent: undefined;
10
10
  hoists: false;
11
11
  bindings: Bindings;
12
+ mutatedBindings: undefined | Set<VarBinding>;
12
13
  }
13
14
  export interface TagScope {
14
15
  parent: Scope;
15
16
  hoists: boolean;
16
17
  bindings: undefined | Bindings;
18
+ mutatedBindings: undefined | Set<VarBinding>;
17
19
  }
18
20
  export type Binding = VarBinding | ParamBinding | HoistedBinding;
19
21
  export interface VarBinding {
@@ -53,7 +55,7 @@ type Bindings = {
53
55
  export declare function crawlProgramScope(parsed: Parsed, scriptParser: ScriptParser): [number, ...number[]] | [...number[], number] | undefined;
54
56
  export declare function getHoists(node: Node.Program): Repeatable<string>;
55
57
  export declare function getHoistSources(node: Node.ParentNode): Repeatable<string>;
56
- export declare function getMutatedVars(node: Node.ParentNode): Repeatable<VarBinding>;
58
+ export declare function getMutatedVars(node: Node.ParentNode): Set<VarBinding> | undefined;
57
59
  export declare function isMutatedVar(node: Node.ParentNode, name: string): boolean;
58
60
  export declare function hasHoists(node: Node.ParentTag): boolean;
59
61
  export declare function getBoundAttrMemberExpressionStartOffset(value: Node.AttrValue): number | undefined;
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  NodeType: () => NodeType,
34
34
  Processors: () => processors_exports,
35
35
  Project: () => project_exports,
@@ -46,7 +46,7 @@ __export(src_exports, {
46
46
  isDefinitionFile: () => isDefinitionFile,
47
47
  parse: () => parse
48
48
  });
49
- module.exports = __toCommonJS(src_exports);
49
+ module.exports = __toCommonJS(index_exports);
50
50
 
51
51
  // src/parser.ts
52
52
  var import_htmljs_parser = require("htmljs-parser");
@@ -1083,7 +1083,8 @@ function crawlProgramScope(parsed, scriptParser) {
1083
1083
  const programScope = {
1084
1084
  parent: void 0,
1085
1085
  hoists: false,
1086
- bindings: {}
1086
+ bindings: {},
1087
+ mutatedBindings: void 0
1087
1088
  };
1088
1089
  programScope.bindings.input = {
1089
1090
  type: 0 /* var */,
@@ -1178,7 +1179,8 @@ function crawlProgramScope(parsed, scriptParser) {
1178
1179
  const bodyScope = {
1179
1180
  parent: parentScope,
1180
1181
  hoists: false,
1181
- bindings: {}
1182
+ bindings: {},
1183
+ mutatedBindings: void 0
1182
1184
  };
1183
1185
  if (child.params) {
1184
1186
  bodyScope.bindings ??= {};
@@ -1249,6 +1251,9 @@ ${read({
1249
1251
  );
1250
1252
  if (binding) {
1251
1253
  binding.mutated = true;
1254
+ (parentScope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(
1255
+ binding
1256
+ );
1252
1257
  }
1253
1258
  }
1254
1259
  break;
@@ -1333,24 +1338,16 @@ function getHoistSources(node) {
1333
1338
  return result;
1334
1339
  }
1335
1340
  function getMutatedVars(node) {
1336
- let result;
1337
- const { bindings } = Scopes.get(node.body);
1338
- for (const key in bindings) {
1339
- const binding = bindings[key];
1340
- if (binding.type === 0 /* var */ && binding.mutated) {
1341
- if (result) {
1342
- result.push(binding);
1343
- } else {
1344
- result = [binding];
1345
- }
1346
- }
1347
- }
1348
- return result;
1341
+ return Scopes.get(node.body).mutatedBindings;
1349
1342
  }
1350
1343
  function isMutatedVar(node, name) {
1351
- const { bindings } = Scopes.get(node.body);
1352
- const binding = bindings == null ? void 0 : bindings[name];
1353
- return (binding == null ? void 0 : binding.type) === 0 /* var */ && binding.mutated;
1344
+ const { mutatedBindings } = Scopes.get(node.body);
1345
+ if (mutatedBindings) {
1346
+ for (const binding of mutatedBindings) {
1347
+ if (binding.name === name) return true;
1348
+ }
1349
+ }
1350
+ return false;
1354
1351
  }
1355
1352
  function hasHoists(node) {
1356
1353
  return node.body ? Scopes.get(node.body).hoists : false;
@@ -1600,6 +1597,7 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
1600
1597
  if (binding) {
1601
1598
  binding.mutated = true;
1602
1599
  mutations.push(start);
1600
+ (scope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(binding);
1603
1601
  }
1604
1602
  }
1605
1603
  }
@@ -1994,7 +1992,7 @@ var ScriptExtractor = class {
1994
1992
  }
1995
1993
  #writeProgram(program) {
1996
1994
  this.#writeCommentPragmas(program);
1997
- const componentFileName = getComponentFilename(this.#filename);
1995
+ const componentFileName = this.#api !== RuntimeAPI.tags ? getComponentFilename(this.#filename) : void 0;
1998
1996
  const inputType = this.#getInputType(program);
1999
1997
  let componentClassBody;
2000
1998
  for (const node of program.static) {
@@ -2084,35 +2082,37 @@ var ScriptExtractor = class {
2084
2082
  );
2085
2083
  }
2086
2084
  }
2087
- if (isExternalComponentFile) {
2088
- if (this.#scriptLang === "ts" /* ts */) {
2089
- this.#extractor.write(
2090
- `import type Component from "${stripExt(
2091
- (0, import_relative_import_path.relativeImportPath)(this.#filename, componentFileName)
2092
- )}";
2085
+ if (this.#api !== RuntimeAPI.tags) {
2086
+ if (isExternalComponentFile) {
2087
+ if (this.#scriptLang === "ts" /* ts */) {
2088
+ this.#extractor.write(
2089
+ `import type Component from "${stripExt(
2090
+ (0, import_relative_import_path.relativeImportPath)(this.#filename, componentFileName)
2091
+ )}";
2093
2092
  `
2094
- );
2095
- } else {
2096
- this.#extractor.write(
2097
- `/** @typedef {import("${stripExt(
2098
- (0, import_relative_import_path.relativeImportPath)(this.#filename, componentFileName)
2099
- )}") extends infer Component ? Component extends { default: infer Component } ? Component : Component : never} Component */
2093
+ );
2094
+ } else {
2095
+ this.#extractor.write(
2096
+ `/** @typedef {import("${stripExt(
2097
+ (0, import_relative_import_path.relativeImportPath)(this.#filename, componentFileName)
2098
+ )}") extends infer Component ? Component extends { default: infer Component } ? Component : Component : never} Component */
2100
2099
  `
2101
- );
2102
- }
2103
- } else {
2104
- const body2 = componentClassBody || " {}";
2105
- if (this.#scriptLang === "ts" /* ts */) {
2106
- this.#extractor.write(
2107
- `abstract class Component${typeParamsStr} extends Marko.Component<Input${typeArgsStr}>`
2108
- ).copy(body2).write("\nexport { type Component }\n");
2100
+ );
2101
+ }
2109
2102
  } else {
2110
- this.#extractor.write(`/**${jsDocTemplateTagsStr}
2111
- * @extends {Marko.Component<Input${typeArgsStr}>}
2112
- * @abstract
2113
- */
2103
+ const body2 = componentClassBody || " {}";
2104
+ if (this.#scriptLang === "ts" /* ts */) {
2105
+ this.#extractor.write(
2106
+ `abstract class Component${typeParamsStr} extends Marko.Component<Input${typeArgsStr}>`
2107
+ ).copy(body2).write("\nexport { type Component }\n");
2108
+ } else {
2109
+ this.#extractor.write(`/**${jsDocTemplateTagsStr}
2110
+ * @extends {Marko.Component<Input${typeArgsStr}>}
2111
+ * @abstract
2112
+ */
2114
2113
  `);
2115
- this.#extractor.write(`export class Component extends Marko.Component`).copy(body2).write("\n");
2114
+ this.#extractor.write(`export class Component extends Marko.Component`).copy(body2).write("\n");
2115
+ }
2116
2116
  }
2117
2117
  }
2118
2118
  const didReturn = !!getReturnTag(program);
@@ -2132,16 +2132,16 @@ var ScriptExtractor = class {
2132
2132
  function ${templateName}() {
2133
2133
  `);
2134
2134
  }
2135
- this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};
2135
+ this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api !== RuntimeAPI.tags ? `
2136
2136
  const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
2137
2137
  const state = ${varShared("state")}(component);
2138
+ const out = ${varShared("out")};` : ""}
2138
2139
  const $signal = ${this.#getCastedType("AbortSignal")};
2139
2140
  const $global = ${varShared("getGlobal")}(
2140
2141
  // @ts-expect-error We expect the compiler to error because we are checking if the MarkoRun.Context is defined.
2141
2142
  (${varShared("error")}, ${this.#getCastedType("MarkoRun.Context")})
2142
2143
  );
2143
- const out = ${varShared("out")};
2144
- ${varShared("noop")}({ input, component, state, out, $global, $signal });
2144
+ ${varShared("noop")}({ ${this.#api !== RuntimeAPI.tags ? "component, state, out, " : ""}input, $global, $signal });
2145
2145
  `);
2146
2146
  const body = this.#processBody(program);
2147
2147
  if (body == null ? void 0 : body.content) {
@@ -2613,7 +2613,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
2613
2613
  }
2614
2614
  } else if (attr.args) {
2615
2615
  this.#extractor.write('"').copy(name).write('": ');
2616
- if (typeof name !== "string" && this.#read(name).startsWith("on")) {
2616
+ if (this.#api !== RuntimeAPI.tags && typeof name !== "string" && this.#read(name).startsWith("on")) {
2617
2617
  const stringLiteralFirstArgMatch = this.#execAtIndex(
2618
2618
  REG_ATTR_ARG_LITERAL,
2619
2619
  attr.args.value.start
package/dist/index.mjs CHANGED
@@ -1043,7 +1043,8 @@ function crawlProgramScope(parsed, scriptParser) {
1043
1043
  const programScope = {
1044
1044
  parent: void 0,
1045
1045
  hoists: false,
1046
- bindings: {}
1046
+ bindings: {},
1047
+ mutatedBindings: void 0
1047
1048
  };
1048
1049
  programScope.bindings.input = {
1049
1050
  type: 0 /* var */,
@@ -1138,7 +1139,8 @@ function crawlProgramScope(parsed, scriptParser) {
1138
1139
  const bodyScope = {
1139
1140
  parent: parentScope,
1140
1141
  hoists: false,
1141
- bindings: {}
1142
+ bindings: {},
1143
+ mutatedBindings: void 0
1142
1144
  };
1143
1145
  if (child.params) {
1144
1146
  bodyScope.bindings ??= {};
@@ -1209,6 +1211,9 @@ ${read({
1209
1211
  );
1210
1212
  if (binding) {
1211
1213
  binding.mutated = true;
1214
+ (parentScope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(
1215
+ binding
1216
+ );
1212
1217
  }
1213
1218
  }
1214
1219
  break;
@@ -1293,24 +1298,16 @@ function getHoistSources(node) {
1293
1298
  return result;
1294
1299
  }
1295
1300
  function getMutatedVars(node) {
1296
- let result;
1297
- const { bindings } = Scopes.get(node.body);
1298
- for (const key in bindings) {
1299
- const binding = bindings[key];
1300
- if (binding.type === 0 /* var */ && binding.mutated) {
1301
- if (result) {
1302
- result.push(binding);
1303
- } else {
1304
- result = [binding];
1305
- }
1306
- }
1307
- }
1308
- return result;
1301
+ return Scopes.get(node.body).mutatedBindings;
1309
1302
  }
1310
1303
  function isMutatedVar(node, name) {
1311
- const { bindings } = Scopes.get(node.body);
1312
- const binding = bindings == null ? void 0 : bindings[name];
1313
- return (binding == null ? void 0 : binding.type) === 0 /* var */ && binding.mutated;
1304
+ const { mutatedBindings } = Scopes.get(node.body);
1305
+ if (mutatedBindings) {
1306
+ for (const binding of mutatedBindings) {
1307
+ if (binding.name === name) return true;
1308
+ }
1309
+ }
1310
+ return false;
1314
1311
  }
1315
1312
  function hasHoists(node) {
1316
1313
  return node.body ? Scopes.get(node.body).hoists : false;
@@ -1560,6 +1557,7 @@ function trackMutations(node, scope, mutations, parentBlock, parentBlockShadows,
1560
1557
  if (binding) {
1561
1558
  binding.mutated = true;
1562
1559
  mutations.push(start);
1560
+ (scope.mutatedBindings ||= /* @__PURE__ */ new Set()).add(binding);
1563
1561
  }
1564
1562
  }
1565
1563
  }
@@ -1957,7 +1955,7 @@ var ScriptExtractor = class {
1957
1955
  }
1958
1956
  #writeProgram(program) {
1959
1957
  this.#writeCommentPragmas(program);
1960
- const componentFileName = getComponentFilename(this.#filename);
1958
+ const componentFileName = this.#api !== RuntimeAPI.tags ? getComponentFilename(this.#filename) : void 0;
1961
1959
  const inputType = this.#getInputType(program);
1962
1960
  let componentClassBody;
1963
1961
  for (const node of program.static) {
@@ -2047,35 +2045,37 @@ var ScriptExtractor = class {
2047
2045
  );
2048
2046
  }
2049
2047
  }
2050
- if (isExternalComponentFile) {
2051
- if (this.#scriptLang === "ts" /* ts */) {
2052
- this.#extractor.write(
2053
- `import type Component from "${stripExt(
2054
- relativeImportPath(this.#filename, componentFileName)
2055
- )}";
2048
+ if (this.#api !== RuntimeAPI.tags) {
2049
+ if (isExternalComponentFile) {
2050
+ if (this.#scriptLang === "ts" /* ts */) {
2051
+ this.#extractor.write(
2052
+ `import type Component from "${stripExt(
2053
+ relativeImportPath(this.#filename, componentFileName)
2054
+ )}";
2056
2055
  `
2057
- );
2058
- } else {
2059
- this.#extractor.write(
2060
- `/** @typedef {import("${stripExt(
2061
- relativeImportPath(this.#filename, componentFileName)
2062
- )}") extends infer Component ? Component extends { default: infer Component } ? Component : Component : never} Component */
2056
+ );
2057
+ } else {
2058
+ this.#extractor.write(
2059
+ `/** @typedef {import("${stripExt(
2060
+ relativeImportPath(this.#filename, componentFileName)
2061
+ )}") extends infer Component ? Component extends { default: infer Component } ? Component : Component : never} Component */
2063
2062
  `
2064
- );
2065
- }
2066
- } else {
2067
- const body2 = componentClassBody || " {}";
2068
- if (this.#scriptLang === "ts" /* ts */) {
2069
- this.#extractor.write(
2070
- `abstract class Component${typeParamsStr} extends Marko.Component<Input${typeArgsStr}>`
2071
- ).copy(body2).write("\nexport { type Component }\n");
2063
+ );
2064
+ }
2072
2065
  } else {
2073
- this.#extractor.write(`/**${jsDocTemplateTagsStr}
2074
- * @extends {Marko.Component<Input${typeArgsStr}>}
2075
- * @abstract
2076
- */
2066
+ const body2 = componentClassBody || " {}";
2067
+ if (this.#scriptLang === "ts" /* ts */) {
2068
+ this.#extractor.write(
2069
+ `abstract class Component${typeParamsStr} extends Marko.Component<Input${typeArgsStr}>`
2070
+ ).copy(body2).write("\nexport { type Component }\n");
2071
+ } else {
2072
+ this.#extractor.write(`/**${jsDocTemplateTagsStr}
2073
+ * @extends {Marko.Component<Input${typeArgsStr}>}
2074
+ * @abstract
2075
+ */
2077
2076
  `);
2078
- this.#extractor.write(`export class Component extends Marko.Component`).copy(body2).write("\n");
2077
+ this.#extractor.write(`export class Component extends Marko.Component`).copy(body2).write("\n");
2078
+ }
2079
2079
  }
2080
2080
  }
2081
2081
  const didReturn = !!getReturnTag(program);
@@ -2095,16 +2095,16 @@ var ScriptExtractor = class {
2095
2095
  function ${templateName}() {
2096
2096
  `);
2097
2097
  }
2098
- this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};
2098
+ this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};${this.#api !== RuntimeAPI.tags ? `
2099
2099
  const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
2100
2100
  const state = ${varShared("state")}(component);
2101
+ const out = ${varShared("out")};` : ""}
2101
2102
  const $signal = ${this.#getCastedType("AbortSignal")};
2102
2103
  const $global = ${varShared("getGlobal")}(
2103
2104
  // @ts-expect-error We expect the compiler to error because we are checking if the MarkoRun.Context is defined.
2104
2105
  (${varShared("error")}, ${this.#getCastedType("MarkoRun.Context")})
2105
2106
  );
2106
- const out = ${varShared("out")};
2107
- ${varShared("noop")}({ input, component, state, out, $global, $signal });
2107
+ ${varShared("noop")}({ ${this.#api !== RuntimeAPI.tags ? "component, state, out, " : ""}input, $global, $signal });
2108
2108
  `);
2109
2109
  const body = this.#processBody(program);
2110
2110
  if (body == null ? void 0 : body.content) {
@@ -2576,7 +2576,7 @@ ${isMutatedVar(tag.parent, valueLiteral) ? `${varLocal("return")}.mutate.` : ""}
2576
2576
  }
2577
2577
  } else if (attr.args) {
2578
2578
  this.#extractor.write('"').copy(name).write('": ');
2579
- if (typeof name !== "string" && this.#read(name).startsWith("on")) {
2579
+ if (this.#api !== RuntimeAPI.tags && typeof name !== "string" && this.#read(name).startsWith("on")) {
2580
2580
  const stringLiteralFirstArgMatch = this.#execAtIndex(
2581
2581
  REG_ATTR_ARG_LITERAL,
2582
2582
  attr.args.value.start
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.5.12",
4
+ "version": "2.5.14",
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"
8
8
  },
9
9
  "dependencies": {
10
- "@babel/parser": "^7.26.3",
11
- "@luxass/strip-json-comments": "^1.3.2",
10
+ "@babel/parser": "^7.26.7",
11
+ "@luxass/strip-json-comments": "^1.4.0",
12
12
  "htmljs-parser": "^5.5.3",
13
13
  "relative-import-path": "^1.0.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@babel/code-frame": "^7.26.2",
17
- "@marko/compiler": "^5.39.6",
17
+ "@marko/compiler": "^5.39.11",
18
18
  "@types/babel__code-frame": "^7.0.6",
19
19
  "@typescript/vfs": "^1.6.0",
20
- "marko": "^5.37.7",
21
- "mitata": "^1.0.21",
20
+ "marko": "^5.37.12",
21
+ "mitata": "^1.0.33",
22
22
  "tsx": "^4.19.2"
23
23
  },
24
24
  "exports": {