bare-script 3.5.5 → 3.7.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.
package/lib/model.js CHANGED
@@ -17,6 +17,15 @@ struct BareScript
17
17
  # The script's statements
18
18
  ScriptStatement[] statements
19
19
 
20
+ # The script name
21
+ optional string scriptName
22
+
23
+ # The script's lines
24
+ optional string[] scriptLines
25
+
26
+ # If true, this is a system include script
27
+ optional bool system
28
+
20
29
 
21
30
  # A script statement
22
31
  union ScriptStatement
@@ -31,7 +40,7 @@ union ScriptStatement
31
40
  ReturnStatement return
32
41
 
33
42
  # A label definition
34
- string label
43
+ LabelStatement label
35
44
 
36
45
  # A function definition
37
46
  FunctionStatement function
@@ -40,8 +49,18 @@ union ScriptStatement
40
49
  IncludeStatement include
41
50
 
42
51
 
52
+ # Script statement base struct
53
+ struct BaseStatement
54
+
55
+ # The script statement's line number
56
+ optional int lineNumber
57
+
58
+ # The number of lines in the script statement (default is 1)
59
+ optional int lineCount
60
+
61
+
43
62
  # An expression statement
44
- struct ExpressionStatement
63
+ struct ExpressionStatement (BaseStatement)
45
64
 
46
65
  # The variable name to assign the expression value
47
66
  optional string name
@@ -51,7 +70,7 @@ struct ExpressionStatement
51
70
 
52
71
 
53
72
  # A jump statement
54
- struct JumpStatement
73
+ struct JumpStatement (BaseStatement)
55
74
 
56
75
  # The label to jump to
57
76
  string label
@@ -61,14 +80,21 @@ struct JumpStatement
61
80
 
62
81
 
63
82
  # A return statement
64
- struct ReturnStatement
83
+ struct ReturnStatement (BaseStatement)
65
84
 
66
85
  # The expression to return
67
86
  optional Expression expr
68
87
 
69
88
 
89
+ # A label statement
90
+ struct LabelStatement (BaseStatement)
91
+
92
+ # The label name
93
+ string name
94
+
95
+
70
96
  # A function definition statement
71
- struct FunctionStatement
97
+ struct FunctionStatement (BaseStatement)
72
98
 
73
99
  # If true, the function is defined as async
74
100
  optional bool async
@@ -87,7 +113,7 @@ struct FunctionStatement
87
113
 
88
114
 
89
115
  # An include statement
90
- struct IncludeStatement
116
+ struct IncludeStatement (BaseStatement)
91
117
 
92
118
  # The list of include scripts to load and execute in the global scope
93
119
  IncludeScript[len > 0] includes
@@ -103,6 +129,36 @@ struct IncludeScript
103
129
  optional bool system
104
130
 
105
131
 
132
+ # The coverage global configuration
133
+ struct CoverageGlobal
134
+
135
+ # If true, coverage is enabled
136
+ optional bool enabled
137
+
138
+ # The map of script name to script coverage
139
+ optional CoverageGlobalScript{} scripts
140
+
141
+
142
+ # The script coverage
143
+ struct CoverageGlobalScript
144
+
145
+ # The script
146
+ BareScript script
147
+
148
+ # The map of script line number string to script statement coverage
149
+ CoverageGlobalStatement{} covered
150
+
151
+
152
+ # The script statement coverage
153
+ struct CoverageGlobalStatement
154
+
155
+ # The script statement
156
+ ScriptStatement statement
157
+
158
+ # The statement's coverage count
159
+ int count
160
+
161
+
106
162
  # An expression
107
163
  union Expression
108
164
 
@@ -363,12 +419,13 @@ export function lintScript(script) {
363
419
  // Function label statement checks
364
420
  } else if (fnStatementKey === 'label') {
365
421
  // Label redefinition?
366
- if (fnStatement.label in fnLabelsDefined) {
422
+ const fnStatementLabel = fnStatement.label.name;
423
+ if (fnStatementLabel in fnLabelsDefined) {
367
424
  warnings.push(
368
- `Redefinition of label "${fnStatement.label}" in function "${statement.function.name}" (index ${ixFnStatement})`
425
+ `Redefinition of label "${fnStatementLabel}" in function "${statement.function.name}" (index ${ixFnStatement})`
369
426
  );
370
427
  } else {
371
- fnLabelsDefined[fnStatement.label] = ixFnStatement;
428
+ fnLabelsDefined[fnStatementLabel] = ixFnStatement;
372
429
  }
373
430
 
374
431
  // Function jump statement checks
@@ -403,10 +460,11 @@ export function lintScript(script) {
403
460
  // Global label statement checks
404
461
  } else if (statementKey === 'label') {
405
462
  // Label redefinition?
406
- if (statement.label in labelsDefined) {
407
- warnings.push(`Redefinition of global label "${statement.label}" (index ${ixStatement})`);
463
+ const statementLabel = statement.label.name;
464
+ if (statementLabel in labelsDefined) {
465
+ warnings.push(`Redefinition of global label "${statementLabel}" (index ${ixStatement})`);
408
466
  } else {
409
- labelsDefined[statement.label] = ixStatement;
467
+ labelsDefined[statementLabel] = ixStatement;
410
468
  }
411
469
 
412
470
  // Global jump statement checks
package/lib/options.js CHANGED
@@ -64,9 +64,52 @@ export function urlFileRelative(file, url) {
64
64
  return url;
65
65
  }
66
66
 
67
- // URL is relative POSIX path
68
- return `${file.slice(0, file.lastIndexOf('/') + 1)}${url}`;
67
+ // URL is relative POSIX path - join with root
68
+ const result = `${file.slice(0, file.lastIndexOf('/') + 1)}${url}`;
69
+
70
+ // Normalize non-URL POSIX paths
71
+ if (!rURL.test(result)) {
72
+ return normalizePath(result);
73
+ }
74
+
75
+ return result;
69
76
  }
70
77
 
71
78
 
79
+ // Regular expression to match URLs
72
80
  export const rURL = /^[a-z]+:/;
81
+
82
+
83
+ // Normalize a POSIX path
84
+ export function normalizePath(filepath) {
85
+ // Handle empty string
86
+ if (!filepath || filepath === '.') {
87
+ return '.';
88
+ }
89
+
90
+ // Check if path is absolute
91
+ const isAbsolute = filepath.startsWith('/');
92
+
93
+ // Split path into segments
94
+ const segments = filepath.split('/').filter(segment => segment !== '' && segment !== '.');
95
+
96
+ // Process segments to handle '..'
97
+ const stack = [];
98
+ for (const segment of segments) {
99
+ if (segment === '..') {
100
+ // Only pop if we're not at the root and stack is not empty
101
+ if (stack.length > 0 && stack[stack.length - 1] !== '..') {
102
+ stack.pop();
103
+ } else if (!isAbsolute) {
104
+ // For relative paths, keep '..' if we can't go up further
105
+ stack.push(segment);
106
+ }
107
+ // For absolute paths, ignore '..' at root
108
+ } else {
109
+ stack.push(segment);
110
+ }
111
+ }
112
+
113
+ // Reconstruct path
114
+ return isAbsolute ? `/${stack.join('/')}` : stack.join('/');
115
+ }