@player-tools/typescript-expression-plugin 0.4.2-next.1 → 0.5.0-next.0

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.
@@ -1,15 +1,18 @@
1
- import { decorateWithTemplateLanguageService } from 'typescript-template-language-service-decorator';
2
- import * as ts from 'typescript/lib/tsserverlibrary';
3
- import { createTSDocString } from '@player-tools/xlr-utils';
4
- import { simpleTransformGenerator, XLRSDK } from '@player-tools/xlr-sdk';
5
- import { parseExpression } from '@player-ui/player';
6
- import { parseTree } from 'jsonc-parser';
1
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/index.ts
2
+ import { decorateWithTemplateLanguageService } from "typescript-template-language-service-decorator";
7
3
 
4
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/service.ts
5
+ import ts from "typescript/lib/tsserverlibrary";
6
+ import { createTSDocString } from "@player-tools/xlr-utils";
7
+ import { XLRSDK } from "@player-tools/xlr-sdk";
8
+ import { parseExpression } from "@player-ui/player";
9
+
10
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/utils.ts
11
+ import { parseTree } from "jsonc-parser";
8
12
  function isInRange(position, location) {
9
13
  return position.character >= location.start.character && position.character <= location.end.character;
10
14
  }
11
15
  function getTokenAtPosition(node, position) {
12
- var _a;
13
16
  if (node.type === "CallExpression") {
14
17
  const anyArgs = node.args.find((arg) => {
15
18
  return getTokenAtPosition(arg, position);
@@ -23,7 +26,7 @@ function getTokenAtPosition(node, position) {
23
26
  }
24
27
  }
25
28
  if (node.type === "Assignment") {
26
- const asTarget = (_a = getTokenAtPosition(node.left, position)) != null ? _a : getTokenAtPosition(node.right, position);
29
+ const asTarget = getTokenAtPosition(node.left, position) ?? getTokenAtPosition(node.right, position);
27
30
  if (asTarget) {
28
31
  return asTarget;
29
32
  }
@@ -33,9 +36,8 @@ function getTokenAtPosition(node, position) {
33
36
  }
34
37
  }
35
38
  function toTSLocation(node) {
36
- var _a, _b;
37
- const start = (_a = node.location) == null ? void 0 : _a.start.character;
38
- const end = (_b = node.location) == null ? void 0 : _b.end.character;
39
+ const start = node.location?.start.character;
40
+ const end = node.location?.end.character;
39
41
  if (start === void 0 || end === void 0) {
40
42
  return {
41
43
  start: 0,
@@ -69,72 +71,41 @@ function convertExprToJSONNode(exprNode) {
69
71
  return parseTree(JSON.stringify(val));
70
72
  }
71
73
 
72
- var __defProp$1 = Object.defineProperty;
73
- var __defProps$1 = Object.defineProperties;
74
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
75
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
76
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
77
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
78
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
79
- var __spreadValues$1 = (a, b) => {
80
- for (var prop in b || (b = {}))
81
- if (__hasOwnProp$1.call(b, prop))
82
- __defNormalProp$1(a, prop, b[prop]);
83
- if (__getOwnPropSymbols$1)
84
- for (var prop of __getOwnPropSymbols$1(b)) {
85
- if (__propIsEnum$1.call(b, prop))
86
- __defNormalProp$1(a, prop, b[prop]);
74
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/transforms.ts
75
+ import { simpleTransformGenerator } from "@player-tools/xlr-sdk";
76
+ var toFunction = simpleTransformGenerator(
77
+ "ref",
78
+ "Expressions",
79
+ (exp) => {
80
+ if (!exp.genericArguments || exp.ref !== "ExpressionHandler") {
81
+ return exp;
87
82
  }
88
- return a;
89
- };
90
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
91
- const toFunction = simpleTransformGenerator("ref", "Expressions", (exp) => {
92
- if (!exp.genericArguments || exp.ref !== "ExpressionHandler") {
93
- return exp;
94
- }
95
- const [args, returnType] = exp.genericArguments;
96
- const parameters = (args.type === "tuple" ? args.elementTypes : []).map((elementType, index) => {
97
- var _a, _b, _c, _d, _e, _f;
83
+ const [args, returnType] = exp.genericArguments;
84
+ const parameters = (args.type === "tuple" ? args.elementTypes : []).map((elementType, index) => {
85
+ return {
86
+ name: elementType.name ?? elementType.type.name ?? elementType.type.title ?? `arg_${index}`,
87
+ type: {
88
+ name: elementType.name ?? elementType.type.name ?? elementType.type.title ?? `arg_${index}`,
89
+ ...elementType.type
90
+ },
91
+ optional: elementType.optional === true ? elementType.optional : void 0
92
+ };
93
+ });
98
94
  return {
99
- name: (_c = (_b = (_a = elementType.name) != null ? _a : elementType.type.name) != null ? _b : elementType.type.title) != null ? _c : `arg_${index}`,
100
- type: __spreadValues$1({
101
- name: (_f = (_e = (_d = elementType.name) != null ? _d : elementType.type.name) != null ? _e : elementType.type.title) != null ? _f : `arg_${index}`
102
- }, elementType.type),
103
- optional: elementType.optional === true ? elementType.optional : void 0
95
+ ...exp,
96
+ type: "function",
97
+ parameters,
98
+ returnType
104
99
  };
105
- });
106
- return __spreadProps$1(__spreadValues$1({}, exp), {
107
- type: "function",
108
- parameters,
109
- returnType
110
- });
111
- });
100
+ }
101
+ );
112
102
 
113
- var __defProp = Object.defineProperty;
114
- var __defProps = Object.defineProperties;
115
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
116
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
117
- var __hasOwnProp = Object.prototype.hasOwnProperty;
118
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
119
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
120
- var __spreadValues = (a, b) => {
121
- for (var prop in b || (b = {}))
122
- if (__hasOwnProp.call(b, prop))
123
- __defNormalProp(a, prop, b[prop]);
124
- if (__getOwnPropSymbols)
125
- for (var prop of __getOwnPropSymbols(b)) {
126
- if (__propIsEnum.call(b, prop))
127
- __defNormalProp(a, prop, b[prop]);
128
- }
129
- return a;
130
- };
131
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
132
- class ExpressionLanguageService {
103
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/service.ts
104
+ var ExpressionLanguageService = class {
133
105
  constructor(options) {
134
106
  this._plugins = [];
135
- var _a;
136
- this.logger = options == null ? void 0 : options.logger;
137
- this._plugins = (_a = options == null ? void 0 : options.plugins) != null ? _a : [];
107
+ this.logger = options?.logger;
108
+ this._plugins = options?.plugins ?? [];
138
109
  this.xlr = new XLRSDK();
139
110
  this._plugins.forEach((p) => {
140
111
  this.xlr.loadDefinitionsFromModule(p, void 0, [toFunction]);
@@ -150,11 +121,13 @@ class ExpressionLanguageService {
150
121
  this._expressions = this.reduceExpression();
151
122
  }
152
123
  reduceExpression() {
153
- const expressions = new Map();
124
+ const expressions = /* @__PURE__ */ new Map();
154
125
  this.xlr.listTypes().forEach((type) => {
155
126
  const typeInfo = this.xlr.getTypeInfo(type.name);
156
- const source = this._plugins.find((value) => value.pluginName === (typeInfo == null ? void 0 : typeInfo.plugin));
157
- if (type.type === "function" && (typeInfo == null ? void 0 : typeInfo.capability) === "Expressions" && source) {
127
+ const source = this._plugins.find(
128
+ (value) => value.pluginName === typeInfo?.plugin
129
+ );
130
+ if (type.type === "function" && typeInfo?.capability === "Expressions" && source) {
158
131
  expressions.set(type.name, {
159
132
  name: type.name,
160
133
  description: type.description,
@@ -166,7 +139,6 @@ class ExpressionLanguageService {
166
139
  return expressions;
167
140
  }
168
141
  getCompletionsAtPosition(context, position) {
169
- var _a, _b;
170
142
  const completionInfo = {
171
143
  isGlobalCompletion: false,
172
144
  isMemberCompletion: false,
@@ -188,7 +160,7 @@ class ExpressionLanguageService {
188
160
  const line = context.text.split(/\n/g)[position.line];
189
161
  const parsed = parseExpression(line, { strict: false });
190
162
  const token = getTokenAtPosition(parsed, position);
191
- if ((token == null ? void 0 : token.type) === "Compound" && token.error) {
163
+ if (token?.type === "Compound" && token.error) {
192
164
  this._expressions.forEach((exp) => {
193
165
  completionInfo.entries.push({
194
166
  name: exp.name,
@@ -200,10 +172,12 @@ class ExpressionLanguageService {
200
172
  });
201
173
  return completionInfo;
202
174
  }
203
- if ((token == null ? void 0 : token.type) === "Identifier") {
204
- const start = (_b = (_a = token.location) == null ? void 0 : _a.start) != null ? _b : { character: 0 };
175
+ if (token?.type === "Identifier") {
176
+ const start = token.location?.start ?? { character: 0 };
205
177
  const wordFromStart = line.slice(start.character, position.character);
206
- const allCompletions = Array.from(this._expressions.keys()).filter((key) => key.startsWith(wordFromStart));
178
+ const allCompletions = Array.from(this._expressions.keys()).filter(
179
+ (key) => key.startsWith(wordFromStart)
180
+ );
207
181
  allCompletions.forEach((c) => {
208
182
  completionInfo.entries.push({
209
183
  name: c,
@@ -217,7 +191,6 @@ class ExpressionLanguageService {
217
191
  return completionInfo;
218
192
  }
219
193
  getCompletionEntryDetails(context, position, name) {
220
- var _a;
221
194
  const expression = this._expressions.get(name);
222
195
  const completionDetails = {
223
196
  name,
@@ -226,7 +199,7 @@ class ExpressionLanguageService {
226
199
  documentation: [
227
200
  {
228
201
  kind: "text",
229
- text: (_a = expression == null ? void 0 : expression.type.description) != null ? _a : ""
202
+ text: expression?.type.description ?? ""
230
203
  }
231
204
  ],
232
205
  displayParts: expression ? createTSDocString(expression.type) : []
@@ -236,13 +209,18 @@ class ExpressionLanguageService {
236
209
  getQuickInfoAtPosition(context, position) {
237
210
  const parsed = parseExpression(context.text, { strict: false });
238
211
  const token = getTokenAtPosition(parsed, position);
239
- if ((token == null ? void 0 : token.type) === "Identifier") {
212
+ if (token?.type === "Identifier") {
240
213
  const expression = this._expressions.get(token.name);
241
214
  if (expression) {
242
- const completionDetails = this.getCompletionEntryDetails(context, position, expression.name);
243
- return __spreadProps(__spreadValues({}, completionDetails), {
215
+ const completionDetails = this.getCompletionEntryDetails(
216
+ context,
217
+ position,
218
+ expression.name
219
+ );
220
+ return {
221
+ ...completionDetails,
244
222
  textSpan: toTSLocation(token)
245
- });
223
+ };
246
224
  }
247
225
  }
248
226
  return void 0;
@@ -253,13 +231,13 @@ class ExpressionLanguageService {
253
231
  if (asJsonNodeValue) {
254
232
  const xlrDiags = this.xlr.validateByType(xlrType, asJsonNodeValue);
255
233
  xlrDiags.forEach((d) => {
256
- diagnostics.push(__spreadProps(__spreadValues({
257
- file: context.node.getSourceFile()
258
- }, toTSLocation(node)), {
234
+ diagnostics.push({
235
+ file: context.node.getSourceFile(),
236
+ ...toTSLocation(node),
259
237
  messageText: d.message,
260
238
  category: ts.DiagnosticCategory.Error,
261
239
  code: 1
262
- }));
240
+ });
263
241
  });
264
242
  }
265
243
  return diagnostics;
@@ -289,23 +267,23 @@ class ExpressionLanguageService {
289
267
  if (expectedArgs.length > actualArgs.length) {
290
268
  const requiredArgs = expectedArgs.filter((a) => !a.optional);
291
269
  if (actualArgs.length < requiredArgs.length) {
292
- diags.push(__spreadProps(__spreadValues({
270
+ diags.push({
293
271
  category: ts.DiagnosticCategory.Error,
294
272
  code: 1,
295
- file: context.node.getSourceFile()
296
- }, toTSLocation(node.callTarget)), {
273
+ file: context.node.getSourceFile(),
274
+ ...toTSLocation(node.callTarget),
297
275
  messageText: `Expected ${requiredArgs.length} argument(s), got ${actualArgs.length}`
298
- }));
276
+ });
299
277
  }
300
278
  }
301
279
  } else {
302
- diags.push(__spreadProps(__spreadValues({
280
+ diags.push({
303
281
  category: ts.DiagnosticCategory.Error,
304
282
  code: 1,
305
- file: context.node.getSourceFile()
306
- }, toTSLocation(node.callTarget)), {
283
+ file: context.node.getSourceFile(),
284
+ ...toTSLocation(node.callTarget),
307
285
  messageText: `Unknown expression ${exprName}`
308
- }));
286
+ });
309
287
  }
310
288
  }
311
289
  return diags;
@@ -321,29 +299,31 @@ class ExpressionLanguageService {
321
299
  const parsed = parseExpression(context.text.trim(), { strict: false });
322
300
  if (parsed.error) {
323
301
  return [
324
- __spreadProps(__spreadValues({
302
+ {
325
303
  category: ts.DiagnosticCategory.Error,
326
304
  code: 1,
327
- file: context.node.getSourceFile()
328
- }, toTSLocation(parsed)), {
305
+ file: context.node.getSourceFile(),
306
+ ...toTSLocation(parsed),
329
307
  messageText: parsed.error.message
330
- })
308
+ }
331
309
  ];
332
310
  }
333
311
  return [];
334
312
  }
335
- }
313
+ };
336
314
 
337
- class LSPLogger {
315
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/logger.ts
316
+ var LSPLogger = class {
338
317
  constructor(info) {
339
318
  this.info = info;
340
319
  }
341
320
  log(msg) {
342
321
  this.info.project.projectService.logger.info(`[player-expr-lsp] ${msg}`);
343
322
  }
344
- }
323
+ };
345
324
 
346
- class Plugin {
325
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/index.ts
326
+ var Plugin = class {
347
327
  constructor(initOptions) {
348
328
  this.initOptions = initOptions;
349
329
  }
@@ -352,19 +332,27 @@ class Plugin {
352
332
  this.logger = logger;
353
333
  const templateService = new ExpressionLanguageService({ logger });
354
334
  this.templateService = templateService;
355
- return decorateWithTemplateLanguageService(this.initOptions.typescript, info.languageService, info.project, templateService, {
356
- tags: ["e", "expr", "expression"],
357
- enableForStringWithSubstitutions: true
358
- }, { logger });
335
+ return decorateWithTemplateLanguageService(
336
+ this.initOptions.typescript,
337
+ info.languageService,
338
+ info.project,
339
+ templateService,
340
+ {
341
+ tags: ["e", "expr", "expression"],
342
+ enableForStringWithSubstitutions: true
343
+ },
344
+ { logger }
345
+ );
359
346
  }
360
347
  onConfigurationChanged(config) {
361
- var _a;
362
- (_a = this.templateService) == null ? void 0 : _a.setConfig(config);
348
+ this.templateService?.setConfig(config);
363
349
  }
364
- }
350
+ };
365
351
  function init(mod) {
366
352
  return new Plugin(mod);
367
353
  }
368
-
369
- export { init as default };
370
- //# sourceMappingURL=index.esm.js.map
354
+ var src_default = init;
355
+ export {
356
+ src_default as default
357
+ };
358
+ //# sourceMappingURL=index.mjs.map