xmlui 0.8.6 → 0.9.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/dist/{apiInterceptorWorker-fLBfPj2T.mjs → apiInterceptorWorker-230V_-Ds.mjs} +1 -1
- package/dist/{index-wd8FRzuM.mjs → index-DUwwx3L4.mjs} +5864 -6108
- package/dist/index.css +274 -301
- package/dist/language-server.mjs +25 -1
- package/dist/{lint-B18Ko6Sy.mjs → lint-gX2osbkz.mjs} +920 -1120
- package/dist/scripts/bin/build.js +2 -2
- package/dist/scripts/bin/start.js +3 -9
- package/dist/scripts/bin/vite-xmlui-plugin.js +2 -2
- package/dist/scripts/bin/viteConfig.js +89 -63
- package/dist/scripts/src/abstractions/scripting/ScriptingSourceTreeExp.js +1 -2
- package/dist/scripts/src/components/Accordion/Accordion.js +6 -16
- package/dist/scripts/src/components/App/AppNative.js +8 -0
- package/dist/scripts/src/components/AppHeader/AppHeader.js +1 -5
- package/dist/scripts/src/components/AppHeader/AppHeaderNative.js +10 -4
- package/dist/scripts/src/components/AutoComplete/AutoComplete.js +13 -19
- package/dist/scripts/src/components/AutoComplete/AutoCompleteContext.js +2 -0
- package/dist/scripts/src/components/AutoComplete/AutoCompleteNative.js +7 -3
- package/dist/scripts/src/components/Avatar/Avatar.js +2 -9
- package/dist/scripts/src/components/Badge/Badge.js +2 -8
- package/dist/scripts/src/components/Button/Button.js +28 -60
- package/dist/scripts/src/components/Card/Card.js +1 -6
- package/dist/scripts/src/components/Checkbox/Checkbox.js +4 -12
- package/dist/scripts/src/components/ComponentProvider.js +4 -0
- package/dist/scripts/src/components/DatePicker/DatePicker.js +3 -10
- package/dist/scripts/src/components/DropdownMenu/DropdownMenu.js +1 -1
- package/dist/scripts/src/components/Form/Form.js +12 -28
- package/dist/scripts/src/components/Form/FormNative.js +9 -0
- package/dist/scripts/src/components/FormItem/HelperText.js +1 -1
- package/dist/scripts/src/components/FormItem/ItemWithLabel.js +2 -2
- package/dist/scripts/src/components/Heading/HeadingNative.js +0 -1
- package/dist/scripts/src/components/HtmlTags/HtmlTags.js +4 -19
- package/dist/scripts/src/components/IconProvider.js +2 -2
- package/dist/scripts/src/components/Link/Link.js +2 -8
- package/dist/scripts/src/components/Markdown/MarkdownNative.js +4 -4
- package/dist/scripts/src/components/ModalDialog/ModalDialog.js +1 -3
- package/dist/scripts/src/components/NavGroup/NavGroup.js +34 -3
- package/dist/scripts/src/components/NavGroup/NavGroupNative.js +24 -12
- package/dist/scripts/src/components/NavLink/NavLink.js +4 -11
- package/dist/scripts/src/components/NavPanel/NavPanel.js +1 -6
- package/dist/scripts/src/components/ProgressBar/ProgressBar.js +2 -8
- package/dist/scripts/src/components/RadioGroup/RadioGroup.js +4 -12
- package/dist/scripts/src/components/Select/Select.js +5 -13
- package/dist/scripts/src/components/Select/SelectNative.js +7 -3
- package/dist/scripts/src/components/Slider/Slider.js +2 -8
- package/dist/scripts/src/components/Spinner/Spinner.js +1 -6
- package/dist/scripts/src/components/SubNavPanel/SubNavPanel.js +22 -0
- package/dist/scripts/src/components/SubNavPanel/SubNavPanelNative.js +9 -0
- package/dist/scripts/src/components/Switch/Switch.js +6 -16
- package/dist/scripts/src/components/Table/Table.js +8 -17
- package/dist/scripts/src/components/TableOfContents/TableOfContents.js +4 -12
- package/dist/scripts/src/components/Tabs/Tabs.js +3 -10
- package/dist/scripts/src/components/Text/Text.js +10 -24
- package/dist/scripts/src/components/TextBox/TextBoxNative.js +1 -1
- package/dist/scripts/src/components/Theme/ThemeNative.js +1 -1
- package/dist/scripts/src/components/ValidationSummary/ValidationSummary.js +3 -3
- package/dist/scripts/src/components-core/DevTools.js +5 -4
- package/dist/scripts/src/components-core/RestApiProxy.js +7 -3
- package/dist/scripts/src/components-core/action/APICall.js +2 -1
- package/dist/scripts/src/components-core/rendering/Container.js +15 -11
- package/dist/scripts/src/components-core/rendering/StateContainer.js +3 -2
- package/dist/scripts/src/components-core/script-runner/BindingTreeEvaluationContext.js +0 -2
- package/dist/scripts/src/components-core/script-runner/ParameterParser.js +1 -1
- package/dist/scripts/src/components-core/script-runner/asyncProxy.js +11 -64
- package/dist/scripts/src/components-core/script-runner/eval-tree-async.js +196 -175
- package/dist/scripts/src/components-core/script-runner/eval-tree-common.js +173 -231
- package/dist/scripts/src/components-core/script-runner/eval-tree-sync.js +129 -100
- package/dist/scripts/src/components-core/script-runner/process-statement-async.js +170 -175
- package/dist/scripts/src/components-core/script-runner/process-statement-common.js +48 -33
- package/dist/scripts/src/components-core/script-runner/process-statement-sync.js +164 -170
- package/dist/scripts/src/components-core/script-runner/statement-queue.js +5 -4
- package/dist/scripts/src/components-core/script-runner/visitors.js +124 -116
- package/dist/scripts/src/components-core/theming/themes/palette.js +1 -0
- package/dist/scripts/src/components-core/theming/themes/root.js +300 -154
- package/dist/scripts/src/components-core/theming/themes/theme-colors.js +510 -510
- package/dist/scripts/src/components-core/theming/themes/xmlui.js +0 -1
- package/dist/scripts/src/components-core/theming/transformThemeVars.js +11 -11
- package/dist/scripts/src/components-core/utils/misc.js +13 -0
- package/dist/scripts/src/components-core/utils/statementUtils.js +56 -53
- package/dist/scripts/src/components-core/xmlui-parser.js +1 -1
- package/dist/scripts/src/parsers/scripting-exp/Lexer.js +1092 -0
- package/dist/scripts/src/parsers/scripting-exp/Parser.js +2635 -0
- package/dist/scripts/src/parsers/scripting-exp/ParserError.js +47 -0
- package/dist/scripts/src/parsers/scripting-exp/TokenTrait.js +109 -0
- package/dist/scripts/src/parsers/scripting-exp/TokenType.js +2 -4
- package/dist/scripts/src/parsers/scripting-exp/code-behind-collect.js +101 -0
- package/dist/scripts/src/parsers/scripting-exp/modules.js +107 -0
- package/dist/scripts/src/parsers/{scripting → scripting-exp}/tree-visitor.js +103 -107
- package/dist/scripts/src/parsers/xmlui-parser/transform.js +12 -12
- package/dist/style.css +245 -286
- package/dist/xmlui-metadata.mjs +2741 -2211
- package/dist/xmlui-metadata.umd.js +2740 -2212
- package/dist/xmlui-parser.d.ts +320 -232
- package/dist/xmlui-parser.mjs +19 -19
- package/dist/xmlui-standalone.umd.js +6770 -7220
- package/dist/xmlui.d.ts +322 -230
- package/dist/xmlui.mjs +1 -1
- package/package.json +10 -6
- package/dist/_commonjsHelpers-CcAunmGO.mjs +0 -33
- package/dist/scripts/src/components-core/script-runner/ICustomOperations.js +0 -34
- package/dist/scripts/src/components-core/script-runner/custom-operations-registry.js +0 -40
- package/dist/scripts/src/components-core/script-runner/custom-ui-data.js +0 -40
- package/dist/scripts/src/components-core/script-runner/syncProxy.js +0 -31
- package/dist/scripts/src/parsers/scripting/code-behind-collect.js +0 -153
- package/dist/scripts/src/parsers/scripting/modules.js +0 -284
- /package/dist/scripts/src/abstractions/scripting/{LogicalThread.js → LogicalThreadExp.js} +0 -0
- /package/dist/scripts/src/abstractions/scripting/{TryScope.js → TryScopeExp.js} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorMessages = exports.ParserError = void 0;
|
|
4
|
+
// The common root class of all parser error objects
|
|
5
|
+
class ParserError extends Error {
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
// --- Set the prototype explicitly.
|
|
10
|
+
Object.setPrototypeOf(this, ParserError.prototype);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ParserError = ParserError;
|
|
14
|
+
// The error messages of error codes
|
|
15
|
+
exports.errorMessages = {
|
|
16
|
+
W001: "An expression expected",
|
|
17
|
+
W002: "Unexpected token: {0}",
|
|
18
|
+
W003: "An identifier expected",
|
|
19
|
+
W004: "'}' expected",
|
|
20
|
+
W005: "']' expected",
|
|
21
|
+
W006: "')' expected",
|
|
22
|
+
W007: "Invalid object property name type",
|
|
23
|
+
W008: "':' expected",
|
|
24
|
+
W009: "'=' expected",
|
|
25
|
+
W010: "Invalid argument list",
|
|
26
|
+
W011: "For loop variable must be initialized",
|
|
27
|
+
W012: "'{' expected",
|
|
28
|
+
W013: "'catch' or 'finally' expected",
|
|
29
|
+
W014: "'(' or expected",
|
|
30
|
+
W015: "'case' or 'default' expected",
|
|
31
|
+
W016: "'default' case can be used only once within a switch statement",
|
|
32
|
+
W017: "Invalid sequence expression",
|
|
33
|
+
W018: "Invalid object literal",
|
|
34
|
+
W019: "Identifier '{0}' is already imported",
|
|
35
|
+
W020: "Function '{0}' is already defined in the module",
|
|
36
|
+
W021: "'{0}' is already exported from the module",
|
|
37
|
+
W022: "Cannot find module '{0}'",
|
|
38
|
+
W023: "Module '{0}' does not export '{1}'",
|
|
39
|
+
W024: "'function' expected",
|
|
40
|
+
W025: "'from' expected",
|
|
41
|
+
W026: "A string literal expected",
|
|
42
|
+
W027: "Cannot declare var ('{0}') in an imported module",
|
|
43
|
+
W028: "Invalid statement used in a module.",
|
|
44
|
+
W029: "An imported module can contain only exported functions",
|
|
45
|
+
W030: "Nested declarations cannot be exported",
|
|
46
|
+
W031: "An identifier in a declaration cannot start with '$'"
|
|
47
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tokenTraits = void 0;
|
|
4
|
+
const TokenType_1 = require("./TokenType");
|
|
5
|
+
// Individual traits of tokens
|
|
6
|
+
exports.tokenTraits = {
|
|
7
|
+
[TokenType_1.TokenType.Eof]: {},
|
|
8
|
+
[TokenType_1.TokenType.Ws]: {},
|
|
9
|
+
[TokenType_1.TokenType.DollarLBrace]: {},
|
|
10
|
+
[TokenType_1.TokenType.Backtick]: { expressionStart: true },
|
|
11
|
+
[TokenType_1.TokenType.BlockComment]: {},
|
|
12
|
+
[TokenType_1.TokenType.EolComment]: {},
|
|
13
|
+
[TokenType_1.TokenType.Unknown]: {},
|
|
14
|
+
[TokenType_1.TokenType.LParent]: { expressionStart: true },
|
|
15
|
+
[TokenType_1.TokenType.RParent]: {},
|
|
16
|
+
[TokenType_1.TokenType.Identifier]: { expressionStart: true, keywordLike: true, isPropLiteral: true },
|
|
17
|
+
[TokenType_1.TokenType.Exponent]: {},
|
|
18
|
+
[TokenType_1.TokenType.Divide]: {},
|
|
19
|
+
[TokenType_1.TokenType.Multiply]: {},
|
|
20
|
+
[TokenType_1.TokenType.Remainder]: {},
|
|
21
|
+
[TokenType_1.TokenType.Plus]: { expressionStart: true, canBeUnary: true },
|
|
22
|
+
[TokenType_1.TokenType.Minus]: { expressionStart: true, canBeUnary: true },
|
|
23
|
+
[TokenType_1.TokenType.BitwiseXor]: {},
|
|
24
|
+
[TokenType_1.TokenType.BitwiseOr]: {},
|
|
25
|
+
[TokenType_1.TokenType.LogicalOr]: {},
|
|
26
|
+
[TokenType_1.TokenType.BitwiseAnd]: {},
|
|
27
|
+
[TokenType_1.TokenType.LogicalAnd]: {},
|
|
28
|
+
[TokenType_1.TokenType.Assignment]: { isAssignment: true },
|
|
29
|
+
[TokenType_1.TokenType.AddAssignment]: { isAssignment: true },
|
|
30
|
+
[TokenType_1.TokenType.SubtractAssignment]: { isAssignment: true },
|
|
31
|
+
[TokenType_1.TokenType.ExponentAssignment]: { isAssignment: true },
|
|
32
|
+
[TokenType_1.TokenType.MultiplyAssignment]: { isAssignment: true },
|
|
33
|
+
[TokenType_1.TokenType.DivideAssignment]: { isAssignment: true },
|
|
34
|
+
[TokenType_1.TokenType.RemainderAssignment]: { isAssignment: true },
|
|
35
|
+
[TokenType_1.TokenType.ShiftLeftAssignment]: { isAssignment: true },
|
|
36
|
+
[TokenType_1.TokenType.ShiftRightAssignment]: { isAssignment: true },
|
|
37
|
+
[TokenType_1.TokenType.SignedShiftRightAssignment]: { isAssignment: true },
|
|
38
|
+
[TokenType_1.TokenType.BitwiseAndAssignment]: { isAssignment: true },
|
|
39
|
+
[TokenType_1.TokenType.BitwiseXorAssignment]: { isAssignment: true },
|
|
40
|
+
[TokenType_1.TokenType.BitwiseOrAssignment]: { isAssignment: true },
|
|
41
|
+
[TokenType_1.TokenType.LogicalAndAssignment]: { isAssignment: true },
|
|
42
|
+
[TokenType_1.TokenType.LogicalOrAssignment]: { isAssignment: true },
|
|
43
|
+
[TokenType_1.TokenType.NullCoalesceAssignment]: { isAssignment: true },
|
|
44
|
+
[TokenType_1.TokenType.Semicolon]: {},
|
|
45
|
+
[TokenType_1.TokenType.Comma]: {},
|
|
46
|
+
[TokenType_1.TokenType.Colon]: {},
|
|
47
|
+
[TokenType_1.TokenType.LSquare]: { expressionStart: true },
|
|
48
|
+
[TokenType_1.TokenType.RSquare]: {},
|
|
49
|
+
[TokenType_1.TokenType.QuestionMark]: {},
|
|
50
|
+
[TokenType_1.TokenType.NullCoalesce]: {},
|
|
51
|
+
[TokenType_1.TokenType.OptionalChaining]: {},
|
|
52
|
+
[TokenType_1.TokenType.BinaryNot]: { expressionStart: true, canBeUnary: true },
|
|
53
|
+
[TokenType_1.TokenType.LBrace]: { expressionStart: true },
|
|
54
|
+
[TokenType_1.TokenType.RBrace]: {},
|
|
55
|
+
[TokenType_1.TokenType.Equal]: {},
|
|
56
|
+
[TokenType_1.TokenType.StrictEqual]: {},
|
|
57
|
+
[TokenType_1.TokenType.LogicalNot]: { expressionStart: true, canBeUnary: true },
|
|
58
|
+
[TokenType_1.TokenType.NotEqual]: {},
|
|
59
|
+
[TokenType_1.TokenType.StrictNotEqual]: {},
|
|
60
|
+
[TokenType_1.TokenType.LessThan]: {},
|
|
61
|
+
[TokenType_1.TokenType.LessThanOrEqual]: {},
|
|
62
|
+
[TokenType_1.TokenType.ShiftLeft]: {},
|
|
63
|
+
[TokenType_1.TokenType.GreaterThan]: {},
|
|
64
|
+
[TokenType_1.TokenType.GreaterThanOrEqual]: {},
|
|
65
|
+
[TokenType_1.TokenType.ShiftRight]: {},
|
|
66
|
+
[TokenType_1.TokenType.SignedShiftRight]: {},
|
|
67
|
+
[TokenType_1.TokenType.Dot]: {},
|
|
68
|
+
[TokenType_1.TokenType.Spread]: { expressionStart: true, isPropLiteral: true },
|
|
69
|
+
[TokenType_1.TokenType.Global]: { expressionStart: true },
|
|
70
|
+
[TokenType_1.TokenType.DecimalLiteral]: { expressionStart: true, isPropLiteral: true },
|
|
71
|
+
[TokenType_1.TokenType.HexadecimalLiteral]: { expressionStart: true, isPropLiteral: true },
|
|
72
|
+
[TokenType_1.TokenType.BinaryLiteral]: { expressionStart: true, isPropLiteral: true },
|
|
73
|
+
[TokenType_1.TokenType.RealLiteral]: { expressionStart: true, isPropLiteral: true },
|
|
74
|
+
[TokenType_1.TokenType.StringLiteral]: { expressionStart: true, isPropLiteral: true },
|
|
75
|
+
[TokenType_1.TokenType.IncOp]: { expressionStart: true },
|
|
76
|
+
[TokenType_1.TokenType.DecOp]: { expressionStart: true },
|
|
77
|
+
[TokenType_1.TokenType.Infinity]: { expressionStart: true, keywordLike: true },
|
|
78
|
+
[TokenType_1.TokenType.NaN]: { expressionStart: true, keywordLike: true },
|
|
79
|
+
[TokenType_1.TokenType.True]: { expressionStart: true, keywordLike: true, isPropLiteral: true },
|
|
80
|
+
[TokenType_1.TokenType.False]: { expressionStart: true, keywordLike: true, isPropLiteral: true },
|
|
81
|
+
[TokenType_1.TokenType.Typeof]: { expressionStart: true, canBeUnary: true, keywordLike: true },
|
|
82
|
+
[TokenType_1.TokenType.Null]: { expressionStart: true, keywordLike: true },
|
|
83
|
+
[TokenType_1.TokenType.Undefined]: { expressionStart: true, keywordLike: true },
|
|
84
|
+
[TokenType_1.TokenType.In]: { keywordLike: true },
|
|
85
|
+
[TokenType_1.TokenType.Let]: { keywordLike: true },
|
|
86
|
+
[TokenType_1.TokenType.Const]: { keywordLike: true },
|
|
87
|
+
[TokenType_1.TokenType.Var]: { keywordLike: true },
|
|
88
|
+
[TokenType_1.TokenType.If]: { keywordLike: true },
|
|
89
|
+
[TokenType_1.TokenType.Else]: { keywordLike: true },
|
|
90
|
+
[TokenType_1.TokenType.Arrow]: { keywordLike: true },
|
|
91
|
+
[TokenType_1.TokenType.Return]: { keywordLike: true },
|
|
92
|
+
[TokenType_1.TokenType.Break]: { keywordLike: true },
|
|
93
|
+
[TokenType_1.TokenType.Continue]: { keywordLike: true },
|
|
94
|
+
[TokenType_1.TokenType.Do]: { keywordLike: true },
|
|
95
|
+
[TokenType_1.TokenType.While]: { keywordLike: true },
|
|
96
|
+
[TokenType_1.TokenType.For]: { keywordLike: true },
|
|
97
|
+
[TokenType_1.TokenType.Of]: { keywordLike: true },
|
|
98
|
+
[TokenType_1.TokenType.Throw]: { keywordLike: true },
|
|
99
|
+
[TokenType_1.TokenType.Try]: { keywordLike: true },
|
|
100
|
+
[TokenType_1.TokenType.Catch]: { keywordLike: true },
|
|
101
|
+
[TokenType_1.TokenType.Finally]: { keywordLike: true },
|
|
102
|
+
[TokenType_1.TokenType.Switch]: { keywordLike: true },
|
|
103
|
+
[TokenType_1.TokenType.Case]: { keywordLike: true },
|
|
104
|
+
[TokenType_1.TokenType.Default]: { keywordLike: true },
|
|
105
|
+
[TokenType_1.TokenType.Delete]: { expressionStart: true, canBeUnary: true, keywordLike: true },
|
|
106
|
+
[TokenType_1.TokenType.Function]: { keywordLike: true, expressionStart: true },
|
|
107
|
+
[TokenType_1.TokenType.As]: { keywordLike: true },
|
|
108
|
+
[TokenType_1.TokenType.From]: { keywordLike: true },
|
|
109
|
+
};
|
|
@@ -105,8 +105,6 @@ var TokenType;
|
|
|
105
105
|
TokenType[TokenType["Default"] = 93] = "Default";
|
|
106
106
|
TokenType[TokenType["Delete"] = 94] = "Delete";
|
|
107
107
|
TokenType[TokenType["Function"] = 95] = "Function";
|
|
108
|
-
TokenType[TokenType["
|
|
109
|
-
TokenType[TokenType["
|
|
110
|
-
TokenType[TokenType["As"] = 98] = "As";
|
|
111
|
-
TokenType[TokenType["From"] = 99] = "From";
|
|
108
|
+
TokenType[TokenType["As"] = 96] = "As";
|
|
109
|
+
TokenType[TokenType["From"] = 97] = "From";
|
|
112
110
|
})(TokenType || (exports.TokenType = TokenType = {}));
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PARSED_MARK_PROP = void 0;
|
|
4
|
+
exports.collectCodeBehindFromSource = collectCodeBehindFromSource;
|
|
5
|
+
exports.removeCodeBehindTokensFromTree = removeCodeBehindTokensFromTree;
|
|
6
|
+
const ScriptingSourceTreeExp_1 = require("../../abstractions/scripting/ScriptingSourceTreeExp");
|
|
7
|
+
const tree_visitor_1 = require("./tree-visitor");
|
|
8
|
+
const modules_1 = require("./modules");
|
|
9
|
+
exports.PARSED_MARK_PROP = "__PARSED__";
|
|
10
|
+
// --- Collect module statements from a parsed module
|
|
11
|
+
function collectCodeBehindFromSource(moduleName, source) {
|
|
12
|
+
const result = {
|
|
13
|
+
vars: {},
|
|
14
|
+
moduleErrors: {},
|
|
15
|
+
functions: {},
|
|
16
|
+
};
|
|
17
|
+
const collectedFunctions = {};
|
|
18
|
+
// --- Parse the module (recursively, including imported modules) in restrictive mode
|
|
19
|
+
const parsedModule = (0, modules_1.parseScriptModule)(moduleName, source);
|
|
20
|
+
if ((0, modules_1.isModuleErrors)(parsedModule)) {
|
|
21
|
+
return Object.assign(Object.assign({}, result), { moduleErrors: parsedModule });
|
|
22
|
+
}
|
|
23
|
+
// --- Collect statements from the module
|
|
24
|
+
parsedModule.statements.forEach((stmt) => {
|
|
25
|
+
switch (stmt.type) {
|
|
26
|
+
case ScriptingSourceTreeExp_1.T_VAR_STATEMENT:
|
|
27
|
+
stmt.decls.forEach((decl) => {
|
|
28
|
+
if (decl.id.name in result.vars) {
|
|
29
|
+
throw new Error(`Duplicated var declaration: '${decl.id.name}'`);
|
|
30
|
+
}
|
|
31
|
+
result.vars[decl.id.name] = {
|
|
32
|
+
[exports.PARSED_MARK_PROP]: true,
|
|
33
|
+
tree: decl.expr,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
break;
|
|
37
|
+
case ScriptingSourceTreeExp_1.T_FUNCTION_DECLARATION:
|
|
38
|
+
addFunctionDeclaration(stmt);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`'${stmt.type}' is not allowed in a code-behind module.`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
45
|
+
// --- Collect function declaration data
|
|
46
|
+
function addFunctionDeclaration(stmt) {
|
|
47
|
+
if ((collectedFunctions === null || collectedFunctions === void 0 ? void 0 : collectedFunctions[stmt.id.name]) !== undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (stmt.id.name in result.functions) {
|
|
51
|
+
throw new Error(`Duplicated function declaration: '${stmt.id.name}'`);
|
|
52
|
+
}
|
|
53
|
+
const arrow = {
|
|
54
|
+
type: ScriptingSourceTreeExp_1.T_ARROW_EXPRESSION,
|
|
55
|
+
args: stmt.args.slice(),
|
|
56
|
+
statement: stmt.stmt,
|
|
57
|
+
// closureContext: obtainClosures({
|
|
58
|
+
// childThreads: [],
|
|
59
|
+
// blocks: [{ vars: {} }],
|
|
60
|
+
// loops: [],
|
|
61
|
+
// breakLabelValue: -1,
|
|
62
|
+
// }),
|
|
63
|
+
};
|
|
64
|
+
collectedFunctions[stmt.id.name] = {
|
|
65
|
+
[exports.PARSED_MARK_PROP]: true,
|
|
66
|
+
tree: arrow,
|
|
67
|
+
};
|
|
68
|
+
result.functions[stmt.id.name] = {
|
|
69
|
+
[exports.PARSED_MARK_PROP]: true,
|
|
70
|
+
tree: arrow,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// --- Remove all code-behind tokens from the tree
|
|
75
|
+
function removeCodeBehindTokensFromTree(declarations) {
|
|
76
|
+
if (!declarations)
|
|
77
|
+
return;
|
|
78
|
+
const state = {
|
|
79
|
+
data: null,
|
|
80
|
+
cancel: false,
|
|
81
|
+
skipChildren: false,
|
|
82
|
+
};
|
|
83
|
+
Object.keys(declarations.vars).forEach((key) => {
|
|
84
|
+
removeTokens(declarations.vars[key]);
|
|
85
|
+
});
|
|
86
|
+
Object.keys(declarations.functions).forEach((key) => {
|
|
87
|
+
removeTokens(declarations.functions[key]);
|
|
88
|
+
});
|
|
89
|
+
function removeTokens(declaration) {
|
|
90
|
+
const nodeVisitor = (before, visited, state) => {
|
|
91
|
+
if (before) {
|
|
92
|
+
if (visited) {
|
|
93
|
+
delete visited.startToken;
|
|
94
|
+
delete visited.endToken;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return state;
|
|
98
|
+
};
|
|
99
|
+
(0, tree_visitor_1.visitNode)(declaration.tree, state, nodeVisitor, nodeVisitor);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isModuleErrors = isModuleErrors;
|
|
4
|
+
exports.parseScriptModule = parseScriptModule;
|
|
5
|
+
const ScriptingSourceTreeExp_1 = require("../../abstractions/scripting/ScriptingSourceTreeExp");
|
|
6
|
+
const Parser_1 = require("./Parser");
|
|
7
|
+
const ParserError_1 = require("./ParserError");
|
|
8
|
+
const TokenType_1 = require("./TokenType");
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the result is a module error
|
|
11
|
+
* @param result Result to check
|
|
12
|
+
* @returns True if the result is a module error
|
|
13
|
+
*/
|
|
14
|
+
function isModuleErrors(result) {
|
|
15
|
+
return result.type !== "ScriptModule";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parses a script module
|
|
19
|
+
* @param moduleName Name of the module
|
|
20
|
+
* @param source Source code to parse
|
|
21
|
+
* @param moduleResolver A function that resolves a module path to the text of the module
|
|
22
|
+
* @returns The parsed and resolved module
|
|
23
|
+
*/
|
|
24
|
+
function parseScriptModule(moduleName, source) {
|
|
25
|
+
// --- Keep track of parsed modules to avoid circular references
|
|
26
|
+
const parsedModules = new Map();
|
|
27
|
+
const moduleErrors = {};
|
|
28
|
+
const parsedModule = doParseModule(moduleName, source);
|
|
29
|
+
return !parsedModule || Object.keys(moduleErrors).length > 0 ? moduleErrors : parsedModule;
|
|
30
|
+
// --- Do the parsing, allow recursion
|
|
31
|
+
function doParseModule(moduleName, source) {
|
|
32
|
+
var _a;
|
|
33
|
+
// --- Do not parse the same module twice
|
|
34
|
+
if (parsedModules.has(moduleName)) {
|
|
35
|
+
return parsedModules.get(moduleName);
|
|
36
|
+
}
|
|
37
|
+
// --- Parse the source code
|
|
38
|
+
const parser = new Parser_1.Parser(source);
|
|
39
|
+
let statements = [];
|
|
40
|
+
try {
|
|
41
|
+
statements = parser.parseStatements();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
moduleErrors[moduleName] = parser.errors;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// --- Check for unparsed tail
|
|
48
|
+
const lastToken = parser.current;
|
|
49
|
+
if (lastToken.type !== TokenType_1.TokenType.Eof) {
|
|
50
|
+
(_a = moduleErrors[moduleName]) !== null && _a !== void 0 ? _a : (moduleErrors[moduleName] = []);
|
|
51
|
+
moduleErrors[moduleName].push({
|
|
52
|
+
code: "W002",
|
|
53
|
+
text: ParserError_1.errorMessages["W002"].replace(/\{(\d+)}/g, () => lastToken.text),
|
|
54
|
+
position: lastToken.startLine,
|
|
55
|
+
line: lastToken.startLine,
|
|
56
|
+
column: lastToken.startColumn,
|
|
57
|
+
});
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const errors = [];
|
|
61
|
+
// --- Collect functions
|
|
62
|
+
const functions = {};
|
|
63
|
+
statements
|
|
64
|
+
.filter((stmt) => stmt.type === ScriptingSourceTreeExp_1.T_FUNCTION_DECLARATION)
|
|
65
|
+
.forEach((stmt) => {
|
|
66
|
+
const func = stmt;
|
|
67
|
+
if (functions[func.id.name]) {
|
|
68
|
+
addErrorMessage("W020", stmt, func.id.name);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
functions[func.id.name] = func;
|
|
72
|
+
});
|
|
73
|
+
// --- Successful module parsing
|
|
74
|
+
const parsedModule = {
|
|
75
|
+
type: "ScriptModule",
|
|
76
|
+
name: moduleName,
|
|
77
|
+
exports,
|
|
78
|
+
functions,
|
|
79
|
+
statements: statements,
|
|
80
|
+
sources: new Map(),
|
|
81
|
+
executed: false,
|
|
82
|
+
};
|
|
83
|
+
// --- Sign this module as parsed
|
|
84
|
+
parsedModules.set(moduleName, parsedModule);
|
|
85
|
+
// --- Catch errors
|
|
86
|
+
if (errors.length > 0) {
|
|
87
|
+
moduleErrors[moduleName] = errors;
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// --- Done.
|
|
91
|
+
return parsedModule;
|
|
92
|
+
function addErrorMessage(code, stmt, ...args) {
|
|
93
|
+
var _a, _b, _c;
|
|
94
|
+
let errorText = ParserError_1.errorMessages[code];
|
|
95
|
+
if (args) {
|
|
96
|
+
args.forEach((o, idx) => (errorText = errorText.replaceAll(`{${idx}}`, args[idx].toString())));
|
|
97
|
+
}
|
|
98
|
+
errors.push({
|
|
99
|
+
code,
|
|
100
|
+
text: ParserError_1.errorMessages[code].replace(/\{(\d+)}/g, (_, index) => args[index]),
|
|
101
|
+
position: (_a = stmt.startToken) === null || _a === void 0 ? void 0 : _a.startPosition,
|
|
102
|
+
line: (_b = stmt.startToken) === null || _b === void 0 ? void 0 : _b.startLine,
|
|
103
|
+
column: (_c = stmt.startToken) === null || _c === void 0 ? void 0 : _c.startColumn,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|