xmlui 0.4.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/dist/Pdf-DeGhSMXe.mjs +19537 -0
- package/dist/Pdf.css +1 -0
- package/dist/apiInterceptorWorker-CwuUhYyc.mjs +9229 -0
- package/dist/array-USo-Szhp.mjs +12 -0
- package/dist/index-C24dkfpd.mjs +1434 -0
- package/dist/index-ao27SnVp.mjs +145185 -0
- package/dist/index.css +1 -0
- package/dist/nivo-bar.es-CWh0ZlxB.mjs +1666 -0
- package/dist/nivo-geo.es-BTqNt5Db.mjs +1579 -0
- package/dist/nivo-legends.es-BuIxHGSU.mjs +6916 -0
- package/dist/nivo-pie.es-BvCBFA0L.mjs +700 -0
- package/dist/react-apexcharts.min-DqWuDOyO.mjs +8881 -0
- package/dist/scripts/bin/bootstrap.js +11 -0
- package/dist/scripts/bin/build.js +256 -0
- package/dist/scripts/bin/index.js +88 -0
- package/dist/scripts/bin/preview.js +27 -0
- package/dist/scripts/bin/start.js +41 -0
- package/dist/scripts/bin/vite-ueml-plugin.js +113 -0
- package/dist/scripts/bin/viteConfig.js +112 -0
- package/dist/scripts/src/abstractions/ActionDefs.js +2 -0
- package/dist/scripts/src/abstractions/AppContextDefs.js +2 -0
- package/dist/scripts/src/abstractions/BlockScope.js +4 -0
- package/dist/scripts/src/abstractions/ComponentDefs.js +2 -0
- package/dist/scripts/src/abstractions/ComponentDescriptorDefs.js +2 -0
- package/dist/scripts/src/abstractions/ContainerDefs.js +2 -0
- package/dist/scripts/src/abstractions/FunctionDefs.js +2 -0
- package/dist/scripts/src/abstractions/RendererDefs.js +2 -0
- package/dist/scripts/src/abstractions/scripting/ScriptParserError.js +2 -0
- package/dist/scripts/src/abstractions/scripting/ScriptingSourceTree.js +2 -0
- package/dist/scripts/src/abstractions/scripting/Token.js +110 -0
- package/dist/scripts/src/components/App/App.js +253 -0
- package/dist/scripts/src/components/App/AppLayoutContext.js +9 -0
- package/dist/scripts/src/components/App/AppStateContext.js +9 -0
- package/dist/scripts/src/components/App/Sheet.js +89 -0
- package/dist/scripts/src/components/AppHeader/AppHeader.js +121 -0
- package/dist/scripts/src/components/AppState/AppState.js +29 -0
- package/dist/scripts/src/components/Avatar/Avatar.js +81 -0
- package/dist/scripts/src/components/Badge/Badge.js +56 -0
- package/dist/scripts/src/components/BarChart/BarChart.js +199 -0
- package/dist/scripts/src/components/Bookmark/Bookmark.js +11 -0
- package/dist/scripts/src/components/Button/Button.js +196 -0
- package/dist/scripts/src/components/Card/Card.js +65 -0
- package/dist/scripts/src/components/ChangeListener/ChangeListener.js +43 -0
- package/dist/scripts/src/components/Chart/Chart.js +158 -0
- package/dist/scripts/src/components/Checkbox/Checkbox.js +43 -0
- package/dist/scripts/src/components/Combobox/Combobox.js +145 -0
- package/dist/scripts/src/components/ComponentProvider.js +357 -0
- package/dist/scripts/src/components/ContentSeparator/ContentSeparator.js +40 -0
- package/dist/scripts/src/components/DatePicker/DatePicker.js +196 -0
- package/dist/scripts/src/components/DropdownMenu/DropdownMenu.js +175 -0
- package/dist/scripts/src/components/EmojiSelector/EmojiSelector.js +56 -0
- package/dist/scripts/src/components/FileInput/FileInput.js +127 -0
- package/dist/scripts/src/components/FileUploadDropZone/FileUploadDropZone.js +106 -0
- package/dist/scripts/src/components/FlowLayout/FlowLayout.js +139 -0
- package/dist/scripts/src/components/Footer/Footer.js +42 -0
- package/dist/scripts/src/components/Form/Form.js +320 -0
- package/dist/scripts/src/components/Form/FormContext.js +9 -0
- package/dist/scripts/src/components/Form/formActions.js +86 -0
- package/dist/scripts/src/components/FormItem/FormItem.js +204 -0
- package/dist/scripts/src/components/FormItem/HelperText.js +27 -0
- package/dist/scripts/src/components/FormItem/ItemWithLabel.js +39 -0
- package/dist/scripts/src/components/FormItem/Validations.js +346 -0
- package/dist/scripts/src/components/FormSection/FormSection.js +45 -0
- package/dist/scripts/src/components/Heading/Heading.js +206 -0
- package/dist/scripts/src/components/HoverCard/HoverCard.js +45 -0
- package/dist/scripts/src/components/Icon/ApiIcon.js +10 -0
- package/dist/scripts/src/components/Icon/Attach.js +10 -0
- package/dist/scripts/src/components/Icon/Binding.js +11 -0
- package/dist/scripts/src/components/Icon/BoardIcon.js +7 -0
- package/dist/scripts/src/components/Icon/BoxIcon.js +10 -0
- package/dist/scripts/src/components/Icon/CheckIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ChevronDownIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ChevronLeft.js +7 -0
- package/dist/scripts/src/components/Icon/ChevronRight.js +7 -0
- package/dist/scripts/src/components/Icon/ChevronUpIcon.js +7 -0
- package/dist/scripts/src/components/Icon/CodeFileIcon.js +10 -0
- package/dist/scripts/src/components/Icon/CodeSandbox.js +10 -0
- package/dist/scripts/src/components/Icon/CompactListIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ContentCopyIcon.js +7 -0
- package/dist/scripts/src/components/Icon/DatabaseIcon.js +11 -0
- package/dist/scripts/src/components/Icon/DocFileIcon.js +10 -0
- package/dist/scripts/src/components/Icon/DocIcon.js +10 -0
- package/dist/scripts/src/components/Icon/DotMenuHorizontalIcon.js +7 -0
- package/dist/scripts/src/components/Icon/DotMenuIcon.js +7 -0
- package/dist/scripts/src/components/Icon/EmailIcon.js +7 -0
- package/dist/scripts/src/components/Icon/EmptyFolderIcon.js +10 -0
- package/dist/scripts/src/components/Icon/ErrorIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ExpressionIcon.js +10 -0
- package/dist/scripts/src/components/Icon/FillPlusCricleIcon.js +7 -0
- package/dist/scripts/src/components/Icon/FilterIcon.js +10 -0
- package/dist/scripts/src/components/Icon/FolderIcon.js +10 -0
- package/dist/scripts/src/components/Icon/GlobeIcon.js +7 -0
- package/dist/scripts/src/components/Icon/HomeIcon.js +7 -0
- package/dist/scripts/src/components/Icon/HyperLinkIcon.js +7 -0
- package/dist/scripts/src/components/Icon/Icon.js +101 -0
- package/dist/scripts/src/components/Icon/ImageFileIcon.js +10 -0
- package/dist/scripts/src/components/Icon/LinkIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ListIcon.js +7 -0
- package/dist/scripts/src/components/Icon/LooseListIcon.js +7 -0
- package/dist/scripts/src/components/Icon/MoonIcon.js +10 -0
- package/dist/scripts/src/components/Icon/MoreOptionsIcon.js +7 -0
- package/dist/scripts/src/components/Icon/PDFIcon.js +10 -0
- package/dist/scripts/src/components/Icon/PenIcon.js +7 -0
- package/dist/scripts/src/components/Icon/PhoneIcon.js +7 -0
- package/dist/scripts/src/components/Icon/PhotoIcon.js +10 -0
- package/dist/scripts/src/components/Icon/PlusIcon.js +7 -0
- package/dist/scripts/src/components/Icon/SearchIcon.js +7 -0
- package/dist/scripts/src/components/Icon/ShareIcon.js +10 -0
- package/dist/scripts/src/components/Icon/SunIcon.js +10 -0
- package/dist/scripts/src/components/Icon/TrashIcon.js +7 -0
- package/dist/scripts/src/components/Icon/TxtIcon.js +10 -0
- package/dist/scripts/src/components/Icon/UnknownFileIcon.js +10 -0
- package/dist/scripts/src/components/Icon/UnlinkIcon.js +10 -0
- package/dist/scripts/src/components/Icon/UserIcon.js +7 -0
- package/dist/scripts/src/components/Icon/WarningIcon.js +7 -0
- package/dist/scripts/src/components/Icon/XlsIcon.js +10 -0
- package/dist/scripts/src/components/IconProvider.js +249 -0
- package/dist/scripts/src/components/IconRegistryContext.js +307 -0
- package/dist/scripts/src/components/Image/Image.js +34 -0
- package/dist/scripts/src/components/Input/InputAdornment.js +14 -0
- package/dist/scripts/src/components/Input/input-abstractions.js +44 -0
- package/dist/scripts/src/components/Items/Items.js +48 -0
- package/dist/scripts/src/components/Link/Link.js +72 -0
- package/dist/scripts/src/components/List/List.js +442 -0
- package/dist/scripts/src/components/Logo/Logo.js +25 -0
- package/dist/scripts/src/components/Map/Map.js +60 -0
- package/dist/scripts/src/components/Map/world_countries.json +45307 -0
- package/dist/scripts/src/components/Markdown/Markdown.js +120 -0
- package/dist/scripts/src/components/ModalDialog/ConfirmationModalContextProvider.js +106 -0
- package/dist/scripts/src/components/ModalDialog/Dialog.js +20 -0
- package/dist/scripts/src/components/ModalDialog/ModalDialog.js +145 -0
- package/dist/scripts/src/components/MultiCombobox/MultiCombobox.js +249 -0
- package/dist/scripts/src/components/MultiSelect/MultiSelect.js +192 -0
- package/dist/scripts/src/components/NavGroup/NavGroup.js +113 -0
- package/dist/scripts/src/components/NavLink/NavLink.js +115 -0
- package/dist/scripts/src/components/NavPanel/NavPanel.js +101 -0
- package/dist/scripts/src/components/NoResult/NoResult.js +39 -0
- package/dist/scripts/src/components/NumberBox/NumberBox.js +373 -0
- package/dist/scripts/src/components/Option/Option.js +41 -0
- package/dist/scripts/src/components/PageMetaTitle/PageMetaTitle.js +22 -0
- package/dist/scripts/src/components/Pages/Pages.js +74 -0
- package/dist/scripts/src/components/Pdf/LazyPdf.js +44 -0
- package/dist/scripts/src/components/Pdf/Pdf.js +19 -0
- package/dist/scripts/src/components/PieChart/PieChart.js +184 -0
- package/dist/scripts/src/components/PositionedContainer/PositionedContainer.js +29 -0
- package/dist/scripts/src/components/ProgressBar/ProgressBar.js +38 -0
- package/dist/scripts/src/components/Queue/Queue.js +286 -0
- package/dist/scripts/src/components/Queue/queueActions.js +87 -0
- package/dist/scripts/src/components/RadioGroup/RadioGroup.js +144 -0
- package/dist/scripts/src/components/RealTimeAdapter/RealTimeAdapter.js +147 -0
- package/dist/scripts/src/components/Redirect/Redirect.js +10 -0
- package/dist/scripts/src/components/Select/Select.js +139 -0
- package/dist/scripts/src/components/Select/SelectContext.js +45 -0
- package/dist/scripts/src/components/SelectionStore/SelectionStore.js +88 -0
- package/dist/scripts/src/components/SpaceFiller/SpaceFiller.js +22 -0
- package/dist/scripts/src/components/Spinner/Spinner.js +59 -0
- package/dist/scripts/src/components/Splitter/Splitter.js +205 -0
- package/dist/scripts/src/components/Splitter/utils.js +17 -0
- package/dist/scripts/src/components/Stack/Stack.js +117 -0
- package/dist/scripts/src/components/StickyBox/StickyBox.js +33 -0
- package/dist/scripts/src/components/Switch/Switch.js +50 -0
- package/dist/scripts/src/components/Table/Table.js +499 -0
- package/dist/scripts/src/components/Table/useRowSelection.js +169 -0
- package/dist/scripts/src/components/TableColumnDef/TableColumnDef.js +44 -0
- package/dist/scripts/src/components/TableColumnDef/TableContext.js +12 -0
- package/dist/scripts/src/components/Tabs/Tabs.js +85 -0
- package/dist/scripts/src/components/Text/Text.js +175 -0
- package/dist/scripts/src/components/TextArea/TextArea.js +194 -0
- package/dist/scripts/src/components/TextArea/TextAreaResizable.js +63 -0
- package/dist/scripts/src/components/TextArea/useComposedRef.js +50 -0
- package/dist/scripts/src/components/TextBox/TextBox.js +145 -0
- package/dist/scripts/src/components/Theme/NotificationToast.js +39 -0
- package/dist/scripts/src/components/Theme/Theme.js +153 -0
- package/dist/scripts/src/components/ThemeChanger/ThemeChanger.js +125 -0
- package/dist/scripts/src/components/Toggle/Toggle.js +88 -0
- package/dist/scripts/src/components/Tree/TreeComponent.js +79 -0
- package/dist/scripts/src/components/ValidationSummary/ValidationSummary.js +59 -0
- package/dist/scripts/src/components/ViewComponentRegistryContext.js +34 -0
- package/dist/scripts/src/components/abstractions.js +2 -0
- package/dist/scripts/src/components/chart-color-schemes.js +43 -0
- package/dist/scripts/src/components/component-utils.js +32 -0
- package/dist/scripts/src/components/container-helpers.js +18 -0
- package/dist/scripts/src/components-core/ApiBoundComponent.js +189 -0
- package/dist/scripts/src/components-core/AppContext.js +17 -0
- package/dist/scripts/src/components-core/ChildrenSlot.js +10 -0
- package/dist/scripts/src/components-core/Component.js +280 -0
- package/dist/scripts/src/components-core/ComponentDecorator.js +63 -0
- package/dist/scripts/src/components-core/CompoundComponent.js +132 -0
- package/dist/scripts/src/components-core/EngineError.js +91 -0
- package/dist/scripts/src/components-core/ErrorBoundary.js +58 -0
- package/dist/scripts/src/components-core/Fragment.js +14 -0
- package/dist/scripts/src/components-core/InvalidComponent.js +15 -0
- package/dist/scripts/src/components-core/LoaderComponent.js +78 -0
- package/dist/scripts/src/components-core/RestApiProxy.js +341 -0
- package/dist/scripts/src/components-core/RootComponent.js +272 -0
- package/dist/scripts/src/components-core/RouteContext.js +45 -0
- package/dist/scripts/src/components-core/ScrollContext.js +9 -0
- package/dist/scripts/src/components-core/UnknownComponent.js +15 -0
- package/dist/scripts/src/components-core/abstractions/ComponentRenderer.js +2 -0
- package/dist/scripts/src/components-core/abstractions/LoaderRenderer.js +2 -0
- package/dist/scripts/src/components-core/abstractions/containers.js +18 -0
- package/dist/scripts/src/components-core/abstractions/treeAbstractions.js +2 -0
- package/dist/scripts/src/components-core/action/ApiAction.js +276 -0
- package/dist/scripts/src/components-core/action/DownloadFileAction.js +80 -0
- package/dist/scripts/src/components-core/action/NavigateAction.js +20 -0
- package/dist/scripts/src/components-core/action/TimedAction.js +21 -0
- package/dist/scripts/src/components-core/action/UploadAction.js +88 -0
- package/dist/scripts/src/components-core/action/actions.js +15 -0
- package/dist/scripts/src/components-core/appContext/date-functions.js +19 -0
- package/dist/scripts/src/components-core/appContext/misc-utils.js +12 -0
- package/dist/scripts/src/components-core/component-hooks.js +25 -0
- package/dist/scripts/src/components-core/constants.js +18 -0
- package/dist/scripts/src/components-core/container/Container.js +1110 -0
- package/dist/scripts/src/components-core/container/ContainerComponentDef.js +16 -0
- package/dist/scripts/src/components-core/container/buildProxy.js +54 -0
- package/dist/scripts/src/components-core/container/collectFnVarDeps.js +26 -0
- package/dist/scripts/src/components-core/container/valueExtractor.js +195 -0
- package/dist/scripts/src/components-core/descriptorHelper.js +75 -0
- package/dist/scripts/src/components-core/interception/abstractions.js +2 -0
- package/dist/scripts/src/components-core/interception/useApiInterceptorContext.js +9 -0
- package/dist/scripts/src/components-core/loader/ApiLoader.js +46 -0
- package/dist/scripts/src/components-core/loader/DataLoader.js +160 -0
- package/dist/scripts/src/components-core/loader/ExternalDataLoader.js +52 -0
- package/dist/scripts/src/components-core/loader/Loader.js +115 -0
- package/dist/scripts/src/components-core/loader/MockLoaderRenderer.js +32 -0
- package/dist/scripts/src/components-core/loader/PageableLoader.js +240 -0
- package/dist/scripts/src/components-core/renderers.js +45 -0
- package/dist/scripts/src/components-core/reportEngineError.js +59 -0
- package/dist/scripts/src/components-core/script-runner/BindingTreeEvaluationContext.js +35 -0
- package/dist/scripts/src/components-core/script-runner/ICustomOperations.js +34 -0
- package/dist/scripts/src/components-core/script-runner/LogicalThread.js +2 -0
- package/dist/scripts/src/components-core/script-runner/LoopScope.js +2 -0
- package/dist/scripts/src/components-core/script-runner/ParameterParser.js +117 -0
- package/dist/scripts/src/components-core/script-runner/TryScope.js +2 -0
- package/dist/scripts/src/components-core/script-runner/asyncProxy.js +96 -0
- package/dist/scripts/src/components-core/script-runner/bannedFunctions.js +34 -0
- package/dist/scripts/src/components-core/script-runner/custom-operations-registry.js +40 -0
- package/dist/scripts/src/components-core/script-runner/custom-ui-data.js +40 -0
- package/dist/scripts/src/components-core/script-runner/eval-tree-async.js +551 -0
- package/dist/scripts/src/components-core/script-runner/eval-tree-common.js +498 -0
- package/dist/scripts/src/components-core/script-runner/eval-tree-sync.js +434 -0
- package/dist/scripts/src/components-core/script-runner/modules.js +250 -0
- package/dist/scripts/src/components-core/script-runner/process-statement-async.js +818 -0
- package/dist/scripts/src/components-core/script-runner/process-statement-common.js +193 -0
- package/dist/scripts/src/components-core/script-runner/process-statement-sync.js +740 -0
- package/dist/scripts/src/components-core/script-runner/statement-queue.js +62 -0
- package/dist/scripts/src/components-core/script-runner/visitors.js +352 -0
- package/dist/scripts/src/components-core/theming/ThemeContext.js +43 -0
- package/dist/scripts/src/components-core/theming/ThemeProvider.js +334 -0
- package/dist/scripts/src/components-core/theming/abstractions.js +11 -0
- package/dist/scripts/src/components-core/theming/extendThemeUtils.js +114 -0
- package/dist/scripts/src/components-core/theming/hvar.js +105 -0
- package/dist/scripts/src/components-core/theming/themeVars.js +62 -0
- package/dist/scripts/src/components-core/theming/themes/base-utils.js +31 -0
- package/dist/scripts/src/components-core/theming/themes/palette.js +53 -0
- package/dist/scripts/src/components-core/theming/themes/root.js +257 -0
- package/dist/scripts/src/components-core/theming/themes/solid.js +16 -0
- package/dist/scripts/src/components-core/theming/themes/theme-colors.js +407 -0
- package/dist/scripts/src/components-core/theming/themes/xmlui.js +32 -0
- package/dist/scripts/src/components-core/theming/transformThemeVars.js +286 -0
- package/dist/scripts/src/components-core/utils/DataLoaderQueryKeyGenerator.js +34 -0
- package/dist/scripts/src/components-core/utils/LruCache.js +184 -0
- package/dist/scripts/src/components-core/utils/actionUtils.js +32 -0
- package/dist/scripts/src/components-core/utils/classnames.js +58 -0
- package/dist/scripts/src/components-core/utils/css-utils.js +127 -0
- package/dist/scripts/src/components-core/utils/date-utils.js +78 -0
- package/dist/scripts/src/components-core/utils/extractParam.js +148 -0
- package/dist/scripts/src/components-core/utils/hooks.js +221 -0
- package/dist/scripts/src/components-core/utils/mergeProps.js +45 -0
- package/dist/scripts/src/components-core/utils/misc.js +460 -0
- package/dist/scripts/src/components-core/utils/statementUtils.js +205 -0
- package/dist/scripts/src/components-core/utils/treeUtils.js +48 -0
- package/dist/scripts/src/components-core/xmlui-parser.js +52 -0
- package/dist/scripts/src/parsers/scripting/InputStream.js +59 -0
- package/dist/scripts/src/parsers/scripting/Lexer.js +1028 -0
- package/dist/scripts/src/parsers/scripting/Parser.js +2647 -0
- package/dist/scripts/src/parsers/scripting/ParserError.js +46 -0
- package/dist/scripts/src/parsers/scripting/TokenTrait.js +109 -0
- package/dist/scripts/src/parsers/scripting/code-behind-collect.js +118 -0
- package/dist/scripts/src/parsers/scripting/tree-visitor.js +602 -0
- package/dist/scripts/src/parsers/style-parser/StyleInputStream.js +39 -0
- package/dist/scripts/src/parsers/style-parser/StyleLexer.js +621 -0
- package/dist/scripts/src/parsers/style-parser/StyleParser.js +1000 -0
- package/dist/scripts/src/parsers/style-parser/errors.js +37 -0
- package/dist/scripts/src/parsers/style-parser/source-tree.js +2 -0
- package/dist/scripts/src/parsers/style-parser/style-compiler.js +513 -0
- package/dist/scripts/src/parsers/style-parser/tokens.js +42 -0
- package/dist/scripts/src/parsers/ueml/ParserError.js +54 -0
- package/dist/scripts/src/parsers/ueml/UemlHelper.js +579 -0
- package/dist/scripts/src/parsers/ueml/UemlInputStream.js +59 -0
- package/dist/scripts/src/parsers/ueml/UemlLexer.js +868 -0
- package/dist/scripts/src/parsers/ueml/UemlParser.js +1439 -0
- package/dist/scripts/src/parsers/ueml/UemlToken.js +24 -0
- package/dist/scripts/src/parsers/ueml/fileExtensions.js +6 -0
- package/dist/scripts/src/parsers/ueml/source-tree.js +2 -0
- package/dist/scripts/src/parsers/ueml/ueml-tree.js +2 -0
- package/dist/scripts/src/parsers/xmlui-parser/CharacterCodes.js +136 -0
- package/dist/scripts/src/parsers/xmlui-parser/diagnostics.js +100 -0
- package/dist/scripts/src/parsers/xmlui-parser/parser.js +476 -0
- package/dist/scripts/src/parsers/xmlui-parser/scanner.js +415 -0
- package/dist/scripts/src/parsers/xmlui-parser/syntax-kind.js +106 -0
- package/dist/scripts/src/parsers/xmlui-parser/syntax-node.js +2 -0
- package/dist/scripts/src/parsers/xmlui-parser/transform.js +922 -0
- package/dist/scripts/src/parsers/xmlui-parser/utils.js +83 -0
- package/dist/xmlui.es.d.ts +1667 -0
- package/dist/xmlui.es.js +17 -0
- package/dist/xmlui.umd.js +1589 -0
- package/package.json +175 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evalBindingExpression = evalBindingExpression;
|
|
4
|
+
exports.evalBinding = evalBinding;
|
|
5
|
+
exports.executeArrowExpressionSync = executeArrowExpressionSync;
|
|
6
|
+
const eval_tree_common_1 = require("./eval-tree-common");
|
|
7
|
+
const Parser_1 = require("../../parsers/scripting/Parser");
|
|
8
|
+
const process_statement_common_1 = require("./process-statement-common");
|
|
9
|
+
const process_statement_sync_1 = require("./process-statement-sync");
|
|
10
|
+
const bannedFunctions_1 = require("./bannedFunctions");
|
|
11
|
+
/**
|
|
12
|
+
* Evaluates the specified binding expression tree and retrieves the evaluated value
|
|
13
|
+
* @param source Binding tree expression
|
|
14
|
+
* @param evalContext Evaluation context
|
|
15
|
+
* @param thread The logical thread to use for evaluation
|
|
16
|
+
* This code uses the JavaScript semantics and errors when evaluating the code.
|
|
17
|
+
*/
|
|
18
|
+
function evalBindingExpression(source, evalContext, thread) {
|
|
19
|
+
// --- Use the main thread by default
|
|
20
|
+
thread !== null && thread !== void 0 ? thread : (thread = evalContext.mainThread);
|
|
21
|
+
// --- Parse the source code
|
|
22
|
+
const wParser = new Parser_1.Parser(source);
|
|
23
|
+
const tree = wParser.parseExpr();
|
|
24
|
+
if (tree === null) {
|
|
25
|
+
// --- This should happen only when an expression is empty
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// --- Check for expression termination
|
|
29
|
+
if (!wParser.isEof) {
|
|
30
|
+
throw new Error("Expression is not terminated properly");
|
|
31
|
+
}
|
|
32
|
+
// --- Ok, valid source, evaluate
|
|
33
|
+
return evalBinding(tree, evalContext, thread);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Evaluates a binding represented by the specified expression
|
|
37
|
+
* @param expr Expression to evaluate
|
|
38
|
+
* @param evalContext Evaluation context to use
|
|
39
|
+
* @param thread The logical thread to use for evaluation
|
|
40
|
+
*/
|
|
41
|
+
function evalBinding(expr, evalContext, thread) {
|
|
42
|
+
const thisStack = [];
|
|
43
|
+
(0, process_statement_common_1.ensureMainThread)(evalContext);
|
|
44
|
+
thread !== null && thread !== void 0 ? thread : (thread = evalContext.mainThread);
|
|
45
|
+
return evalBindingExpressionTree(thisStack, expr, evalContext, thread !== null && thread !== void 0 ? thread : evalContext.mainThread);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Executes the specified arrow function
|
|
49
|
+
* @param expr Arrow function expression to run
|
|
50
|
+
* @param evalContext Evaluation context to use
|
|
51
|
+
* @param thread The logical thread to use for evaluation
|
|
52
|
+
* @param args Arguments of the arrow function to execute
|
|
53
|
+
*/
|
|
54
|
+
function executeArrowExpressionSync(expr, evalContext, thread, ...args) {
|
|
55
|
+
// --- Just an extra safety check
|
|
56
|
+
if (expr.type !== "ArrowE") {
|
|
57
|
+
throw new Error("executeArrowExpression expects an 'ArrowExpression' object.");
|
|
58
|
+
}
|
|
59
|
+
// --- This is the evaluator that an arrow expression uses internally
|
|
60
|
+
const evaluator = evalBindingExpressionTree;
|
|
61
|
+
// --- Compiles the Arrow function to a JavaScript function
|
|
62
|
+
const nativeFunction = createArrowFunction(evaluator, expr);
|
|
63
|
+
// --- Run the compiled arrow function. Note, we have two prefix arguments:
|
|
64
|
+
// --- #1: The names of arrow function arguments
|
|
65
|
+
// --- #2: The evaluation context the arrow function runs in
|
|
66
|
+
// --- #others: The real arguments of the arrow function
|
|
67
|
+
return nativeFunction(expr.args, evalContext, thread !== null && thread !== void 0 ? thread : evalContext.mainThread, ...args);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Evaluates the specified binding expression tree and retrieves the evaluated value
|
|
71
|
+
* @param expr Binding tree expression
|
|
72
|
+
* @param thisStack Stack of "this" object to use with function calls
|
|
73
|
+
* @param evalContext Evaluation context
|
|
74
|
+
* @param thread The logical thread to use for evaluation
|
|
75
|
+
* This code uses the JavaScript semantics and errors when evaluating the code.
|
|
76
|
+
* We use `thisStack` to keep track of the partial results of the evaluation tree so that we can set
|
|
77
|
+
* the real `this` context when invoking a function.
|
|
78
|
+
*/
|
|
79
|
+
function evalBindingExpressionTree(thisStack, expr, evalContext, thread) {
|
|
80
|
+
if (!evalContext.options) {
|
|
81
|
+
evalContext.options = { defaultToOptionalMemberAccess: true };
|
|
82
|
+
}
|
|
83
|
+
// --- Prepare evaluation
|
|
84
|
+
let customOp = null;
|
|
85
|
+
const evaluator = evalBindingExpressionTree;
|
|
86
|
+
// --- Reset the expression scope
|
|
87
|
+
expr.valueScope = expr.valueIndex = undefined;
|
|
88
|
+
// --- Process the expression according to its type
|
|
89
|
+
switch (expr.type) {
|
|
90
|
+
case "LitE":
|
|
91
|
+
return (0, eval_tree_common_1.evalLiteral)(thisStack, expr);
|
|
92
|
+
case "IdE":
|
|
93
|
+
return (0, eval_tree_common_1.evalIdentifier)(thisStack, expr, evalContext, thread);
|
|
94
|
+
case "MembE":
|
|
95
|
+
return evalMemberAccess(evaluator, thisStack, expr, evalContext, thread);
|
|
96
|
+
case "CMembE":
|
|
97
|
+
return evalCalculatedMemberAccess(evaluator, thisStack, expr, evalContext, thread);
|
|
98
|
+
case "SeqE":
|
|
99
|
+
return evalSequence(evaluator, thisStack, expr, evalContext, thread);
|
|
100
|
+
case "ALitE":
|
|
101
|
+
return evalArrayLiteral(evaluator, thisStack, expr, evalContext, thread);
|
|
102
|
+
case "OLitE":
|
|
103
|
+
return evalObjectLiteral(evaluator, thisStack, expr, evalContext, thread);
|
|
104
|
+
case "UnaryE":
|
|
105
|
+
return evalUnary(evaluator, thisStack, customOp, expr, evalContext, thread);
|
|
106
|
+
case "BinaryE":
|
|
107
|
+
return evalBinary(evaluator, thisStack, customOp, expr, evalContext, thread);
|
|
108
|
+
case "CondE":
|
|
109
|
+
return evalConditional(evaluator, thisStack, expr, evalContext, thread);
|
|
110
|
+
case "AsgnE":
|
|
111
|
+
return evalAssignment(evaluator, thisStack, expr, evalContext, thread);
|
|
112
|
+
case "PrefE":
|
|
113
|
+
case "PostfE":
|
|
114
|
+
return evalPreOrPost(evaluator, thisStack, expr, evalContext, thread);
|
|
115
|
+
case "InvokeE":
|
|
116
|
+
// --- Special sync handling
|
|
117
|
+
const funcResult = evalFunctionInvocation(evaluator, thisStack, expr, evalContext, thread);
|
|
118
|
+
if ((0, eval_tree_common_1.isPromise)(funcResult)) {
|
|
119
|
+
throw new Error("Promises (async function calls) are not allowed in binding expressions.");
|
|
120
|
+
}
|
|
121
|
+
return funcResult;
|
|
122
|
+
case "ArrowE":
|
|
123
|
+
// --- Special sync handling
|
|
124
|
+
return (0, eval_tree_common_1.evalArrow)(thisStack, expr, thread);
|
|
125
|
+
case "SpreadE":
|
|
126
|
+
throw new Error("Cannot use spread expression (...) with the current intermediate value.");
|
|
127
|
+
default:
|
|
128
|
+
throw new Error(`Unknown expression tree node: ${expr.type}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function evalMemberAccess(evaluator, thisStack, expr, evalContext, thread) {
|
|
132
|
+
const parentObj = evaluator(thisStack, expr.object, evalContext, thread);
|
|
133
|
+
return (0, eval_tree_common_1.evalMemberAccessCore)(parentObj, thisStack, expr, evalContext);
|
|
134
|
+
}
|
|
135
|
+
function evalCalculatedMemberAccess(evaluator, thisStack, expr, evalContext, thread) {
|
|
136
|
+
const parentObj = evaluator(thisStack, expr.object, evalContext, thread);
|
|
137
|
+
// --- At this point we definitely keep the parent object on `thisStack`, as it will be the context object
|
|
138
|
+
// --- of a FunctionInvocationExpression, if that follows the MemberAccess. Other operations would call
|
|
139
|
+
// --- `thisStack.pop()` to remove the result from the previous `evalBindingExpressionTree` call.
|
|
140
|
+
const memberObj = evaluator(thisStack, expr.member, evalContext, thread);
|
|
141
|
+
thisStack.pop();
|
|
142
|
+
return (0, eval_tree_common_1.evalCalculatedMemberAccessCore)(parentObj, memberObj, thisStack, expr, evalContext);
|
|
143
|
+
}
|
|
144
|
+
function evalSequence(evaluator, thisStack, expr, evalContext, thread) {
|
|
145
|
+
if (!expr.expressions || expr.expressions.length === 0) {
|
|
146
|
+
throw new Error(`Missing expression sequence`);
|
|
147
|
+
}
|
|
148
|
+
const result = expr.expressions.map((e) => {
|
|
149
|
+
const exprValue = evaluator(thisStack, e, evalContext, thread);
|
|
150
|
+
thisStack.pop();
|
|
151
|
+
return exprValue;
|
|
152
|
+
});
|
|
153
|
+
const lastObj = result[result.length - 1];
|
|
154
|
+
thisStack.push(lastObj);
|
|
155
|
+
return lastObj;
|
|
156
|
+
}
|
|
157
|
+
function evalArrayLiteral(evaluator, thisStack, expr, evalContext, thread) {
|
|
158
|
+
const arrayValue = [];
|
|
159
|
+
for (const item of expr.items) {
|
|
160
|
+
if (item.type === "SpreadE") {
|
|
161
|
+
const spreadArray = evaluator(thisStack, item.operand, evalContext, thread);
|
|
162
|
+
thisStack.pop();
|
|
163
|
+
if (!Array.isArray(spreadArray)) {
|
|
164
|
+
throw new Error("Spread operator within an array literal expects an array operand.");
|
|
165
|
+
}
|
|
166
|
+
arrayValue.push(...spreadArray);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
arrayValue.push(evaluator(thisStack, item, evalContext, thread));
|
|
170
|
+
thisStack.pop();
|
|
171
|
+
thisStack.push(arrayValue);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return arrayValue;
|
|
175
|
+
}
|
|
176
|
+
function evalObjectLiteral(evaluator, thisStack, expr, evalContext, thread) {
|
|
177
|
+
const objectHash = {};
|
|
178
|
+
for (const prop of expr.props) {
|
|
179
|
+
if (!Array.isArray(prop)) {
|
|
180
|
+
// --- We're using a spread expression
|
|
181
|
+
const spreadItems = evaluator(thisStack, prop.operand, evalContext, thread);
|
|
182
|
+
thisStack.pop();
|
|
183
|
+
if (Array.isArray(spreadItems)) {
|
|
184
|
+
// --- Spread of an array
|
|
185
|
+
for (let i = 0; i < spreadItems.length; i++) {
|
|
186
|
+
objectHash[i] = spreadItems[i];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else if (typeof spreadItems === "object") {
|
|
190
|
+
// --- Spread of a hash object
|
|
191
|
+
for (const [key, value] of Object.entries(spreadItems)) {
|
|
192
|
+
objectHash[key] = value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
// --- We're using key/[value] pairs
|
|
198
|
+
let key;
|
|
199
|
+
switch (prop[0].type) {
|
|
200
|
+
case "LitE":
|
|
201
|
+
key = prop[0].value;
|
|
202
|
+
break;
|
|
203
|
+
case "IdE":
|
|
204
|
+
key = prop[0].name;
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
key = evaluator(thisStack, prop[0], evalContext, thread);
|
|
208
|
+
thisStack.pop();
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
objectHash[key] = evaluator(thisStack, prop[1], evalContext, thread);
|
|
212
|
+
thisStack.pop();
|
|
213
|
+
}
|
|
214
|
+
thisStack.push(objectHash);
|
|
215
|
+
return objectHash;
|
|
216
|
+
}
|
|
217
|
+
function evalUnary(evaluator, thisStack, customOp, expr, evalContext, thread) {
|
|
218
|
+
const operand = evaluator(thisStack, expr.operand, evalContext, thread);
|
|
219
|
+
thisStack.pop();
|
|
220
|
+
return (0, eval_tree_common_1.evalUnaryCore)(expr, operand, thisStack, customOp);
|
|
221
|
+
}
|
|
222
|
+
function evalBinary(evaluator, thisStack, customOp, expr, evalContext, thread) {
|
|
223
|
+
const l = evaluator(thisStack, expr.left, evalContext, thread);
|
|
224
|
+
thisStack.pop();
|
|
225
|
+
if (expr.operator === "&&" && !l) {
|
|
226
|
+
thisStack.push(l);
|
|
227
|
+
return l;
|
|
228
|
+
}
|
|
229
|
+
if (expr.operator === "||" && l) {
|
|
230
|
+
thisStack.push(l);
|
|
231
|
+
return l;
|
|
232
|
+
}
|
|
233
|
+
const r = evaluator(thisStack, expr.right, evalContext, thread);
|
|
234
|
+
thisStack.pop();
|
|
235
|
+
return (0, eval_tree_common_1.evalBinaryCore)(l, r, thisStack, customOp, expr.operator);
|
|
236
|
+
}
|
|
237
|
+
function evalConditional(evaluator, thisStack, expr, evalContext, thread) {
|
|
238
|
+
const condition = evaluator(thisStack, expr.condition, evalContext, thread);
|
|
239
|
+
thisStack.pop();
|
|
240
|
+
return evaluator(thisStack, condition ? expr.consequent : expr.alternate, evalContext, thread);
|
|
241
|
+
}
|
|
242
|
+
function evalAssignment(evaluator, thisStack, expr, evalContext, thread) {
|
|
243
|
+
const leftValue = expr.leftValue;
|
|
244
|
+
evaluator(thisStack, leftValue, evalContext, thread);
|
|
245
|
+
thisStack.pop();
|
|
246
|
+
const newValue = evaluator(thisStack, expr.operand, evalContext, thread);
|
|
247
|
+
thisStack.pop();
|
|
248
|
+
return (0, eval_tree_common_1.evalAssignmentCore)(leftValue, newValue, thisStack, expr, thread);
|
|
249
|
+
}
|
|
250
|
+
function evalPreOrPost(evaluator, thisStack, expr, evalContext, thread) {
|
|
251
|
+
const operand = expr.operand;
|
|
252
|
+
evaluator(thisStack, operand, evalContext, thread);
|
|
253
|
+
thisStack.pop();
|
|
254
|
+
return (0, eval_tree_common_1.evalPreOrPostCore)(operand, thisStack, expr, evalContext, thread);
|
|
255
|
+
}
|
|
256
|
+
function evalFunctionInvocation(evaluator, thisStack, expr, evalContext, thread) {
|
|
257
|
+
var _a, _b, _c, _d;
|
|
258
|
+
let functionObj;
|
|
259
|
+
let implicitContextObject = null;
|
|
260
|
+
// --- Check for contexted object
|
|
261
|
+
if (expr.object.type === "MembE" && expr.object.object.type === "IdE") {
|
|
262
|
+
const hostObject = evaluator(thisStack, expr.object.object, evalContext, thread);
|
|
263
|
+
functionObj = (0, eval_tree_common_1.evalMemberAccessCore)(hostObject, thisStack, expr.object, evalContext);
|
|
264
|
+
if (hostObject === null || hostObject === void 0 ? void 0 : hostObject._SUPPORT_IMPLICIT_CONTEXT) {
|
|
265
|
+
implicitContextObject = hostObject;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// --- Get the object on which to invoke the function
|
|
270
|
+
functionObj = evaluator(thisStack, expr.object, evalContext, thread);
|
|
271
|
+
}
|
|
272
|
+
thisStack.pop();
|
|
273
|
+
// --- Keep function arguments here, we pass it to the function later
|
|
274
|
+
const functionArgs = [];
|
|
275
|
+
// --- The functionObj may be an ArrowExpression. In this care we need to create the invokable arrow function
|
|
276
|
+
if (functionObj === null || functionObj === void 0 ? void 0 : functionObj._ARROW_EXPR_) {
|
|
277
|
+
functionArgs.push(functionObj.args, evalContext, thread, ...expr.arguments.map((a) => (Object.assign(Object.assign({}, a), { _EXPRESSION_: true }))));
|
|
278
|
+
functionObj = createArrowFunction(evaluator, functionObj);
|
|
279
|
+
}
|
|
280
|
+
else if (expr.object.type === "ArrowE") {
|
|
281
|
+
// --- We delay evaluating expression values. We pass the argument names as the first parameter, and then
|
|
282
|
+
// --- all parameter expressions
|
|
283
|
+
functionArgs.push(expr.object.args, evalContext, thread, ...expr.arguments.map((a) => (Object.assign(Object.assign({}, a), { _EXPRESSION_: true }))));
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
// --- We evaluate the argument values to pass to a JavaScript function
|
|
287
|
+
for (let i = 0; i < expr.arguments.length; i++) {
|
|
288
|
+
const arg = expr.arguments[i];
|
|
289
|
+
if (arg.type === "SpreadE") {
|
|
290
|
+
const funcArg = evaluator([], arg.operand, evalContext, thread);
|
|
291
|
+
if (!Array.isArray(funcArg)) {
|
|
292
|
+
throw new Error("Spread operator within a function invocation expects an array operand.");
|
|
293
|
+
}
|
|
294
|
+
functionArgs.push(...funcArg);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
if (arg.type === "ArrowE") {
|
|
298
|
+
const funcArg = createArrowFunction(evaluator, arg);
|
|
299
|
+
const wrappedFunc = (...args) => funcArg(arg.args, evalContext, thread, ...args);
|
|
300
|
+
functionArgs.push(wrappedFunc);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const funcArg = evaluator([], arg, evalContext, thread);
|
|
304
|
+
if (funcArg === null || funcArg === void 0 ? void 0 : funcArg._ARROW_EXPR_) {
|
|
305
|
+
const wrappedFuncArg = createArrowFunction(evaluator, funcArg);
|
|
306
|
+
const wrappedFunc = (...args) => wrappedFuncArg(funcArg.args, evalContext, thread, ...args);
|
|
307
|
+
functionArgs.push(wrappedFunc);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
functionArgs.push(funcArg);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// --- We can pass implicit arguments to JavaScript function
|
|
316
|
+
if (implicitContextObject) {
|
|
317
|
+
// --- Let's obtain the implicit context
|
|
318
|
+
if (evalContext.implicitContextGetter) {
|
|
319
|
+
const implicitContext = evalContext.implicitContextGetter(implicitContextObject);
|
|
320
|
+
functionArgs.unshift(implicitContext);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
throw new Error("Cannot use implicitContextGetter, it is undefined");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// --- Check if the function is banned from running
|
|
328
|
+
const bannedInfo = (0, bannedFunctions_1.isBannedFunction)(functionObj);
|
|
329
|
+
if (bannedInfo.banned) {
|
|
330
|
+
throw new Error(`Function ${(_b = (_a = bannedInfo.func) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "unknown"} is not allowed to call. ${(_c = bannedInfo === null || bannedInfo === void 0 ? void 0 : bannedInfo.help) !== null && _c !== void 0 ? _c : ""}`);
|
|
331
|
+
}
|
|
332
|
+
// --- We use context for "this"
|
|
333
|
+
const currentContext = thisStack.length > 0 ? thisStack.pop() : evalContext.localContext;
|
|
334
|
+
// --- Now, invoke the function
|
|
335
|
+
const value = ((_d = evalContext.options) === null || _d === void 0 ? void 0 : _d.defaultToOptionalMemberAccess)
|
|
336
|
+
? functionObj === null || functionObj === void 0 ? void 0 : functionObj.call(currentContext, ...functionArgs)
|
|
337
|
+
: functionObj.call(currentContext, ...functionArgs);
|
|
338
|
+
thisStack.push(value);
|
|
339
|
+
return value;
|
|
340
|
+
}
|
|
341
|
+
function createArrowFunction(evaluator, expr) {
|
|
342
|
+
// --- Use this function, it evaluates the arrow function
|
|
343
|
+
return (...args) => {
|
|
344
|
+
var _a;
|
|
345
|
+
// --- Prepare the variables to pass
|
|
346
|
+
const runTimeEvalContext = args[1];
|
|
347
|
+
const runtimeThread = args[2];
|
|
348
|
+
// --- Create the thread that runs the arrow function
|
|
349
|
+
const workingThread = {
|
|
350
|
+
parent: runtimeThread,
|
|
351
|
+
childThreads: [],
|
|
352
|
+
blocks: [{ vars: {} }],
|
|
353
|
+
loops: [],
|
|
354
|
+
breakLabelValue: -1,
|
|
355
|
+
closures: expr.closureContext,
|
|
356
|
+
};
|
|
357
|
+
runtimeThread.childThreads.push(workingThread);
|
|
358
|
+
// --- Assign argument values to names
|
|
359
|
+
const arrowBlock = { vars: {} };
|
|
360
|
+
(_a = workingThread.blocks) !== null && _a !== void 0 ? _a : (workingThread.blocks = []);
|
|
361
|
+
workingThread.blocks.push(arrowBlock);
|
|
362
|
+
const argSpecs = args[0];
|
|
363
|
+
for (let i = 0; i < argSpecs.length; i++) {
|
|
364
|
+
// --- Turn argument specification into processable variable declarations
|
|
365
|
+
const argSpec = argSpecs[i];
|
|
366
|
+
let decl;
|
|
367
|
+
switch (argSpec.type) {
|
|
368
|
+
case "IdE": {
|
|
369
|
+
decl = {
|
|
370
|
+
type: "VarD",
|
|
371
|
+
id: argSpec.name,
|
|
372
|
+
};
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
case "Destr": {
|
|
376
|
+
decl = {
|
|
377
|
+
type: "VarD",
|
|
378
|
+
id: argSpec.id,
|
|
379
|
+
arrayDestruct: argSpec.arrayDestruct,
|
|
380
|
+
objectDestruct: argSpec.objectDestruct,
|
|
381
|
+
};
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
default:
|
|
385
|
+
throw new Error("Unexpected arrow argument specification");
|
|
386
|
+
}
|
|
387
|
+
if (decl) {
|
|
388
|
+
// --- Get the actual value to work with
|
|
389
|
+
let argVal = args[i + 3];
|
|
390
|
+
if (argVal === null || argVal === void 0 ? void 0 : argVal._EXPRESSION_) {
|
|
391
|
+
argVal = evaluator([], argVal, runTimeEvalContext, runtimeThread);
|
|
392
|
+
}
|
|
393
|
+
(0, process_statement_sync_1.processDeclarations)(arrowBlock, runTimeEvalContext, runtimeThread, [decl], false, true, argVal);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// --- Evaluate the arrow expression body
|
|
397
|
+
let returnValue;
|
|
398
|
+
let statements;
|
|
399
|
+
switch (expr.statement.type) {
|
|
400
|
+
case "EmptyS":
|
|
401
|
+
statements = [];
|
|
402
|
+
break;
|
|
403
|
+
case "ExprS":
|
|
404
|
+
// --- Create a new thread for the call
|
|
405
|
+
statements = [
|
|
406
|
+
{
|
|
407
|
+
type: "RetS",
|
|
408
|
+
expression: expr.statement.expression,
|
|
409
|
+
},
|
|
410
|
+
];
|
|
411
|
+
break;
|
|
412
|
+
case "BlockS":
|
|
413
|
+
// --- Create a new thread for the call
|
|
414
|
+
statements = expr.statement.statements;
|
|
415
|
+
break;
|
|
416
|
+
default:
|
|
417
|
+
throw new Error(`Arrow expression with a body of '${expr.statement.type}' is not supported yet.`);
|
|
418
|
+
}
|
|
419
|
+
// --- Process the statement with a new processor
|
|
420
|
+
(0, process_statement_sync_1.processStatementQueue)(statements, runTimeEvalContext, workingThread);
|
|
421
|
+
// --- Return value is in a return value slot
|
|
422
|
+
returnValue = workingThread.returnValue;
|
|
423
|
+
// --- Remove the current working thread
|
|
424
|
+
const workingIndex = runtimeThread.childThreads.indexOf(workingThread);
|
|
425
|
+
if (workingIndex < 0) {
|
|
426
|
+
throw new Error("Cannot find thread to remove.");
|
|
427
|
+
}
|
|
428
|
+
runtimeThread.childThreads.splice(workingIndex, 1);
|
|
429
|
+
// --- Remove the function level block
|
|
430
|
+
workingThread.blocks.pop();
|
|
431
|
+
// --- Return the function value
|
|
432
|
+
return returnValue;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isModuleErrors = isModuleErrors;
|
|
4
|
+
exports.parseScriptModule = parseScriptModule;
|
|
5
|
+
const Parser_1 = require("../../parsers/scripting/Parser");
|
|
6
|
+
const Token_1 = require("../../abstractions/scripting/Token");
|
|
7
|
+
const process_statement_async_1 = require("./process-statement-async");
|
|
8
|
+
const tree_visitor_1 = require("../../parsers/scripting/tree-visitor");
|
|
9
|
+
const ParserError_1 = require("../../parsers/scripting/ParserError");
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the result is a module error
|
|
12
|
+
* @param result Result to check
|
|
13
|
+
* @returns True if the result is a module error
|
|
14
|
+
*/
|
|
15
|
+
function isModuleErrors(result) {
|
|
16
|
+
return result.type !== "ScriptModule";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parses a script module
|
|
20
|
+
* @param moduleName Name of the module
|
|
21
|
+
* @param source Source code to parse
|
|
22
|
+
* @param moduleResolver A function that resolves a module path to the text of the module
|
|
23
|
+
* @returns The parsed and resolved module
|
|
24
|
+
*/
|
|
25
|
+
function parseScriptModule(moduleName, source, moduleResolver, restrictiveMode = false) {
|
|
26
|
+
// --- Keep track of parsed modules to avoid circular references
|
|
27
|
+
const parsedModules = new Map();
|
|
28
|
+
const moduleErrors = {};
|
|
29
|
+
const parsedModule = doParseModule(moduleName, source, moduleResolver, true);
|
|
30
|
+
return !parsedModule || Object.keys(moduleErrors).length > 0 ? moduleErrors : parsedModule;
|
|
31
|
+
// --- Do the parsing, allow recursion
|
|
32
|
+
function doParseModule(moduleName, source, moduleResolver, topLevel = false) {
|
|
33
|
+
var _a;
|
|
34
|
+
// --- Do not parse the same module twice
|
|
35
|
+
if (parsedModules.has(moduleName)) {
|
|
36
|
+
return parsedModules.get(moduleName);
|
|
37
|
+
}
|
|
38
|
+
// --- Parse the source code
|
|
39
|
+
const parser = new Parser_1.Parser(source);
|
|
40
|
+
let statements = [];
|
|
41
|
+
try {
|
|
42
|
+
statements = parser.parseStatements();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
moduleErrors[moduleName] = parser.errors;
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// --- Check for unparsed tail
|
|
49
|
+
const lastToken = parser.current;
|
|
50
|
+
if (lastToken.type !== Token_1.TokenType.Eof) {
|
|
51
|
+
(_a = moduleErrors[moduleName]) !== null && _a !== void 0 ? _a : (moduleErrors[moduleName] = []);
|
|
52
|
+
moduleErrors[moduleName].push({
|
|
53
|
+
code: "W002",
|
|
54
|
+
text: ParserError_1.errorMessages["W002"].replace(/\{(\d+)}/g, () => lastToken.text),
|
|
55
|
+
position: lastToken.location.startLine,
|
|
56
|
+
line: lastToken.location.startLine,
|
|
57
|
+
column: lastToken.location.startColumn,
|
|
58
|
+
});
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const errors = [];
|
|
62
|
+
// --- Visit all statements in the module
|
|
63
|
+
const emptyState = {
|
|
64
|
+
data: null,
|
|
65
|
+
cancel: false,
|
|
66
|
+
skipChildren: false,
|
|
67
|
+
};
|
|
68
|
+
(0, tree_visitor_1.visitNode)(statements, emptyState, (before, stmt, state, parent, tag) => {
|
|
69
|
+
if (!before)
|
|
70
|
+
return state;
|
|
71
|
+
if (topLevel) {
|
|
72
|
+
// --- Restrict top-level statements
|
|
73
|
+
switch (stmt.type) {
|
|
74
|
+
case "VarS":
|
|
75
|
+
// --- Allow on top-level var declarations in a top-level module
|
|
76
|
+
if (parent) {
|
|
77
|
+
addErrorMessage("W027", stmt);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case "FuncD":
|
|
81
|
+
case "ImportD":
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
if (restrictiveMode && !parent) {
|
|
85
|
+
addErrorMessage("W028", stmt, stmt.type);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
switch (stmt.type) {
|
|
92
|
+
case "VarS":
|
|
93
|
+
addErrorMessage("W027", stmt);
|
|
94
|
+
break;
|
|
95
|
+
case "FuncD":
|
|
96
|
+
if (restrictiveMode && !stmt.isExported) {
|
|
97
|
+
addErrorMessage("W029", stmt);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "ImportD":
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
if (restrictiveMode && !parent) {
|
|
104
|
+
addErrorMessage("W028", stmt, stmt.type);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return state;
|
|
110
|
+
});
|
|
111
|
+
// // --- Check for forbidden "var" declarations
|
|
112
|
+
// statements.forEach((stmt) => {
|
|
113
|
+
// if (topLevel) {
|
|
114
|
+
// // --- Restrict top-level statements
|
|
115
|
+
// switch (stmt.type) {
|
|
116
|
+
// case "VarS":
|
|
117
|
+
// case "FuncD":
|
|
118
|
+
// case "ImportD":
|
|
119
|
+
// break;
|
|
120
|
+
// default:
|
|
121
|
+
// if (restrictiveMode) {
|
|
122
|
+
// addErrorMessage("W028", stmt, stmt.type);
|
|
123
|
+
// }
|
|
124
|
+
// break;
|
|
125
|
+
// }
|
|
126
|
+
// } else {
|
|
127
|
+
// switch (stmt.type) {
|
|
128
|
+
// case "VarS":
|
|
129
|
+
// addErrorMessage("W027", stmt);
|
|
130
|
+
// break;
|
|
131
|
+
// case "FuncD":
|
|
132
|
+
// if (restrictiveMode && !stmt.isExported) {
|
|
133
|
+
// addErrorMessage("W029", stmt);
|
|
134
|
+
// }
|
|
135
|
+
// break;
|
|
136
|
+
// case "ImportD":
|
|
137
|
+
// break;
|
|
138
|
+
// default:
|
|
139
|
+
// if (restrictiveMode) {
|
|
140
|
+
// addErrorMessage("W028", stmt, stmt.type);
|
|
141
|
+
// }
|
|
142
|
+
// break;
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
145
|
+
// });
|
|
146
|
+
// --- Hoist functions
|
|
147
|
+
const functions = {};
|
|
148
|
+
statements
|
|
149
|
+
.filter((stmt) => stmt.type === "FuncD")
|
|
150
|
+
.forEach((stmt) => {
|
|
151
|
+
const func = stmt;
|
|
152
|
+
if (functions[func.name]) {
|
|
153
|
+
addErrorMessage("W020", stmt, func.name);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
functions[func.name] = func;
|
|
157
|
+
});
|
|
158
|
+
// --- Collect exports
|
|
159
|
+
const exports = new Map();
|
|
160
|
+
statements.forEach((stmt) => {
|
|
161
|
+
if (stmt.type === "ConstS" && stmt.isExported) {
|
|
162
|
+
(0, process_statement_async_1.visitLetConstDeclarations)(stmt, (id) => {
|
|
163
|
+
if (exports.has(id)) {
|
|
164
|
+
addErrorMessage("W021", stmt, id);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
exports.set(id, stmt);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (stmt.type === "FuncD" && stmt.isExported) {
|
|
172
|
+
if (exports.has(stmt.name)) {
|
|
173
|
+
addErrorMessage("W021", stmt, stmt.name);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
exports.set(stmt.name, stmt);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// --- Successful module parsing
|
|
181
|
+
const parsedModule = {
|
|
182
|
+
type: "ScriptModule",
|
|
183
|
+
name: moduleName,
|
|
184
|
+
exports,
|
|
185
|
+
importedModules: [],
|
|
186
|
+
imports: [],
|
|
187
|
+
functions,
|
|
188
|
+
statements,
|
|
189
|
+
executed: false,
|
|
190
|
+
};
|
|
191
|
+
// --- Sign this module as parsed
|
|
192
|
+
parsedModules.set(moduleName, parsedModule);
|
|
193
|
+
// --- Load imported modules and resolve imports
|
|
194
|
+
const importedModules = [];
|
|
195
|
+
const imports = {};
|
|
196
|
+
for (let i = 0; i < statements.length; i++) {
|
|
197
|
+
const stmt = statements[i];
|
|
198
|
+
if (stmt.type !== "ImportD") {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
// --- Find the imported module
|
|
202
|
+
const source = moduleResolver(moduleName, stmt.moduleFile);
|
|
203
|
+
if (source === null) {
|
|
204
|
+
addErrorMessage("W022", stmt, stmt.moduleFile);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
// --- Parse the imported module
|
|
208
|
+
const imported = doParseModule(stmt.moduleFile, source, moduleResolver);
|
|
209
|
+
if (!imported) {
|
|
210
|
+
// --- Error in the imported module
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// --- Successful import
|
|
214
|
+
importedModules.push(imported);
|
|
215
|
+
// --- Extract imported names
|
|
216
|
+
for (const key in stmt.imports) {
|
|
217
|
+
if (imported.exports.has(stmt.imports[key])) {
|
|
218
|
+
imports[key] = imported.exports.get(stmt.imports[key]);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
addErrorMessage("W023", stmt, stmt.moduleFile, key);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// --- Catch errors
|
|
226
|
+
if (errors.length > 0) {
|
|
227
|
+
moduleErrors[moduleName] = errors;
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
// --- All imported modules use this module as a parent
|
|
231
|
+
importedModules.forEach((m) => (m.parent = parsedModule));
|
|
232
|
+
// --- Done.
|
|
233
|
+
parsedModule.importedModules = importedModules;
|
|
234
|
+
parsedModule.imports = imports;
|
|
235
|
+
return parsedModule;
|
|
236
|
+
function addErrorMessage(code, stmt, ...args) {
|
|
237
|
+
let errorText = ParserError_1.errorMessages[code];
|
|
238
|
+
if (args) {
|
|
239
|
+
args.forEach((o, idx) => (errorText = errorText.replaceAll(`{${idx}}`, args[idx].toString())));
|
|
240
|
+
}
|
|
241
|
+
errors.push({
|
|
242
|
+
code,
|
|
243
|
+
text: ParserError_1.errorMessages[code].replace(/\{(\d+)}/g, (_, index) => args[index]),
|
|
244
|
+
position: stmt.startPosition,
|
|
245
|
+
line: stmt.startLine,
|
|
246
|
+
column: stmt.startColumn,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|