@xano/xanoscript-language-server 11.6.1 → 11.6.2

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.
@@ -6,7 +6,8 @@
6
6
  "Bash(node --input-type=module -e:*)",
7
7
  "Bash(git checkout:*)",
8
8
  "Bash(ls:*)",
9
- "Bash(npm run lint:*)"
9
+ "Bash(npm run lint:*)",
10
+ "Bash(grep:*)"
10
11
  ]
11
12
  }
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "11.6.1",
3
+ "version": "11.6.2",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -11,6 +11,7 @@ import {
11
11
  export function switchCaseFn($) {
12
12
  return () => {
13
13
  $.sectionStack.push("switchCaseFn");
14
+ $.SUBRULE($.optionalCommentBlockFn);
14
15
  $.CONSUME(CaseToken); // "case"
15
16
  $.CONSUME(LParent); // "("
16
17
  $.SUBRULE($.expressionFn);
@@ -101,4 +101,18 @@ describe("switchFn", () => {
101
101
  }`);
102
102
  expect(parser.errors).to.not.be.empty;
103
103
  });
104
+
105
+ it("switchFn accepts comments on case", () => {
106
+ const parser = parse(`switch ("myvar") {
107
+ // a comment for this case
108
+ case (1) break
109
+
110
+ default {
111
+ debug.stop {
112
+ value = "do something"
113
+ }
114
+ }
115
+ }`);
116
+ expect(parser.errors).to.be.empty;
117
+ });
104
118
  });
@@ -18,6 +18,7 @@ import {
18
18
  TenantVariable,
19
19
  WebflowVariable,
20
20
  } from "../../lexer/variables.js";
21
+ import { isBlacklistedVariableName } from "../generic/assignableVariableProperty.js";
21
22
 
22
23
  /**
23
24
  * represent $var.x or $x, the only format accepting an assigment
@@ -54,6 +55,16 @@ export function varFn($) {
54
55
  { ALT: () => $.CONSUME(WebflowVariable) },
55
56
  ]);
56
57
  if (variable.image) {
58
+ // Check for blacklisted variable names
59
+ const nameWithoutPrefix = variable.image.startsWith("$")
60
+ ? variable.image.slice(1)
61
+ : variable.image;
62
+ if (isBlacklistedVariableName(nameWithoutPrefix)) {
63
+ $.addInvalidValueError(
64
+ variable,
65
+ `'${variable.image}' is a reserved variable name and should not be used as a variable.`,
66
+ );
67
+ }
57
68
  // we can directly add the variable here but
58
69
  // not necessary for the `assignableVariableProperty` below
59
70
  // which will add it on its own
@@ -191,4 +191,105 @@ describe("varFn", () => {
191
191
  }`);
192
192
  expect(parser.errors).to.be.empty;
193
193
  });
194
+
195
+ // Blacklisted variable names - these conflict with built-in variables
196
+ // Some are blocked at lexer level (separate tokens), others at parser level
197
+ describe("blacklisted variable names", () => {
198
+ // These are lexed as ShortFormVariable and need explicit blacklisting
199
+ const shortFormBlacklisted = ["output", "db", "toolset"];
200
+
201
+ for (const name of shortFormBlacklisted) {
202
+ it(`rejects var $${name} as variable name (short form)`, () => {
203
+ const parser = parse(`var $${name} {
204
+ value = "test"
205
+ }`);
206
+ expect(parser.errors).to.not.be.empty;
207
+ expect(parser.errors[0].message).to.include("reserved");
208
+ });
209
+
210
+ it(`rejects var.update $${name} as variable name (short form)`, () => {
211
+ const parser = parse(`var.update $${name} {
212
+ value = "test"
213
+ }`);
214
+ expect(parser.errors).to.not.be.empty;
215
+ expect(parser.errors[0].message).to.include("reserved");
216
+ });
217
+ }
218
+
219
+ // These are separate tokens and already rejected by the parser
220
+ const separateTokenBlacklisted = [
221
+ "auth",
222
+ "input",
223
+ "env",
224
+ "response",
225
+ "error",
226
+ "this",
227
+ ];
228
+
229
+ for (const name of separateTokenBlacklisted) {
230
+ it(`rejects var $${name} as variable name (separate token)`, () => {
231
+ const parser = parse(`var $${name} {
232
+ value = "test"
233
+ }`);
234
+ if (parser.errors.length === 0) {
235
+ console.log(parser.errors, name);
236
+ }
237
+ expect(parser.errors).to.not.be.empty;
238
+ });
239
+
240
+ it(`rejects var.update $${name} as variable name (separate token)`, () => {
241
+ const parser = parse(`var.update $${name} {
242
+ value = "test"
243
+ }`);
244
+ expect(parser.errors).to.not.be.empty;
245
+ });
246
+ }
247
+
248
+ // $var is the LongFormVariable prefix, parser expects a dot after it
249
+ it("rejects var $var as variable name (long form prefix)", () => {
250
+ const parser = parse(`var $var {
251
+ value = "test"
252
+ }`);
253
+ expect(parser.errors).to.not.be.empty;
254
+ });
255
+
256
+ // All blacklisted names should be rejected in long form via var.update
257
+ const allBlacklisted = [
258
+ "auth",
259
+ "input",
260
+ "env",
261
+ "response",
262
+ "output",
263
+ "var",
264
+ "db",
265
+ "error",
266
+ "toolset",
267
+ "this",
268
+ ];
269
+
270
+ for (const name of allBlacklisted) {
271
+ it(`rejects var.update $var.${name} as variable name (long form)`, () => {
272
+ const parser = parse(`var.update $var.${name} {
273
+ value = "test"
274
+ }`);
275
+ expect(parser.errors).to.not.be.empty;
276
+ expect(parser.errors[0].message).to.include("reserved");
277
+ });
278
+ }
279
+
280
+ // Ensure valid names still work
281
+ it("accepts var $user as variable name", () => {
282
+ const parser = parse(`var $user {
283
+ value = "test"
284
+ }`);
285
+ expect(parser.errors).to.be.empty;
286
+ });
287
+
288
+ it("accepts var $my_input as variable name", () => {
289
+ const parser = parse(`var $my_input {
290
+ value = "test"
291
+ }`);
292
+ expect(parser.errors).to.be.empty;
293
+ });
294
+ });
194
295
  });
@@ -34,4 +34,80 @@ describe("asVariable", () => {
34
34
  const parser = parse("as $$clients");
35
35
  expect(parser.errors).to.not.be.empty;
36
36
  });
37
+
38
+ // Blacklisted variable names - these conflict with built-in variables
39
+ // Some are blocked at lexer level (separate tokens), others at parser level
40
+ describe("blacklisted variable names", () => {
41
+ // These are lexed as ShortFormVariable and need explicit blacklisting
42
+ const shortFormBlacklisted = ["output", "db", "toolset"];
43
+
44
+ for (const name of shortFormBlacklisted) {
45
+ it(`rejects as $${name} (short form)`, () => {
46
+ const parser = parse(`as $${name}`);
47
+ expect(parser.errors).to.not.be.empty;
48
+ expect(parser.errors[0].message).to.include("reserved");
49
+ });
50
+ }
51
+
52
+ // These are separate tokens and already rejected by the parser
53
+ const separateTokenBlacklisted = [
54
+ "auth",
55
+ "input",
56
+ "env",
57
+ "response",
58
+ "error",
59
+ "this",
60
+ ];
61
+
62
+ for (const name of separateTokenBlacklisted) {
63
+ it(`rejects as $${name} (separate token)`, () => {
64
+ const parser = parse(`as $${name}`);
65
+ expect(parser.errors).to.not.be.empty;
66
+ });
67
+ }
68
+
69
+ // $var is the LongFormVariable prefix, parser expects a dot after it
70
+ it("rejects as $var (long form prefix)", () => {
71
+ const parser = parse("as $var");
72
+ expect(parser.errors).to.not.be.empty;
73
+ });
74
+
75
+ // All blacklisted names should be rejected in long form ($var.name)
76
+ const allBlacklisted = [
77
+ "auth",
78
+ "input",
79
+ "env",
80
+ "response",
81
+ "output",
82
+ "var",
83
+ "db",
84
+ "error",
85
+ "toolset",
86
+ "this",
87
+ ];
88
+
89
+ for (const name of allBlacklisted) {
90
+ it(`rejects as $var.${name} (long form)`, () => {
91
+ const parser = parse(`as $var.${name}`);
92
+ expect(parser.errors).to.not.be.empty;
93
+ expect(parser.errors[0].message).to.include("reserved");
94
+ });
95
+ }
96
+
97
+ // Ensure valid names still work
98
+ it("accepts as $user", () => {
99
+ const parser = parse("as $user");
100
+ expect(parser.errors).to.be.empty;
101
+ });
102
+
103
+ it("accepts as $my_input", () => {
104
+ const parser = parse("as $my_input");
105
+ expect(parser.errors).to.be.empty;
106
+ });
107
+
108
+ it("accepts as $var.my_var", () => {
109
+ const parser = parse("as $var.my_var");
110
+ expect(parser.errors).to.be.empty;
111
+ });
112
+ });
37
113
  });
@@ -1,5 +1,7 @@
1
+ import { MismatchedTokenException } from "chevrotain";
1
2
  import { DotToken, Identifier } from "../../lexer/tokens.js";
2
- import { LongFormVariable,ShortFormVariable } from "../../lexer/variables.js";
3
+ import { LongFormVariable, ShortFormVariable } from "../../lexer/variables.js";
4
+ import { isBlacklistedVariableName } from "./assignableVariableProperty.js";
3
5
 
4
6
  /**
5
7
  * represent $var.x or $x, the only format accepting an assigment
@@ -7,11 +9,15 @@ import { LongFormVariable,ShortFormVariable } from "../../lexer/variables.js";
7
9
  */
8
10
  export function assignableVariableAs($) {
9
11
  return () => {
12
+ let variableName = "";
13
+ let variableToken = null;
10
14
  $.OR([
11
15
  // "$users"
12
16
  {
13
17
  ALT: () => {
14
- $.CONSUME(ShortFormVariable);
18
+ const variable = $.CONSUME(ShortFormVariable);
19
+ variableName = variable.image;
20
+ variableToken = variable;
15
21
  },
16
22
  },
17
23
  // "$var.users"
@@ -19,9 +25,26 @@ export function assignableVariableAs($) {
19
25
  ALT: () => {
20
26
  $.CONSUME(LongFormVariable);
21
27
  $.CONSUME(DotToken);
22
- $.CONSUME(Identifier);
28
+ const variable = $.CONSUME(Identifier);
29
+ variableName = `$${variable.image}`;
30
+ variableToken = variable;
23
31
  },
24
32
  },
25
33
  ]);
34
+
35
+ // Check for blacklisted variable names
36
+ if (variableName && variableToken) {
37
+ const nameWithoutPrefix = variableName.startsWith("$")
38
+ ? variableName.slice(1)
39
+ : variableName;
40
+ if (isBlacklistedVariableName(nameWithoutPrefix)) {
41
+ $.SAVE_ERROR(
42
+ new MismatchedTokenException(
43
+ `'${variableName}' is a reserved variable name and cannot be used`,
44
+ variableToken
45
+ )
46
+ );
47
+ }
48
+ }
26
49
  };
27
50
  }
@@ -49,4 +49,56 @@ describe("assignableVariableAs", () => {
49
49
  const parser = parse(`"someting"`);
50
50
  expect(parser.errors).to.not.be.empty;
51
51
  });
52
+
53
+ // Blacklisted variable names - used in loop contexts (each as $variable)
54
+ describe("blacklisted variable names", () => {
55
+ // These are lexed as ShortFormVariable and need explicit blacklisting
56
+ const shortFormBlacklisted = ["output", "db", "toolset"];
57
+
58
+ for (const name of shortFormBlacklisted) {
59
+ it(`rejects $${name} (short form)`, () => {
60
+ const parser = parse(`$${name}`);
61
+ expect(parser.errors).to.not.be.empty;
62
+ expect(parser.errors[0].message).to.include("reserved");
63
+ });
64
+ }
65
+
66
+ // All blacklisted names should be rejected in long form ($var.name)
67
+ const allBlacklisted = [
68
+ "auth",
69
+ "input",
70
+ "env",
71
+ "response",
72
+ "output",
73
+ "var",
74
+ "db",
75
+ "error",
76
+ "toolset",
77
+ "this",
78
+ ];
79
+
80
+ for (const name of allBlacklisted) {
81
+ it(`rejects $var.${name} (long form)`, () => {
82
+ const parser = parse(`$var.${name}`);
83
+ expect(parser.errors).to.not.be.empty;
84
+ expect(parser.errors[0].message).to.include("reserved");
85
+ });
86
+ }
87
+
88
+ // Ensure valid names still work
89
+ it("accepts $item", () => {
90
+ const parser = parse("$item");
91
+ expect(parser.errors).to.be.empty;
92
+ });
93
+
94
+ it("accepts $i", () => {
95
+ const parser = parse("$i");
96
+ expect(parser.errors).to.be.empty;
97
+ });
98
+
99
+ it("accepts $var.my_var", () => {
100
+ const parser = parse("$var.my_var");
101
+ expect(parser.errors).to.be.empty;
102
+ });
103
+ });
52
104
  });
@@ -1,3 +1,4 @@
1
+ import { MismatchedTokenException } from "chevrotain";
1
2
  import { PipeToken } from "../../lexer/control.js";
2
3
  import { DotToken, Identifier, NewlineToken } from "../../lexer/tokens.js";
3
4
  import {
@@ -20,6 +21,31 @@ import {
20
21
  WebflowVariable,
21
22
  } from "../../lexer/variables.js";
22
23
 
24
+ // Blacklisted variable names that conflict with built-in variables
25
+ // These names cannot be used for user-defined variables because they
26
+ // would conflict with their shorthand form (e.g., $var.input -> $input)
27
+ export const BLACKLISTED_VARIABLE_NAMES = [
28
+ "auth",
29
+ "input",
30
+ "env",
31
+ "response",
32
+ "output",
33
+ "var",
34
+ "db",
35
+ "error",
36
+ "toolset",
37
+ "this",
38
+ ];
39
+
40
+ /**
41
+ * Check if a variable name is blacklisted
42
+ * @param {string} name - Variable name without $ prefix
43
+ * @returns {boolean}
44
+ */
45
+ export function isBlacklistedVariableName(name) {
46
+ return BLACKLISTED_VARIABLE_NAMES.includes(name);
47
+ }
48
+
23
49
  /**
24
50
  * represent $var.x or $x, the only format accepting an assigment
25
51
  * @param {import('../base_parser.js').XanoBaseParser} $
@@ -27,6 +53,7 @@ import {
27
53
  export function assignableVariableProperty($) {
28
54
  return () => {
29
55
  let variableName = "";
56
+ let variableToken = null;
30
57
  $.OR({
31
58
  DEF: [
32
59
  // "$users" or env property tokens like "$http_headers"
@@ -53,6 +80,7 @@ export function assignableVariableProperty($) {
53
80
  { ALT: () => $.CONSUME(WebflowVariable) },
54
81
  ]);
55
82
  variableName = variable.image;
83
+ variableToken = variable;
56
84
  },
57
85
  },
58
86
  // "$var.users"
@@ -62,11 +90,29 @@ export function assignableVariableProperty($) {
62
90
  $.CONSUME(DotToken);
63
91
  const variable = $.CONSUME(Identifier);
64
92
  variableName = `$${variable.image}`;
93
+ variableToken = variable;
65
94
  },
66
95
  },
67
96
  ],
68
97
  ERR_MSG: "expecting variable (e.g. $variable or $var.variable)",
69
98
  });
99
+
100
+ // Check for blacklisted variable names
101
+ if (variableName && variableToken) {
102
+ // Extract the name without $ prefix for checking
103
+ const nameWithoutPrefix = variableName.startsWith("$")
104
+ ? variableName.slice(1)
105
+ : variableName;
106
+ if (isBlacklistedVariableName(nameWithoutPrefix)) {
107
+ $.SAVE_ERROR(
108
+ new MismatchedTokenException(
109
+ `'${variableName}' is a reserved variable name and cannot be used`,
110
+ variableToken
111
+ )
112
+ );
113
+ }
114
+ }
115
+
70
116
  $.SUBRULE($.chainedIdentifier);
71
117
 
72
118
  $.MANY({
@@ -49,4 +49,81 @@ describe("assignableVariableProperty", () => {
49
49
  const parser = parse(`$users|trim`);
50
50
  expect(parser.errors).to.be.empty;
51
51
  });
52
+
53
+ // Blacklisted variable names - these conflict with built-in variables
54
+ // Some are blocked at lexer level (separate tokens), others at parser level
55
+ describe("blacklisted variable names", () => {
56
+ // These are lexed as ShortFormVariable and need explicit blacklisting
57
+ const shortFormBlacklisted = ["output", "db", "toolset"];
58
+
59
+ for (const name of shortFormBlacklisted) {
60
+ it(`rejects $${name} as assignable variable (short form)`, () => {
61
+ const parser = parse(`$${name}`);
62
+ expect(parser.errors).to.not.be.empty;
63
+ expect(parser.errors[0].message).to.include("reserved");
64
+ });
65
+ }
66
+
67
+ // These are separate tokens and already rejected by the parser
68
+ // (not in the OR alternatives of assignableVariableProperty)
69
+ const separateTokenBlacklisted = [
70
+ "auth",
71
+ "input",
72
+ "env",
73
+ "response",
74
+ "error",
75
+ "this",
76
+ ];
77
+
78
+ for (const name of separateTokenBlacklisted) {
79
+ it(`rejects $${name} as assignable variable (separate token)`, () => {
80
+ const parser = parse(`$${name}`);
81
+ expect(parser.errors).to.not.be.empty;
82
+ });
83
+ }
84
+
85
+ // $var is the LongFormVariable prefix, parser expects a dot after it
86
+ it("rejects $var as assignable variable (long form prefix)", () => {
87
+ const parser = parse("$var");
88
+ expect(parser.errors).to.not.be.empty;
89
+ });
90
+
91
+ // All blacklisted names should be rejected in long form ($var.name)
92
+ const allBlacklisted = [
93
+ "auth",
94
+ "input",
95
+ "env",
96
+ "response",
97
+ "output",
98
+ "var",
99
+ "db",
100
+ "error",
101
+ "toolset",
102
+ "this",
103
+ ];
104
+
105
+ for (const name of allBlacklisted) {
106
+ it(`rejects $var.${name} as assignable variable (long form)`, () => {
107
+ const parser = parse(`$var.${name}`);
108
+ expect(parser.errors).to.not.be.empty;
109
+ expect(parser.errors[0].message).to.include("reserved");
110
+ });
111
+ }
112
+
113
+ // Ensure valid names still work
114
+ it("accepts $user as assignable variable", () => {
115
+ const parser = parse("$user");
116
+ expect(parser.errors).to.be.empty;
117
+ });
118
+
119
+ it("accepts $my_input as assignable variable", () => {
120
+ const parser = parse("$my_input");
121
+ expect(parser.errors).to.be.empty;
122
+ });
123
+
124
+ it("accepts $var.my_var as assignable variable", () => {
125
+ const parser = parse("$var.my_var");
126
+ expect(parser.errors).to.be.empty;
127
+ });
128
+ });
52
129
  });
@@ -75,7 +75,7 @@ function "ledash/ends_with" {
75
75
  each as $index {
76
76
  conditional {
77
77
  description = "compare every element using position as an offset on the string"
78
-
78
+
79
79
  if (($text|get:$position - $index - 1:null) !== ($target|get:($target|count) - $index - 1:null)) {
80
80
  return {
81
81
  value = false
@@ -27,7 +27,7 @@ query all_zip verb=GET {
27
27
  zip.extract {
28
28
  zip = $zip_file
29
29
  password = ""
30
- } as $output
30
+ } as $extracted_output
31
31
 
32
32
  zip.view_contents {
33
33
  zip = $input.file