jslike 1.3.1 → 1.4.1
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/bin/jslike.js +1 -1
- package/dist/editor/monaco/index.cjs +239 -0
- package/dist/editor/monaco/index.d.cts +236 -0
- package/dist/editor/monaco/index.d.ts +236 -0
- package/dist/editor/monaco/index.js +214 -0
- package/dist/editor/wang-prism.cjs +109 -0
- package/dist/editor/wang-prism.d.ts +136 -0
- package/dist/editor/wang-prism.js +109 -0
- package/{src → dist/esm}/cli/wang-run.js +0 -0
- package/{src → dist/esm}/cli/wang-validate.js +0 -0
- package/dist/esm/editor/wang-prism.js +136 -0
- package/{src → dist/esm}/index.js +2 -6
- package/{src → dist/esm}/runtime/environment.js +11 -1
- package/dist/index.cjs +8112 -0
- package/dist/index.d.cts +9482 -0
- package/dist/index.d.ts +9482 -0
- package/dist/index.js +8078 -0
- package/dist/validator/index.cjs +5753 -0
- package/dist/validator/index.d.cts +103 -0
- package/dist/validator/index.d.ts +103 -0
- package/dist/validator/index.js +5727 -0
- package/package.json +50 -10
- /package/{src/editor/wang-prism.js → dist/editor/wang-prism.d.cts} +0 -0
- /package/{src → dist/esm}/ast/nodes.js +0 -0
- /package/{src → dist/esm}/editor/monaco/index.js +0 -0
- /package/{src → dist/esm}/errors/enhanced-error.js +0 -0
- /package/{src → dist/esm}/interpreter/index.js +0 -0
- /package/{src → dist/esm}/interpreter/interpreter.js +0 -0
- /package/{src → dist/esm}/metadata/index.js +0 -0
- /package/{src → dist/esm}/parser.js +0 -0
- /package/{src → dist/esm}/resolvers/memory.js +0 -0
- /package/{src → dist/esm}/runtime/builtins.js +0 -0
- /package/{src → dist/esm}/validator/index.js +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parse } from '../index.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WangValidator - Syntax validation for Wang/JSLike code
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WangValidator {
|
|
9
|
+
/**
|
|
10
|
+
* Validate code and return validation result
|
|
11
|
+
* @param {string} code - The code to validate
|
|
12
|
+
* @param {object} options - Validation options
|
|
13
|
+
* @param {boolean} options.includeAST - Whether to include AST in result
|
|
14
|
+
* @returns {object} Validation result
|
|
15
|
+
*/
|
|
16
|
+
validate(code, options = {}) {
|
|
17
|
+
try {
|
|
18
|
+
// Parse the code
|
|
19
|
+
const ast = parse(code);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
valid: true,
|
|
23
|
+
ast: options.includeAST ? ast : undefined
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
// Extract line and column from error
|
|
27
|
+
const line = error.loc?.line || 1;
|
|
28
|
+
const column = error.loc?.column || 0;
|
|
29
|
+
|
|
30
|
+
// Generate suggestion for common errors
|
|
31
|
+
const suggestion = this.getSuggestion(error, code);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
valid: false,
|
|
35
|
+
error: {
|
|
36
|
+
message: error.message,
|
|
37
|
+
line,
|
|
38
|
+
column,
|
|
39
|
+
suggestion
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate suggestions for common syntax errors
|
|
47
|
+
* @param {Error} error - The parse error
|
|
48
|
+
* @param {string} code - The original code
|
|
49
|
+
* @returns {string|undefined} Suggestion text
|
|
50
|
+
*/
|
|
51
|
+
getSuggestion(error, code) {
|
|
52
|
+
const message = error.message.toLowerCase();
|
|
53
|
+
|
|
54
|
+
// Common error patterns and suggestions
|
|
55
|
+
if (message.includes('unexpected token')) {
|
|
56
|
+
if (message.includes('}')) {
|
|
57
|
+
return 'Check for missing opening brace or extra closing brace';
|
|
58
|
+
}
|
|
59
|
+
if (message.includes('{')) {
|
|
60
|
+
return 'Check for missing closing brace or misplaced opening brace';
|
|
61
|
+
}
|
|
62
|
+
if (message.includes(')')) {
|
|
63
|
+
return 'Check for missing opening parenthesis or extra closing parenthesis';
|
|
64
|
+
}
|
|
65
|
+
if (message.includes('(')) {
|
|
66
|
+
return 'Check for missing closing parenthesis';
|
|
67
|
+
}
|
|
68
|
+
return 'Check syntax near the error location';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (message.includes('unterminated string')) {
|
|
72
|
+
return 'Add closing quote to string literal';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (message.includes('unterminated template')) {
|
|
76
|
+
return 'Add closing backtick to template literal';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (message.includes('identifier expected')) {
|
|
80
|
+
return 'Provide a valid identifier name';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (message.includes('unexpected end of input')) {
|
|
84
|
+
return 'Check for unclosed brackets, braces, or parentheses';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (message.includes('invalid left-hand side')) {
|
|
88
|
+
return 'Check that assignment target is a valid variable or property';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (message.includes('duplicate parameter')) {
|
|
92
|
+
return 'Remove duplicate parameter name in function definition';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (message.includes('strict mode')) {
|
|
96
|
+
return 'This syntax is not allowed in strict mode';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { WangValidator };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parse } from '../index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WangValidator - Syntax validation for Wang/JSLike code
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WangValidator {
|
|
9
|
+
/**
|
|
10
|
+
* Validate code and return validation result
|
|
11
|
+
* @param {string} code - The code to validate
|
|
12
|
+
* @param {object} options - Validation options
|
|
13
|
+
* @param {boolean} options.includeAST - Whether to include AST in result
|
|
14
|
+
* @returns {object} Validation result
|
|
15
|
+
*/
|
|
16
|
+
validate(code, options = {}) {
|
|
17
|
+
try {
|
|
18
|
+
// Parse the code
|
|
19
|
+
const ast = parse(code);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
valid: true,
|
|
23
|
+
ast: options.includeAST ? ast : undefined
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
// Extract line and column from error
|
|
27
|
+
const line = error.loc?.line || 1;
|
|
28
|
+
const column = error.loc?.column || 0;
|
|
29
|
+
|
|
30
|
+
// Generate suggestion for common errors
|
|
31
|
+
const suggestion = this.getSuggestion(error, code);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
valid: false,
|
|
35
|
+
error: {
|
|
36
|
+
message: error.message,
|
|
37
|
+
line,
|
|
38
|
+
column,
|
|
39
|
+
suggestion
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate suggestions for common syntax errors
|
|
47
|
+
* @param {Error} error - The parse error
|
|
48
|
+
* @param {string} code - The original code
|
|
49
|
+
* @returns {string|undefined} Suggestion text
|
|
50
|
+
*/
|
|
51
|
+
getSuggestion(error, code) {
|
|
52
|
+
const message = error.message.toLowerCase();
|
|
53
|
+
|
|
54
|
+
// Common error patterns and suggestions
|
|
55
|
+
if (message.includes('unexpected token')) {
|
|
56
|
+
if (message.includes('}')) {
|
|
57
|
+
return 'Check for missing opening brace or extra closing brace';
|
|
58
|
+
}
|
|
59
|
+
if (message.includes('{')) {
|
|
60
|
+
return 'Check for missing closing brace or misplaced opening brace';
|
|
61
|
+
}
|
|
62
|
+
if (message.includes(')')) {
|
|
63
|
+
return 'Check for missing opening parenthesis or extra closing parenthesis';
|
|
64
|
+
}
|
|
65
|
+
if (message.includes('(')) {
|
|
66
|
+
return 'Check for missing closing parenthesis';
|
|
67
|
+
}
|
|
68
|
+
return 'Check syntax near the error location';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (message.includes('unterminated string')) {
|
|
72
|
+
return 'Add closing quote to string literal';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (message.includes('unterminated template')) {
|
|
76
|
+
return 'Add closing backtick to template literal';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (message.includes('identifier expected')) {
|
|
80
|
+
return 'Provide a valid identifier name';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (message.includes('unexpected end of input')) {
|
|
84
|
+
return 'Check for unclosed brackets, braces, or parentheses';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (message.includes('invalid left-hand side')) {
|
|
88
|
+
return 'Check that assignment target is a valid variable or property';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (message.includes('duplicate parameter')) {
|
|
92
|
+
return 'Remove duplicate parameter name in function definition';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (message.includes('strict mode')) {
|
|
96
|
+
return 'This syntax is not allowed in strict mode';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { WangValidator };
|