@hyperfixi/core 3.3.0 → 4.0.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/README.md +57 -179
- package/dist/ast-utils/index.cjs +74 -806
- package/dist/ast-utils/index.d.ts +1 -1
- package/dist/ast-utils/index.mjs +74 -805
- package/dist/ast-utils/interchange/engine-positions.d.ts +3 -0
- package/dist/ast-utils/interchange/index.d.ts +1 -2
- package/dist/hyperfixi.js +19 -2
- package/dist/index.d.ts +2 -22
- package/dist/index.mjs +3 -29128
- package/dist/lsp-metadata.cjs +77 -73
- package/dist/lsp-metadata.d.ts +4 -4
- package/dist/lsp-metadata.mjs +77 -73
- package/dist/metadata.cjs +34 -266
- package/dist/metadata.d.ts +31 -26
- package/dist/metadata.mjs +34 -266
- package/dist/multilingual/index.cjs +16 -382
- package/dist/multilingual/index.d.ts +4 -32
- package/dist/multilingual/index.mjs +15 -377
- package/dist/reference/index.cjs +67 -216
- package/dist/reference/index.d.ts +0 -3
- package/dist/reference/index.mjs +68 -216
- package/dist/version.d.ts +1 -1
- package/package.json +13 -179
- package/dist/__test-utils__/context-builders.d.ts +0 -42
- package/dist/__test-utils__/error-testing.d.ts +0 -18
- package/dist/__test-utils__/index.d.ts +0 -6
- package/dist/__test-utils__/mock-types.d.ts +0 -57
- package/dist/__test-utils__/parser-context-mock.d.ts +0 -7
- package/dist/__test-utils__/parser-helpers.d.ts +0 -38
- package/dist/api/hyperscript-api.d.ts +0 -90
- package/dist/api/lokascript-api.d.ts +0 -9
- package/dist/ast/command-slots.d.ts +0 -140
- package/dist/ast/guards.d.ts +0 -15
- package/dist/ast/legacy.d.ts +0 -15
- package/dist/ast/nodes.d.ts +0 -243
- package/dist/ast-utils/interchange/from-core.d.ts +0 -12
- package/dist/ast-utils/interchange/to-core.d.ts +0 -8
- package/dist/behaviors/boosted.d.ts +0 -29
- package/dist/behaviors/history-swap.d.ts +0 -24
- package/dist/behaviors/index.cjs +0 -1155
- package/dist/behaviors/index.d.ts +0 -4
- package/dist/behaviors/index.mjs +0 -1145
- package/dist/bundle-generator/executor-core.d.ts +0 -4
- package/dist/bundle-generator/generator.d.ts +0 -4
- package/dist/bundle-generator/index.cjs +0 -2804
- package/dist/bundle-generator/index.d.ts +0 -6
- package/dist/bundle-generator/index.mjs +0 -2779
- package/dist/bundle-generator/parser-templates.d.ts +0 -6
- package/dist/bundle-generator/template-capabilities.d.ts +0 -12
- package/dist/bundle-generator/templates.d.ts +0 -12
- package/dist/bundle-generator/types.d.ts +0 -34
- package/dist/chunks/bridge-CI9SOl8u.js +0 -2
- package/dist/chunks/browser-modular-7CpI5VF2.js +0 -2
- package/dist/chunks/index-BwXDEK0m.js +0 -2
- package/dist/chunks/index-DQi2o8Lk.js +0 -2
- package/dist/chunks/index-uCOQ8Qn0.js +0 -2
- package/dist/commands/advanced/js.d.ts +0 -40
- package/dist/commands/animation/measure.d.ts +0 -43
- package/dist/commands/animation/settle.d.ts +0 -38
- package/dist/commands/animation/start-view-transition.d.ts +0 -38
- package/dist/commands/animation/take.d.ts +0 -41
- package/dist/commands/animation/transition.d.ts +0 -49
- package/dist/commands/async/fetch.d.ts +0 -61
- package/dist/commands/async/wait.d.ts +0 -51
- package/dist/commands/behaviors/install.d.ts +0 -40
- package/dist/commands/content/append.d.ts +0 -26
- package/dist/commands/content/insertion-base.d.ts +0 -60
- package/dist/commands/content/prepend.d.ts +0 -26
- package/dist/commands/control-flow/break.d.ts +0 -29
- package/dist/commands/control-flow/continue.d.ts +0 -29
- package/dist/commands/control-flow/exit.d.ts +0 -29
- package/dist/commands/control-flow/halt.d.ts +0 -39
- package/dist/commands/control-flow/if.d.ts +0 -58
- package/dist/commands/control-flow/repeat.d.ts +0 -50
- package/dist/commands/control-flow/return.d.ts +0 -33
- package/dist/commands/control-flow/signal-base.d.ts +0 -18
- package/dist/commands/control-flow/throw.d.ts +0 -34
- package/dist/commands/control-flow/unless.d.ts +0 -3
- package/dist/commands/data/clear.d.ts +0 -37
- package/dist/commands/data/decrement.d.ts +0 -3
- package/dist/commands/data/default.d.ts +0 -60
- package/dist/commands/data/get.d.ts +0 -35
- package/dist/commands/data/increment.d.ts +0 -42
- package/dist/commands/data/set.d.ts +0 -76
- package/dist/commands/decorators/index.d.ts +0 -14
- package/dist/commands/dom/add.d.ts +0 -44
- package/dist/commands/dom/close.d.ts +0 -32
- package/dist/commands/dom/dom-modification-base.d.ts +0 -48
- package/dist/commands/dom/empty.d.ts +0 -32
- package/dist/commands/dom/hide.d.ts +0 -28
- package/dist/commands/dom/make.d.ts +0 -34
- package/dist/commands/dom/open.d.ts +0 -34
- package/dist/commands/dom/process-partials.d.ts +0 -51
- package/dist/commands/dom/put.d.ts +0 -42
- package/dist/commands/dom/remove.d.ts +0 -46
- package/dist/commands/dom/reset.d.ts +0 -32
- package/dist/commands/dom/select.d.ts +0 -32
- package/dist/commands/dom/show.d.ts +0 -29
- package/dist/commands/dom/swap.d.ts +0 -65
- package/dist/commands/dom/toggle.d.ts +0 -69
- package/dist/commands/dom/visibility-base.d.ts +0 -22
- package/dist/commands/events/send.d.ts +0 -3
- package/dist/commands/events/trigger.d.ts +0 -49
- package/dist/commands/execution/blur.d.ts +0 -32
- package/dist/commands/execution/call.d.ts +0 -35
- package/dist/commands/execution/focus.d.ts +0 -32
- package/dist/commands/execution/pseudo-command.d.ts +0 -41
- package/dist/commands/helpers/attribute-manipulation.d.ts +0 -11
- package/dist/commands/helpers/attribute-target.d.ts +0 -9
- package/dist/commands/helpers/batch-dom-operations.d.ts +0 -12
- package/dist/commands/helpers/body-ops.d.ts +0 -10
- package/dist/commands/helpers/class-manipulation.d.ts +0 -11
- package/dist/commands/helpers/condition-helpers.d.ts +0 -4
- package/dist/commands/helpers/dom-mutation.d.ts +0 -16
- package/dist/commands/helpers/duration-parsing.d.ts +0 -8
- package/dist/commands/helpers/element-property-access.d.ts +0 -7
- package/dist/commands/helpers/element-resolution.d.ts +0 -16
- package/dist/commands/helpers/error-helpers.d.ts +0 -17
- package/dist/commands/helpers/event-helpers.d.ts +0 -13
- package/dist/commands/helpers/event-waiting.d.ts +0 -37
- package/dist/commands/helpers/index.d.ts +0 -32
- package/dist/commands/helpers/input-validator.d.ts +0 -23
- package/dist/commands/helpers/loop-executor.d.ts +0 -56
- package/dist/commands/helpers/numeric-target-parser.d.ts +0 -21
- package/dist/commands/helpers/property-target.d.ts +0 -20
- package/dist/commands/helpers/selector-type-detection.d.ts +0 -24
- package/dist/commands/helpers/slots.d.ts +0 -5
- package/dist/commands/helpers/smart-element.d.ts +0 -16
- package/dist/commands/helpers/style-manipulation.d.ts +0 -16
- package/dist/commands/helpers/target-elements.d.ts +0 -5
- package/dist/commands/helpers/temporal-modifiers.d.ts +0 -15
- package/dist/commands/helpers/url-argument-parser.d.ts +0 -13
- package/dist/commands/helpers/url-validation.d.ts +0 -7
- package/dist/commands/helpers/variable-access.d.ts +0 -13
- package/dist/commands/helpers/visibility-target-parser.d.ts +0 -15
- package/dist/commands/helpers/write-target.d.ts +0 -42
- package/dist/commands/index.cjs +0 -24168
- package/dist/commands/index.d.ts +0 -171
- package/dist/commands/index.mjs +0 -23981
- package/dist/commands/manifest.d.ts +0 -17
- package/dist/commands/navigation/go.d.ts +0 -58
- package/dist/commands/navigation/push-url.d.ts +0 -48
- package/dist/commands/navigation/replace-url.d.ts +0 -3
- package/dist/commands/navigation/scroll-to.d.ts +0 -43
- package/dist/commands/templates/render.d.ts +0 -47
- package/dist/commands/utility/beep.d.ts +0 -41
- package/dist/commands/utility/breakpoint.d.ts +0 -32
- package/dist/commands/utility/copy.d.ts +0 -41
- package/dist/commands/utility/log.d.ts +0 -36
- package/dist/commands/utility/pick.d.ts +0 -47
- package/dist/commands/utility/tell.d.ts +0 -39
- package/dist/compatibility/browser-bundle-classic.d.ts +0 -17
- package/dist/compatibility/browser-bundle-hybrid-complete.d.ts +0 -22
- package/dist/compatibility/browser-bundle-hybrid-hx.d.ts +0 -43
- package/dist/compatibility/browser-bundle-lite.d.ts +0 -15
- package/dist/compatibility/browser-bundle-modular.d.ts +0 -18
- package/dist/compatibility/browser-bundle-multilingual.d.ts +0 -19
- package/dist/compatibility/browser-bundle-semantic-complete.d.ts +0 -24
- package/dist/compatibility/browser-bundle-textshelf-minimal.d.ts +0 -16
- package/dist/compatibility/browser-bundle-textshelf-profile.d.ts +0 -18
- package/dist/compatibility/browser-modular.d.ts +0 -42
- package/dist/compatibility/browser-tests/helpers/semantic-page.d.ts +0 -3
- package/dist/compatibility/browser-tests/test-utils.d.ts +0 -21
- package/dist/compatibility/bundle-shell.d.ts +0 -13
- package/dist/compatibility/bundle-sources.d.ts +0 -4
- package/dist/compatibility/eval-hyperscript.d.ts +0 -16
- package/dist/compatibility/hyperscript-adapter.d.ts +0 -38
- package/dist/core/ast-property-utils.d.ts +0 -2
- package/dist/core/context.d.ts +0 -19
- package/dist/core/dom.d.ts +0 -15
- package/dist/core/evaluator-types.d.ts +0 -5
- package/dist/core/events.d.ts +0 -48
- package/dist/core/executor.d.ts +0 -34
- package/dist/core/expression-evaluator.d.ts +0 -6
- package/dist/core/expression-registry.d.ts +0 -8
- package/dist/core/scope-hooks.d.ts +0 -24
- package/dist/debug/debug-controller.d.ts +0 -62
- package/dist/debug/index.d.ts +0 -5
- package/dist/dom/attribute-processor.d.ts +0 -75
- package/dist/dom/detect-language.d.ts +0 -3
- package/dist/dom/minimal-attribute-processor.d.ts +0 -20
- package/dist/expressions/base-expression.d.ts +0 -27
- package/dist/expressions/bundles/common-expressions.d.ts +0 -10
- package/dist/expressions/bundles/core-expressions.d.ts +0 -8
- package/dist/expressions/bundles/full-expressions.d.ts +0 -11
- package/dist/expressions/bundles/index.d.ts +0 -7
- package/dist/expressions/collection/index.d.ts +0 -10
- package/dist/expressions/conversion/index.d.ts +0 -31
- package/dist/expressions/expression-tiers.d.ts +0 -13
- package/dist/expressions/index.cjs +0 -4331
- package/dist/expressions/index.d.ts +0 -13
- package/dist/expressions/index.mjs +0 -4312
- package/dist/expressions/logical/index.d.ts +0 -61
- package/dist/expressions/mathematical/index.d.ts +0 -80
- package/dist/expressions/positional/index.d.ts +0 -31
- package/dist/expressions/properties/index.d.ts +0 -27
- package/dist/expressions/property-access-utils.d.ts +0 -23
- package/dist/expressions/references/index.d.ts +0 -39
- package/dist/expressions/shared/comparison-utils.d.ts +0 -10
- package/dist/expressions/shared/index.d.ts +0 -10
- package/dist/expressions/shared/number-utils.d.ts +0 -8
- package/dist/expressions/shared/tracking.d.ts +0 -20
- package/dist/expressions/shared/validation-utils.d.ts +0 -13
- package/dist/expressions/special/index.d.ts +0 -78
- package/dist/expressions/type-helpers.d.ts +0 -11
- package/dist/expressions/type-registry.d.ts +0 -57
- package/dist/expressions/validation-helpers.d.ts +0 -15
- package/dist/htmx/hcon.d.ts +0 -9
- package/dist/htmx/htmx-attribute-processor.d.ts +0 -120
- package/dist/htmx/htmx-translator.d.ts +0 -22
- package/dist/htmx/i18n-hooks.d.ts +0 -18
- package/dist/htmx/i18n-orchestrator.d.ts +0 -16
- package/dist/htmx/index.d.ts +0 -3
- package/dist/htmx/lang-resolver.d.ts +0 -3
- package/dist/htmx/sse.d.ts +0 -60
- package/dist/htmx/ws.d.ts +0 -59
- package/dist/hyperfixi-browser-classic-i18n.js +0 -2
- package/dist/hyperfixi-browser.js +0 -2
- package/dist/hyperfixi-classic-i18n.js +0 -2
- package/dist/hyperfixi-hx-v4.js +0 -1
- package/dist/hyperfixi-hx.js +0 -1
- package/dist/hyperfixi-hybrid-complete.js +0 -1
- package/dist/hyperfixi-hybrid-hx.js +0 -1
- package/dist/hyperfixi-multilingual.js +0 -2
- package/dist/hyperfixi.mjs +0 -2
- package/dist/i18n/error-catalog.d.ts +0 -12
- package/dist/index.cjs +0 -29159
- package/dist/index.min.js +0 -2
- package/dist/lib/dom-globals-shim.d.ts +0 -2
- package/dist/lib/index.d.ts +0 -4
- package/dist/lib/morph-adapter.d.ts +0 -9
- package/dist/lib/swap-executor.d.ts +0 -12
- package/dist/lib/view-transitions.d.ts +0 -7
- package/dist/lokascript-browser-classic-i18n.js +0 -2
- package/dist/lokascript-browser.js +0 -2
- package/dist/lokascript-hybrid-complete.js +0 -1
- package/dist/lokascript-hybrid-hx.js +0 -1
- package/dist/lokascript-multilingual.js +0 -2
- package/dist/lse/index.cjs +0 -84
- package/dist/lse/index.d.ts +0 -15
- package/dist/lse/index.mjs +0 -71
- package/dist/multilingual/bridge.d.ts +0 -38
- package/dist/multilingual/schema-roles.d.ts +0 -3
- package/dist/parser/__types__/test-helpers.d.ts +0 -25
- package/dist/parser/command-grammar.d.ts +0 -14
- package/dist/parser/command-node-builder.d.ts +0 -46
- package/dist/parser/command-parsers/animation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/async-commands.d.ts +0 -5
- package/dist/parser/command-parsers/control-flow-commands.d.ts +0 -7
- package/dist/parser/command-parsers/declared-commands.d.ts +0 -6
- package/dist/parser/command-parsers/dom-commands.d.ts +0 -11
- package/dist/parser/command-parsers/event-commands.d.ts +0 -4
- package/dist/parser/command-parsers/navigation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/utility-commands.d.ts +0 -14
- package/dist/parser/command-parsers/variable-commands.d.ts +0 -12
- package/dist/parser/error-handler.d.ts +0 -34
- package/dist/parser/extensions.d.ts +0 -43
- package/dist/parser/full-parser.cjs +0 -7943
- package/dist/parser/full-parser.d.ts +0 -4
- package/dist/parser/full-parser.mjs +0 -7940
- package/dist/parser/helpers/ast-helpers.d.ts +0 -24
- package/dist/parser/helpers/parsing-helpers.d.ts +0 -19
- package/dist/parser/helpers/token-helpers.d.ts +0 -28
- package/dist/parser/hybrid/aliases.cjs +0 -44
- package/dist/parser/hybrid/aliases.d.ts +0 -7
- package/dist/parser/hybrid/aliases.mjs +0 -37
- package/dist/parser/hybrid/ast-types.cjs +0 -3
- package/dist/parser/hybrid/ast-types.d.ts +0 -97
- package/dist/parser/hybrid/ast-types.mjs +0 -2
- package/dist/parser/hybrid/index.cjs +0 -1185
- package/dist/parser/hybrid/index.d.ts +0 -6
- package/dist/parser/hybrid/index.mjs +0 -1175
- package/dist/parser/hybrid/parser-core.cjs +0 -1171
- package/dist/parser/hybrid/parser-core.d.ts +0 -69
- package/dist/parser/hybrid/parser-core.mjs +0 -1169
- package/dist/parser/hybrid/tokenizer.cjs +0 -255
- package/dist/parser/hybrid/tokenizer.d.ts +0 -9
- package/dist/parser/hybrid/tokenizer.mjs +0 -252
- package/dist/parser/hybrid-parser.cjs +0 -1249
- package/dist/parser/hybrid-parser.d.ts +0 -10
- package/dist/parser/hybrid-parser.mjs +0 -1242
- package/dist/parser/parser-constants.d.ts +0 -100
- package/dist/parser/parser-interface.d.ts +0 -12
- package/dist/parser/parser-types.d.ts +0 -164
- package/dist/parser/parser.d.ts +0 -165
- package/dist/parser/pratt-parser.d.ts +0 -41
- package/dist/parser/regex-parser.cjs +0 -422
- package/dist/parser/regex-parser.d.ts +0 -4
- package/dist/parser/regex-parser.mjs +0 -419
- package/dist/parser/runtime.d.ts +0 -14
- package/dist/parser/semantic-integration.d.ts +0 -17
- package/dist/parser/token-consumer.d.ts +0 -34
- package/dist/parser/token-predicates.d.ts +0 -77
- package/dist/parser/tokenizer.d.ts +0 -28
- package/dist/parser/types.d.ts +0 -105
- package/dist/performance/expression-cache.d.ts +0 -78
- package/dist/performance/integration.d.ts +0 -40
- package/dist/performance/production-monitor.d.ts +0 -67
- package/dist/registry/browser-types.cjs +0 -81
- package/dist/registry/browser-types.d.ts +0 -20
- package/dist/registry/browser-types.mjs +0 -76
- package/dist/registry/environment.cjs +0 -36
- package/dist/registry/environment.d.ts +0 -19
- package/dist/registry/environment.mjs +0 -30
- package/dist/registry/event-source-registry.d.ts +0 -54
- package/dist/registry/examples/server-commands.d.ts +0 -6
- package/dist/registry/examples/server-event-source.d.ts +0 -32
- package/dist/registry/index.cjs +0 -14055
- package/dist/registry/index.d.ts +0 -39
- package/dist/registry/index.mjs +0 -14039
- package/dist/registry/runtime-integration.d.ts +0 -23
- package/dist/registry/universal-types.cjs +0 -91
- package/dist/registry/universal-types.d.ts +0 -35
- package/dist/registry/universal-types.mjs +0 -86
- package/dist/runtime/cleanup-registry.d.ts +0 -47
- package/dist/runtime/command-adapter.d.ts +0 -69
- package/dist/runtime/environment.d.ts +0 -75
- package/dist/runtime/plugin.d.ts +0 -14
- package/dist/runtime/runtime-base.d.ts +0 -100
- package/dist/runtime/runtime-factory.d.ts +0 -29
- package/dist/runtime/runtime.d.ts +0 -20
- package/dist/runtime/temporal-modifiers.d.ts +0 -37
- package/dist/test-setup.d.ts +0 -28
- package/dist/test-utilities.d.ts +0 -39
- package/dist/types/base-types.d.ts +0 -231
- package/dist/types/code-fix.d.ts +0 -39
- package/dist/types/command-metadata.d.ts +0 -57
- package/dist/types/command-types.d.ts +0 -262
- package/dist/types/context-types.d.ts +0 -106
- package/dist/types/core-context.d.ts +0 -22
- package/dist/types/core.d.ts +0 -143
- package/dist/types/error-codes.d.ts +0 -207
- package/dist/types/expression-types.d.ts +0 -155
- package/dist/types/hooks.d.ts +0 -45
- package/dist/types/index.d.ts +0 -32
- package/dist/types/program.d.ts +0 -8
- package/dist/types/result.d.ts +0 -73
- package/dist/types/template-types.d.ts +0 -162
- package/dist/types/type-guards.d.ts +0 -24
- package/dist/types/unified-types.d.ts +0 -91
- package/dist/utils/beep.d.ts +0 -8
- package/dist/utils/debug-events.d.ts +0 -41
- package/dist/utils/debug.d.ts +0 -35
- package/dist/utils/dom-utils.d.ts +0 -16
- package/dist/utils/element-check.d.ts +0 -8
- package/dist/utils/keyboard-shortcuts.d.ts +0 -18
- package/dist/utils/performance.d.ts +0 -40
- package/dist/validation/command-pattern-validator.d.ts +0 -53
- package/dist/validation/common-validators.d.ts +0 -24
- package/dist/validation/lightweight-validators.d.ts +0 -113
- package/dist/validation/partial-validation-types.d.ts +0 -50
- package/dist/validation/partial-validator.d.ts +0 -6
- package/dist/validation/partial-warning-formatter.d.ts +0 -6
- package/dist/validation/validate-cli.d.ts +0 -41
- package/vocab/htmx/ar.js +0 -62
- package/vocab/htmx/bn.js +0 -65
- package/vocab/htmx/de.js +0 -83
- package/vocab/htmx/en.js +0 -24
- package/vocab/htmx/es.js +0 -79
- package/vocab/htmx/fr.js +0 -79
- package/vocab/htmx/he.js +0 -61
- package/vocab/htmx/hi.js +0 -81
- package/vocab/htmx/id.js +0 -76
- package/vocab/htmx/it.js +0 -79
- package/vocab/htmx/ja.js +0 -85
- package/vocab/htmx/ko.js +0 -81
- package/vocab/htmx/ms.js +0 -58
- package/vocab/htmx/pl.js +0 -80
- package/vocab/htmx/pt.js +0 -81
- package/vocab/htmx/qu.js +0 -83
- package/vocab/htmx/ru.js +0 -82
- package/vocab/htmx/sw.js +0 -79
- package/vocab/htmx/th.js +0 -67
- package/vocab/htmx/tl.js +0 -56
- package/vocab/htmx/tr.js +0 -86
- package/vocab/htmx/uk.js +0 -82
- package/vocab/htmx/vi.js +0 -59
- package/vocab/htmx/zh.js +0 -79
package/dist/ast-utils/index.cjs
CHANGED
|
@@ -2189,819 +2189,88 @@ function minifyAST(ast) {
|
|
|
2189
2189
|
return normalizeVisitResult(visitor.visit(ast, createVisitorContext()), ast);
|
|
2190
2190
|
}
|
|
2191
2191
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
p.column = node.column;
|
|
2205
|
-
return p;
|
|
2206
|
-
}
|
|
2207
|
-
function convertNode(node, infer) {
|
|
2208
|
-
if (!node)
|
|
2209
|
-
return { type: 'literal', value: null };
|
|
2210
|
-
switch (node.type) {
|
|
2211
|
-
case 'eventHandler':
|
|
2212
|
-
return convertEventHandler(node, infer);
|
|
2213
|
-
case 'command':
|
|
2214
|
-
return convertCommand$1(node, infer);
|
|
2215
|
-
case 'CommandSequence':
|
|
2216
|
-
return convertCommandSequence(node, infer);
|
|
2217
|
-
case 'Program': {
|
|
2218
|
-
const statements = (node.statements ?? []);
|
|
2219
|
-
if (statements.length === 0) {
|
|
2220
|
-
return { type: 'literal', value: null, ...pos(node) };
|
|
2221
|
-
}
|
|
2222
|
-
if (statements.length === 1) {
|
|
2223
|
-
return convertNode(statements[0], infer);
|
|
2224
|
-
}
|
|
2225
|
-
return convertNode(statements[0], infer);
|
|
2226
|
-
}
|
|
2227
|
-
case 'block':
|
|
2228
|
-
return convertBlock(node, infer);
|
|
2229
|
-
case 'errorCommand':
|
|
2230
|
-
return {
|
|
2231
|
-
type: 'error',
|
|
2232
|
-
message: node.message ?? 'Parse error',
|
|
2233
|
-
token: node.token ?? undefined,
|
|
2234
|
-
...pos(node),
|
|
2235
|
-
};
|
|
2236
|
-
case 'literal':
|
|
2237
|
-
return {
|
|
2238
|
-
type: 'literal',
|
|
2239
|
-
value: node.value,
|
|
2240
|
-
...pos(node),
|
|
2241
|
-
};
|
|
2242
|
-
case 'string':
|
|
2243
|
-
return { type: 'literal', value: node.value, ...pos(node) };
|
|
2244
|
-
case 'selector':
|
|
2245
|
-
return {
|
|
2246
|
-
type: 'selector',
|
|
2247
|
-
value: (node.value ?? node.selector ?? ''),
|
|
2248
|
-
...pos(node),
|
|
2249
|
-
};
|
|
2250
|
-
case 'contextReference':
|
|
2251
|
-
return {
|
|
2252
|
-
type: 'identifier',
|
|
2253
|
-
value: (node.name ?? node.contextType ?? ''),
|
|
2254
|
-
...pos(node),
|
|
2255
|
-
};
|
|
2256
|
-
case 'identifier':
|
|
2257
|
-
if (node.scope === 'element' || node.scope === 'local' || node.scope === 'global') {
|
|
2258
|
-
return {
|
|
2259
|
-
type: 'variable',
|
|
2260
|
-
name: (node.name ?? ''),
|
|
2261
|
-
scope: node.scope,
|
|
2262
|
-
...pos(node),
|
|
2263
|
-
};
|
|
2264
|
-
}
|
|
2265
|
-
return {
|
|
2266
|
-
type: 'identifier',
|
|
2267
|
-
value: (node.name ?? node.value ?? ''),
|
|
2268
|
-
name: (node.name ?? ''),
|
|
2269
|
-
...pos(node),
|
|
2270
|
-
};
|
|
2271
|
-
case 'propertyAccess':
|
|
2272
|
-
case 'possessiveExpression':
|
|
2273
|
-
return convertPossessive(node, infer);
|
|
2274
|
-
case 'memberExpression':
|
|
2275
|
-
return convertMember(node, infer);
|
|
2276
|
-
case 'binaryExpression':
|
|
2277
|
-
return convertBinary(node, infer);
|
|
2278
|
-
case 'callExpression':
|
|
2279
|
-
return convertCall(node, infer);
|
|
2280
|
-
case 'unaryExpression':
|
|
2281
|
-
return {
|
|
2282
|
-
type: 'unary',
|
|
2283
|
-
operator: node.operator,
|
|
2284
|
-
operand: convertNode(node.argument ?? node.operand, infer),
|
|
2285
|
-
...pos(node),
|
|
2286
|
-
};
|
|
2287
|
-
case 'typeCheckExpression':
|
|
2288
|
-
return {
|
|
2289
|
-
type: 'typeCheck',
|
|
2290
|
-
value: convertNode(node.value, infer),
|
|
2291
|
-
typeName: String(node.typeName),
|
|
2292
|
-
nullOk: node.nullOk !== false,
|
|
2293
|
-
negated: node.negated === true,
|
|
2294
|
-
...pos(node),
|
|
2295
|
-
};
|
|
2296
|
-
case 'timeExpression':
|
|
2297
|
-
return { type: 'literal', value: node.value, ...pos(node) };
|
|
2298
|
-
case 'templateLiteral':
|
|
2299
|
-
return { type: 'literal', value: (node.raw ?? ''), ...pos(node) };
|
|
2300
|
-
case 'variable':
|
|
2301
|
-
return {
|
|
2302
|
-
type: 'variable',
|
|
2303
|
-
name: (node.name ?? ''),
|
|
2304
|
-
scope: (node.scope ?? 'local'),
|
|
2305
|
-
...pos(node),
|
|
2306
|
-
};
|
|
2307
|
-
case 'arrayLiteral':
|
|
2308
|
-
return {
|
|
2309
|
-
type: 'array',
|
|
2310
|
-
elements: (node.elements ?? []).map(element => convertNode(element, infer)),
|
|
2311
|
-
...pos(node),
|
|
2312
|
-
};
|
|
2313
|
-
case 'attributeAccess':
|
|
2314
|
-
return {
|
|
2315
|
-
type: 'possessive',
|
|
2316
|
-
object: { type: 'identifier', value: 'me' },
|
|
2317
|
-
property: `@${node.attributeName}`,
|
|
2318
|
-
...pos(node),
|
|
2319
|
-
};
|
|
2320
|
-
case 'propertyOfExpression': {
|
|
2321
|
-
const property = node.property;
|
|
2322
|
-
return {
|
|
2323
|
-
type: 'possessive',
|
|
2324
|
-
object: convertNode(node.target, infer),
|
|
2325
|
-
property: (property?.name ?? property?.value ?? ''),
|
|
2326
|
-
...pos(node),
|
|
2327
|
-
};
|
|
2328
|
-
}
|
|
2329
|
-
case 'htmlSelector':
|
|
2330
|
-
return {
|
|
2331
|
-
type: 'selector',
|
|
2332
|
-
value: (node.value ?? node.selector ?? ''),
|
|
2333
|
-
...pos(node),
|
|
2334
|
-
};
|
|
2335
|
-
case 'positional':
|
|
2336
|
-
return {
|
|
2337
|
-
type: 'positional',
|
|
2338
|
-
position: node.position,
|
|
2339
|
-
...(node.target ? { target: convertNode(node.target, infer) } : {}),
|
|
2340
|
-
...pos(node),
|
|
2341
|
-
};
|
|
2342
|
-
case 'positionalExpression':
|
|
2343
|
-
return {
|
|
2344
|
-
type: 'positional',
|
|
2345
|
-
position: node.operator,
|
|
2346
|
-
...(node.argument ? { target: convertNode(node.argument, infer) } : {}),
|
|
2347
|
-
...pos(node),
|
|
2348
|
-
};
|
|
2349
|
-
default:
|
|
2350
|
-
return {
|
|
2351
|
-
type: 'error',
|
|
2352
|
-
message: `Unknown core AST node type: ${node.type}`,
|
|
2353
|
-
...pos(node),
|
|
2354
|
-
};
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
function convertEventHandler(node, infer) {
|
|
2358
|
-
const event = (node.event ?? 'click');
|
|
2359
|
-
const commands = (node.commands ?? node.body ?? []);
|
|
2360
|
-
const body = commands.map(cmd => convertNode(cmd, infer));
|
|
2361
|
-
const modifiers = buildEventModifiers(node);
|
|
2362
|
-
return { type: 'event', event, modifiers, body, ...pos(node) };
|
|
2363
|
-
}
|
|
2364
|
-
function convertCommand$1(node, infer) {
|
|
2365
|
-
const name = node.name;
|
|
2366
|
-
if (name === '__ERROR__') {
|
|
2367
|
-
return {
|
|
2368
|
-
type: 'error',
|
|
2369
|
-
message: node.diagnostics?.[0]
|
|
2370
|
-
?.message ?? 'Parse error',
|
|
2371
|
-
...pos(node),
|
|
2372
|
-
};
|
|
2373
|
-
}
|
|
2374
|
-
if (name === 'if' || name === 'unless') {
|
|
2375
|
-
return convertIfCommand(node, infer);
|
|
2376
|
-
}
|
|
2377
|
-
if (name === 'repeat') {
|
|
2378
|
-
return convertRepeatCommand(node, infer);
|
|
2379
|
-
}
|
|
2380
|
-
const original = node.originalCommand;
|
|
2381
|
-
const sum = node.modifiers?.to;
|
|
2382
|
-
const counted = node.args?.[0];
|
|
2383
|
-
if (name === 'set' &&
|
|
2384
|
-
(original === 'increment' || original === 'decrement') &&
|
|
2385
|
-
sum?.type === 'binaryExpression' &&
|
|
2386
|
-
counted) {
|
|
2387
|
-
return convertCommand$1({
|
|
2388
|
-
...node,
|
|
2389
|
-
name: original,
|
|
2390
|
-
args: [counted],
|
|
2391
|
-
modifiers: { by: sum.right },
|
|
2392
|
-
originalCommand: undefined,
|
|
2393
|
-
}, infer);
|
|
2394
|
-
}
|
|
2395
|
-
const args = (node.args ?? []).map(arg => convertNode(arg, infer));
|
|
2396
|
-
const target = node.target ? convertNode(node.target, infer) : undefined;
|
|
2397
|
-
const modifiers = node.modifiers
|
|
2398
|
-
? convertModifiers(node.modifiers, infer)
|
|
2399
|
-
: undefined;
|
|
2400
|
-
const roles = inferRoles(name, args, modifiers, target, infer);
|
|
2401
|
-
return {
|
|
2402
|
-
type: 'command',
|
|
2403
|
-
name,
|
|
2404
|
-
args,
|
|
2405
|
-
...(target ? { target } : {}),
|
|
2406
|
-
...(modifiers && Object.keys(modifiers).length > 0 ? { modifiers } : {}),
|
|
2407
|
-
...(roles ? { roles } : {}),
|
|
2408
|
-
...(node.partial ? { partial: true } : {}),
|
|
2409
|
-
...pos(node),
|
|
2410
|
-
};
|
|
2411
|
-
}
|
|
2412
|
-
function convertIfCommand(node, infer) {
|
|
2413
|
-
const args = (node.args ?? []);
|
|
2414
|
-
let condition;
|
|
2415
|
-
let thenBranch;
|
|
2416
|
-
let elseBranch;
|
|
2417
|
-
if (node.condition) {
|
|
2418
|
-
condition = convertNode(node.condition, infer);
|
|
2419
|
-
thenBranch = (node.thenBranch ?? node.then ?? []).map(n => convertNode(n, infer));
|
|
2420
|
-
elseBranch = node.elseBranch
|
|
2421
|
-
? node.elseBranch.map(n => convertNode(n, infer))
|
|
2422
|
-
: node.else
|
|
2423
|
-
? node.else.map(n => convertNode(n, infer))
|
|
2424
|
-
: undefined;
|
|
2425
|
-
}
|
|
2426
|
-
else {
|
|
2427
|
-
condition = args[0] ? convertNode(args[0], infer) : { type: 'literal', value: true };
|
|
2428
|
-
thenBranch = extractBlockCommands(args[1], infer);
|
|
2429
|
-
elseBranch = args[2] ? extractBlockCommands(args[2], infer) : undefined;
|
|
2430
|
-
}
|
|
2431
|
-
if (node.name === 'unless') {
|
|
2432
|
-
condition = { type: 'unary', operator: 'not', operand: condition };
|
|
2433
|
-
}
|
|
2434
|
-
return {
|
|
2435
|
-
type: 'if',
|
|
2436
|
-
condition,
|
|
2437
|
-
thenBranch,
|
|
2438
|
-
...(elseBranch ? { elseBranch } : {}),
|
|
2439
|
-
...pos(node),
|
|
2440
|
-
};
|
|
2441
|
-
}
|
|
2442
|
-
function convertRepeatCommand(node, infer) {
|
|
2443
|
-
const slots = (node.modifiers ?? {});
|
|
2444
|
-
const form = slotText(slots.loopType);
|
|
2445
|
-
if (form === undefined)
|
|
2446
|
-
return convertPositionalRepeat(node, infer);
|
|
2447
|
-
const [bodyBlock, elseBlock] = (node.args ?? []);
|
|
2448
|
-
const body = extractBlockCommands(bodyBlock, infer);
|
|
2449
|
-
const indexName = slotText(slots.index);
|
|
2450
|
-
const shared = {
|
|
2451
|
-
...(indexName ? { indexName } : {}),
|
|
2452
|
-
...(elseBlock ? { elseBody: extractBlockCommands(elseBlock, infer) } : {}),
|
|
2453
|
-
...pos(node),
|
|
2454
|
-
};
|
|
2455
|
-
const operand = (slot) => (slot ? convertNode(slot, infer) : undefined);
|
|
2456
|
-
switch (form) {
|
|
2457
|
-
case 'for':
|
|
2458
|
-
return {
|
|
2459
|
-
type: 'foreach',
|
|
2460
|
-
itemName: slotText(slots.for) ?? 'it',
|
|
2461
|
-
collection: operand(slots.in) ?? { type: 'literal', value: null },
|
|
2462
|
-
body,
|
|
2463
|
-
...shared,
|
|
2464
|
-
};
|
|
2465
|
-
case 'times':
|
|
2466
|
-
return { type: 'repeat', count: operand(slots.times), body, ...shared };
|
|
2467
|
-
case 'while':
|
|
2468
|
-
case 'until': {
|
|
2469
|
-
const test = operand(slots[form]) ?? { type: 'literal', value: form === 'until' };
|
|
2470
|
-
return {
|
|
2471
|
-
type: 'while',
|
|
2472
|
-
condition: form === 'until' ? { type: 'unary', operator: 'not', operand: test } : test,
|
|
2473
|
-
...(slots.bottomTested?.value === true ? { bottomTested: true } : {}),
|
|
2474
|
-
body,
|
|
2475
|
-
...shared,
|
|
2476
|
-
};
|
|
2477
|
-
}
|
|
2478
|
-
case 'until-event': {
|
|
2479
|
-
const event = slotText(slots.event);
|
|
2480
|
-
if (!event) {
|
|
2481
|
-
return { type: 'error', message: "'repeat until event' has no event name", ...pos(node) };
|
|
2482
|
-
}
|
|
2483
|
-
const target = operand(slots.from);
|
|
2484
|
-
return {
|
|
2485
|
-
type: 'repeat',
|
|
2486
|
-
untilEvent: event,
|
|
2487
|
-
...(target ? { untilEventTarget: target } : {}),
|
|
2488
|
-
body,
|
|
2489
|
-
...shared,
|
|
2490
|
-
};
|
|
2491
|
-
}
|
|
2492
|
-
default:
|
|
2493
|
-
return { type: 'repeat', body, ...shared };
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
function slotText(slot) {
|
|
2497
|
-
const text = slot?.value ?? slot?.name;
|
|
2498
|
-
return typeof text === 'string' ? text : undefined;
|
|
2499
|
-
}
|
|
2500
|
-
function convertPositionalRepeat(node, infer) {
|
|
2501
|
-
const args = (node.args ?? []);
|
|
2502
|
-
if (args.length === 0) {
|
|
2503
|
-
return { type: 'repeat', body: [], ...pos(node) };
|
|
2504
|
-
}
|
|
2505
|
-
const loopTypeNode = args[0];
|
|
2506
|
-
const loopType = (loopTypeNode?.name ?? loopTypeNode?.value ?? 'forever');
|
|
2507
|
-
const bodyBlock = args[args.length - 1];
|
|
2508
|
-
switch (loopType) {
|
|
2509
|
-
case 'times': {
|
|
2510
|
-
const count = args[1] ? convertNode(args[1], infer) : undefined;
|
|
2511
|
-
return {
|
|
2512
|
-
type: 'repeat',
|
|
2513
|
-
count,
|
|
2514
|
-
body: extractBlockCommands(bodyBlock, infer),
|
|
2515
|
-
...pos(node),
|
|
2516
|
-
};
|
|
2517
|
-
}
|
|
2518
|
-
case 'for': {
|
|
2519
|
-
const itemName = (args[1]?.value ?? 'item');
|
|
2520
|
-
const collection = args[2]
|
|
2521
|
-
? convertNode(args[2], infer)
|
|
2522
|
-
: { type: 'identifier', value: '[]' };
|
|
2523
|
-
return {
|
|
2524
|
-
type: 'foreach',
|
|
2525
|
-
itemName,
|
|
2526
|
-
collection,
|
|
2527
|
-
body: extractBlockCommands(bodyBlock, infer),
|
|
2528
|
-
...pos(node),
|
|
2529
|
-
};
|
|
2530
|
-
}
|
|
2531
|
-
case 'while': {
|
|
2532
|
-
const condition = args[1]
|
|
2533
|
-
? convertNode(args[1], infer)
|
|
2534
|
-
: { type: 'literal', value: true };
|
|
2535
|
-
return {
|
|
2536
|
-
type: 'while',
|
|
2537
|
-
condition,
|
|
2538
|
-
body: extractBlockCommands(bodyBlock, infer),
|
|
2539
|
-
...pos(node),
|
|
2540
|
-
};
|
|
2541
|
-
}
|
|
2542
|
-
default:
|
|
2543
|
-
return {
|
|
2544
|
-
type: 'repeat',
|
|
2545
|
-
body: extractBlockCommands(bodyBlock, infer),
|
|
2546
|
-
...pos(node),
|
|
2547
|
-
};
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
function convertCommandSequence(node, infer) {
|
|
2551
|
-
const commands = (node.commands ?? []);
|
|
2552
|
-
if (commands.length === 1) {
|
|
2553
|
-
return convertNode(commands[0], infer);
|
|
2554
|
-
}
|
|
2555
|
-
return {
|
|
2556
|
-
type: 'event',
|
|
2557
|
-
event: 'click',
|
|
2558
|
-
body: commands.map(cmd => convertNode(cmd, infer)),
|
|
2559
|
-
...pos(node),
|
|
2560
|
-
};
|
|
2561
|
-
}
|
|
2562
|
-
function convertBlock(node, infer) {
|
|
2563
|
-
const commands = (node.commands ?? []);
|
|
2564
|
-
if (commands.length === 1) {
|
|
2565
|
-
return convertNode(commands[0], infer);
|
|
2566
|
-
}
|
|
2567
|
-
return {
|
|
2568
|
-
type: 'event',
|
|
2569
|
-
event: 'click',
|
|
2570
|
-
body: commands.map(cmd => convertNode(cmd, infer)),
|
|
2571
|
-
...pos(node),
|
|
2572
|
-
};
|
|
2573
|
-
}
|
|
2574
|
-
function convertPossessive(node, infer) {
|
|
2575
|
-
const object = node.object
|
|
2576
|
-
? convertNode(node.object, infer)
|
|
2577
|
-
: { type: 'identifier', value: 'me' };
|
|
2578
|
-
const property = typeof node.property === 'string'
|
|
2579
|
-
? node.property
|
|
2580
|
-
: (node.property?.name ?? node.property?.value ?? '');
|
|
2581
|
-
return { type: 'possessive', object, property, ...pos(node) };
|
|
2582
|
-
}
|
|
2583
|
-
function convertMember(node, infer) {
|
|
2584
|
-
const object = node.object
|
|
2585
|
-
? convertNode(node.object, infer)
|
|
2586
|
-
: { type: 'identifier', value: 'me' };
|
|
2587
|
-
const property = typeof node.property === 'string'
|
|
2588
|
-
? node.property
|
|
2589
|
-
: node.property
|
|
2590
|
-
? convertNode(node.property, infer)
|
|
2591
|
-
: { type: 'literal', value: '' };
|
|
2592
|
-
return {
|
|
2593
|
-
type: 'member',
|
|
2594
|
-
object,
|
|
2595
|
-
property,
|
|
2596
|
-
computed: (node.computed ?? false),
|
|
2597
|
-
...pos(node),
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
function convertBinary(node, infer) {
|
|
2601
|
-
return {
|
|
2602
|
-
type: 'binary',
|
|
2603
|
-
operator: (node.operator ?? ''),
|
|
2604
|
-
left: convertNode(node.left, infer),
|
|
2605
|
-
right: convertNode(node.right, infer),
|
|
2606
|
-
...pos(node),
|
|
2607
|
-
};
|
|
2608
|
-
}
|
|
2609
|
-
function convertCall(node, infer) {
|
|
2610
|
-
const callee = typeof node.callee === 'string'
|
|
2611
|
-
? { type: 'identifier', value: node.callee, name: node.callee }
|
|
2612
|
-
: convertNode(node.callee, infer);
|
|
2613
|
-
const args = (node.arguments ?? node.args ?? []).map(a => convertNode(a, infer));
|
|
2614
|
-
return { type: 'call', callee, args, ...pos(node) };
|
|
2615
|
-
}
|
|
2616
|
-
function convertModifiers(modifiers, infer) {
|
|
2617
|
-
const result = {};
|
|
2618
|
-
for (const [key, value] of Object.entries(modifiers)) {
|
|
2619
|
-
result[key] = convertNode(value, infer);
|
|
2620
|
-
}
|
|
2621
|
-
return result;
|
|
2622
|
-
}
|
|
2623
|
-
function buildEventModifiers(node) {
|
|
2624
|
-
return {
|
|
2625
|
-
...(node.once ? { once: true } : {}),
|
|
2626
|
-
...(node.debounce ? { debounce: node.debounce } : {}),
|
|
2627
|
-
...(node.throttle ? { throttle: node.throttle } : {}),
|
|
2628
|
-
...(node.prevent ? { prevent: true } : {}),
|
|
2629
|
-
...(node.stop ? { stop: true } : {}),
|
|
2630
|
-
...(node.capture ? { capture: true } : {}),
|
|
2631
|
-
...(node.passive ? { passive: true } : {}),
|
|
2632
|
-
...(node.from ? { from: node.from } : {}),
|
|
2633
|
-
...(node.selector && !node.from ? { from: node.selector } : {}),
|
|
2634
|
-
};
|
|
2635
|
-
}
|
|
2636
|
-
function extractBlockCommands(block, infer) {
|
|
2637
|
-
if (!block)
|
|
2638
|
-
return [];
|
|
2639
|
-
if (block.type === 'block') {
|
|
2640
|
-
return (block.commands ?? []).map(cmd => convertNode(cmd, infer));
|
|
2641
|
-
}
|
|
2642
|
-
return [convertNode(block, infer)];
|
|
2643
|
-
}
|
|
2644
|
-
function inferRoles(name, args, modifiers, target, infer) {
|
|
2645
|
-
const roles = {};
|
|
2646
|
-
switch (name) {
|
|
2647
|
-
case 'set': {
|
|
2648
|
-
const toVal = modifiers?.to;
|
|
2649
|
-
const second = args[1];
|
|
2650
|
-
const marksTo = second?.type === 'identifier' &&
|
|
2651
|
-
String(second.name ?? second.value ?? '').toLowerCase() === 'to';
|
|
2652
|
-
if (marksTo && !toVal) {
|
|
2653
|
-
return infer
|
|
2654
|
-
? infer(name, args, modifiers, target)
|
|
2655
|
-
: null;
|
|
2656
|
-
}
|
|
2657
|
-
if (args[0])
|
|
2658
|
-
roles.destination = args[0];
|
|
2659
|
-
if (toVal && typeof toVal === 'object' && 'type' in toVal) {
|
|
2660
|
-
roles.patient = toVal;
|
|
2661
|
-
}
|
|
2662
|
-
else if (args[1]) {
|
|
2663
|
-
roles.patient = args[1];
|
|
2664
|
-
}
|
|
2665
|
-
break;
|
|
2666
|
-
}
|
|
2667
|
-
case 'go': {
|
|
2668
|
-
const kw = (n) => {
|
|
2669
|
-
if (!n || typeof n !== 'object')
|
|
2670
|
-
return undefined;
|
|
2671
|
-
const v = n;
|
|
2672
|
-
if (v.type === 'identifier') {
|
|
2673
|
-
if (typeof v.name === 'string' && v.name !== '')
|
|
2674
|
-
return v.name;
|
|
2675
|
-
return typeof v.value === 'string' ? v.value : undefined;
|
|
2676
|
-
}
|
|
2677
|
-
if (v.type === 'literal' && typeof v.value === 'string')
|
|
2678
|
-
return v.value;
|
|
2679
|
-
return undefined;
|
|
2680
|
-
};
|
|
2681
|
-
const asNode = (x) => x && typeof x === 'object' && 'type' in x ? x : undefined;
|
|
2682
|
-
let destination;
|
|
2683
|
-
let method;
|
|
2684
|
-
const onMod = asNode(modifiers?.on);
|
|
2685
|
-
const slotUrl = asNode(modifiers?.url);
|
|
2686
|
-
const slotOf = asNode(modifiers?.of);
|
|
2687
|
-
const slotHistory = kw(asNode(modifiers?.back)) ?? kw(asNode(modifiers?.forward));
|
|
2688
|
-
if (slotHistory === 'back' || slotHistory === 'forward') {
|
|
2689
|
-
destination = { type: 'identifier', value: slotHistory, name: slotHistory };
|
|
2690
|
-
}
|
|
2691
|
-
else if (slotUrl) {
|
|
2692
|
-
destination = slotUrl;
|
|
2693
|
-
method = { type: 'literal', value: 'url' };
|
|
2694
|
-
}
|
|
2695
|
-
else if (slotOf) {
|
|
2696
|
-
destination = slotOf;
|
|
2697
|
-
}
|
|
2698
|
-
else if (args.length === 0 && onMod) {
|
|
2699
|
-
destination = onMod;
|
|
2700
|
-
if (kw(asNode(modifiers?.method)) === 'url') {
|
|
2701
|
-
method = { type: 'literal', value: 'url' };
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
else {
|
|
2705
|
-
const words = args.map(kw);
|
|
2706
|
-
const urlIdx = words.indexOf('url');
|
|
2707
|
-
if (urlIdx !== -1 && args[urlIdx + 1]) {
|
|
2708
|
-
destination = args[urlIdx + 1];
|
|
2709
|
-
method = { type: 'literal', value: 'url' };
|
|
2710
|
-
}
|
|
2711
|
-
else {
|
|
2712
|
-
const SKIP = new Set(['to', 'the']);
|
|
2713
|
-
const POSITION = new Set([
|
|
2714
|
-
'top',
|
|
2715
|
-
'middle',
|
|
2716
|
-
'bottom',
|
|
2717
|
-
'left',
|
|
2718
|
-
'center',
|
|
2719
|
-
'right',
|
|
2720
|
-
'smoothly',
|
|
2721
|
-
'instantly',
|
|
2722
|
-
'in',
|
|
2723
|
-
'new',
|
|
2724
|
-
'window',
|
|
2725
|
-
]);
|
|
2726
|
-
const headIdx = args.findIndex((_, i) => {
|
|
2727
|
-
const w = words[i];
|
|
2728
|
-
return w === undefined || !SKIP.has(w);
|
|
2729
|
-
});
|
|
2730
|
-
const headWord = headIdx !== -1 ? words[headIdx] : undefined;
|
|
2731
|
-
const ofIdx = words.indexOf('of');
|
|
2732
|
-
if (headWord === 'back' || headWord === 'forward') {
|
|
2733
|
-
destination = { type: 'identifier', value: headWord, name: headWord };
|
|
2734
|
-
}
|
|
2735
|
-
else if (ofIdx !== -1 && args[ofIdx + 1]) {
|
|
2736
|
-
destination = kw(args[ofIdx + 1]) === 'the' ? args[ofIdx + 2] : args[ofIdx + 1];
|
|
2737
|
-
}
|
|
2738
|
-
else if (headIdx !== -1 && !POSITION.has(headWord ?? '')) {
|
|
2739
|
-
destination = args[headIdx];
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
const destWord = kw(destination);
|
|
2744
|
-
if ((destWord === 'back' || destWord === 'forward') && destination?.type !== 'identifier') {
|
|
2745
|
-
destination = { type: 'identifier', value: destWord, name: destWord };
|
|
2746
|
-
}
|
|
2747
|
-
if (!destination && target)
|
|
2748
|
-
destination = target;
|
|
2749
|
-
if (destination)
|
|
2750
|
-
roles.destination = destination;
|
|
2751
|
-
if (method)
|
|
2752
|
-
roles.method = method;
|
|
2753
|
-
break;
|
|
2754
|
-
}
|
|
2755
|
-
default:
|
|
2756
|
-
return infer
|
|
2757
|
-
? infer(name, args, modifiers, target)
|
|
2758
|
-
: null;
|
|
2759
|
-
}
|
|
2760
|
-
return Object.keys(roles).length > 0 ? roles : null;
|
|
2761
|
-
}
|
|
2762
|
-
|
|
2763
|
-
const POS = { start: 0, end: 0, line: 1, column: 0 };
|
|
2764
|
-
function nodePos(node) {
|
|
2765
|
-
return {
|
|
2766
|
-
start: node.start ?? POS.start,
|
|
2767
|
-
end: node.end ?? POS.end,
|
|
2768
|
-
line: node.line ?? POS.line,
|
|
2769
|
-
column: node.column ?? POS.column,
|
|
2770
|
-
};
|
|
2771
|
-
}
|
|
2772
|
-
function toCoreAST(node) {
|
|
2773
|
-
if (!node)
|
|
2774
|
-
return { type: 'literal', value: null, raw: 'null', ...POS };
|
|
2192
|
+
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
2193
|
+
const isEngineSpan = (value) => isRecord(value) &&
|
|
2194
|
+
typeof value.type === 'string' &&
|
|
2195
|
+
typeof value.start === 'number' &&
|
|
2196
|
+
typeof value.end === 'number';
|
|
2197
|
+
const COMMAND_TYPES = {
|
|
2198
|
+
call: ['getCommand'],
|
|
2199
|
+
trigger: ['sendCommand'],
|
|
2200
|
+
toggle: ['toggleCommand', 'toggleElementCommand'],
|
|
2201
|
+
transition: ['transitionCommand', 'viewTransitionCommand'],
|
|
2202
|
+
};
|
|
2203
|
+
function engineTypesFor(node) {
|
|
2775
2204
|
switch (node.type) {
|
|
2776
2205
|
case 'event':
|
|
2777
|
-
return
|
|
2778
|
-
case 'command':
|
|
2779
|
-
return convertCommand(node);
|
|
2206
|
+
return ['onFeature'];
|
|
2780
2207
|
case 'if':
|
|
2781
|
-
return
|
|
2208
|
+
return ['ifCommand'];
|
|
2782
2209
|
case 'repeat':
|
|
2783
|
-
return convertRepeat(node);
|
|
2784
2210
|
case 'foreach':
|
|
2785
|
-
return convertForEach(node);
|
|
2786
2211
|
case 'while':
|
|
2787
|
-
return
|
|
2788
|
-
case '
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
value: node.value,
|
|
2792
|
-
raw: node.value === null ? 'null' : node.value === undefined ? '' : String(node.value),
|
|
2793
|
-
...nodePos(node),
|
|
2794
|
-
};
|
|
2795
|
-
case 'identifier':
|
|
2796
|
-
return { type: 'identifier', name: node.name ?? node.value, ...nodePos(node) };
|
|
2797
|
-
case 'selector':
|
|
2798
|
-
return { type: 'selector', value: node.value, ...nodePos(node) };
|
|
2799
|
-
case 'variable':
|
|
2800
|
-
return { type: 'identifier', name: node.name, scope: node.scope, ...nodePos(node) };
|
|
2801
|
-
case 'binary':
|
|
2802
|
-
return {
|
|
2803
|
-
type: 'binaryExpression',
|
|
2804
|
-
operator: node.operator,
|
|
2805
|
-
left: toCoreAST(node.left),
|
|
2806
|
-
right: toCoreAST(node.right),
|
|
2807
|
-
...nodePos(node),
|
|
2808
|
-
};
|
|
2809
|
-
case 'unary':
|
|
2810
|
-
return {
|
|
2811
|
-
type: 'unaryExpression',
|
|
2812
|
-
operator: node.operator,
|
|
2813
|
-
argument: toCoreAST(node.operand),
|
|
2814
|
-
prefix: true,
|
|
2815
|
-
...nodePos(node),
|
|
2816
|
-
};
|
|
2817
|
-
case 'typeCheck':
|
|
2818
|
-
return {
|
|
2819
|
-
type: 'typeCheckExpression',
|
|
2820
|
-
value: toCoreAST(node.value),
|
|
2821
|
-
typeName: node.typeName,
|
|
2822
|
-
nullOk: node.nullOk,
|
|
2823
|
-
negated: node.negated,
|
|
2824
|
-
...nodePos(node),
|
|
2825
|
-
};
|
|
2826
|
-
case 'member':
|
|
2827
|
-
return {
|
|
2828
|
-
type: 'memberExpression',
|
|
2829
|
-
object: toCoreAST(node.object),
|
|
2830
|
-
property: typeof node.property === 'string'
|
|
2831
|
-
? { type: 'identifier', name: node.property, ...POS }
|
|
2832
|
-
: toCoreAST(node.property),
|
|
2833
|
-
computed: node.computed ?? false,
|
|
2834
|
-
...nodePos(node),
|
|
2835
|
-
};
|
|
2836
|
-
case 'array':
|
|
2837
|
-
return {
|
|
2838
|
-
type: 'arrayLiteral',
|
|
2839
|
-
elements: node.elements.map(element => toCoreAST(element)),
|
|
2840
|
-
...nodePos(node),
|
|
2841
|
-
};
|
|
2842
|
-
case 'possessive':
|
|
2843
|
-
return {
|
|
2844
|
-
type: 'possessiveExpression',
|
|
2845
|
-
object: toCoreAST(node.object),
|
|
2846
|
-
property: { type: 'identifier', name: node.property, ...POS },
|
|
2847
|
-
...nodePos(node),
|
|
2848
|
-
};
|
|
2849
|
-
case 'call':
|
|
2850
|
-
return {
|
|
2851
|
-
type: 'callExpression',
|
|
2852
|
-
callee: toCoreAST(node.callee),
|
|
2853
|
-
arguments: (node.args ?? []).map(a => toCoreAST(a)),
|
|
2854
|
-
...nodePos(node),
|
|
2855
|
-
};
|
|
2856
|
-
case 'positional':
|
|
2857
|
-
return {
|
|
2858
|
-
type: 'callExpression',
|
|
2859
|
-
callee: { type: 'identifier', name: node.position, ...POS },
|
|
2860
|
-
arguments: node.target ? [toCoreAST(node.target)] : [],
|
|
2861
|
-
...nodePos(node),
|
|
2862
|
-
};
|
|
2863
|
-
case 'error':
|
|
2864
|
-
return { type: 'literal', value: null, raw: 'null', ...POS };
|
|
2865
|
-
default: {
|
|
2866
|
-
return { type: 'literal', value: null, raw: 'null', ...POS };
|
|
2867
|
-
}
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
function convertEvent(node) {
|
|
2871
|
-
const commands = (node.body ?? []).map(cmd => toCoreAST(cmd));
|
|
2872
|
-
const modifiers = flattenEventModifiers(node.modifiers);
|
|
2873
|
-
return {
|
|
2874
|
-
type: 'eventHandler',
|
|
2875
|
-
event: node.event,
|
|
2876
|
-
commands,
|
|
2877
|
-
...modifiers,
|
|
2878
|
-
...nodePos(node),
|
|
2879
|
-
};
|
|
2880
|
-
}
|
|
2881
|
-
function convertCommand(node) {
|
|
2882
|
-
const result = {
|
|
2883
|
-
type: 'command',
|
|
2884
|
-
name: node.name,
|
|
2885
|
-
args: (node.args ?? []).map(a => toCoreAST(a)),
|
|
2886
|
-
isBlocking: false,
|
|
2887
|
-
...nodePos(node),
|
|
2888
|
-
};
|
|
2889
|
-
if (node.target) {
|
|
2890
|
-
result.target = toCoreAST(node.target);
|
|
2891
|
-
}
|
|
2892
|
-
if (node.modifiers && Object.keys(node.modifiers).length > 0) {
|
|
2893
|
-
const convertedModifiers = {};
|
|
2894
|
-
for (const [key, value] of Object.entries(node.modifiers)) {
|
|
2895
|
-
convertedModifiers[key] =
|
|
2896
|
-
value && typeof value === 'object' && 'type' in value
|
|
2897
|
-
? toCoreAST(value)
|
|
2898
|
-
: value;
|
|
2212
|
+
return ['repeatCommand'];
|
|
2213
|
+
case 'command': {
|
|
2214
|
+
const name = typeof node.name === 'string' ? node.name : '';
|
|
2215
|
+
return COMMAND_TYPES[name] ?? [`${name}Command`];
|
|
2899
2216
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
}
|
|
2904
|
-
function
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2217
|
+
default:
|
|
2218
|
+
return [];
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
function engineSpans(tree, out = []) {
|
|
2222
|
+
if (Array.isArray(tree)) {
|
|
2223
|
+
for (const item of tree)
|
|
2224
|
+
engineSpans(item, out);
|
|
2225
|
+
return out;
|
|
2226
|
+
}
|
|
2227
|
+
if (!isRecord(tree))
|
|
2228
|
+
return out;
|
|
2229
|
+
if (isEngineSpan(tree) && /(Command|Feature)$/.test(tree.type))
|
|
2230
|
+
out.push(tree);
|
|
2231
|
+
for (const value of Object.values(tree)) {
|
|
2232
|
+
if (typeof value === 'object' && value !== null)
|
|
2233
|
+
engineSpans(value, out);
|
|
2234
|
+
}
|
|
2235
|
+
return out;
|
|
2236
|
+
}
|
|
2237
|
+
function withEnginePositions(nodes, source, engineTree) {
|
|
2238
|
+
const spans = engineSpans(engineTree);
|
|
2239
|
+
let cursor = 0;
|
|
2240
|
+
const lineStarts = [0];
|
|
2241
|
+
for (let i = 0; i < source.length; i++)
|
|
2242
|
+
if (source[i] === '\n')
|
|
2243
|
+
lineStarts.push(i + 1);
|
|
2244
|
+
const lineAndColumn = (offset) => {
|
|
2245
|
+
let line = 0;
|
|
2246
|
+
while (line + 1 < lineStarts.length && (lineStarts[line + 1] ?? Infinity) <= offset)
|
|
2247
|
+
line++;
|
|
2248
|
+
return { line: line + 1, column: offset - (lineStarts[line] ?? 0) };
|
|
2930
2249
|
};
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2250
|
+
const place = (value) => {
|
|
2251
|
+
if (Array.isArray(value))
|
|
2252
|
+
return value.map(place);
|
|
2253
|
+
if (!isRecord(value) || typeof value.type !== 'string')
|
|
2254
|
+
return value;
|
|
2255
|
+
let span = typeof value.start === 'number' && typeof value.end === 'number'
|
|
2256
|
+
? { start: value.start, end: value.end }
|
|
2257
|
+
: undefined;
|
|
2258
|
+
const kinds = engineTypesFor(value);
|
|
2259
|
+
if (kinds.length > 0) {
|
|
2260
|
+
const index = spans.findIndex((s, i) => i >= cursor && kinds.includes(s.type));
|
|
2261
|
+
const match = spans[index];
|
|
2262
|
+
if (match) {
|
|
2263
|
+
span = { start: match.start, end: match.end };
|
|
2264
|
+
cursor = index + 1;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
const out = {};
|
|
2268
|
+
for (const [key, child] of Object.entries(value)) {
|
|
2269
|
+
out[key] = typeof child === 'object' ? place(child) : child;
|
|
2270
|
+
}
|
|
2271
|
+
return span ? { ...out, ...span, ...lineAndColumn(span.start) } : out;
|
|
2947
2272
|
};
|
|
2948
|
-
|
|
2949
|
-
function slotString(value) {
|
|
2950
|
-
return { type: 'string', value, ...POS };
|
|
2951
|
-
}
|
|
2952
|
-
function convertRepeat(node) {
|
|
2953
|
-
if (node.count !== undefined) {
|
|
2954
|
-
const times = typeof node.count === 'number'
|
|
2955
|
-
? { type: 'literal', value: node.count, raw: String(node.count), ...POS }
|
|
2956
|
-
: toCoreAST(node.count);
|
|
2957
|
-
return loopCommand(node, 'times', { times });
|
|
2958
|
-
}
|
|
2959
|
-
if (node.whileCondition !== undefined) {
|
|
2960
|
-
return loopCommand(node, 'while', { while: toCoreAST(node.whileCondition) });
|
|
2961
|
-
}
|
|
2962
|
-
if (node.untilEvent !== undefined) {
|
|
2963
|
-
return loopCommand(node, 'until-event', {
|
|
2964
|
-
event: slotString(node.untilEvent),
|
|
2965
|
-
from: node.untilEventTarget ? toCoreAST(node.untilEventTarget) : undefined,
|
|
2966
|
-
});
|
|
2967
|
-
}
|
|
2968
|
-
return loopCommand(node, 'forever', {});
|
|
2969
|
-
}
|
|
2970
|
-
function convertForEach(node) {
|
|
2971
|
-
return loopCommand(node, 'for', {
|
|
2972
|
-
for: slotString(node.itemName),
|
|
2973
|
-
in: toCoreAST(node.collection),
|
|
2974
|
-
});
|
|
2975
|
-
}
|
|
2976
|
-
function convertWhile(node) {
|
|
2977
|
-
return loopCommand(node, 'while', {
|
|
2978
|
-
while: toCoreAST(node.condition),
|
|
2979
|
-
bottomTested: node.bottomTested
|
|
2980
|
-
? { type: 'literal', value: true, raw: 'true', ...POS }
|
|
2981
|
-
: undefined,
|
|
2982
|
-
});
|
|
2983
|
-
}
|
|
2984
|
-
function flattenEventModifiers(modifiers) {
|
|
2985
|
-
if (!modifiers)
|
|
2986
|
-
return {};
|
|
2987
|
-
const flat = {};
|
|
2988
|
-
if (modifiers.once)
|
|
2989
|
-
flat.once = true;
|
|
2990
|
-
if (modifiers.prevent)
|
|
2991
|
-
flat.prevent = true;
|
|
2992
|
-
if (modifiers.stop)
|
|
2993
|
-
flat.stop = true;
|
|
2994
|
-
if (modifiers.capture)
|
|
2995
|
-
flat.capture = true;
|
|
2996
|
-
if (modifiers.passive)
|
|
2997
|
-
flat.passive = true;
|
|
2998
|
-
if (modifiers.debounce)
|
|
2999
|
-
flat.debounce = modifiers.debounce;
|
|
3000
|
-
if (modifiers.throttle)
|
|
3001
|
-
flat.throttle = modifiers.throttle;
|
|
3002
|
-
if (modifiers.from)
|
|
3003
|
-
flat.from = modifiers.from;
|
|
3004
|
-
return flat;
|
|
2273
|
+
return nodes.map(node => place(node));
|
|
3005
2274
|
}
|
|
3006
2275
|
|
|
3007
2276
|
var DiagnosticSeverity;
|
|
@@ -3645,7 +2914,6 @@ exports.findDeadCode = findDeadCode;
|
|
|
3645
2914
|
exports.findFirst = findFirst;
|
|
3646
2915
|
exports.findNodes = findNodes;
|
|
3647
2916
|
exports.format = format;
|
|
3648
|
-
exports.fromCoreAST = fromCoreAST;
|
|
3649
2917
|
exports.generate = generate;
|
|
3650
2918
|
exports.generateCommand = generateCommand;
|
|
3651
2919
|
exports.generateDocumentation = generateDocumentation;
|
|
@@ -3669,7 +2937,7 @@ exports.query = query;
|
|
|
3669
2937
|
exports.queryAll = queryAll;
|
|
3670
2938
|
exports.queryXPath = queryXPath;
|
|
3671
2939
|
exports.suggestOptimizations = suggestOptimizations;
|
|
3672
|
-
exports.toCoreAST = toCoreAST;
|
|
3673
2940
|
exports.transform = transform;
|
|
3674
2941
|
exports.visit = visit;
|
|
2942
|
+
exports.withEnginePositions = withEnginePositions;
|
|
3675
2943
|
//# sourceMappingURL=index.cjs.map
|