@torpor/view 0.1.11 → 0.3.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/.oxlintrc.json +3 -0
- package/CHANGELOG.md +37 -0
- package/README.md +28 -27
- package/dist/Component-d19HOoEw.d.ts +11 -0
- package/dist/Component-d19HOoEw.d.ts.map +1 -0
- package/dist/ServerSlotRender-BiG4xB8e.d.ts +41 -0
- package/dist/ServerSlotRender-BiG4xB8e.d.ts.map +1 -0
- package/dist/compile.d.ts +202 -148
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +3380 -3747
- package/dist/compile.js.map +1 -1
- package/dist/formatText-B0FXBdFT.js +410 -0
- package/dist/formatText-B0FXBdFT.js.map +1 -0
- package/dist/index.d.ts +373 -170
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +826 -760
- package/dist/index.js.map +1 -1
- package/dist/ssr.d.ts +13 -8
- package/dist/ssr.d.ts.map +1 -0
- package/dist/ssr.js +18 -27
- package/dist/ssr.js.map +1 -1
- package/package.json +18 -22
- package/scripts/buildTestOutput.ts +1 -1
- package/scripts/copyToRepl.ts +9 -7
- package/src/ambient.d.ts +1 -0
- package/src/compile/build/client/BuildStatus.ts +6 -4
- package/src/compile/build/client/addMappedText.ts +25 -0
- package/src/compile/build/client/buildAddFragment.ts +26 -4
- package/src/compile/build/client/buildAwaitNode.ts +86 -54
- package/src/compile/build/client/buildCode.ts +91 -57
- package/src/compile/build/client/buildComponentNode.ts +23 -43
- package/src/compile/build/client/buildControlNode.ts +5 -4
- package/src/compile/build/client/buildElementNode.ts +70 -78
- package/src/compile/build/client/buildForNode.ts +24 -12
- package/src/compile/build/client/buildFragment.ts +29 -43
- package/src/compile/build/client/buildFragmentText.ts +27 -20
- package/src/compile/build/client/buildHtmlNode.ts +5 -3
- package/src/compile/build/client/buildIfNode.ts +44 -29
- package/src/compile/build/client/buildMount.ts +1 -1
- package/src/compile/build/client/buildNode.ts +8 -7
- package/src/compile/build/client/buildReplaceNode.ts +5 -3
- package/src/compile/build/client/buildRootNode.ts +2 -2
- package/src/compile/build/client/buildRun.ts +1 -1
- package/src/compile/build/client/buildScriptNode.ts +5 -3
- package/src/compile/build/client/buildSlotNode.ts +7 -23
- package/src/compile/build/client/buildSpecialNode.ts +10 -14
- package/src/compile/build/client/buildStyles.ts +53 -18
- package/src/compile/build/client/buildSwitchNode.ts +53 -32
- package/src/compile/build/client/buildTextNode.ts +31 -28
- package/src/compile/build/client/replaceForVarNames.ts +1 -1
- package/src/compile/build/client/stashRun.ts +22 -0
- package/src/compile/build/client/stashRunWithOffsets.ts +32 -0
- package/src/compile/build/server/BuildServerStatus.ts +3 -3
- package/src/compile/build/server/buildServerAwaitNode.ts +5 -5
- package/src/compile/build/server/buildServerCode.ts +60 -39
- package/src/compile/build/server/buildServerComponentNode.ts +21 -41
- package/src/compile/build/server/buildServerControlNode.ts +7 -4
- package/src/compile/build/server/buildServerElementNode.ts +18 -29
- package/src/compile/build/server/buildServerForNode.ts +5 -5
- package/src/compile/build/server/buildServerHtmlNode.ts +3 -3
- package/src/compile/build/server/buildServerIfNode.ts +5 -5
- package/src/compile/build/server/buildServerNode.ts +7 -6
- package/src/compile/build/server/buildServerReplaceNode.ts +5 -5
- package/src/compile/build/server/buildServerRootNode.ts +2 -2
- package/src/compile/build/server/buildServerScriptNode.ts +1 -1
- package/src/compile/build/server/buildServerSlotNode.ts +14 -26
- package/src/compile/build/server/buildServerSpecialNode.ts +10 -13
- package/src/compile/build/server/buildServerSwitchNode.ts +5 -5
- package/src/compile/build/server/buildServerTextNode.ts +9 -23
- package/src/compile/build/utils/nextVarName.ts +2 -2
- package/src/compile/build.ts +9 -4
- package/src/compile/buildType.ts +2 -2
- package/src/compile/parse/ParseComponentStatus.ts +24 -0
- package/src/compile/parse/ParseStatus.ts +6 -26
- package/src/compile/parse/addSpaceElement.ts +6 -5
- package/src/compile/parse/parseCode.ts +116 -60
- package/src/compile/parse/parseControl.ts +34 -32
- package/src/compile/parse/parseElement.ts +56 -121
- package/src/compile/parse/parseImports.ts +1 -1
- package/src/compile/parse/parseInlineScript.ts +12 -26
- package/src/compile/parse/parseMarkup.ts +9 -3
- package/src/compile/parse/parseStyles.ts +4 -4
- package/src/compile/parse/parseTag.ts +50 -8
- package/src/compile/parse/parseText.ts +96 -0
- package/src/compile/parse/scopeStyles.ts +9 -8
- package/src/compile/parse/slottifyChildNodes.ts +8 -7
- package/src/compile/parse/utils/accept.ts +1 -1
- package/src/compile/parse/utils/addError.ts +24 -6
- package/src/compile/parse/utils/consumeAlphaNumeric.ts +1 -1
- package/src/compile/parse/utils/consumeNonSpace.ts +1 -1
- package/src/compile/parse/utils/consumeSpace.ts +1 -1
- package/src/compile/parse/utils/consumeUntil.ts +1 -1
- package/src/compile/parse/utils/expect.ts +1 -1
- package/src/compile/parse.ts +1 -1
- package/src/compile/types/BuildResult.ts +5 -2
- package/src/compile/types/CompileError.ts +8 -5
- package/src/compile/types/Import.ts +2 -2
- package/src/compile/types/ParseResult.ts +4 -4
- package/src/compile/types/ScriptChunk.ts +6 -0
- package/src/compile/types/SourceMapping.ts +7 -0
- package/src/compile/types/SourceRange.ts +4 -0
- package/src/compile/types/nodes/Attribute.ts +7 -2
- package/src/compile/types/nodes/ControlNode.ts +8 -6
- package/src/compile/types/nodes/ElementNode.ts +11 -6
- package/src/compile/types/nodes/Fragment.ts +10 -2
- package/src/compile/types/nodes/NodeType.ts +3 -1
- package/src/compile/types/nodes/OperationType.ts +3 -1
- package/src/compile/types/nodes/ParentNode.ts +4 -4
- package/src/compile/types/nodes/RootNode.ts +5 -5
- package/src/compile/types/nodes/TemplateNode.ts +3 -3
- package/src/compile/types/nodes/TextNode.ts +5 -3
- package/src/compile/types/styles/Attribute.ts +2 -2
- package/src/compile/types/styles/Style.ts +3 -3
- package/src/compile/types/styles/StyleBlock.ts +3 -3
- package/src/compile/utils/Builder.ts +25 -11
- package/src/compile/utils/endOfString.ts +8 -0
- package/src/compile/utils/endOfTemplateString.ts +14 -0
- package/src/compile/{types/nodes → utils}/isComponentNode.ts +2 -2
- package/src/compile/utils/isControlNode.ts +6 -0
- package/src/compile/utils/isElementNode.ts +6 -0
- package/src/compile/utils/isParentNode.ts +6 -0
- package/src/compile/{types/nodes → utils}/isSpaceNode.ts +3 -3
- package/src/compile/utils/isSpecialNode.ts +6 -0
- package/src/compile/utils/isTextNode.ts +6 -0
- package/src/compile.ts +2 -2
- package/src/debug/printNode.ts +12 -8
- package/src/debug/printRanges.ts +74 -0
- package/src/debug/printSignalDiagram.ts +139 -0
- package/src/debug/printSimpleDiagram.ts +88 -0
- package/src/index.ts +15 -8
- package/src/render/$batch.ts +22 -0
- package/src/render/$cache.ts +34 -0
- package/src/render/$mount.ts +1 -1
- package/src/render/$peek.ts +14 -0
- package/src/render/$run.ts +16 -13
- package/src/render/$serverBatch.ts +3 -0
- package/src/render/$serverCache.ts +3 -0
- package/src/render/$serverMount.ts +1 -1
- package/src/render/$serverPeek.ts +3 -0
- package/src/render/$serverRun.ts +1 -1
- package/src/render/$unwrap.ts +3 -1
- package/src/render/$watch.ts +12 -13
- package/src/render/addAnimation.ts +1 -1
- package/src/render/addFragment.ts +16 -24
- package/src/render/applyProps.ts +1 -1
- package/src/render/buildClasses.ts +31 -0
- package/src/render/buildStyles.ts +19 -0
- package/src/render/clearLayoutSlot.ts +1 -1
- package/src/render/clearRange.ts +43 -50
- package/src/render/context.ts +19 -48
- package/src/render/fillLayoutSlot.ts +3 -3
- package/src/render/getFragment.ts +1 -1
- package/src/render/hydrate.ts +9 -2
- package/src/render/hydrateRoot.ts +2 -2
- package/src/render/isCommentNode.ts +3 -0
- package/src/render/isFragmentNode.ts +3 -0
- package/src/render/isTextNode.ts +3 -0
- package/src/render/mount.ts +12 -4
- package/src/render/moveRange.ts +5 -3
- package/src/render/newListItem.ts +4 -4
- package/src/render/newRange.ts +6 -5
- package/src/render/nodeAnchor.ts +6 -6
- package/src/render/nodeCheckHydrationBreak.ts +3 -3
- package/src/render/nodeChild.ts +2 -2
- package/src/render/nodeNext.ts +2 -2
- package/src/render/nodeRoot.ts +18 -4
- package/src/render/popRange.ts +2 -2
- package/src/render/pushRange.ts +12 -4
- package/src/render/runControl.ts +1 -5
- package/src/render/runControlBranch.ts +10 -24
- package/src/render/runList.ts +6 -5
- package/src/render/runListItems.ts +39 -39
- package/src/render/setAttribute.ts +1 -1
- package/src/render/setDynamicElement.ts +2 -2
- package/src/ssr.ts +7 -4
- package/src/types/Animation.ts +1 -1
- package/src/types/BuildOptions.ts +6 -2
- package/src/types/Cleanup.ts +3 -1
- package/src/types/Component.ts +4 -2
- package/src/types/Computed.ts +62 -0
- package/src/types/Context.ts +99 -0
- package/src/types/Effect.ts +45 -9
- package/src/types/ListItem.ts +3 -3
- package/src/types/ProxyData.ts +6 -4
- package/src/types/ProxySignal.ts +28 -0
- package/src/types/Range.ts +10 -16
- package/src/types/ServerComponent.ts +5 -3
- package/src/types/ServerSlotRender.ts +3 -1
- package/src/types/SlotRender.ts +4 -2
- package/src/types/Subscription.ts +57 -0
- package/src/types/Template.ts +6 -5
- package/src/types/TemplateComponent.ts +7 -5
- package/src/types/WatchOptions.ts +8 -2
- package/src/types/constants.ts +14 -0
- package/src/watch/batchEnd.ts +17 -0
- package/src/watch/batchStart.ts +5 -0
- package/src/watch/checkComputed.ts +46 -0
- package/src/watch/checkEffect.ts +30 -0
- package/src/watch/checkSources.ts +63 -0
- package/src/watch/clearSources.ts +39 -0
- package/src/watch/clearTargets.ts +28 -0
- package/src/watch/deactivateSources.ts +19 -0
- package/src/watch/proxyGet.ts +106 -51
- package/src/watch/proxySet.ts +17 -13
- package/src/watch/runCleanups.ts +40 -0
- package/src/watch/runComputed.ts +36 -0
- package/src/watch/runEffect.ts +38 -13
- package/src/watch/symbols.ts +3 -1
- package/src/watch/trackEffect.ts +63 -15
- package/src/watch/trackProxyEffect.ts +21 -0
- package/src/watch/transferEffects.ts +66 -62
- package/src/watch/triggerEffects.ts +55 -18
- package/src/watch/updateSignal.ts +102 -0
- package/src/wrappers/ReactiveDate.ts +68 -0
- package/test/attributes/attributes.test.ts +2 -2
- package/test/attributes/components/output/Attributes-client.ts +8 -20
- package/test/attributes/components/output/Attributes-server.ts +9 -11
- package/test/attributes/components/temp/{Attributes-client-4620a40099e57a7fdaab895b204d85881f6dbfb7.ts → Attributes-client-9b2935d7824ba501776fdc6c48861422c15b6a12.ts} +8 -20
- package/test/attributes/components/temp/Attributes-server-716db6e335e5a372a34dd931e5f358ee6d1869e5.ts +16 -0
- package/test/attributes/disappearing.test.ts +2 -2
- package/test/attributes/parse.test.ts +161 -248
- package/test/await/await.test.ts +2 -2
- package/test/await/components/Await.torp +11 -13
- package/test/await/components/output/Await-client.ts +31 -46
- package/test/await/components/output/Await-server.ts +13 -14
- package/test/await/components/temp/{Await-client-9c30564ea39457e614e60c0cc0a71c431e8a1e76.ts → Await-client-e969f4bd0712acf259ddfaa5a3b3448307201fd2.ts} +31 -46
- package/test/await/components/temp/{Await-server-f02f39af3bb3344ca6b18a1d64d60b21913fba31.ts → Await-server-614014fab69e234b8271088b10397cf0452d9a76.ts} +13 -14
- package/test/bench/components/Bench.torp +4 -4
- package/test/bench/components/output/Bench-client.ts +43 -46
- package/test/bench/components/output/Bench-server.ts +16 -17
- package/test/bench/components/temp/Bench-client-7f31596dafc8077370d8d90b1bb9b6e0208154e7.ts +205 -0
- package/test/bench/components/temp/{Bench-server-00cefa588803c01ca4f2741c595e4f045cdd101e.ts → Bench-server-341b20073668f4f2160cd2ba37847c7db15e1e0f.ts} +16 -17
- package/test/bind/bind.test.ts +2 -2
- package/test/bind/component.test.ts +2 -2
- package/test/bind/components/BindComponent.torp +3 -18
- package/test/bind/components/BindText.torp +8 -10
- package/test/bind/components/output/BindComponent-client.ts +26 -47
- package/test/bind/components/output/BindComponent-server.ts +25 -36
- package/test/bind/components/output/BindText-client.ts +9 -16
- package/test/bind/components/output/BindText-server.ts +10 -11
- package/test/bind/components/temp/BindComponent-client-22eccb5354a2b0267841e015f3a2a0baf534bf89.ts +72 -0
- package/test/bind/components/temp/BindComponent-server-0da6ba90a409468fd1f7358f8198e96b7595ff80.ts +41 -0
- package/test/bind/components/temp/{BindText-client-134676d616abbad6b8a7ec48df0a2e38cbfe3b87.ts → BindText-client-7692ae1570533cc17e2186e9c7d4768529e4a2fe.ts} +9 -16
- package/test/bind/components/temp/BindText-server-6801c5f8e66a65405b45061bc037a011620c0591.ts +20 -0
- package/test/build-server/build-server.test.ts +2 -1
- package/test/build-server/components/IfNested.torp +11 -13
- package/test/{if/components/temp/IfNested-client-f3045daba052e459add6e7f84e8d21ba7b0d81e4.ts → build-server/components/output/IfNested-client.ts} +23 -27
- package/test/build-server/components/output/IfNested-server.ts +29 -0
- package/test/build-server/components/temp/IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts +88 -0
- package/test/build-server/components/temp/IfNested-server-7a53e4969b5dfe5073f05edbcb1b986f718bb939.ts +29 -0
- package/test/buildHtml.ts +3 -2
- package/test/buildOutputFiles.ts +7 -7
- package/test/child-component/child-component.test.ts +2 -2
- package/test/child-component/components/ParentChild.torp +1 -3
- package/test/child-component/components/output/ParentChild-client.ts +13 -24
- package/test/child-component/components/output/ParentChild-server.ts +20 -22
- package/test/child-component/components/temp/{ParentChild-client-50ca7e499599209c9d674f2561413ca14a282c22.ts → ParentChild-client-2dfd600f7d409630d429a1d2d18c038bd08b08da.ts} +13 -24
- package/test/child-component/components/temp/ParentChild-server-448d57c3229189c1d297d01dfb0f33646d280e90.ts +37 -0
- package/test/class/class.test.ts +2 -2
- package/test/class/components/Class.torp +22 -24
- package/test/class/components/output/Class-client.ts +17 -37
- package/test/class/components/output/Class-server.ts +25 -25
- package/test/class/components/temp/{Class-client-de2491c550647203bea08727fa8c88f30654db0a.ts → Class-client-5af6a50cd454ae019b2aa79457ba7ead83b8c056.ts} +17 -37
- package/test/class/components/temp/Class-server-eb70ff01fbc7d6d53e16c3593ba021a6bf0317f9.ts +40 -0
- package/test/comments/html-comments.test.ts +16 -24
- package/test/comments/js-block-comments.test.ts +16 -25
- package/test/comments/js-line-comments.test.ts +16 -25
- package/test/component/component.test.ts +2 -2
- package/test/component/components/Component.torp +1 -1
- package/test/component/components/output/Component-client.ts +5 -10
- package/test/component/components/output/Component-server.ts +13 -13
- package/test/component/components/output/Header-client.ts +6 -12
- package/test/component/components/output/Header-server.ts +9 -11
- package/test/component/components/temp/{Component-client-350d20784712c710929cc3ab34c6828b0ea338d8.ts → Component-client-fdc327499be0a01f987d0f2897baf022a247c77c.ts} +5 -10
- package/test/component/components/temp/Component-server-f53221ac7b1c922ef10de2d1fe8fb534d0169fe7.ts +24 -0
- package/test/component/components/temp/{Header-client-903877003b220272b0cb5bfd62d7d748ad46c477.ts → Header-client-6beb5770e68e6b19595e53e20bc906765fc6c260.ts} +6 -12
- package/test/component/components/temp/Header-server-940b0984f9b6c11f310db9200c9075ded385eda5.ts +16 -0
- package/test/console/components/output/Console-client.ts +5 -10
- package/test/console/components/output/Console-server.ts +9 -11
- package/test/console/components/temp/{Console-client-4fa3b3679cee88bf6151185438e36d14010944b7.ts → Console-client-2b58290ac407ebbe89a0613d64eb9cd141b99887.ts} +5 -10
- package/test/console/components/temp/Console-server-bde0121ce434f767435b1841fc4c24402becdba2.ts +15 -0
- package/test/console/console.test.ts +2 -2
- package/test/const/components/Const.torp +4 -6
- package/test/const/components/output/Const-client.ts +8 -13
- package/test/const/components/output/Const-server.ts +10 -12
- package/test/const/components/temp/{Const-client-7dff2758c14bfbd208e301a702ae1781e6daba1b.ts → Const-client-d1037557e7ef75a8fe06f56816e65883047e9421.ts} +8 -13
- package/test/const/components/temp/Const-server-32ddc3617afe2324f17a4cff6c0f086df6694778.ts +18 -0
- package/test/const/const.test.ts +2 -2
- package/test/context/components/ChildA.torp +10 -0
- package/test/context/components/ChildB.torp +8 -0
- package/test/context/components/Parent.torp +11 -0
- package/test/context/components/output/ChildA-client.ts +38 -0
- package/test/context/components/output/ChildA-server.ts +19 -0
- package/test/{party/components/temp/CssStyle-client-37465dd48d1479db1bae513eb0b92c4e9a15e9ea.ts → context/components/output/ChildB-client.ts} +10 -12
- package/test/context/components/output/ChildB-server.ts +18 -0
- package/test/context/components/output/Parent-server.ts +31 -0
- package/test/context/components/temp/ChildA-client-9dea3e29ffcb82ca1779f6ff671e19b1c106fc4a.ts +38 -0
- package/test/context/components/temp/ChildA-server-54024d23c8241c3f475068f4fe3a3a14fd1c5870.ts +19 -0
- package/test/{special-head/components/temp/Head-client-18616689a7d6f83ca076c9d825606b049de9d3ef.ts → context/components/temp/ChildB-client-4b801099936c8aa013a1220f291375f67eba1acb.ts} +10 -21
- package/test/context/components/temp/ChildB-server-f9b71341863bf869248bd406dbe8c7726a30ff90.ts +18 -0
- package/test/context/components/temp/Parent-client-9898b2e521527c86d69905053b6727ea8fd28166.ts +41 -0
- package/test/context/components/temp/Parent-server-b592ff0f516f4592e56d3a0bcb1f271ed28e812c.ts +31 -0
- package/test/context/context.test.ts +37 -0
- package/test/effects/components/For.torp +3 -5
- package/test/effects/components/If.torp +5 -7
- package/test/effects/components/NestedIf.torp +6 -8
- package/test/effects/components/output/For-client.ts +23 -25
- package/test/effects/components/output/For-server.ts +10 -12
- package/test/effects/components/output/If-client.ts +19 -25
- package/test/effects/components/output/If-server.ts +11 -13
- package/test/effects/components/output/NestedIf-client.ts +26 -31
- package/test/effects/components/output/NestedIf-server.ts +13 -15
- package/test/effects/components/temp/{For-client-35bf9bea43f53d6c0cf807f9e31500765fa0b455.ts → For-client-7c7d7c0dba2547f816b9bd9c6a95d6873ec00ffd.ts} +23 -25
- package/test/effects/components/temp/For-server-9e2de4efaff38ecf6c8a169c629d83c385489ca1.ts +20 -0
- package/test/effects/components/temp/{If-client-efb994796596d9d08f59a0ab5ffdacc74bd04545.ts → If-client-f0480a98f80b32612d12765c6838ff6db5982e82.ts} +19 -25
- package/test/effects/components/temp/If-server-ab409671b5d4c918047394a37b6e96b0e17063ca.ts +22 -0
- package/test/effects/components/temp/{NestedIf-client-845b3789b8a938439bff758bc9b3731d769c8ff6.ts → NestedIf-client-702deffd158f219c5da4199b563a62cd54385a7f.ts} +26 -31
- package/test/effects/components/temp/NestedIf-server-40f6bfd99a7e75fb4f9f874adab77e5eed97c629.ts +26 -0
- package/test/effects/for-effect.test.ts +15 -15
- package/test/effects/if-effect.test.ts +7 -7
- package/test/effects/nested-if-effect.test.ts +11 -11
- package/test/events/components/Increment.torp +10 -12
- package/test/events/components/output/Increment-client.ts +10 -15
- package/test/events/components/output/Increment-server.ts +11 -12
- package/test/events/components/temp/{Increment-client-1b5f9e231c5c4fc059d77ca0da632719283e5ac4.ts → Increment-client-84c09711baf098c82ee226598ba7a36913616b75.ts} +10 -15
- package/test/events/components/temp/Increment-server-e77c6b207023ac60e033ca542ee82473ef017f74.ts +23 -0
- package/test/events/events.test.ts +9 -15
- package/test/for/components/output/For-client.ts +19 -19
- package/test/for/components/output/For-server.ts +11 -13
- package/test/for/components/output/ForEscape-client.ts +23 -37
- package/test/for/components/output/ForEscape-server.ts +12 -13
- package/test/for/components/output/ForIn-client.ts +19 -20
- package/test/for/components/output/ForIn-server.ts +11 -13
- package/test/for/components/output/ForOf-client.ts +19 -20
- package/test/for/components/output/ForOf-server.ts +11 -13
- package/test/for/components/temp/{For-client-8ecb11a2f34c81f837bffdb88598da06d8c19158.ts → For-client-2f6b4b81670b0ba31b01176b4f61ebf321e945bb.ts} +19 -19
- package/test/for/components/temp/For-server-5144615e53d23da5062b7169e847e0777d068738.ts +20 -0
- package/test/for/components/temp/{ForEscape-client-14e7648415d967cdc57bf03d176eb6b6dddf0fb2.ts → ForEscape-client-8d0fcc940851e687173b6a9129c3d83e0fc771ef.ts} +23 -37
- package/test/for/components/temp/ForEscape-server-b359d8d3e12bac290855a1b27387ddd963562c08.ts +23 -0
- package/test/for/components/temp/{ForIn-client-25cd67f246a50fc6d926a8c66aa5e106f19578a8.ts → ForIn-client-fa0614a1c7b8aa6e8819ed91a518479fd80453ae.ts} +19 -20
- package/test/for/components/temp/ForIn-server-5fd472a7a5a5c00b384791780025a0c3bdc9c41b.ts +20 -0
- package/test/for/components/temp/{ForOf-client-8f6598ccd9dc7b79aff6167b90ccea94f3029c84.ts → ForOf-client-11006c4239d9018363e582dc5b54b50477d652e7.ts} +19 -20
- package/test/for/components/temp/ForOf-server-197b29abcb60412c6c8670b2d4a2e644b650faa3.ts +20 -0
- package/test/for/for-escape.test.ts +2 -2
- package/test/for/for-in.test.ts +4 -4
- package/test/for/for-of.test.ts +4 -4
- package/test/for/for-with-key.test.ts +28 -36
- package/test/for/for.test.ts +2 -2
- package/test/function/components/Function.torp +7 -10
- package/test/function/components/output/Function-client.ts +9 -15
- package/test/function/components/output/Function-server.ts +11 -13
- package/test/function/components/temp/{Function-client-4e2168306756eb927d5ed4b673334b357eecaa74.ts → Function-client-ec5fe7d599d6099bdfab78c2a0c8edf77a23cd9b.ts} +9 -15
- package/test/function/components/temp/Function-server-fee2402b0ef4ad4c3d2779afb190ce46dbedf737.ts +25 -0
- package/test/function/function.test.ts +7 -13
- package/test/helpers.ts +44 -9
- package/test/html/components/output/Html-client.ts +6 -12
- package/test/html/components/output/Html-server.ts +9 -11
- package/test/html/components/temp/{Html-client-93b0d666142c64cd651dc37f14f12884b2f30612.ts → Html-client-82ff34dcdcbdf4be1112bcb1baac8027cdc32de7.ts} +6 -12
- package/test/html/components/temp/Html-server-14fa484fc2a617bc0f24432a2e37e7a756f87a0f.ts +15 -0
- package/test/html/html.test.ts +2 -2
- package/test/hydrateComponent.ts +4 -5
- package/test/if/components/output/IfAfterIf-client.ts +21 -23
- package/test/if/components/output/IfAfterIf-server.ts +12 -14
- package/test/if/components/output/IfElse-client.ts +14 -18
- package/test/if/components/output/IfElse-server.ts +11 -13
- package/test/if/components/output/IfElseIf-client.ts +16 -22
- package/test/if/components/output/IfElseIf-server.ts +12 -14
- package/test/if/components/output/IfFalse-client.ts +13 -16
- package/test/if/components/output/IfFalse-server.ts +10 -12
- package/test/if/components/output/IfNested-client.ts +23 -27
- package/test/if/components/output/IfNested-server.ts +14 -16
- package/test/if/components/temp/{IfAfterIf-client-6b4833209a01cdad18d453839e9c8b5dad2a8510.ts → IfAfterIf-client-c1cfd21a6ace4945703ba8f46aada923a60265d9.ts} +21 -23
- package/test/if/components/temp/IfAfterIf-server-26c9a638e3933a53208bfe66f8f37067511a28aa.ts +23 -0
- package/test/if/components/temp/{IfElse-client-f7eb8e5fe5e62975a2442c4b0ff3344fa44cef69.ts → IfElse-client-06dfcacd3a5225dcb0947587bcd4fae9ec3d3c1e.ts} +14 -18
- package/test/if/components/temp/IfElse-server-146b3779f85ea02a281c6042dddefa5372945fb0.ts +22 -0
- package/test/if/components/temp/{IfElseIf-client-734f1b2d9133294573770c1ffc2b589273498532.ts → IfElseIf-client-26df9a728c9cb712d5ac0235b4c99885f25545b8.ts} +16 -22
- package/test/if/components/temp/IfElseIf-server-f094cdb45bc0fcd3144ca493346994b2445d2ff0.ts +25 -0
- package/test/if/components/temp/{IfFalse-client-8a388cb48b4a5879d491f57d1f2551834de1e72e.ts → IfFalse-client-de6fc8e9eb222153608490e6d172e9aae9000aa1.ts} +13 -16
- package/test/if/components/temp/IfFalse-server-b6d3446fd7d4219d5cb3c1009dec76870e73fa30.ts +19 -0
- package/test/if/components/temp/IfNested-client-eefdd449fa700b2e7326bc72df8b32ddcadf9d21.ts +88 -0
- package/test/if/components/temp/IfNested-server-7a53e4969b5dfe5073f05edbcb1b986f718bb939.ts +29 -0
- package/test/if/else-if-true.test.ts +4 -4
- package/test/if/else-true.test.ts +4 -4
- package/test/if/if-after-if.test.ts +4 -4
- package/test/if/if-else-false.test.ts +4 -4
- package/test/if/if-else-true.test.ts +4 -4
- package/test/if/if-false.test.ts +4 -4
- package/test/if/if-nested.test.ts +4 -4
- package/test/imports/commented-imports.ts +1 -1
- package/test/imports/imports.ts +1 -1
- package/test/imports/multiple-imports.ts +1 -1
- package/test/mount/components/Mount.torp +1 -1
- package/test/mount/components/output/Mount-client.ts +6 -11
- package/test/mount/components/output/Mount-server.ts +11 -13
- package/test/mount/components/temp/{Mount-client-efa5c34fbfc7646e114a1a58f0814b6dff33e566.ts → Mount-client-29896228d7d0ef3692a9d13065c1bbfbe3198cdc.ts} +6 -11
- package/test/mount/components/temp/Mount-server-1c5aef88b8cc25b8e02851c0aa7fedffea987224.ts +22 -0
- package/test/mount/mount.test.ts +4 -4
- package/test/mountComponent.ts +1 -1
- package/test/on-mount/components/OnMount.torp +1 -1
- package/test/on-mount/components/output/OnMount-client.ts +5 -10
- package/test/on-mount/components/output/OnMount-server.ts +9 -11
- package/test/on-mount/components/temp/{OnMount-client-4bb62e8bf1fcd67798598fe03bf5455a57f0a6be.ts → OnMount-client-038f8c6bbcf0278406909d6ba5394f311924fda9.ts} +5 -10
- package/test/on-mount/components/temp/OnMount-server-ff4afcd976fd907c539e763d7887b38c61737be7.ts +15 -0
- package/test/on-mount/on-mount.test.ts +6 -6
- package/test/party/1-declare-state.test.ts +2 -2
- package/test/party/10-on-mount.test.ts +2 -2
- package/test/party/12-props.test.ts +2 -2
- package/test/party/13-emit-to-parent.test.ts +2 -2
- package/test/party/14-slot.test.ts +2 -2
- package/test/party/15-slot-fallback.test.ts +2 -2
- package/test/party/16-context.test.ts +2 -2
- package/test/party/17-input-text.test.ts +2 -2
- package/test/party/18-input-checkbox.test.ts +2 -2
- package/test/party/19-input-radio.test.ts +2 -2
- package/test/party/2-update-state.test.ts +2 -2
- package/test/party/20-input-select.test.ts +2 -2
- package/test/party/3-computed-state.test.ts +2 -2
- package/test/party/4-minimal-template.test.ts +2 -2
- package/test/party/5-styling.test.ts +2 -2
- package/test/party/6-loop.test.ts +2 -2
- package/test/party/7-event-click.test.ts +2 -2
- package/test/party/8-dom-ref.test.ts +4 -4
- package/test/party/9-conditional.test.ts +2 -2
- package/test/party/components/AnswerButton.torp +2 -5
- package/test/party/components/AnswerButtonApp.torp +3 -5
- package/test/party/components/ColorSelect.torp +8 -10
- package/test/party/components/Counter.torp +2 -4
- package/test/party/components/CssStyle.torp +2 -4
- package/test/party/components/FunnyButton.torp +2 -2
- package/test/party/components/FunnyButtonApp.torp +2 -4
- package/test/party/components/InputFocused.torp +1 -1
- package/test/party/components/InputHello.torp +2 -4
- package/test/party/components/IsAvailable.torp +3 -5
- package/test/party/components/PickPill.torp +5 -7
- package/test/party/components/TrafficLight.torp +12 -14
- package/test/party/components/UserProfile.torp +4 -6
- package/test/party/components/UserProfileApp.torp +1 -1
- package/test/party/components/UserProfileContext.torp +6 -8
- package/test/party/components/UserProfileContextApp.torp +3 -5
- package/test/party/components/output/AnswerButton-client.ts +7 -14
- package/test/party/components/output/AnswerButton-server.ts +8 -10
- package/test/party/components/output/AnswerButtonApp-client.ts +10 -16
- package/test/party/components/output/AnswerButtonApp-server.ts +14 -13
- package/test/party/components/output/ColorSelect-client.ts +26 -30
- package/test/party/components/output/ColorSelect-server.ts +12 -13
- package/test/party/components/output/Colors-client.ts +19 -20
- package/test/party/components/output/Colors-server.ts +12 -13
- package/test/party/components/output/Counter-client.ts +11 -16
- package/test/party/components/output/Counter-server.ts +10 -11
- package/test/party/components/output/CssStyle-client.ts +7 -12
- package/test/party/components/output/CssStyle-server.ts +12 -11
- package/test/party/components/output/DoubleCount-client.ts +6 -11
- package/test/party/components/output/DoubleCount-server.ts +10 -11
- package/test/party/components/output/FunnyButton-client.ts +4 -10
- package/test/party/components/output/FunnyButton-server.ts +11 -12
- package/test/party/components/output/FunnyButtonApp-client.ts +12 -22
- package/test/party/components/output/FunnyButtonApp-server.ts +21 -20
- package/test/party/components/output/HelloWorld-client.ts +5 -10
- package/test/party/components/output/HelloWorld-server.ts +9 -11
- package/test/party/components/output/InputFocused-client.ts +6 -11
- package/test/party/components/output/InputFocused-server.ts +11 -13
- package/test/party/components/output/InputHello-client.ts +12 -17
- package/test/party/components/output/InputHello-server.ts +10 -11
- package/test/party/components/output/IsAvailable-client.ts +12 -17
- package/test/party/components/output/IsAvailable-server.ts +10 -11
- package/test/party/components/output/Name-client.ts +6 -11
- package/test/party/components/output/Name-server.ts +10 -11
- package/test/party/components/output/NameUpdate-client.ts +6 -11
- package/test/party/components/output/NameUpdate-server.ts +10 -11
- package/test/party/components/output/PageTitle-client.ts +6 -11
- package/test/party/components/output/PageTitle-server.ts +10 -11
- package/test/party/components/output/PickPill-client.ts +12 -17
- package/test/party/components/output/PickPill-server.ts +10 -11
- package/test/party/components/output/Time-client.ts +6 -11
- package/test/party/components/output/Time-server.ts +10 -11
- package/test/party/components/output/TrafficLight-client.ts +21 -29
- package/test/party/components/output/TrafficLight-server.ts +14 -15
- package/test/party/components/output/UserProfile-client.ts +12 -24
- package/test/party/components/output/UserProfile-server.ts +8 -10
- package/test/party/components/output/UserProfileApp-client.ts +6 -11
- package/test/party/components/output/UserProfileApp-server.ts +14 -14
- package/test/party/components/output/UserProfileContext-client.ts +12 -18
- package/test/party/components/output/UserProfileContext-server.ts +10 -10
- package/test/party/components/output/UserProfileContextApp-client.ts +12 -18
- package/test/party/components/output/UserProfileContextApp-server.ts +15 -14
- package/test/party/components/temp/{AnswerButton-client-ad8f8db36b7aaa68d8de5898a324bacfbe9f20df.ts → AnswerButton-client-df895c3e7a88fd7ede9f951fc9de2ed75c27a5cb.ts} +7 -14
- package/test/party/components/temp/AnswerButton-server-fa0e78b504a78d0e2dcd33a9a589f62e5b99c675.ts +15 -0
- package/test/party/components/temp/{AnswerButtonApp-client-5661f07868550612bcdeee268b82c473af6a2613.ts → AnswerButtonApp-client-4c05ef36b1c0e93370fb463643419928717fa701.ts} +10 -16
- package/test/party/components/temp/AnswerButtonApp-server-062042691dabfa1a20d4088030c0b5bee1cd0be2.ts +39 -0
- package/test/party/components/temp/{ColorSelect-client-70bf59d6399d63c0eed421b9d370a1e5c97a89ca.ts → ColorSelect-client-5db8d1b0924361fdb5efb867c14491402ec9668c.ts} +26 -30
- package/test/party/components/temp/ColorSelect-server-8722b440cb7266a18a71b35c166be6dd6566fcec.ts +33 -0
- package/test/party/components/temp/{Colors-client-806316cc5e01e8235c0b025cad34b1068addf5a5.ts → Colors-client-6d3ac693e85bdda50b8742282915997063a32769.ts} +19 -20
- package/test/party/components/temp/Colors-server-16572e26a55214c26683ce560b058b55d8c92685.ts +22 -0
- package/test/party/components/temp/{Counter-client-3b876c148f2b14da1766eff77eb6c494f7be6414.ts → Counter-client-0c604a107c5b84cdbf725f307dfe29d34f8a2cc8.ts} +11 -16
- package/test/party/components/temp/Counter-server-db18f030a6e02ab17708d6a17eb3e590965090e5.ts +25 -0
- package/test/party/components/temp/CssStyle-client-2a642d115ad52539f97c051c34687b8d6d12b324.ts +24 -0
- package/test/party/components/temp/CssStyle-server-0477c5497707dd9071105e5ec9045a3a7d1dd62d.ts +18 -0
- package/test/party/components/temp/{DoubleCount-client-6d4cf1e54368e3c6082e37c1e04f9ecde90624f2.ts → DoubleCount-client-8c85c3af12c471ea23bb702bbf5a3e240420f3ec.ts} +6 -11
- package/test/party/components/temp/DoubleCount-server-5b04bb31269f9c8de6c25be427f57ab6e3d4dc19.ts +24 -0
- package/test/party/components/temp/{FunnyButton-client-6d5662018a5a5529fd52ee82f7c88975b5c3355a.ts → FunnyButton-client-850dd3da0fa803c1bce5c53e88fcd2d48d279eb8.ts} +4 -10
- package/test/party/components/temp/{FunnyButton-server-e0adab2be2d283acb8a8b580479ade999dc918e9.ts → FunnyButton-server-3df0067ec21476e7525d1c3de7099431c976f73b.ts} +11 -12
- package/test/party/components/temp/{FunnyButtonApp-client-daa929c6d64f67e4a1a387b884317a4bb615b5d4.ts → FunnyButtonApp-client-00300846d11a3d0a5a620c2ade87b935b7f0ebf8.ts} +12 -22
- package/test/party/components/temp/FunnyButtonApp-server-4cd83d2c71615fe4c905920e5ea836df4ed66c5e.ts +37 -0
- package/test/party/components/temp/{HelloWorld-client-7344e400b4adb975fa8263d3081a06de0a793e57.ts → HelloWorld-client-890b311ad9a3919379acdc1d52807ea36cc9f489.ts} +5 -10
- package/test/party/components/temp/HelloWorld-server-e2c800d7f5cd3e772a9e5bbd7af58b00611b79d5.ts +15 -0
- package/test/party/components/temp/{InputFocused-client-20d755aea7dfaf1fd5e42dcade8fb7867f59ef28.ts → InputFocused-client-03527f9ceb52f66ac53887dbc884a0aa83bb7a23.ts} +6 -11
- package/test/party/components/temp/InputFocused-server-544a76ea64852474a3c7bf450b6fac36cbaf21c6.ts +23 -0
- package/test/party/components/temp/{InputHello-client-2a4cbd980534fde14b9d3e8a2f8e4f59a4f15d64.ts → InputHello-client-f65a477624975b68b7aaa3614fbf198d4476480f.ts} +12 -17
- package/test/party/components/temp/InputHello-server-102d293d6c0fff7feda50d64bbd607df7d09393a.ts +22 -0
- package/test/party/components/temp/{IsAvailable-client-3949f85aea0e935c3b59ab1389baee836eff1866.ts → IsAvailable-client-8767437fd92cf79713de5b00828e1502e38d79e3.ts} +12 -17
- package/test/party/components/temp/IsAvailable-server-2cf1e0d72df4bc194b5e00a1b415ba99f488525f.ts +21 -0
- package/test/party/components/temp/{Name-client-62f0dab96aff130e81882099d7c0a111ba99cebd.ts → Name-client-08903a8df8bdff5288170d3c89658192956587a9.ts} +6 -11
- package/test/party/components/temp/Name-server-7d95226078ef4cd13b0ac6c5365ccbe4b8b9c0a2.ts +21 -0
- package/test/party/components/temp/{NameUpdate-client-6ceb440637c99142bafcf8512eabf831c113b8c7.ts → NameUpdate-client-d65b2476c3721d2efddf9385a61433e2a2dd0d72.ts} +6 -11
- package/test/party/components/temp/NameUpdate-server-9c901f861eddfde14440c2591dfafb2b1fb1993d.ts +22 -0
- package/test/party/components/temp/{PageTitle-client-75fea3a37fb1213bc13f56160bb6779486b2e6e9.ts → PageTitle-client-c006df9a3e662488a1db089de53fd485c6b923e4.ts} +6 -11
- package/test/party/components/temp/PageTitle-server-f4676ec6feccaa03b89d52835c6635536eb885ef.ts +26 -0
- package/test/party/components/temp/{PickPill-client-0f13aa652cb1bd45f57d5a249f8364e80204441a.ts → PickPill-client-af8357daf3f6633c7f451d0bddd72fefe786d5c3.ts} +12 -17
- package/test/party/components/temp/PickPill-server-d8fb383bc25f7d26bb0153088a2ee19c765fc66b.ts +22 -0
- package/test/party/components/temp/{Time-client-2013f274e90b45be3138727f2298305e1951131f.ts → Time-client-94380d45de7275a5cec98e5f58c15b74b13e9c3e.ts} +6 -11
- package/test/party/components/temp/{Time-server-8e0278a4b16925903f3c4ceedbf1332cde4921fa.ts → Time-server-3f71a83b6fd357b57e85344281454ee793024e7b.ts} +10 -11
- package/test/party/components/temp/{TrafficLight-client-4a90675ca6157ed7701aefa0d9141575960a1d47.ts → TrafficLight-client-12b20962b4146ef08fe0c37597441533c7699408.ts} +21 -29
- package/test/party/components/temp/TrafficLight-server-625a774075633be88822f4d345e1421a77aba98a.ts +39 -0
- package/test/party/components/temp/{UserProfile-client-11c2a928de5a5ed4cab45186f08ca09f6161afb5.ts → UserProfile-client-e5330b2c96bd8b225cb6291bc8b1d9f35c93307e.ts} +12 -24
- package/test/party/components/temp/UserProfile-server-6e89fd7f8ade8e8d64630e5da8361d7a1fa2ff5a.ts +21 -0
- package/test/party/components/temp/{UserProfileApp-client-e0bfaa4ffed336c8be4b23dd81800501980c9938.ts → UserProfileApp-client-4c86e4f9a0d042f4f4811868f0146e872b17353c.ts} +6 -11
- package/test/party/components/temp/UserProfileApp-server-754d269451abf8fd04e519b8edde33d25c73ce28.ts +27 -0
- package/test/party/components/temp/{UserProfileContext-client-c97c077254210061b3c9ba561f681c0cf4f6167f.ts → UserProfileContext-client-424131db3cc89ae4babe127b9108ffc5696c9e1d.ts} +12 -18
- package/test/party/components/temp/UserProfileContext-server-e72e8ccee2703cce216f2368a1555d64acc2654c.ts +20 -0
- package/test/party/components/temp/{UserProfileContextApp-client-05ce216919de6ffde56d1c2c39299173d9b611b3.ts → UserProfileContextApp-client-5f94a7ccf3e4542ea40d8046ad75eeb21005c55f.ts} +12 -18
- package/test/party/components/temp/UserProfileContextApp-server-267ac147e0e59e53aeb6741a8cd0f3ef1216051f.ts +34 -0
- package/test/preact.test.ts +2560 -0
- package/test/props/components/Reactive.torp +2 -4
- package/test/props/components/output/Reactive-client.ts +12 -22
- package/test/props/components/output/Reactive-server.ts +20 -20
- package/test/props/components/temp/{Reactive-client-cf6e602b2f74fce8e9451b6c41c6f8ff8eab63a3.ts → Reactive-client-9bc3643675fc563f96efb00bc3c4b843ba4b7f2e.ts} +12 -22
- package/test/props/components/temp/Reactive-server-8a84d0fc1f375d91438d840ca9753e32d86366ac.ts +40 -0
- package/test/props/reactive.test.ts +2 -2
- package/test/replace/components/Replace.torp +3 -5
- package/test/replace/components/output/Replace-client.ts +10 -19
- package/test/replace/components/output/Replace-server.ts +11 -12
- package/test/replace/components/temp/{Replace-client-2a9ee3430708b469fa31bbc6989eed5b2f22984d.ts → Replace-client-6f21ff3eb303bd5488d211087dc35fcf998d4e2a.ts} +10 -19
- package/test/replace/components/temp/Replace-server-b536cf6d792ae73aaa7f5ea04cda6858a07479f9.ts +21 -0
- package/test/replace/replace.test.ts +2 -2
- package/test/script/script-with-comments.test.ts +14 -19
- package/test/script/script-with-strings.test.ts +14 -19
- package/test/script/script.test.ts +14 -19
- package/test/slots/basic-slot.test.ts +2 -2
- package/test/slots/components/Article.torp +3 -3
- package/test/slots/components/Basic.torp +1 -1
- package/test/slots/components/Header.torp +2 -2
- package/test/slots/components/Let.torp +3 -3
- package/test/slots/components/List.torp +1 -1
- package/test/slots/components/Named.torp +3 -3
- package/test/slots/components/Unused.torp +1 -1
- package/test/slots/components/output/Article-client.ts +4 -8
- package/test/slots/components/output/Article-server.ts +14 -15
- package/test/slots/components/output/Basic-client.ts +7 -14
- package/test/slots/components/output/Basic-server.ts +17 -18
- package/test/slots/components/output/Header-client.ts +4 -9
- package/test/slots/components/output/Header-server.ts +11 -12
- package/test/slots/components/output/Let-client.ts +7 -14
- package/test/slots/components/output/Let-server.ts +16 -17
- package/test/slots/components/output/List-client.ts +17 -16
- package/test/slots/components/output/List-server.ts +12 -13
- package/test/slots/components/output/Named-client.ts +9 -19
- package/test/slots/components/output/Named-server.ts +21 -23
- package/test/slots/components/output/Unused-client.ts +5 -10
- package/test/slots/components/output/Unused-server.ts +13 -13
- package/test/slots/components/temp/{Article-client-3f2da4b399f94ae8c329489e1ba0ba98196df9c5.ts → Article-client-0b674ee98ae7f85021bfb8b912f28e3c4b35e877.ts} +4 -8
- package/test/slots/components/temp/Article-server-3db1718b70b86b456514b54ae17a597d07cc0ca9.ts +27 -0
- package/test/slots/components/temp/{Basic-client-a2c4bf685d4b75d0395da427b7754c2a58374dd7.ts → Basic-client-196f7f0244dca0baeffb547eec55c089a108283d.ts} +7 -14
- package/test/slots/components/temp/Basic-server-a22e6ec236b84e09d4d59c7abc4f0b22bf60f22c.ts +32 -0
- package/test/slots/components/temp/{Header-client-d7418b71df5db36d58a73e909233863a6c03678b.ts → Header-client-e5c784d60469523803898ee4d8b85fb82a7b7c0b.ts} +4 -9
- package/test/slots/components/temp/Header-server-3182d735443d9cf6a0cc7891919cc2c08df2aa8f.ts +21 -0
- package/test/slots/components/temp/{Let-client-913f9dede92b68a3f4a13d1f56f99b3e08e01efe.ts → Let-client-645271fcd63cd500001c75740b22b1b387330657.ts} +7 -14
- package/test/slots/components/temp/Let-server-b6d6e2012155c7533a0eb4ee0aaf00157a7d4493.ts +35 -0
- package/test/slots/components/temp/{List-client-6bc2d267a8b2028a14b12b2c70feb7c6a47d6d64.ts → List-client-ee6047ac396dc0b6fce5e38af51c38093fae83a2.ts} +17 -16
- package/test/slots/components/temp/List-server-1ee246e864cdb31bb8f52cf4424b6ef0e9b41cf1.ts +25 -0
- package/test/slots/components/temp/{Named-client-f6e7a984759ce8f50bc52dcf56f6f06cab925a80.ts → Named-client-559988562c5de1ae6017d2ad6de063f4363064b6.ts} +9 -19
- package/test/slots/components/temp/Named-server-f2ce3d301e916ea38901a92185c25512b11d42d4.ts +41 -0
- package/test/slots/components/temp/{Unused-client-ea0a096aa7a1c958f3bf807f35340b96f8a025ee.ts → Unused-client-52d1828bd28ebf7046a2e948a369563c0ea83b98.ts} +5 -10
- package/test/slots/components/temp/Unused-server-f5248f5cd4616c65eaf27c67385f13ed671accad.ts +22 -0
- package/test/slots/let-slot.test.ts +4 -4
- package/test/slots/named-slot.test.ts +2 -2
- package/test/slots/unused-slot.test.ts +2 -2
- package/test/source-maps/components/Source.torp +19 -0
- package/test/source-maps/components/output/Source-client.ts +63 -0
- package/test/source-maps/components/output/Source-server.ts +26 -0
- package/test/source-maps/components/temp/Source-client-ae8c4811ff658c13ee8c9b9e0e53fff1b83b178b.ts +63 -0
- package/test/source-maps/components/temp/Source-server-70b20214c52b8820f450324943e8a1ffb0a72d5e.ts +26 -0
- package/test/source-maps/parse.test.ts +62 -0
- package/test/special-component/components/BigTitle.torp +1 -1
- package/test/special-component/components/Component.torp +2 -2
- package/test/special-component/components/SmallTitle.torp +1 -1
- package/test/special-component/components/output/BigTitle-client.ts +4 -8
- package/test/special-component/components/output/BigTitle-server.ts +10 -11
- package/test/special-component/components/output/Component-client.ts +7 -15
- package/test/special-component/components/output/Component-server.ts +19 -19
- package/test/special-component/components/output/SmallTitle-client.ts +4 -8
- package/test/special-component/components/output/SmallTitle-server.ts +10 -11
- package/test/special-component/components/temp/{BigTitle-client-c4bd66406d55ce83ab4491c4114d563055e1c275.ts → BigTitle-client-cb3055f809aaf17bd1fa82748d039ac3730a8d44.ts} +4 -8
- package/test/special-component/components/temp/BigTitle-server-fef9d1e1deacfde2be4469c2e63a801b2e518dff.ts +19 -0
- package/test/special-component/components/temp/{Component-client-c39c66cf5274445bb863fd759e0ef223613a9f3a.ts → Component-client-0eb9553b52acce2dfa564242295a4c57a38bd540.ts} +7 -15
- package/test/special-component/components/temp/Component-server-9d0fddeff790bfb2b6cfbcd2edf677837f5b8120.ts +43 -0
- package/test/special-component/components/temp/{SmallTitle-client-e4b3e51243ca4f1efca21ac0f957b81e8bc93167.ts → SmallTitle-client-5a65b233be29395e9650f57d9708a33de1279af3.ts} +4 -8
- package/test/special-component/components/temp/SmallTitle-server-11f8b6b3c613716d6a5371883a9b55434bb43ad5.ts +19 -0
- package/test/special-component/special-component.test.ts +2 -2
- package/test/special-element/components/Element.torp +2 -2
- package/test/special-element/components/output/Element-client.ts +5 -11
- package/test/special-element/components/output/Element-server.ts +9 -11
- package/test/special-element/components/temp/{Element-client-c5701ed44faa4ec8ae558505063684a84cada3f2.ts → Element-client-745e610fbd5c652d327c8ac349d49d5ee4c8d9ea.ts} +5 -11
- package/test/special-element/components/temp/Element-server-7aef6d0ed7369aa2418183519c8320e0409a5641.ts +15 -0
- package/test/special-element/special-element.test.ts +2 -2
- package/test/special-head/components/Head.torp +2 -6
- package/test/special-head/components/output/Head-client.ts +8 -27
- package/test/special-head/components/output/Head-server.ts +8 -13
- package/test/special-head/components/temp/Head-client-bbbb5e712247ee41ca65a7ffd457987de5e99b3e.ts +19 -0
- package/test/special-head/components/temp/Head-server-c3de2e6b56aabc095380370d8bf93ae3bc7c10d9.ts +12 -0
- package/test/special-head/special-head.test.ts +2 -2
- package/test/special-self/components/Self.torp +4 -6
- package/test/special-self/components/output/Self-client.ts +18 -23
- package/test/special-self/components/output/Self-server.ts +14 -14
- package/test/special-self/components/temp/{Self-client-43a0a90fac58867c88bf32221883e8da342a0295.ts → Self-client-dfe57df69e3677e94f7b5f3657c82602054ef19e.ts} +18 -23
- package/test/special-self/components/temp/Self-server-5d135dab2b6fd4ba7fe3f56768f0725607d36bd9.ts +27 -0
- package/test/special-self/special-self.test.ts +2 -2
- package/test/style/components/Style.torp +1 -1
- package/test/style/components/output/Style-client.ts +7 -13
- package/test/style/components/output/Style-server.ts +10 -12
- package/test/style/components/temp/{Style-client-bc13f8dbb5f754e4eebb2473fc63a139ebf1ba92.ts → Style-client-9491a5aff97f118df542f976d7f7a21e7cc88c62.ts} +7 -13
- package/test/style/components/temp/Style-server-8b8cbe1868cab30d9e34dda52921652768ada1db.ts +16 -0
- package/test/style/parse.test.ts +507 -193
- package/test/style/style.test.ts +2 -2
- package/test/svg/components/Shape.torp +1 -1
- package/test/svg/components/output/Shape-client.ts +23 -23
- package/test/svg/components/output/Shape-server.ts +12 -13
- package/test/svg/components/temp/{Shape-client-052ea7838de07222602834de58968a3f89e6ea56.ts → Shape-client-4cc148d8b70d3750d2982360aad76b74d194b60e.ts} +23 -23
- package/test/svg/components/temp/Shape-server-76aaef570e067031ff39635ffe37626364c2200a.ts +23 -0
- package/test/svg/svg.test.ts +4 -4
- package/test/switch/components/Switch.torp +16 -18
- package/test/switch/components/output/Switch-client.ts +22 -30
- package/test/switch/components/output/Switch-server.ts +12 -14
- package/test/switch/components/temp/{Switch-client-30113fadf131c72e7c24160fa62068b651716896.ts → Switch-client-5fc00f4d41300dc7587b113d8e53a102beca7558.ts} +22 -30
- package/test/switch/components/temp/Switch-server-440f7e852145b79656c0023ddc776e4d1d077d2a.ts +36 -0
- package/test/switch/switch-values.test.ts +4 -4
- package/test/template/basic-file.test.ts +61 -88
- package/test/template/empty-file.test.ts +7 -12
- package/test/template/errors.test.ts +64 -34
- package/test/text/components/Text.torp +5 -7
- package/test/text/components/output/Text-client.ts +9 -17
- package/test/text/components/output/Text-server.ts +8 -10
- package/test/text/components/temp/{Text-client-e335aae6d8aef389dfdbb5bee14e3dd3d41e86bd.ts → Text-client-6c3be8a1a31a13eff86ce8b5330829cd15b07fab.ts} +9 -17
- package/test/text/components/temp/Text-server-ac34d47e755aa39b2d89cb44f854450c3db1ddff.ts +22 -0
- package/test/text/text.test.ts +4 -4
- package/test/watch-array/ArrayState.ts +2 -2
- package/test/watch-array/array-all-functions-unkeyed.test.ts +16 -14
- package/test/watch-array/array-all-functions.test.ts +16 -14
- package/test/watch-array/array-empty.test.ts +8 -6
- package/test/watch-array/array-entries.test.ts +11 -9
- package/test/watch-array/array-indexes.test.ts +11 -9
- package/test/watch-array/array-pop.test.ts +10 -8
- package/test/watch-array/array-push.test.ts +10 -8
- package/test/watch-array/array-reassign.test.ts +11 -9
- package/test/watch-array/array-reverse.test.ts +10 -8
- package/test/watch-array/array-set-object.test.ts +10 -8
- package/test/watch-array/array-set-property.test.ts +10 -8
- package/test/watch-array/array-shift.test.ts +10 -8
- package/test/watch-array/array-sort.test.ts +11 -9
- package/test/watch-array/array-splice-add.test.ts +10 -8
- package/test/watch-array/array-splice-delete-all.test.ts +10 -8
- package/test/watch-array/array-splice-delete-and-add.test.ts +10 -8
- package/test/watch-array/array-splice-delete-end.test.ts +10 -8
- package/test/watch-array/array-splice-delete.test.ts +10 -8
- package/test/watch-array/array-swap.test.ts +10 -8
- package/test/watch-array/array-unshift.test.ts +10 -8
- package/test/watch-array/array-update-assignment.test.ts +10 -8
- package/test/watch-array/components/output/Array-client.ts +19 -21
- package/test/watch-array/components/output/Array-server.ts +11 -13
- package/test/watch-array/components/output/ArrayEntries-client.ts +21 -23
- package/test/watch-array/components/output/ArrayEntries-server.ts +11 -13
- package/test/watch-array/components/output/ArrayIndexes-client.ts +19 -21
- package/test/watch-array/components/output/ArrayIndexes-server.ts +11 -13
- package/test/watch-array/components/output/ArrayUnkeyed-client.ts +19 -20
- package/test/watch-array/components/output/ArrayUnkeyed-server.ts +11 -13
- package/test/watch-array/components/temp/{Array-client-d048f5c224a3f2e2729878dbb069ce15ca913e12.ts → Array-client-552f81452d33fe6dc715c9f6bb7986f06475d761.ts} +19 -21
- package/test/watch-array/components/temp/Array-server-16921ef3289ecba5881fcd59e3353fbfad60d4d3.ts +20 -0
- package/test/watch-array/components/temp/{ArrayEntries-client-741607b276718f5deb520e3b657dbf6abbb8081c.ts → ArrayEntries-client-736755fba2492e74812ff9c905202810de54e15a.ts} +21 -23
- package/test/watch-array/components/temp/ArrayEntries-server-ac150fc9fd18c1d9dab9b329f7703e190f5c2725.ts +20 -0
- package/test/watch-array/components/temp/{ArrayIndexes-client-8ab14b254ef67dafad5228c9ec1906eb3b3babef.ts → ArrayIndexes-client-a496328fa92ffca676ab8893013a0cfec1734ad1.ts} +19 -21
- package/test/watch-array/components/temp/ArrayIndexes-server-e8fc511c0d27796dc1733f8cc63377f7a4511f76.ts +20 -0
- package/test/watch-array/components/temp/{ArrayUnkeyed-client-9684aba82757748815b94c04bf3f8d1f98332535.ts → ArrayUnkeyed-client-5a2c5cb1fecba52653f7f35cfd07627682930c15.ts} +19 -20
- package/test/watch-array/components/temp/ArrayUnkeyed-server-916a5cdb7c36d95946cafdc69dca782291af24e4.ts +20 -0
- package/test/watch-object/components/Watched.torp +5 -7
- package/test/watch-object/components/output/Watched-client.ts +7 -13
- package/test/watch-object/components/output/Watched-server.ts +8 -10
- package/test/watch-object/components/temp/{Watched-client-d26e846bbeb8271ec5dc2a1ceb75b362af44d3bd.ts → Watched-client-1f0409aa6e2c425d0319a23caec7d10ad313d579.ts} +7 -13
- package/test/watch-object/components/temp/Watched-server-156afd257b562162d86417f2bbf5afe1bf57de06.ts +16 -0
- package/test/watch-object/watch-object.test.ts +11 -9
- package/{tsup.config.ts → tsdown.config.ts} +2 -4
- package/dist/Component-CysAnHpO.d.cts +0 -8
- package/dist/Component-CysAnHpO.d.ts +0 -8
- package/dist/ServerSlotRender-t1sOutne.d.cts +0 -15
- package/dist/ServerSlotRender-t1sOutne.d.ts +0 -15
- package/dist/chunk-EGRHWZRV.js +0 -1
- package/dist/chunk-EGRHWZRV.js.map +0 -1
- package/dist/chunk-T6JGCJ5T.js +0 -45
- package/dist/chunk-T6JGCJ5T.js.map +0 -1
- package/dist/compile.cjs +0 -4074
- package/dist/compile.cjs.map +0 -1
- package/dist/compile.d.cts +0 -156
- package/dist/index.cjs +0 -895
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -208
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
- package/dist/ssr.cjs +0 -106
- package/dist/ssr.cjs.map +0 -1
- package/dist/ssr.d.cts +0 -14
- package/src/compile/build/client/buildHeadNode.ts +0 -17
- package/src/compile/build/utils/isReactiveAttribute.ts +0 -16
- package/src/compile/types/nodes/isControlNode.ts +0 -6
- package/src/compile/types/nodes/isElementNode.ts +0 -6
- package/src/compile/types/nodes/isParentNode.ts +0 -6
- package/src/compile/types/nodes/isSpecialNode.ts +0 -6
- package/src/compile/types/nodes/isTextNode.ts +0 -6
- package/src/debug/printHtml.ts +0 -25
- package/src/render/getClasses.ts +0 -24
- package/src/render/getStyles.ts +0 -7
- package/src/render/isComment.ts +0 -3
- package/src/render/isText.ts +0 -3
- package/src/types/ProxyPropData.ts +0 -11
- package/src/watch/removeEffect.ts +0 -34
- package/test/attributes/components/temp/Attributes-server-80f9f58fd6cb30df11867386d4f0b15b44401ebe.ts +0 -18
- package/test/bench/components/temp/Bench-client-fca94b485c6263778751927240ab3ca4048d7a10.ts +0 -208
- package/test/bind/components/temp/BindComponent-client-6f650efb818a185ef33e1b071cfd77415a803dd3.ts +0 -93
- package/test/bind/components/temp/BindComponent-server-2e6caf0cbbb2831eb4bfbd7dcd6cf4d5c422d047.ts +0 -52
- package/test/bind/components/temp/BindText-server-807a1ddcb68410b30429cb088d2e204ed6f585b2.ts +0 -21
- package/test/child-component/components/temp/ParentChild-server-5e4a7fa5f4cd1c7dbe6866819025d2c03bfc62cb.ts +0 -39
- package/test/class/components/temp/Class-server-c24c01d0d3a98169172aba453c183c4152705be9.ts +0 -40
- package/test/component/components/temp/Component-server-57f59c74599572da6322a67cb97848cfbfcf6968.ts +0 -24
- package/test/component/components/temp/Header-server-6969d20782edd8f99d4b5c5b7b5563ce26e6dc2d.ts +0 -18
- package/test/console/components/temp/Console-server-cfb2208b130d5f15403df19ae8341aaa1c9ad33a.ts +0 -17
- package/test/const/components/temp/Const-server-1cf6ed84f72d3b15b318b80937b8de1f2c0f188c.ts +0 -20
- package/test/effects/components/temp/For-server-efe60939d185315f4c9b567b6867c6d5af14d9aa.ts +0 -22
- package/test/effects/components/temp/If-server-2424b7b812d350d7eb8ff9afb1146807217320cd.ts +0 -24
- package/test/effects/components/temp/NestedIf-server-ab260586490cb5afed31377d2226bb5a1fc30e2d.ts +0 -28
- package/test/events/components/temp/Increment-server-b084f43082e2ec31dbe5f9edc1cb6e37e4c8df9d.ts +0 -24
- package/test/for/components/temp/For-server-3b6ead39728c79206203c519a215390d07d80f7e.ts +0 -22
- package/test/for/components/temp/ForEscape-server-ed906c8cd593a0b467073ada415734de31dc38d9.ts +0 -24
- package/test/for/components/temp/ForIn-server-c8f13304a2ba235e091685256909fbfa50bdd5fd.ts +0 -22
- package/test/for/components/temp/ForOf-server-8c2c33ca6595bf0a5e952ca9971e595e18446623.ts +0 -22
- package/test/function/components/temp/Function-server-2b19d0cd881c31dc67132107c6e322a18701c318.ts +0 -27
- package/test/html/components/temp/Html-server-d159b0ef04b1f65ae4f9e05a7b44b21e7aa14cf9.ts +0 -17
- package/test/if/components/temp/IfAfterIf-server-a5005147e7902d1a5a048c9fe07feb9804eb6560.ts +0 -25
- package/test/if/components/temp/IfElse-server-80d93e5fc4ceba7a645f7081fa11b177dbe730d0.ts +0 -24
- package/test/if/components/temp/IfElseIf-server-ddc7348705d51b02538301e0aa704130748992cf.ts +0 -27
- package/test/if/components/temp/IfFalse-server-e8385013cfdde584b43cc0d71311cbb417859116.ts +0 -21
- package/test/if/components/temp/IfNested-server-285a5d8e0e0fcc8ccf421df152fdc00811782835.ts +0 -31
- package/test/mount/components/temp/Mount-server-62f94f276c2d6c9048765a77b575cb21146917f1.ts +0 -24
- package/test/on-mount/components/temp/OnMount-server-c531f718eb68754ea6c3001d5db9c07c511e434c.ts +0 -17
- package/test/party/components/temp/AnswerButton-server-928b5d447afa865fa09e0142c79bb1f2c1b86875.ts +0 -17
- package/test/party/components/temp/AnswerButtonApp-server-e4ea88e0f4d65508950594437e5e34424bd28897.ts +0 -38
- package/test/party/components/temp/ColorSelect-server-90f83722bd85155ebb2b8ccdaf053cd28d3152be.ts +0 -34
- package/test/party/components/temp/Colors-server-e13d49ba57f7b0dc6fb10a333ec872f5207e1ff0.ts +0 -23
- package/test/party/components/temp/Counter-server-7adf9376b38d97f1fd4b9c14108e6814e81f14ea.ts +0 -26
- package/test/party/components/temp/CssStyle-server-90a950501a20bfa5feac84ca6d97898c25bce2ed.ts +0 -17
- package/test/party/components/temp/DoubleCount-server-62c94483ebe9661e5ecc4f489787e32448ddcafa.ts +0 -25
- package/test/party/components/temp/FunnyButtonApp-server-80d85ede7da558154a5aa17cd602d6724bf1c9cb.ts +0 -36
- package/test/party/components/temp/HelloWorld-server-e0ed80e7531f303952a4af30d646263ff2e4ead6.ts +0 -17
- package/test/party/components/temp/InputFocused-server-ee70758a515227c04788be0e298a79c277994ccd.ts +0 -25
- package/test/party/components/temp/InputHello-server-1b9dd5442ded022abe92a9075ca5a4bb90486cbe.ts +0 -23
- package/test/party/components/temp/IsAvailable-server-123daa1ae56b77defe6666faddb44ba4252dd0fb.ts +0 -22
- package/test/party/components/temp/Name-server-a402418f1ca2d8a0e6403596ec03ec47b5ff40ec.ts +0 -22
- package/test/party/components/temp/NameUpdate-server-b7dcc875e894a5606544fcd78bda575ea07632ca.ts +0 -23
- package/test/party/components/temp/PageTitle-server-12dcb4e437aaef227c704a2ee8bbdee55ca323dc.ts +0 -27
- package/test/party/components/temp/PickPill-server-f10dae4708e36775a5e1a5ad10c6c0c309335009.ts +0 -23
- package/test/party/components/temp/TrafficLight-server-04bb3b2f11322ccc97a9a8a8fbb26c3c99843042.ts +0 -40
- package/test/party/components/temp/UserProfile-server-a0576b8d9dd15b3fab6c11758984c686ddfe2f66.ts +0 -23
- package/test/party/components/temp/UserProfileApp-server-86c204098fd0ffbeded50372354488768b255156.ts +0 -27
- package/test/party/components/temp/UserProfileContext-server-2d32476b00448bdec6c1c45aac5087a5152c2471.ts +0 -20
- package/test/party/components/temp/UserProfileContextApp-server-c970abaa8326db9a5efc3a5c64741743ae0dd1ca.ts +0 -33
- package/test/props/components/temp/Reactive-server-206bcc8984bad12c5712661b77d000216cdfe66d.ts +0 -40
- package/test/replace/components/temp/Replace-server-9519943d193b681e1d7894a0d7952affdfb0660c.ts +0 -22
- package/test/slots/components/temp/Article-server-b84141b05064f5ea1e4b535faafe459df0d875fb.ts +0 -28
- package/test/slots/components/temp/Basic-server-6b37594c9bf74e0c86a05b20213f69651e2cc937.ts +0 -33
- package/test/slots/components/temp/Header-server-d8e8ccb129d84478f0c4f8dc8ad1d2091188cc7b.ts +0 -22
- package/test/slots/components/temp/Let-server-8cad3b1199bec801bc3a1f2f3dbc20f2ef1e9741.ts +0 -36
- package/test/slots/components/temp/List-server-f4f63df4d19e15311da347284935a1bb530a8df4.ts +0 -26
- package/test/slots/components/temp/Named-server-2aac48bb8c7300d1a8858917fe81edc17c6372fa.ts +0 -43
- package/test/slots/components/temp/Unused-server-6e832928d7db6c43c556e7bda8af34ac37c0d4c1.ts +0 -22
- package/test/special-component/components/temp/BigTitle-server-d8919a4c975e022c936584bd668917cb89aa8e20.ts +0 -20
- package/test/special-component/components/temp/Component-server-14cd9beb57d6e833f75ab8c6624eb9841444ef63.ts +0 -43
- package/test/special-component/components/temp/SmallTitle-server-0a9b5098e4dda96f8c1da30294d71b39997dd118.ts +0 -20
- package/test/special-element/components/temp/Element-server-166d672256ef4635168de0090e490e48b569c7d6.ts +0 -17
- package/test/special-head/components/temp/Head-server-c0956653b544ff632e36da15d5f7623fa285953a.ts +0 -17
- package/test/special-self/components/temp/Self-server-b857c30c279a16dd81ad29567fb8abb9b2a0c239.ts +0 -27
- package/test/style/components/temp/Style-server-85720cb43e20ab000f98bc632c29454a51ae92d9.ts +0 -18
- package/test/svg/components/temp/Shape-server-9951ff1dcc7aa0827f28d3f8d970813767115ae3.ts +0 -24
- package/test/switch/components/temp/Switch-server-c1b5e1c657438ee3d8afdbf2166c5295cafc5604.ts +0 -38
- package/test/text/components/temp/Text-server-e37d33aa182f36461927d8ce36040bfd05e2f227.ts +0 -24
- package/test/watch-array/components/temp/Array-server-c907209008ac6177f614b62931a2bb1f1c3a04e1.ts +0 -22
- package/test/watch-array/components/temp/ArrayEntries-server-57c1ab0045fa4a02de95f69a65de6f54efe9850c.ts +0 -22
- package/test/watch-array/components/temp/ArrayIndexes-server-f093878b94a37617e2e697a786caa680f75630a7.ts +0 -22
- package/test/watch-array/components/temp/ArrayUnkeyed-server-c893fa024be07e5e7fce608c3ae456bdf2279dbe.ts +0 -22
- package/test/watch-object/components/temp/Watched-server-312fca1e769d7594fc5bb6295ccf55b544dd2f4d.ts +0 -18
- /package/src/compile/{build/utils → utils}/isFullyReactive.ts +0 -0
- /package/src/compile/{build/utils → utils}/isReactive.ts +0 -0
package/dist/compile.cjs
DELETED
|
@@ -1,4074 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/compile.ts
|
|
21
|
-
var compile_exports = {};
|
|
22
|
-
__export(compile_exports, {
|
|
23
|
-
build: () => build,
|
|
24
|
-
buildType: () => buildType,
|
|
25
|
-
parse: () => parse
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(compile_exports);
|
|
28
|
-
|
|
29
|
-
// src/compile/utils/Builder.ts
|
|
30
|
-
var Builder = class {
|
|
31
|
-
#text = "";
|
|
32
|
-
#space = 0;
|
|
33
|
-
prepend(text) {
|
|
34
|
-
this.#text = text + "\n" + this.#text;
|
|
35
|
-
}
|
|
36
|
-
append(text) {
|
|
37
|
-
text = text.trim();
|
|
38
|
-
let i = 0;
|
|
39
|
-
while (i < text.length) {
|
|
40
|
-
while (text[i] === " " || text[i] === " ") {
|
|
41
|
-
i++;
|
|
42
|
-
}
|
|
43
|
-
if (text[i] === ";") {
|
|
44
|
-
i++;
|
|
45
|
-
} else if (text[i] === "\n") {
|
|
46
|
-
this.#text += "\n";
|
|
47
|
-
} else {
|
|
48
|
-
if (text[i] === "}" || text[i] === ")" || text[i] === "]") {
|
|
49
|
-
this.#space -= 1;
|
|
50
|
-
}
|
|
51
|
-
this.#text += " ".repeat(Math.max(0, this.#space));
|
|
52
|
-
const start = i;
|
|
53
|
-
while (i < text.length && text[i] !== "\n") {
|
|
54
|
-
if (text[i] === "`") {
|
|
55
|
-
i++;
|
|
56
|
-
let level = 0;
|
|
57
|
-
while (i < text.length && !(text[i] === "`" && text[i - 1] !== "\\" && level === 0)) {
|
|
58
|
-
if (text[i] === "{" && (level > 0 || text[i - 1] === "$")) {
|
|
59
|
-
level += 1;
|
|
60
|
-
} else if (text[i] === "}" && level > 0) {
|
|
61
|
-
level -= 1;
|
|
62
|
-
}
|
|
63
|
-
i++;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
i++;
|
|
67
|
-
}
|
|
68
|
-
const line = text.substring(start, i + 1);
|
|
69
|
-
if (line.startsWith("*")) {
|
|
70
|
-
this.#text += " ";
|
|
71
|
-
}
|
|
72
|
-
this.#text += line;
|
|
73
|
-
if (text[i - 1] === "{" || text[i - 1] === "(" || text[i - 1] === "[") {
|
|
74
|
-
this.#space += 1;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
i++;
|
|
78
|
-
}
|
|
79
|
-
if (!this.#text.endsWith("\n\n")) {
|
|
80
|
-
this.#text += "\n";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
toString() {
|
|
84
|
-
return this.#text;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// src/compile/types/comments.ts
|
|
89
|
-
var ANCHOR_COMMENT = "<!>";
|
|
90
|
-
var HYDRATION_START_COMMENT = "<![>";
|
|
91
|
-
var HYDRATION_END_COMMENT = "<!]>";
|
|
92
|
-
var HYDRATION_BREAK_COMMENT = "<!^>";
|
|
93
|
-
|
|
94
|
-
// src/compile/utils/trimQuotes.ts
|
|
95
|
-
function trimQuotes(text) {
|
|
96
|
-
let start = 0;
|
|
97
|
-
let end = text.length;
|
|
98
|
-
while (text[start] === "'" && text[end - 1] === "'" || text[start] === '"' && text[end - 1] === '"' || text[start] === "`" && text[end - 1] === "`") {
|
|
99
|
-
start += 1;
|
|
100
|
-
end -= 1;
|
|
101
|
-
}
|
|
102
|
-
return text.substring(start, end);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/compile/build/utils/isReactive.ts
|
|
106
|
-
function isReactive(text) {
|
|
107
|
-
return text.includes("{") && text.includes("}");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// src/compile/build/client/buildFragmentText.ts
|
|
111
|
-
function buildFragmentText(node, status, b) {
|
|
112
|
-
const fragments = [];
|
|
113
|
-
buildNodeFragmentText(node, status, fragments);
|
|
114
|
-
if (fragments.length) {
|
|
115
|
-
b.append(`const t_fragments: DocumentFragment[] = [];`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function buildNodeFragmentText(node, status, fragments, currentFragment) {
|
|
119
|
-
switch (node.type) {
|
|
120
|
-
case "root": {
|
|
121
|
-
buildRootFragmentText(node, status, fragments);
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case "control": {
|
|
125
|
-
buildControlFragmentText(node, status, fragments, currentFragment);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
case "component": {
|
|
129
|
-
buildComponentFragmentText(node, status, fragments, currentFragment);
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case "element": {
|
|
133
|
-
let ns = node.tagName === "svg";
|
|
134
|
-
if (ns) status.ns = true;
|
|
135
|
-
buildElementFragmentText(node, status, fragments, currentFragment);
|
|
136
|
-
if (ns) status.ns = false;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case "text": {
|
|
140
|
-
const content = node.content;
|
|
141
|
-
if (currentFragment) {
|
|
142
|
-
currentFragment.text += isReactive(content) ? "#" : content;
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
case "special": {
|
|
147
|
-
buildSpecialFragmentText(node, status, fragments, currentFragment);
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function buildRootFragmentText(node, status, fragments) {
|
|
153
|
-
node.fragment = { number: fragments.length, text: "", ns: status.ns, events: [], animations: [] };
|
|
154
|
-
fragments.push(node.fragment);
|
|
155
|
-
for (let child of node.children) {
|
|
156
|
-
buildNodeFragmentText(child, status, fragments, node.fragment);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function buildControlFragmentText(node, status, fragments, currentFragment) {
|
|
160
|
-
switch (node.operation) {
|
|
161
|
-
case "@if group":
|
|
162
|
-
case "@switch group":
|
|
163
|
-
case "@for group":
|
|
164
|
-
case "@await group":
|
|
165
|
-
case "@replace group":
|
|
166
|
-
case "@html group": {
|
|
167
|
-
currentFragment.text += ANCHOR_COMMENT;
|
|
168
|
-
for (let child of node.children) {
|
|
169
|
-
buildNodeFragmentText(child, status, fragments, currentFragment);
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
default: {
|
|
174
|
-
node.fragment = {
|
|
175
|
-
number: fragments.length,
|
|
176
|
-
text: "",
|
|
177
|
-
ns: status.ns,
|
|
178
|
-
events: [],
|
|
179
|
-
animations: []
|
|
180
|
-
};
|
|
181
|
-
fragments.push(node.fragment);
|
|
182
|
-
for (let child of node.children) {
|
|
183
|
-
buildNodeFragmentText(child, status, fragments, node.fragment);
|
|
184
|
-
}
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function buildComponentFragmentText(node, status, fragments, currentFragment) {
|
|
190
|
-
currentFragment.text += ANCHOR_COMMENT;
|
|
191
|
-
if (node.children.length) {
|
|
192
|
-
node.fragment = {
|
|
193
|
-
number: fragments.length,
|
|
194
|
-
text: "",
|
|
195
|
-
ns: status.ns,
|
|
196
|
-
events: [],
|
|
197
|
-
animations: []
|
|
198
|
-
};
|
|
199
|
-
fragments.push(node.fragment);
|
|
200
|
-
for (let child of node.children) {
|
|
201
|
-
buildNodeFragmentText(child, status, fragments, node.fragment);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function buildElementFragmentText(node, status, fragments, currentFragment) {
|
|
206
|
-
let needsClass = node.scopeStyles;
|
|
207
|
-
currentFragment.text += `<${node.tagName}`;
|
|
208
|
-
let attributesText = node.attributes.filter((a) => !a.name.startsWith("on") && !a.name.includes(":")).map((a) => {
|
|
209
|
-
if (a.value && isReactive(a.value) && !a.name.includes(":")) {
|
|
210
|
-
if (a.name.startsWith("data-")) {
|
|
211
|
-
return `${a.name}=""`;
|
|
212
|
-
}
|
|
213
|
-
} else if (a.name === "class" && node.scopeStyles) {
|
|
214
|
-
needsClass = false;
|
|
215
|
-
let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
216
|
-
return `${a.name}=${value}`;
|
|
217
|
-
} else {
|
|
218
|
-
return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
|
|
219
|
-
}
|
|
220
|
-
}).filter(Boolean).join(" ");
|
|
221
|
-
if (attributesText) {
|
|
222
|
-
currentFragment.text += " " + attributesText;
|
|
223
|
-
}
|
|
224
|
-
if (needsClass) {
|
|
225
|
-
currentFragment.text += ` class="torp-${status.styleHash}"`;
|
|
226
|
-
}
|
|
227
|
-
currentFragment.text += ">";
|
|
228
|
-
for (let child of node.children) {
|
|
229
|
-
buildNodeFragmentText(child, status, fragments, currentFragment);
|
|
230
|
-
}
|
|
231
|
-
currentFragment.text += `</${node.tagName}>`;
|
|
232
|
-
}
|
|
233
|
-
function buildSpecialFragmentText(node, status, fragments, currentFragment) {
|
|
234
|
-
switch (node.tagName) {
|
|
235
|
-
case ":slot": {
|
|
236
|
-
currentFragment.text += ANCHOR_COMMENT;
|
|
237
|
-
for (let child of node.children) {
|
|
238
|
-
buildNodeFragmentText(child, status, fragments, node.fragment);
|
|
239
|
-
}
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
case ":fill": {
|
|
243
|
-
node.fragment = {
|
|
244
|
-
number: fragments.length,
|
|
245
|
-
text: "",
|
|
246
|
-
ns: status.ns,
|
|
247
|
-
events: [],
|
|
248
|
-
animations: []
|
|
249
|
-
};
|
|
250
|
-
fragments.push(node.fragment);
|
|
251
|
-
for (let child of node.children) {
|
|
252
|
-
buildNodeFragmentText(child, status, fragments, node.fragment);
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case ":element": {
|
|
257
|
-
buildComponentFragmentText(node, status, fragments, currentFragment);
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
case ":component": {
|
|
261
|
-
buildComponentFragmentText(node, status, fragments, currentFragment);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
case ":head": {
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
default: {
|
|
268
|
-
throw new Error(`Invalid special node: ${node.tagName}`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/compile/types/nodes/isSpecialNode.ts
|
|
274
|
-
function isSpecialNode(node) {
|
|
275
|
-
return node.type === "special";
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/compile/utils/trimMatched.ts
|
|
279
|
-
function trimMatched(text, startChar, endChar) {
|
|
280
|
-
let start = 0;
|
|
281
|
-
let end = text.length;
|
|
282
|
-
while (text[start] === startChar && text[end - 1] === endChar) {
|
|
283
|
-
start += 1;
|
|
284
|
-
end -= 1;
|
|
285
|
-
}
|
|
286
|
-
return text.substring(start, end);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// src/compile/build/utils/isFullyReactive.ts
|
|
290
|
-
function isFullyReactive(text) {
|
|
291
|
-
return text.trim().startsWith("{") && text.trim().endsWith("}");
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// src/compile/build/utils/nextVarName.ts
|
|
295
|
-
function nextVarName(name, status) {
|
|
296
|
-
if (!status.varNames[name]) {
|
|
297
|
-
status.varNames[name] = 1;
|
|
298
|
-
}
|
|
299
|
-
let varName = `t_${name}_${status.varNames[name]}`;
|
|
300
|
-
status.varNames[name] += 1;
|
|
301
|
-
return varName;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// src/compile/build/client/buildAddFragment.ts
|
|
305
|
-
function buildAddFragment(node, status, b, parentName, anchorName) {
|
|
306
|
-
if (node.fragment) {
|
|
307
|
-
const fragment = node.fragment;
|
|
308
|
-
const fragmentName = `t_fragment_${fragment.number}`;
|
|
309
|
-
status.imports.add("t_add_fragment");
|
|
310
|
-
let params = [fragmentName, parentName, anchorName];
|
|
311
|
-
if (fragment.endVarName) {
|
|
312
|
-
params.push(fragment.endVarName);
|
|
313
|
-
}
|
|
314
|
-
b.append(`t_add_fragment(${params.join(", ")});`);
|
|
315
|
-
if (fragment.endVarName) {
|
|
316
|
-
status.imports.add("t_next");
|
|
317
|
-
b.append(`t_next(${fragment.endVarName});`);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// src/compile/parse/utils/isSpaceChar.ts
|
|
323
|
-
function isSpaceChar(text, index) {
|
|
324
|
-
let code = text.charCodeAt(index);
|
|
325
|
-
return code === 32 || code >= 9 && code <= 13;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// src/compile/parse/utils/isSpace.ts
|
|
329
|
-
function isSpace(text) {
|
|
330
|
-
for (let i = 0; i < text.length; i++) {
|
|
331
|
-
if (!isSpaceChar(text, i)) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// src/compile/types/nodes/isControlNode.ts
|
|
339
|
-
function isControlNode(node) {
|
|
340
|
-
return node.type === "control";
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/compile/types/nodes/isElementNode.ts
|
|
344
|
-
function isElementNode(node) {
|
|
345
|
-
return node.type === "element";
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/compile/types/nodes/isTextNode.ts
|
|
349
|
-
function isTextNode(node) {
|
|
350
|
-
return node.type === "text";
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// src/compile/build/utils/isReactiveAttribute.ts
|
|
354
|
-
function isReactiveAttribute(name, value) {
|
|
355
|
-
return isFullyReactive(name) || isReactive(value) || name.startsWith("on");
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// src/compile/build/client/buildFragment.ts
|
|
359
|
-
function buildFragment(node, status, b, parentName, anchorName) {
|
|
360
|
-
if (node.fragment) {
|
|
361
|
-
const fragment = node.fragment;
|
|
362
|
-
const fragmentName = `t_fragment_${fragment.number}`;
|
|
363
|
-
if (status.options?.useCreateElement) {
|
|
364
|
-
let fragmentPath = { parent: null, type: "fragment", children: [] };
|
|
365
|
-
let varPaths = /* @__PURE__ */ new Map();
|
|
366
|
-
declareFragmentVars(
|
|
367
|
-
node.fragment,
|
|
368
|
-
node,
|
|
369
|
-
fragmentPath,
|
|
370
|
-
status,
|
|
371
|
-
b,
|
|
372
|
-
parentName,
|
|
373
|
-
anchorName,
|
|
374
|
-
varPaths,
|
|
375
|
-
false,
|
|
376
|
-
true
|
|
377
|
-
);
|
|
378
|
-
fragmentPath.children.length = 0;
|
|
379
|
-
varPaths.clear();
|
|
380
|
-
status.imports.add("t_frg");
|
|
381
|
-
b.append(`const ${fragmentName} = t_frg([`);
|
|
382
|
-
declareFragmentVars(
|
|
383
|
-
node.fragment,
|
|
384
|
-
node,
|
|
385
|
-
fragmentPath,
|
|
386
|
-
status,
|
|
387
|
-
b,
|
|
388
|
-
parentName,
|
|
389
|
-
anchorName,
|
|
390
|
-
varPaths,
|
|
391
|
-
false,
|
|
392
|
-
false
|
|
393
|
-
);
|
|
394
|
-
b.append(`]);`);
|
|
395
|
-
} else {
|
|
396
|
-
status.imports.add("t_fragment");
|
|
397
|
-
const fragmentText = fragment.text.replaceAll("`", "\\`").replaceAll(/\s+/g, " ");
|
|
398
|
-
b.append(
|
|
399
|
-
`const ${fragmentName} = t_fragment($parent.ownerDocument!, t_fragments, ${fragment.number}, \`${fragmentText}\`${fragment.ns ? ", true" : ""});`
|
|
400
|
-
);
|
|
401
|
-
let fragmentPath = { parent: null, type: "fragment", children: [] };
|
|
402
|
-
let varPaths = /* @__PURE__ */ new Map();
|
|
403
|
-
maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths);
|
|
404
|
-
declareFragmentVars(
|
|
405
|
-
node.fragment,
|
|
406
|
-
node,
|
|
407
|
-
fragmentPath,
|
|
408
|
-
status,
|
|
409
|
-
b,
|
|
410
|
-
parentName,
|
|
411
|
-
anchorName,
|
|
412
|
-
varPaths,
|
|
413
|
-
false,
|
|
414
|
-
true
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
function maybeAddRootNodeDeclaration(node, fragment, fragmentName, status, b, varPaths) {
|
|
420
|
-
if (!node.children.length) return;
|
|
421
|
-
let firstNode = node.children[0];
|
|
422
|
-
let firstNodeIsLastNode = node.children.length === 1;
|
|
423
|
-
if (isControlNode(firstNode) && firstNode.operation.endsWith(" group") || isElementNode(firstNode) && elementNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode) || isTextNode(firstNode) && textNodeNeedsDeclaration(firstNode, true, firstNodeIsLastNode)) {
|
|
424
|
-
} else {
|
|
425
|
-
status.imports.add("t_root");
|
|
426
|
-
const rootName = `t_root_${fragment.number}`;
|
|
427
|
-
const params = [fragmentName];
|
|
428
|
-
if (firstNode.type === "text") {
|
|
429
|
-
params.push("true");
|
|
430
|
-
}
|
|
431
|
-
const rootPath = `t_root(${params.join(", ")})`;
|
|
432
|
-
b.append("// @ts-ignore");
|
|
433
|
-
b.append(`const ${rootName} = ${rootPath};`);
|
|
434
|
-
varPaths.set(`t_root(${fragmentName})`, rootName);
|
|
435
|
-
printDebug(rootName, status, b);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function declareFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
|
|
439
|
-
switch (node.type) {
|
|
440
|
-
case "root": {
|
|
441
|
-
declareRootFragmentVars(
|
|
442
|
-
fragment,
|
|
443
|
-
node,
|
|
444
|
-
path,
|
|
445
|
-
status,
|
|
446
|
-
b,
|
|
447
|
-
parentName,
|
|
448
|
-
anchorName,
|
|
449
|
-
varPaths,
|
|
450
|
-
declare
|
|
451
|
-
);
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
case "control": {
|
|
455
|
-
declareControlFragmentVars(
|
|
456
|
-
fragment,
|
|
457
|
-
node,
|
|
458
|
-
path,
|
|
459
|
-
status,
|
|
460
|
-
b,
|
|
461
|
-
parentName,
|
|
462
|
-
anchorName,
|
|
463
|
-
varPaths,
|
|
464
|
-
declare
|
|
465
|
-
);
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
case "component": {
|
|
469
|
-
declareComponentFragmentVars(
|
|
470
|
-
fragment,
|
|
471
|
-
node,
|
|
472
|
-
path,
|
|
473
|
-
status,
|
|
474
|
-
b,
|
|
475
|
-
parentName,
|
|
476
|
-
anchorName,
|
|
477
|
-
varPaths,
|
|
478
|
-
declare
|
|
479
|
-
);
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
case "element": {
|
|
483
|
-
declareElementFragmentVars(
|
|
484
|
-
fragment,
|
|
485
|
-
node,
|
|
486
|
-
path,
|
|
487
|
-
status,
|
|
488
|
-
b,
|
|
489
|
-
parentName,
|
|
490
|
-
anchorName,
|
|
491
|
-
varPaths,
|
|
492
|
-
lastChild,
|
|
493
|
-
declare
|
|
494
|
-
);
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
case "text": {
|
|
498
|
-
declareTextFragmentVars(
|
|
499
|
-
fragment,
|
|
500
|
-
node,
|
|
501
|
-
path,
|
|
502
|
-
status,
|
|
503
|
-
b,
|
|
504
|
-
varPaths,
|
|
505
|
-
lastChild,
|
|
506
|
-
declare
|
|
507
|
-
);
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
case "special": {
|
|
511
|
-
declareSpecialFragmentVars(
|
|
512
|
-
fragment,
|
|
513
|
-
node,
|
|
514
|
-
path,
|
|
515
|
-
status,
|
|
516
|
-
b,
|
|
517
|
-
parentName,
|
|
518
|
-
anchorName,
|
|
519
|
-
varPaths,
|
|
520
|
-
lastChild,
|
|
521
|
-
declare
|
|
522
|
-
);
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
default: {
|
|
526
|
-
throw new Error(`Invalid node type: ${node.type}`);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
function declareRootFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
|
|
531
|
-
for (let [i, child] of node.children.entries()) {
|
|
532
|
-
declareFragmentVars(
|
|
533
|
-
fragment,
|
|
534
|
-
child,
|
|
535
|
-
path,
|
|
536
|
-
status,
|
|
537
|
-
b,
|
|
538
|
-
parentName,
|
|
539
|
-
anchorName,
|
|
540
|
-
varPaths,
|
|
541
|
-
i === node.children.length - 1,
|
|
542
|
-
declare
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
function declareControlFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
|
|
547
|
-
switch (node.operation) {
|
|
548
|
-
case "@if group":
|
|
549
|
-
case "@switch group":
|
|
550
|
-
case "@for group":
|
|
551
|
-
case "@await group":
|
|
552
|
-
case "@replace group":
|
|
553
|
-
case "@html group": {
|
|
554
|
-
const operation = node.operation.substring(1).replace(" group", "");
|
|
555
|
-
declareParentAndAnchorFragmentVars(
|
|
556
|
-
fragment,
|
|
557
|
-
node,
|
|
558
|
-
path,
|
|
559
|
-
status,
|
|
560
|
-
b,
|
|
561
|
-
parentName,
|
|
562
|
-
anchorName,
|
|
563
|
-
varPaths,
|
|
564
|
-
operation,
|
|
565
|
-
declare
|
|
566
|
-
);
|
|
567
|
-
break;
|
|
568
|
-
}
|
|
569
|
-
default: {
|
|
570
|
-
for (let [i, child] of node.children.entries()) {
|
|
571
|
-
declareFragmentVars(
|
|
572
|
-
fragment,
|
|
573
|
-
child,
|
|
574
|
-
path,
|
|
575
|
-
status,
|
|
576
|
-
b,
|
|
577
|
-
parentName,
|
|
578
|
-
anchorName,
|
|
579
|
-
varPaths,
|
|
580
|
-
i === node.children.length - 1,
|
|
581
|
-
declare
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
function declareComponentFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, declare) {
|
|
589
|
-
declareParentAndAnchorFragmentVars(
|
|
590
|
-
fragment,
|
|
591
|
-
node,
|
|
592
|
-
path,
|
|
593
|
-
status,
|
|
594
|
-
b,
|
|
595
|
-
parentName,
|
|
596
|
-
anchorName,
|
|
597
|
-
varPaths,
|
|
598
|
-
"comp",
|
|
599
|
-
declare
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
function elementTypeName(node) {
|
|
603
|
-
switch (node.tagName.toLowerCase()) {
|
|
604
|
-
case "div":
|
|
605
|
-
case "input":
|
|
606
|
-
return `HTML${node.tagName.substring(0, 1).toUpperCase() + node.tagName.substring(1)}Element`;
|
|
607
|
-
case "textarea":
|
|
608
|
-
return "HTMLTextAreaElement";
|
|
609
|
-
}
|
|
610
|
-
return "HTMLElement";
|
|
611
|
-
}
|
|
612
|
-
function declareElementFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
|
|
613
|
-
const tagName = node.tagName === ":element" ? "element" : node.tagName;
|
|
614
|
-
let elementPath = { parent: path, type: tagName, children: [] };
|
|
615
|
-
path.children.push(elementPath);
|
|
616
|
-
const topLevel = !path.parent;
|
|
617
|
-
const declareVariable = elementNodeNeedsDeclaration(node, topLevel, lastChild);
|
|
618
|
-
if (declare) {
|
|
619
|
-
if (declareVariable) {
|
|
620
|
-
node.varName = nextVarName(tagName, status);
|
|
621
|
-
if (topLevel) {
|
|
622
|
-
fragment.endVarName = node.varName;
|
|
623
|
-
}
|
|
624
|
-
const varPath = getFragmentVarPath(fragment, status, node.varName, elementPath, varPaths);
|
|
625
|
-
if (status.options?.useCreateElement) {
|
|
626
|
-
b.append(`let ${node.varName};`);
|
|
627
|
-
} else {
|
|
628
|
-
if (node.tagName === ":element") {
|
|
629
|
-
b.append(`let ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
|
|
630
|
-
} else {
|
|
631
|
-
if (topLevel && lastChild) {
|
|
632
|
-
b.append("// @ts-ignore");
|
|
633
|
-
}
|
|
634
|
-
b.append(`const ${node.varName} = ${varPath} as ${elementTypeName(node)};`);
|
|
635
|
-
printDebug(node.varName, status, b);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
let childParentName = node.children.find((c) => !!c.parentName)?.parentName;
|
|
641
|
-
if (!declare) {
|
|
642
|
-
let attributes = node.attributes.filter((a) => !a.name.startsWith("on") && !a.name.includes(":")).map((a) => {
|
|
643
|
-
if (a.value && isReactive(a.value)) {
|
|
644
|
-
return `"${a.name}": "#"`;
|
|
645
|
-
} else if (a.value) {
|
|
646
|
-
return `"${a.name}": "${trimQuotes(a.value) || a.name}"`;
|
|
647
|
-
} else {
|
|
648
|
-
return `"${a.name}": true"`;
|
|
649
|
-
}
|
|
650
|
-
}).join(", ");
|
|
651
|
-
status.imports.add("t_elm");
|
|
652
|
-
if (declareVariable) {
|
|
653
|
-
b.append(
|
|
654
|
-
`(${childParentName ? `${childParentName} = ` : ""}${node.varName} = t_elm("${node.tagName}", {${attributes}}, [`
|
|
655
|
-
);
|
|
656
|
-
} else if (childParentName) {
|
|
657
|
-
b.append(`(${childParentName} = t_elm("${node.tagName}", {${attributes}}, [`);
|
|
658
|
-
} else {
|
|
659
|
-
b.append(`t_elm("${node.tagName}", {${attributes}}, [`);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
for (let [i, child] of node.children.entries()) {
|
|
663
|
-
declareFragmentVars(
|
|
664
|
-
fragment,
|
|
665
|
-
child,
|
|
666
|
-
elementPath,
|
|
667
|
-
status,
|
|
668
|
-
b,
|
|
669
|
-
parentName,
|
|
670
|
-
anchorName,
|
|
671
|
-
varPaths,
|
|
672
|
-
i === node.children.length - 1,
|
|
673
|
-
declare
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
if (!declare) {
|
|
677
|
-
if (declareVariable || childParentName) {
|
|
678
|
-
b.append("])),");
|
|
679
|
-
} else {
|
|
680
|
-
b.append("]),");
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
function elementNodeNeedsDeclaration(node, topLevel, lastChild) {
|
|
685
|
-
const hasReactiveAttribute = node.attributes.some(
|
|
686
|
-
(a) => a.value && isReactiveAttribute(a.name, a.value)
|
|
687
|
-
);
|
|
688
|
-
const isDynamicElement = node.tagName === ":element" && node.attributes.find((a) => a.name === "self");
|
|
689
|
-
return hasReactiveAttribute || isDynamicElement || topLevel && lastChild;
|
|
690
|
-
}
|
|
691
|
-
function declareTextFragmentVars(fragment, node, path, status, b, varPaths, lastChild, declare) {
|
|
692
|
-
const lastType = path.children[path.children.length - 1]?.type;
|
|
693
|
-
if (lastType === "text" || lastType === "space") {
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
let textPath = { parent: path, type: isSpace(node.content) ? "space" : "text", children: [] };
|
|
697
|
-
path.children.push(textPath);
|
|
698
|
-
const topLevel = !path.parent;
|
|
699
|
-
const declareVariable = textNodeNeedsDeclaration(node, topLevel, lastChild);
|
|
700
|
-
if (declare) {
|
|
701
|
-
if (declareVariable) {
|
|
702
|
-
node.varName = nextVarName("text", status);
|
|
703
|
-
if (topLevel) {
|
|
704
|
-
fragment.endVarName = node.varName;
|
|
705
|
-
}
|
|
706
|
-
const varPath = getFragmentVarPath(fragment, status, node.varName, textPath, varPaths);
|
|
707
|
-
if (status.options?.useCreateElement) {
|
|
708
|
-
b.append(`let ${node.varName};`);
|
|
709
|
-
} else {
|
|
710
|
-
if (topLevel && lastChild) {
|
|
711
|
-
b.append("// @ts-ignore");
|
|
712
|
-
}
|
|
713
|
-
b.append(`const ${node.varName} = ${varPath};`);
|
|
714
|
-
printDebug(node.varName, status, b);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
} else {
|
|
718
|
-
status.imports.add("t_txt");
|
|
719
|
-
if (declareVariable) {
|
|
720
|
-
b.append(`(${node.varName} = t_txt(" ")),`);
|
|
721
|
-
} else {
|
|
722
|
-
b.append(`t_txt("${node.content}"),`);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
function textNodeNeedsDeclaration(node, topLevel, lastChild) {
|
|
727
|
-
return isReactive(node.content) || topLevel && lastChild;
|
|
728
|
-
}
|
|
729
|
-
function declareSpecialFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
|
|
730
|
-
if (node.tagName === ":slot") {
|
|
731
|
-
declareParentAndAnchorFragmentVars(
|
|
732
|
-
fragment,
|
|
733
|
-
node,
|
|
734
|
-
path,
|
|
735
|
-
status,
|
|
736
|
-
b,
|
|
737
|
-
parentName,
|
|
738
|
-
anchorName,
|
|
739
|
-
varPaths,
|
|
740
|
-
"slot",
|
|
741
|
-
declare
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
switch (node.tagName) {
|
|
745
|
-
case ":slot":
|
|
746
|
-
case ":fill": {
|
|
747
|
-
for (let [i, child] of node.children.entries()) {
|
|
748
|
-
declareFragmentVars(
|
|
749
|
-
fragment,
|
|
750
|
-
child,
|
|
751
|
-
path,
|
|
752
|
-
status,
|
|
753
|
-
b,
|
|
754
|
-
parentName,
|
|
755
|
-
anchorName,
|
|
756
|
-
varPaths,
|
|
757
|
-
i === node.children.length - 1,
|
|
758
|
-
declare
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
case ":element": {
|
|
764
|
-
declareElementFragmentVars(
|
|
765
|
-
fragment,
|
|
766
|
-
node,
|
|
767
|
-
path,
|
|
768
|
-
status,
|
|
769
|
-
b,
|
|
770
|
-
parentName,
|
|
771
|
-
anchorName,
|
|
772
|
-
varPaths,
|
|
773
|
-
lastChild,
|
|
774
|
-
declare
|
|
775
|
-
);
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
case ":component": {
|
|
779
|
-
declareComponentFragmentVars(
|
|
780
|
-
fragment,
|
|
781
|
-
node,
|
|
782
|
-
path,
|
|
783
|
-
status,
|
|
784
|
-
b,
|
|
785
|
-
parentName,
|
|
786
|
-
anchorName,
|
|
787
|
-
varPaths,
|
|
788
|
-
declare
|
|
789
|
-
);
|
|
790
|
-
break;
|
|
791
|
-
}
|
|
792
|
-
case ":head": {
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
default: {
|
|
796
|
-
throw new Error(`Invalid special node: ${node.tagName}`);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
function declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, name, declare) {
|
|
801
|
-
const topLevel = !path.parent;
|
|
802
|
-
if (topLevel) {
|
|
803
|
-
node.parentName = `t_fragment_${fragment.number}`;
|
|
804
|
-
} else {
|
|
805
|
-
const parentPath = path;
|
|
806
|
-
const oldChildren = parentPath.children;
|
|
807
|
-
parentPath.children = [];
|
|
808
|
-
const parentVarPath = getFragmentVarPath(fragment, status, "?", parentPath, varPaths);
|
|
809
|
-
parentPath.children = oldChildren;
|
|
810
|
-
if (varPaths.has(parentVarPath)) {
|
|
811
|
-
node.parentName = varPaths.get(parentVarPath);
|
|
812
|
-
} else {
|
|
813
|
-
if (declare) {
|
|
814
|
-
node.parentName = nextVarName(`${name}_parent`, status);
|
|
815
|
-
if (status.options?.useCreateElement) {
|
|
816
|
-
b.append(`let ${node.parentName} as HTMLElement;`);
|
|
817
|
-
} else {
|
|
818
|
-
b.append(`const ${node.parentName} = ${parentVarPath} as HTMLElement;`);
|
|
819
|
-
printDebug(node.parentName, status, b);
|
|
820
|
-
}
|
|
821
|
-
varPaths.set(parentVarPath, node.parentName);
|
|
822
|
-
} else {
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
if (declare) {
|
|
827
|
-
const anchorPath = { parent: path, type: "#", children: [] };
|
|
828
|
-
path.children.push(anchorPath);
|
|
829
|
-
node.varName = nextVarName(`${name}_anchor`, status);
|
|
830
|
-
const anchorVarPath = getFragmentVarPath(fragment, status, node.varName, anchorPath, varPaths);
|
|
831
|
-
if (status.options?.useCreateElement) {
|
|
832
|
-
b.append(`let ${node.varName};`);
|
|
833
|
-
} else {
|
|
834
|
-
status.imports.add("t_anchor");
|
|
835
|
-
b.append(`let ${node.varName} = t_anchor(${anchorVarPath}) as HTMLElement;`);
|
|
836
|
-
printDebug(node.varName, status, b);
|
|
837
|
-
}
|
|
838
|
-
} else {
|
|
839
|
-
status.imports.add("t_cmt");
|
|
840
|
-
b.append(`(${node.varName} = t_cmt()),`);
|
|
841
|
-
}
|
|
842
|
-
buildNode(node, status, b, parentName, anchorName);
|
|
843
|
-
node.handled = true;
|
|
844
|
-
}
|
|
845
|
-
function getFragmentVarPath(fragment, status, name, path, varPaths) {
|
|
846
|
-
let node = path;
|
|
847
|
-
while (node.parent) {
|
|
848
|
-
node = node.parent;
|
|
849
|
-
}
|
|
850
|
-
let varName = `t_fragment_${fragment.number}`;
|
|
851
|
-
let varPath = getFragmentVarPathPart(node, varName, status, true);
|
|
852
|
-
for (let [existingPath, existingName] of varPaths) {
|
|
853
|
-
if (varPath.includes(existingPath)) {
|
|
854
|
-
varPath = varPath.replace(existingPath, existingName);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
if (name !== "?") {
|
|
858
|
-
varPaths.set(varPath, name);
|
|
859
|
-
varPaths.set(name, name);
|
|
860
|
-
}
|
|
861
|
-
while (varPath.includes("t_next(t_next(")) {
|
|
862
|
-
status.imports.add("t_skip");
|
|
863
|
-
const match = varPath.match(/(t_next\(){2,}/)[0];
|
|
864
|
-
const count = match.length / "t_next(".length;
|
|
865
|
-
const pos = varPath.indexOf("t_next(t_next(");
|
|
866
|
-
const head = varPath.substring(0, pos);
|
|
867
|
-
let level = 0;
|
|
868
|
-
let end = 0;
|
|
869
|
-
for (let i = pos + match.length; i < varPath.length; i++) {
|
|
870
|
-
if (varPath[i] === "(") {
|
|
871
|
-
level++;
|
|
872
|
-
} else if (varPath[i] === ")") {
|
|
873
|
-
if (level === 0) {
|
|
874
|
-
end = i;
|
|
875
|
-
break;
|
|
876
|
-
} else {
|
|
877
|
-
level--;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
const tail = varPath.substring(end + count);
|
|
882
|
-
const param = varPath.substring(pos + match.length, end);
|
|
883
|
-
varPath = `${head}t_skip(${param}, ${count})${tail}`;
|
|
884
|
-
}
|
|
885
|
-
varPath = varPath.replaceAll("t_next_text", "t_next");
|
|
886
|
-
return varPath;
|
|
887
|
-
}
|
|
888
|
-
function getFragmentVarPathPart(path, varPath, status, root = false) {
|
|
889
|
-
if (root) {
|
|
890
|
-
status.imports.add("t_root");
|
|
891
|
-
varPath = `t_root(${varPath})`;
|
|
892
|
-
} else {
|
|
893
|
-
status.imports.add("t_child");
|
|
894
|
-
varPath = `t_child(${varPath})`;
|
|
895
|
-
}
|
|
896
|
-
for (let [i, child] of path.children.entries()) {
|
|
897
|
-
if (i > 0) {
|
|
898
|
-
if (child.type === "text" || child.type === "space") {
|
|
899
|
-
varPath = `t_next_text(${varPath}, true)`;
|
|
900
|
-
} else {
|
|
901
|
-
status.imports.add("t_next");
|
|
902
|
-
varPath = `t_next(${varPath})`;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
if (i === path.children.length - 1 && child.children.length) {
|
|
906
|
-
varPath = getFragmentVarPathPart(child, varPath, status);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
return varPath;
|
|
910
|
-
}
|
|
911
|
-
var debug = false;
|
|
912
|
-
function printDebug(varName, status, b) {
|
|
913
|
-
if (debug) {
|
|
914
|
-
status.imports.add("t_print");
|
|
915
|
-
b.append(`console.log("${varName}:", t_print(${varName}));`);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// src/compile/build/client/replaceForVarNames.ts
|
|
920
|
-
function replaceForVarNames(value, status) {
|
|
921
|
-
for (let varName of status.forVarNames) {
|
|
922
|
-
value = value.replaceAll(
|
|
923
|
-
new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"),
|
|
924
|
-
`$1t_item.data.${varName}$2`
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
return value;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// src/compile/build/client/buildRun.ts
|
|
931
|
-
function buildRun(functionName, functionBody, status, b) {
|
|
932
|
-
functionBody = replaceForVarNames(functionBody, status);
|
|
933
|
-
status.imports.add("$run");
|
|
934
|
-
b.append(`$run(function ${functionName}() {`);
|
|
935
|
-
b.append(functionBody);
|
|
936
|
-
b.append("});");
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
// src/compile/build/client/buildComponentNode.ts
|
|
940
|
-
function buildComponentNode(node, status, b, root = false) {
|
|
941
|
-
b.append("");
|
|
942
|
-
b.append("/* @component */");
|
|
943
|
-
const componentHasProps = node.attributes.length || root;
|
|
944
|
-
const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
|
|
945
|
-
if (componentHasProps) {
|
|
946
|
-
status.imports.add("$watch");
|
|
947
|
-
b.append(`const ${propsName}: any = $watch({});`);
|
|
948
|
-
for (let { name, value } of node.attributes) {
|
|
949
|
-
if (name === "self" && node.tagName === ":component") {
|
|
950
|
-
} else if (name.startsWith("{") && name.endsWith("}")) {
|
|
951
|
-
name = name.substring(1, name.length - 1);
|
|
952
|
-
const propName = name.split(".").at(-1);
|
|
953
|
-
buildRun("setProp", `${propsName}["${propName}"] = ${name};`, status, b);
|
|
954
|
-
} else if (name.startsWith("&") && value != null && isFullyReactive(value)) {
|
|
955
|
-
name = name.substring(1);
|
|
956
|
-
value = value.substring(1, value.length - 1);
|
|
957
|
-
buildRun("setProp", `${propsName}["${name}"] = ${value};`, status, b);
|
|
958
|
-
buildRun("setBinding", `${value} = ${propsName}["${name}"];`, status, b);
|
|
959
|
-
} else if (name === ":class" && value != null && isFullyReactive(value)) {
|
|
960
|
-
status.imports.add("t_class");
|
|
961
|
-
value = value.substring(1, value.length - 1);
|
|
962
|
-
if (node.scopeStyles) {
|
|
963
|
-
value += `, "torp-${status.styleHash}"`;
|
|
964
|
-
}
|
|
965
|
-
buildRun("setClasses", `${propsName}["class"] = t_class(${value});`, status, b);
|
|
966
|
-
} else if (name === ":style" && value != null && isFullyReactive(value)) {
|
|
967
|
-
status.imports.add("t_style");
|
|
968
|
-
value = value.substring(1, value.length - 1);
|
|
969
|
-
buildRun("setStyles", `${propsName}["style"] = t_style(${value});`, status, b);
|
|
970
|
-
} else if (value != null) {
|
|
971
|
-
let fullyReactive = isFullyReactive(value);
|
|
972
|
-
let partlyReactive = isReactive(value);
|
|
973
|
-
if (fullyReactive) {
|
|
974
|
-
value = value.substring(1, value.length - 1);
|
|
975
|
-
} else if (partlyReactive) {
|
|
976
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
977
|
-
}
|
|
978
|
-
if (name === "class") {
|
|
979
|
-
value = `"${trimQuotes(value)} torp-${status.styleHash}"`;
|
|
980
|
-
}
|
|
981
|
-
const setProp = `${propsName}["${name}"] = ${value};`;
|
|
982
|
-
if (fullyReactive || partlyReactive) {
|
|
983
|
-
buildRun("setProp", setProp, status, b);
|
|
984
|
-
} else {
|
|
985
|
-
b.append(setProp);
|
|
986
|
-
}
|
|
987
|
-
} else {
|
|
988
|
-
b.append(`${propsName}["${name}"] = true;`);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
if (root) {
|
|
992
|
-
status.imports.add("$run");
|
|
993
|
-
b.append(`
|
|
994
|
-
if ($props) {
|
|
995
|
-
const propNames = [${status.props.map((p) => `'${p}'`).join(", ")}];
|
|
996
|
-
for (let name of Object.keys($props)) {
|
|
997
|
-
if (!name.startsWith("$") && !propNames.includes(name)) {
|
|
998
|
-
$run(() => ${propsName}[name] = $props[name]);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}`);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
const componentHasSlots = node.children.length;
|
|
1005
|
-
const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
|
|
1006
|
-
if (componentHasSlots) {
|
|
1007
|
-
b.append(`const ${slotsName}: Record<string, SlotRender> = {};`);
|
|
1008
|
-
for (let slot of node.children) {
|
|
1009
|
-
if (isSpecialNode(slot)) {
|
|
1010
|
-
const nameAttribute = slot.attributes.find((a) => a.name === "name");
|
|
1011
|
-
const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
|
|
1012
|
-
const slotParams = [
|
|
1013
|
-
"$sparent: ParentNode",
|
|
1014
|
-
"$sanchor: Node | null",
|
|
1015
|
-
"//@ts-ignore\n$sprops?: Record<PropertyKey, any>",
|
|
1016
|
-
"//@ts-ignore\n$context?: Record<PropertyKey, any>"
|
|
1017
|
-
];
|
|
1018
|
-
b.append(`${slotsName}["${slotName}"] = (
|
|
1019
|
-
${slotParams.join(",\n")}
|
|
1020
|
-
) => {`);
|
|
1021
|
-
buildFragment(slot, status, b, "$sparent", "$sanchor");
|
|
1022
|
-
status.fragmentStack.push({
|
|
1023
|
-
fragment: slot.fragment,
|
|
1024
|
-
path: ""
|
|
1025
|
-
});
|
|
1026
|
-
for (let child of slot.children) {
|
|
1027
|
-
buildNode(child, status, b, "$sparent", "$sanchor");
|
|
1028
|
-
}
|
|
1029
|
-
status.fragmentStack.pop();
|
|
1030
|
-
buildAddFragment(slot, status, b, "$sparent", "$sanchor");
|
|
1031
|
-
b.append(`}`);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
const compParentName = node.parentName;
|
|
1036
|
-
const compAnchorName = node.varName;
|
|
1037
|
-
let renderParams = `${compParentName}, ${compAnchorName}, ${propsName}, $context`;
|
|
1038
|
-
if (slotsName !== "undefined") {
|
|
1039
|
-
renderParams += `, ${slotsName}`;
|
|
1040
|
-
}
|
|
1041
|
-
let componentName = node.tagName;
|
|
1042
|
-
if (componentName === ":component") {
|
|
1043
|
-
let selfAttribute = node.attributes.find((a) => a.name === "self");
|
|
1044
|
-
if (selfAttribute && selfAttribute.value) {
|
|
1045
|
-
componentName = trimMatched(selfAttribute.value, "{", "}");
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
b.append(`${componentName}(${renderParams});`);
|
|
1049
|
-
b.append("");
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
// src/compile/build/client/buildAwaitNode.ts
|
|
1053
|
-
function buildAwaitNode(node, status, b) {
|
|
1054
|
-
const awaitParentName = node.parentName;
|
|
1055
|
-
const awaitAnchorName = node.varName;
|
|
1056
|
-
const awaitRangeName = nextVarName("await_range", status);
|
|
1057
|
-
const awaitTokenName = nextVarName("await_token", status);
|
|
1058
|
-
const oldRangeName = nextVarName("old_range", status);
|
|
1059
|
-
const branches = node.children.filter((n) => isControlNode(n));
|
|
1060
|
-
let awaitBranch = branches.find((n) => n.operation === "@await");
|
|
1061
|
-
if (!awaitBranch) {
|
|
1062
|
-
}
|
|
1063
|
-
let thenBranch = branches.find((n) => n.operation === "@then");
|
|
1064
|
-
if (!thenBranch) {
|
|
1065
|
-
thenBranch = {
|
|
1066
|
-
type: "control",
|
|
1067
|
-
operation: "@then",
|
|
1068
|
-
statement: "then",
|
|
1069
|
-
children: []
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
let catchBranch = branches.find((n) => n.operation === "@catch");
|
|
1073
|
-
if (!catchBranch) {
|
|
1074
|
-
catchBranch = {
|
|
1075
|
-
type: "control",
|
|
1076
|
-
operation: "@catch",
|
|
1077
|
-
statement: "catch",
|
|
1078
|
-
children: []
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
const awaiterName = trimMatched(awaitBranch.statement.substring("await".length).trim(), "(", ")");
|
|
1082
|
-
const thenVar = trimMatched(thenBranch.statement.substring("then".length).trim(), "(", ")");
|
|
1083
|
-
const catchVar = trimMatched(catchBranch.statement.substring("catch".length).trim(), "(", ")");
|
|
1084
|
-
status.imports.add("t_range");
|
|
1085
|
-
status.imports.add("t_run_control");
|
|
1086
|
-
b.append("");
|
|
1087
|
-
b.append(`
|
|
1088
|
-
/* @await */
|
|
1089
|
-
const ${awaitRangeName} = t_range();
|
|
1090
|
-
${awaitRangeName}.index = -1;
|
|
1091
|
-
let ${awaitTokenName} = 0;
|
|
1092
|
-
t_run_control(${awaitRangeName}, ${awaitAnchorName}, (t_before) => {
|
|
1093
|
-
${awaitTokenName}++;`);
|
|
1094
|
-
buildAwaitBranch(awaitBranch, status, b, awaitParentName, awaitRangeName, 0);
|
|
1095
|
-
status.imports.add("t_push_range");
|
|
1096
|
-
status.imports.add("t_pop_range");
|
|
1097
|
-
b.append(`
|
|
1098
|
-
((token) => {
|
|
1099
|
-
${awaiterName}
|
|
1100
|
-
.then((${thenVar}) => {
|
|
1101
|
-
if (token === ${awaitTokenName}) {
|
|
1102
|
-
let ${oldRangeName} = t_push_range(${awaitRangeName});`);
|
|
1103
|
-
buildAwaitBranch(thenBranch, status, b, awaitParentName, awaitRangeName, 1);
|
|
1104
|
-
b.append(`t_pop_range(${oldRangeName});
|
|
1105
|
-
}
|
|
1106
|
-
})
|
|
1107
|
-
.catch((${catchVar}) => {
|
|
1108
|
-
if (token === ${awaitTokenName}) {
|
|
1109
|
-
let ${oldRangeName} = t_push_range(${awaitRangeName});`);
|
|
1110
|
-
buildAwaitBranch(catchBranch, status, b, awaitParentName, awaitRangeName, 2);
|
|
1111
|
-
b.append(`t_pop_range(${oldRangeName});
|
|
1112
|
-
}
|
|
1113
|
-
});
|
|
1114
|
-
})(${awaitTokenName});
|
|
1115
|
-
});`);
|
|
1116
|
-
b.append("");
|
|
1117
|
-
}
|
|
1118
|
-
function buildAwaitBranch(node, status, b, parentName, rangeName, index) {
|
|
1119
|
-
status.imports.add("t_run_branch");
|
|
1120
|
-
b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
|
|
1121
|
-
buildFragment(node, status, b, parentName, "t_before");
|
|
1122
|
-
status.fragmentStack.push({
|
|
1123
|
-
fragment: node.fragment,
|
|
1124
|
-
path: ""
|
|
1125
|
-
});
|
|
1126
|
-
for (let child of node.children) {
|
|
1127
|
-
buildNode(child, status, b, parentName, "t_before");
|
|
1128
|
-
}
|
|
1129
|
-
status.fragmentStack.pop();
|
|
1130
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1131
|
-
b.append(`});`);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// src/compile/utils/trimEnd.ts
|
|
1135
|
-
function trimEnd(text, char) {
|
|
1136
|
-
let end = text.length;
|
|
1137
|
-
while (text[end - 1] === char) {
|
|
1138
|
-
end -= 1;
|
|
1139
|
-
}
|
|
1140
|
-
return text.substring(0, end);
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// src/compile/build/client/buildForNode.ts
|
|
1144
|
-
var forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
|
|
1145
|
-
var forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,1}/g;
|
|
1146
|
-
var forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
|
|
1147
|
-
function buildForNode(node, status, b) {
|
|
1148
|
-
const forParentName = node.parentName;
|
|
1149
|
-
const forAnchorName = node.varName;
|
|
1150
|
-
node = node.children[0];
|
|
1151
|
-
const forVarNames = [];
|
|
1152
|
-
const forIndexMatch = node.statement.match(forLoopRegex);
|
|
1153
|
-
if (forIndexMatch) {
|
|
1154
|
-
const forVarMatches = forIndexMatch[1].matchAll(forLoopVarsRegex);
|
|
1155
|
-
for (let match of forVarMatches) {
|
|
1156
|
-
forVarNames.push(match[1]);
|
|
1157
|
-
}
|
|
1158
|
-
} else {
|
|
1159
|
-
const forOfMatch = node.statement.match(forOfRegex);
|
|
1160
|
-
if (forOfMatch) {
|
|
1161
|
-
const match = forOfMatch[1];
|
|
1162
|
-
if (match.startsWith("{") && match.endsWith("}") || match.startsWith("[") && match.endsWith("]")) {
|
|
1163
|
-
forVarNames.push(
|
|
1164
|
-
...trimMatched(trimMatched(match, "{", "}"), "[", "]").split(",").map((m) => m.trim())
|
|
1165
|
-
);
|
|
1166
|
-
} else {
|
|
1167
|
-
forVarNames.push(match);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
const forRangeName = nextVarName("for_range", status);
|
|
1172
|
-
const key = node.children.find(
|
|
1173
|
-
(n) => n.type === "control" && n.operation === "@key"
|
|
1174
|
-
);
|
|
1175
|
-
let keyStatement = key ? key.statement : "";
|
|
1176
|
-
if (keyStatement) {
|
|
1177
|
-
keyStatement = trimEnd(keyStatement.substring(keyStatement.indexOf("=") + 1).trim(), ";");
|
|
1178
|
-
}
|
|
1179
|
-
status.imports.add("t_range");
|
|
1180
|
-
status.imports.add("t_run_list");
|
|
1181
|
-
status.imports.add("t_list_item");
|
|
1182
|
-
status.imports.add("ListItem");
|
|
1183
|
-
b.append("");
|
|
1184
|
-
b.append(`
|
|
1185
|
-
/* @for */
|
|
1186
|
-
let ${forRangeName} = t_range();
|
|
1187
|
-
t_run_list(
|
|
1188
|
-
${forRangeName},
|
|
1189
|
-
${forParentName},
|
|
1190
|
-
${forAnchorName},
|
|
1191
|
-
function createNewItems() {
|
|
1192
|
-
let t_new_items: ListItem[] = [];
|
|
1193
|
-
${node.statement} {
|
|
1194
|
-
t_new_items.push(t_list_item({ ${forVarNames.join(",\n")} }${keyStatement ? `, ${keyStatement}` : ""}));
|
|
1195
|
-
/*t_new_items.push({
|
|
1196
|
-
${keyStatement ? `key: ${keyStatement},` : ";"}
|
|
1197
|
-
data: { ${forVarNames.join(",\n")} }
|
|
1198
|
-
});*/
|
|
1199
|
-
}
|
|
1200
|
-
return t_new_items;
|
|
1201
|
-
},
|
|
1202
|
-
function createListItem(t_item, t_before) {`);
|
|
1203
|
-
status.forVarNames = forVarNames;
|
|
1204
|
-
buildForItem(node, status, b, forParentName);
|
|
1205
|
-
status.forVarNames = [];
|
|
1206
|
-
b.append(`}`);
|
|
1207
|
-
b.append(`);`);
|
|
1208
|
-
b.append("");
|
|
1209
|
-
}
|
|
1210
|
-
function buildForItem(node, status, b, parentName) {
|
|
1211
|
-
const oldRangeName = nextVarName("old_range", status);
|
|
1212
|
-
status.imports.add("t_push_range");
|
|
1213
|
-
b.append(`let ${oldRangeName} = t_push_range(t_item, true);`);
|
|
1214
|
-
buildFragment(node, status, b, parentName, "t_before");
|
|
1215
|
-
status.fragmentStack.push({
|
|
1216
|
-
fragment: node.fragment,
|
|
1217
|
-
path: ""
|
|
1218
|
-
});
|
|
1219
|
-
for (let child of node.children) {
|
|
1220
|
-
if (isControlNode(child) && child.operation === "@key") {
|
|
1221
|
-
continue;
|
|
1222
|
-
}
|
|
1223
|
-
buildNode(child, status, b, parentName, "t_before");
|
|
1224
|
-
}
|
|
1225
|
-
status.fragmentStack.pop();
|
|
1226
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1227
|
-
status.imports.add("t_pop_range");
|
|
1228
|
-
b.append(`t_pop_range(${oldRangeName});`);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
// src/compile/build/client/buildHtmlNode.ts
|
|
1232
|
-
function buildHtmlNode(node, status, b) {
|
|
1233
|
-
const htmlAnchorName = node.varName;
|
|
1234
|
-
const htmlParentName = node.parentName || htmlAnchorName + ".parentNode";
|
|
1235
|
-
const htmlRangeName = nextVarName("html_range", status);
|
|
1236
|
-
node = node.children[0];
|
|
1237
|
-
status.imports.add("t_range");
|
|
1238
|
-
status.imports.add("t_run_control");
|
|
1239
|
-
b.append("");
|
|
1240
|
-
b.append(`
|
|
1241
|
-
/* @html */
|
|
1242
|
-
const ${htmlRangeName} = t_range();
|
|
1243
|
-
t_run_control(${htmlRangeName}, ${htmlAnchorName}, (t_before) => {`);
|
|
1244
|
-
buildHtmlBranch(node, status, b, htmlParentName, htmlRangeName);
|
|
1245
|
-
b.append("});");
|
|
1246
|
-
b.append("");
|
|
1247
|
-
}
|
|
1248
|
-
function buildHtmlBranch(node, status, b, parentName, rangeName) {
|
|
1249
|
-
status.imports.add("t_run_branch");
|
|
1250
|
-
b.append(`${node.statement};`);
|
|
1251
|
-
b.append(`t_run_branch(${rangeName}, -1, () => {`);
|
|
1252
|
-
const templateName = nextVarName("template", status);
|
|
1253
|
-
const fragmentName = `t_fragment_${node.fragment.number}`;
|
|
1254
|
-
b.append(`const ${templateName} = document.createElement("template");`);
|
|
1255
|
-
b.append(`${templateName}.innerHTML = ${node.statement};`);
|
|
1256
|
-
b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
|
|
1257
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1258
|
-
b.append(`});`);
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
// src/compile/build/client/buildIfNode.ts
|
|
1262
|
-
function buildIfNode(node, status, b) {
|
|
1263
|
-
const ifAnchorName = node.varName;
|
|
1264
|
-
const ifParentName = node.parentName || ifAnchorName + ".parentNode";
|
|
1265
|
-
const ifRangeName = nextVarName("if_range", status);
|
|
1266
|
-
const branches = node.children.filter((n) => isControlNode(n));
|
|
1267
|
-
if (branches.findIndex((n) => n.operation === "@else") === -1) {
|
|
1268
|
-
const elseBranch = {
|
|
1269
|
-
type: "control",
|
|
1270
|
-
operation: "@else",
|
|
1271
|
-
statement: "else",
|
|
1272
|
-
children: []
|
|
1273
|
-
};
|
|
1274
|
-
branches.push(elseBranch);
|
|
1275
|
-
}
|
|
1276
|
-
status.imports.add("t_range");
|
|
1277
|
-
status.imports.add("t_run_control");
|
|
1278
|
-
b.append("");
|
|
1279
|
-
b.append(`
|
|
1280
|
-
/* @if */
|
|
1281
|
-
const ${ifRangeName} = t_range();
|
|
1282
|
-
t_run_control(${ifRangeName}, ${ifAnchorName}, (t_before) => {`);
|
|
1283
|
-
for (let [i, branch] of branches.entries()) {
|
|
1284
|
-
buildIfBranch(branch, status, b, ifParentName, ifRangeName, i);
|
|
1285
|
-
}
|
|
1286
|
-
b.append("});");
|
|
1287
|
-
b.append("");
|
|
1288
|
-
}
|
|
1289
|
-
function buildIfBranch(node, status, b, parentName, rangeName, index) {
|
|
1290
|
-
status.imports.add("t_run_branch");
|
|
1291
|
-
b.append(`${replaceForVarNames(node.statement, status)} {`);
|
|
1292
|
-
b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
|
|
1293
|
-
buildFragment(node, status, b, parentName, "t_before");
|
|
1294
|
-
status.fragmentStack.push({
|
|
1295
|
-
fragment: node.fragment,
|
|
1296
|
-
path: ""
|
|
1297
|
-
});
|
|
1298
|
-
for (let child of node.children) {
|
|
1299
|
-
buildNode(child, status, b, parentName, "t_before");
|
|
1300
|
-
}
|
|
1301
|
-
status.fragmentStack.pop();
|
|
1302
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1303
|
-
b.append(`});`);
|
|
1304
|
-
b.append(`}`);
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
// src/compile/build/client/buildReplaceNode.ts
|
|
1308
|
-
function buildReplaceNode(node, status, b) {
|
|
1309
|
-
const replaceAnchorName = node.varName;
|
|
1310
|
-
const replaceParentName = node.parentName || replaceAnchorName + ".parentNode";
|
|
1311
|
-
const replaceRangeName = nextVarName("replace_range", status);
|
|
1312
|
-
node = node.children[0];
|
|
1313
|
-
status.imports.add("t_range");
|
|
1314
|
-
status.imports.add("t_run_control");
|
|
1315
|
-
b.append("");
|
|
1316
|
-
b.append(`
|
|
1317
|
-
/* @replace */
|
|
1318
|
-
const ${replaceRangeName} = t_range();
|
|
1319
|
-
t_run_control(${replaceRangeName}, ${replaceAnchorName}, (t_before) => {`);
|
|
1320
|
-
buildReplaceBranch(node, status, b, replaceParentName, replaceRangeName);
|
|
1321
|
-
b.append("});");
|
|
1322
|
-
b.append("");
|
|
1323
|
-
}
|
|
1324
|
-
function buildReplaceBranch(node, status, b, parentName, rangeName) {
|
|
1325
|
-
status.imports.add("t_run_branch");
|
|
1326
|
-
b.append(`${replaceForVarNames(node.statement, status)};`);
|
|
1327
|
-
b.append(`t_run_branch(${rangeName}, -1, () => {`);
|
|
1328
|
-
buildFragment(node, status, b, parentName, "t_before");
|
|
1329
|
-
status.fragmentStack.push({
|
|
1330
|
-
fragment: node.fragment,
|
|
1331
|
-
path: ""
|
|
1332
|
-
});
|
|
1333
|
-
for (let child of node.children) {
|
|
1334
|
-
buildNode(child, status, b, parentName, "t_before");
|
|
1335
|
-
}
|
|
1336
|
-
status.fragmentStack.pop();
|
|
1337
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1338
|
-
b.append(`});`);
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
// src/compile/build/client/buildScriptNode.ts
|
|
1342
|
-
function buildScriptNode(node, b) {
|
|
1343
|
-
b.append(`/* ${node.operation} */`);
|
|
1344
|
-
b.append(`${maybeAppend(node.statement, ";")}`);
|
|
1345
|
-
}
|
|
1346
|
-
function maybeAppend(text, end) {
|
|
1347
|
-
if (!text.endsWith(end)) {
|
|
1348
|
-
text += end;
|
|
1349
|
-
}
|
|
1350
|
-
return text;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
// src/compile/build/client/buildSwitchNode.ts
|
|
1354
|
-
function buildSwitchNode(node, status, b) {
|
|
1355
|
-
const switchParentName = node.parentName;
|
|
1356
|
-
const switchAnchorName = node.varName;
|
|
1357
|
-
const switchRangeName = nextVarName("switch_range", status);
|
|
1358
|
-
const branches = node.children.filter((n) => isControlNode(n));
|
|
1359
|
-
if (branches.findIndex((n) => n.operation === "@default") === -1) {
|
|
1360
|
-
const defaultBranch = {
|
|
1361
|
-
type: "control",
|
|
1362
|
-
operation: "@default",
|
|
1363
|
-
statement: "default",
|
|
1364
|
-
children: []
|
|
1365
|
-
};
|
|
1366
|
-
branches.push(defaultBranch);
|
|
1367
|
-
}
|
|
1368
|
-
status.imports.add("t_range");
|
|
1369
|
-
status.imports.add("t_run_control");
|
|
1370
|
-
b.append("");
|
|
1371
|
-
b.append(`
|
|
1372
|
-
/* @switch */
|
|
1373
|
-
const ${switchRangeName} = t_range();
|
|
1374
|
-
t_run_control(${switchRangeName}, ${switchAnchorName}, (t_before) => {
|
|
1375
|
-
${node.statement} {`);
|
|
1376
|
-
for (let [i, branch] of branches.entries()) {
|
|
1377
|
-
buildSwitchBranch(branch, status, b, switchParentName, switchRangeName, i);
|
|
1378
|
-
}
|
|
1379
|
-
b.append(`}
|
|
1380
|
-
});`);
|
|
1381
|
-
b.append("");
|
|
1382
|
-
}
|
|
1383
|
-
function buildSwitchBranch(node, status, b, parentName, rangeName, index) {
|
|
1384
|
-
status.imports.add("t_run_branch");
|
|
1385
|
-
b.append(`${replaceForVarNames(node.statement, status)} {`);
|
|
1386
|
-
b.append(`t_run_branch(${rangeName}, ${index}, () => {`);
|
|
1387
|
-
buildFragment(node, status, b, parentName, "t_before");
|
|
1388
|
-
status.fragmentStack.push({
|
|
1389
|
-
fragment: node.fragment,
|
|
1390
|
-
path: ""
|
|
1391
|
-
});
|
|
1392
|
-
for (let child of node.children) {
|
|
1393
|
-
buildNode(child, status, b, parentName, "t_before");
|
|
1394
|
-
}
|
|
1395
|
-
status.fragmentStack.pop();
|
|
1396
|
-
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1397
|
-
b.append(`});`);
|
|
1398
|
-
b.append(`break;`);
|
|
1399
|
-
b.append(`}`);
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
// src/compile/build/client/buildControlNode.ts
|
|
1403
|
-
function buildControlNode(node, status, b) {
|
|
1404
|
-
switch (node.operation) {
|
|
1405
|
-
case "@if group": {
|
|
1406
|
-
buildIfNode(node, status, b);
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
case "@if":
|
|
1410
|
-
case "@else if":
|
|
1411
|
-
case "@else": {
|
|
1412
|
-
break;
|
|
1413
|
-
}
|
|
1414
|
-
case "@switch group": {
|
|
1415
|
-
buildSwitchNode(node, status, b);
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
case "@case":
|
|
1419
|
-
case "@default": {
|
|
1420
|
-
break;
|
|
1421
|
-
}
|
|
1422
|
-
case "@for group": {
|
|
1423
|
-
buildForNode(node, status, b);
|
|
1424
|
-
break;
|
|
1425
|
-
}
|
|
1426
|
-
case "@for":
|
|
1427
|
-
case "@key": {
|
|
1428
|
-
break;
|
|
1429
|
-
}
|
|
1430
|
-
case "@await group": {
|
|
1431
|
-
buildAwaitNode(node, status, b);
|
|
1432
|
-
break;
|
|
1433
|
-
}
|
|
1434
|
-
case "@await":
|
|
1435
|
-
case "@then":
|
|
1436
|
-
case "@catch": {
|
|
1437
|
-
break;
|
|
1438
|
-
}
|
|
1439
|
-
case "@replace group": {
|
|
1440
|
-
buildReplaceNode(node, status, b);
|
|
1441
|
-
break;
|
|
1442
|
-
}
|
|
1443
|
-
case "@replace": {
|
|
1444
|
-
break;
|
|
1445
|
-
}
|
|
1446
|
-
case "@html group": {
|
|
1447
|
-
buildHtmlNode(node, status, b);
|
|
1448
|
-
break;
|
|
1449
|
-
}
|
|
1450
|
-
case "@html": {
|
|
1451
|
-
break;
|
|
1452
|
-
}
|
|
1453
|
-
case "@const":
|
|
1454
|
-
case "@console":
|
|
1455
|
-
case "@debugger": {
|
|
1456
|
-
buildScriptNode(node, b);
|
|
1457
|
-
break;
|
|
1458
|
-
}
|
|
1459
|
-
case "@function":
|
|
1460
|
-
case "@async function": {
|
|
1461
|
-
b.append("");
|
|
1462
|
-
buildScriptNode(node, b);
|
|
1463
|
-
b.append("");
|
|
1464
|
-
break;
|
|
1465
|
-
}
|
|
1466
|
-
default: {
|
|
1467
|
-
throw new Error(`Invalid operation: ${node.operation}`);
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
// src/compile/build/client/buildMount.ts
|
|
1473
|
-
function buildMount(functionName, functionBody, status, b) {
|
|
1474
|
-
functionBody = replaceForVarNames(functionBody, status);
|
|
1475
|
-
status.imports.add("$mount");
|
|
1476
|
-
b.append(`$mount(function ${functionName}() {`);
|
|
1477
|
-
b.append(functionBody);
|
|
1478
|
-
b.append("});");
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
// src/compile/build/client/buildElementNode.ts
|
|
1482
|
-
function buildElementNode(node, status, b, parentName, root = false) {
|
|
1483
|
-
if (status.inHead) {
|
|
1484
|
-
if (node.tagName === "title") {
|
|
1485
|
-
buildTitleNode(node, status, b);
|
|
1486
|
-
return;
|
|
1487
|
-
} else {
|
|
1488
|
-
buildHeadNode(node, status, b);
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
const varName = node.varName;
|
|
1493
|
-
if (varName) {
|
|
1494
|
-
if (node.tagName === ":element") {
|
|
1495
|
-
buildDynamicElementNode(node, status, b);
|
|
1496
|
-
}
|
|
1497
|
-
if (root) {
|
|
1498
|
-
}
|
|
1499
|
-
buildElementAttributes(node, varName, status, b);
|
|
1500
|
-
}
|
|
1501
|
-
const oldPreserveWhitespace = status.preserveWhitespace;
|
|
1502
|
-
status.preserveWhitespace = ["code", "pre"].includes(node.tagName);
|
|
1503
|
-
for (let child of node.children) {
|
|
1504
|
-
buildNode(child, status, b, parentName, "null");
|
|
1505
|
-
}
|
|
1506
|
-
status.preserveWhitespace = oldPreserveWhitespace;
|
|
1507
|
-
}
|
|
1508
|
-
function buildDynamicElementNode(node, status, b) {
|
|
1509
|
-
let selfAttribute = node.attributes.find((a) => a.name === "self");
|
|
1510
|
-
if (selfAttribute && selfAttribute.value) {
|
|
1511
|
-
status.imports.add("$run");
|
|
1512
|
-
status.imports.add("t_dynamic");
|
|
1513
|
-
let selfValue = trimMatched(selfAttribute.value, "{", "}");
|
|
1514
|
-
b.append(`$run(function setDynamic() {`);
|
|
1515
|
-
b.append(`${node.varName} = t_dynamic(${node.varName}, ${selfValue});`);
|
|
1516
|
-
let parentName = node.varName;
|
|
1517
|
-
buildFragment(node, status, b, parentName, "null");
|
|
1518
|
-
status.fragmentStack.push({
|
|
1519
|
-
fragment: node.fragment,
|
|
1520
|
-
path: ""
|
|
1521
|
-
});
|
|
1522
|
-
for (let child of node.children) {
|
|
1523
|
-
buildNode(child, status, b, parentName, "null");
|
|
1524
|
-
}
|
|
1525
|
-
status.fragmentStack.pop();
|
|
1526
|
-
buildAddFragment(node, status, b, parentName, "null");
|
|
1527
|
-
b.append(`});`);
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
function buildTitleNode(node, status, b) {
|
|
1531
|
-
let content = node.children[0].content || "";
|
|
1532
|
-
content = content.replace(/\s+/g, " ");
|
|
1533
|
-
let reactiveStarted = false;
|
|
1534
|
-
let reactiveCount = 0;
|
|
1535
|
-
for (let i = 0; i < content.length; i++) {
|
|
1536
|
-
if (content[i] === "{") {
|
|
1537
|
-
reactiveStarted = true;
|
|
1538
|
-
} else if (content[i] === "}") {
|
|
1539
|
-
if (reactiveStarted) {
|
|
1540
|
-
reactiveCount += 1;
|
|
1541
|
-
reactiveStarted = false;
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
if (reactiveCount) {
|
|
1546
|
-
status.imports.add("t_fmt");
|
|
1547
|
-
if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) {
|
|
1548
|
-
content = `t_fmt(${content.substring(1, content.length - 1)})`;
|
|
1549
|
-
} else {
|
|
1550
|
-
content = `\`${content.replaceAll("{", "${t_fmt(").replaceAll("}", ")}")}\``;
|
|
1551
|
-
}
|
|
1552
|
-
} else {
|
|
1553
|
-
content = `"${content}"`;
|
|
1554
|
-
}
|
|
1555
|
-
status.imports.add("$run");
|
|
1556
|
-
b.append(`
|
|
1557
|
-
$run(function runTitle() {
|
|
1558
|
-
const t_old_title = document.title;
|
|
1559
|
-
document.title = ${content};
|
|
1560
|
-
return () => document.title = t_old_title;
|
|
1561
|
-
});`);
|
|
1562
|
-
}
|
|
1563
|
-
function buildHeadNode(node, status, b) {
|
|
1564
|
-
status.imports.add("$run");
|
|
1565
|
-
b.append(`
|
|
1566
|
-
$run(function runHead() {
|
|
1567
|
-
const t_head_el = document.createElement("${node.tagName}");
|
|
1568
|
-
document.getElementsByTagName("head")[0].appendChild(t_head_el);`);
|
|
1569
|
-
for (let { name, value } of node.attributes) {
|
|
1570
|
-
if (name.startsWith("{") && name.endsWith("}")) {
|
|
1571
|
-
name = name.substring(1, name.length - 1);
|
|
1572
|
-
const propName = name.split(".").at(-1);
|
|
1573
|
-
buildRun("setAttribute", `t_head_el.setAttribute("${propName}", ${name});`, status, b);
|
|
1574
|
-
} else if (value != null && isReactive(value)) {
|
|
1575
|
-
if (isFullyReactive(value)) {
|
|
1576
|
-
value = value.substring(1, value.length - 1);
|
|
1577
|
-
} else {
|
|
1578
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
1579
|
-
}
|
|
1580
|
-
status.imports.add("t_attribute");
|
|
1581
|
-
buildRun("setAttribute", `t_attribute(t_head_el, "${name}", ${value});`, status, b);
|
|
1582
|
-
} else if (value != null) {
|
|
1583
|
-
status.imports.add("t_attribute");
|
|
1584
|
-
b.append(`t_attribute(t_head_el, "${name}", ${value});`);
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
b.append(`
|
|
1588
|
-
});`);
|
|
1589
|
-
}
|
|
1590
|
-
function buildElementAttributes(node, varName, status, b) {
|
|
1591
|
-
const refAttribute = node.attributes.find((a) => a.name === "&ref");
|
|
1592
|
-
if (refAttribute) {
|
|
1593
|
-
let value = refAttribute.value;
|
|
1594
|
-
if (value != null && isFullyReactive(value)) {
|
|
1595
|
-
value = value.substring(1, value.length - 1);
|
|
1596
|
-
b.append(`${value} = ${varName};`);
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
for (let { name, value } of node.attributes) {
|
|
1600
|
-
if (name === "self" && node.tagName === ":element") {
|
|
1601
|
-
} else if (name === "&ref") {
|
|
1602
|
-
} else if (name.startsWith("{") && name.endsWith("}")) {
|
|
1603
|
-
name = name.substring(1, name.length - 1);
|
|
1604
|
-
const propName = name.split(".").at(-1);
|
|
1605
|
-
buildRun("setAttribute", `${varName}.setAttribute("${propName}", ${name});`, status, b);
|
|
1606
|
-
} else if (value != null && isReactive(value)) {
|
|
1607
|
-
if (isFullyReactive(value)) {
|
|
1608
|
-
value = value.substring(1, value.length - 1);
|
|
1609
|
-
} else {
|
|
1610
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
1611
|
-
}
|
|
1612
|
-
if (name === "&group") {
|
|
1613
|
-
buildBindGroupAttribute(node, varName, value, status, b);
|
|
1614
|
-
} else if (name === "&value" || name === "&checked") {
|
|
1615
|
-
buildBindAttribute(node, varName, name, value, status, b);
|
|
1616
|
-
} else if (name === ":onmount") {
|
|
1617
|
-
buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
|
|
1618
|
-
} else if (name.startsWith("on")) {
|
|
1619
|
-
buildEventAttribute(varName, name, value, status, b);
|
|
1620
|
-
} else if (name.startsWith(":transition")) {
|
|
1621
|
-
buildTransitionAttribute(node, varName, name, value, status, b);
|
|
1622
|
-
} else if (name === "class") {
|
|
1623
|
-
if (node.scopeStyles) {
|
|
1624
|
-
value += `+ "torp-${status.styleHash}"`;
|
|
1625
|
-
}
|
|
1626
|
-
buildRun("setClassName", `${varName}.className = ${value};`, status, b);
|
|
1627
|
-
} else if (name === ":class") {
|
|
1628
|
-
status.imports.add("t_class");
|
|
1629
|
-
if (node.scopeStyles) {
|
|
1630
|
-
value += `, "torp-${status.styleHash}"`;
|
|
1631
|
-
}
|
|
1632
|
-
buildRun("setClasses", `${varName}.className = t_class(${value});`, status, b);
|
|
1633
|
-
} else if (name === ":style") {
|
|
1634
|
-
status.imports.add("t_style");
|
|
1635
|
-
buildRun("setStyles", `${varName}.setAttribute("style", t_style(${value}));`, status, b);
|
|
1636
|
-
} else if (name.includes("-")) {
|
|
1637
|
-
status.imports.add("t_attribute");
|
|
1638
|
-
buildRun("setDataAttribute", `t_attribute(${varName}, "${name}", ${value});`, status, b);
|
|
1639
|
-
} else {
|
|
1640
|
-
status.imports.add("t_attribute");
|
|
1641
|
-
buildRun("setAttribute", `t_attribute(${varName}, "${name}", ${value});`, status, b);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
function buildBindGroupAttribute(node, varName, value, status, b) {
|
|
1647
|
-
value = replaceForVarNames(value, status);
|
|
1648
|
-
let eventName = "change";
|
|
1649
|
-
let inputValue = node.attributes.find((a) => a.name === "value")?.value;
|
|
1650
|
-
let set = `${value} == ${inputValue}`;
|
|
1651
|
-
let propName = "checked";
|
|
1652
|
-
const setAttribute = `${varName}.${propName} = ${set}`;
|
|
1653
|
-
buildRun("setBinding", `${setAttribute};`, status, b);
|
|
1654
|
-
status.imports.add("t_event");
|
|
1655
|
-
b.append(`t_event(${varName}, "${eventName}", (e) => {
|
|
1656
|
-
if (e.target.${propName}) ${value} = ${inputValue};
|
|
1657
|
-
});`);
|
|
1658
|
-
}
|
|
1659
|
-
function buildBindAttribute(node, varName, name, value, status, b) {
|
|
1660
|
-
value = replaceForVarNames(value, status);
|
|
1661
|
-
let eventName = "input";
|
|
1662
|
-
let defaultValue = '""';
|
|
1663
|
-
let inputValue = "e.target.value";
|
|
1664
|
-
if (node.tagName === "input") {
|
|
1665
|
-
let typeAttribute = node.attributes.find((a) => a.name === "type");
|
|
1666
|
-
if (typeAttribute && typeAttribute.value) {
|
|
1667
|
-
switch (trimQuotes(typeAttribute.value)) {
|
|
1668
|
-
case "number": {
|
|
1669
|
-
defaultValue = "0";
|
|
1670
|
-
inputValue = "Number(e.target.value)";
|
|
1671
|
-
break;
|
|
1672
|
-
}
|
|
1673
|
-
case "checkbox": {
|
|
1674
|
-
defaultValue = "false";
|
|
1675
|
-
inputValue = "e.target.checked";
|
|
1676
|
-
break;
|
|
1677
|
-
}
|
|
1678
|
-
case "radio": {
|
|
1679
|
-
eventName = "change";
|
|
1680
|
-
inputValue = "e.target.value";
|
|
1681
|
-
break;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
} else if (node.tagName === "select") {
|
|
1686
|
-
eventName = "change";
|
|
1687
|
-
}
|
|
1688
|
-
let set = `${value} || ${defaultValue}`;
|
|
1689
|
-
const propName = name.substring(1);
|
|
1690
|
-
const setAttribute = `${varName}.${propName} = ${set}`;
|
|
1691
|
-
buildRun("setBinding", `${setAttribute};`, status, b);
|
|
1692
|
-
status.imports.add("t_event");
|
|
1693
|
-
b.append(`t_event(${varName}, "${eventName}", (e) => ${value} = ${inputValue});`);
|
|
1694
|
-
}
|
|
1695
|
-
function buildEventAttribute(varName, name, value, status, b) {
|
|
1696
|
-
value = replaceForVarNames(value, status);
|
|
1697
|
-
const eventName = name.substring(2);
|
|
1698
|
-
status.imports.add("t_event");
|
|
1699
|
-
b.append(`t_event(${varName}, "${eventName}", ${value});`);
|
|
1700
|
-
}
|
|
1701
|
-
function buildTransitionAttribute(node, varName, name, value, status, b) {
|
|
1702
|
-
value = replaceForVarNames(value, status);
|
|
1703
|
-
status.imports.add("t_animate");
|
|
1704
|
-
let entryVarName = nextVarName("trans_in", status);
|
|
1705
|
-
let exitVarName = nextVarName("trans_out", status);
|
|
1706
|
-
if (name === ":transition") {
|
|
1707
|
-
b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
|
|
1708
|
-
b.append(`const ${exitVarName} = ${entryVarName};`);
|
|
1709
|
-
b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
|
|
1710
|
-
} else if (name === ":transition-in") {
|
|
1711
|
-
let outAttribute = node.attributes.find((a) => a.name === ":transition-out");
|
|
1712
|
-
if (outAttribute && outAttribute.value) {
|
|
1713
|
-
let outValue = trimMatched(outAttribute.value, "{", "}");
|
|
1714
|
-
b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
|
|
1715
|
-
b.append(`const ${exitVarName} = ${getAnimationDetails(outValue)};`);
|
|
1716
|
-
b.append(`t_animate(${varName}, ${entryVarName}, ${exitVarName});`);
|
|
1717
|
-
} else {
|
|
1718
|
-
b.append(`const ${entryVarName} = ${getAnimationDetails(value)};`);
|
|
1719
|
-
b.append(`t_animate(${varName}, ${entryVarName});`);
|
|
1720
|
-
}
|
|
1721
|
-
} else if (name === ":transition-out") {
|
|
1722
|
-
let inAttribute = node.attributes.find((a) => a.name === ":transition-in");
|
|
1723
|
-
if (inAttribute) {
|
|
1724
|
-
return;
|
|
1725
|
-
} else {
|
|
1726
|
-
b.append(`const ${exitVarName} = ${getAnimationDetails(value)};`);
|
|
1727
|
-
b.append(`t_animate(${varName}, null, ${entryVarName});`);
|
|
1728
|
-
}
|
|
1729
|
-
} else {
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
function getAnimationDetails(value) {
|
|
1733
|
-
let parts = [];
|
|
1734
|
-
let start = 0;
|
|
1735
|
-
let squareCount = 0;
|
|
1736
|
-
let curlyCount = 0;
|
|
1737
|
-
for (let i = 0; i < value.length; i++) {
|
|
1738
|
-
let char = value[i];
|
|
1739
|
-
switch (char) {
|
|
1740
|
-
case ",":
|
|
1741
|
-
if (squareCount === 0 && curlyCount === 0) {
|
|
1742
|
-
parts.push(value.substring(start, i));
|
|
1743
|
-
start = i + 1;
|
|
1744
|
-
}
|
|
1745
|
-
break;
|
|
1746
|
-
case "[":
|
|
1747
|
-
squareCount += 1;
|
|
1748
|
-
break;
|
|
1749
|
-
case "]":
|
|
1750
|
-
squareCount -= 1;
|
|
1751
|
-
break;
|
|
1752
|
-
case "{":
|
|
1753
|
-
curlyCount += 1;
|
|
1754
|
-
break;
|
|
1755
|
-
case "}":
|
|
1756
|
-
curlyCount -= 1;
|
|
1757
|
-
break;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
parts.push(value.substring(start));
|
|
1761
|
-
let keyframes = parts[0]?.trim();
|
|
1762
|
-
let options = parts[1]?.trim();
|
|
1763
|
-
return `{ ${[`keyframes: ${keyframes}`, options ? `options: ${options}` : null].filter(Boolean).join(", ")} }`;
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
// src/compile/build/client/buildRootNode.ts
|
|
1767
|
-
function buildRootNode(node, status, b, parentName, anchorName) {
|
|
1768
|
-
buildFragment(node, status, b, parentName, anchorName);
|
|
1769
|
-
status.fragmentStack.push({
|
|
1770
|
-
fragment: node.fragment,
|
|
1771
|
-
path: "0:ch/"
|
|
1772
|
-
});
|
|
1773
|
-
for (let child of node.children) {
|
|
1774
|
-
buildNode(child, status, b, parentName, anchorName, true);
|
|
1775
|
-
}
|
|
1776
|
-
status.fragmentStack.pop();
|
|
1777
|
-
buildAddFragment(node, status, b, parentName, anchorName);
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
// src/compile/build/client/buildHeadNode.ts
|
|
1781
|
-
function buildHeadNode2(node, status, b) {
|
|
1782
|
-
b.append("");
|
|
1783
|
-
b.append("/* @head */");
|
|
1784
|
-
status.inHead = true;
|
|
1785
|
-
for (let child of node.children) {
|
|
1786
|
-
buildNode(child, status, b, "undefined", "undefined");
|
|
1787
|
-
}
|
|
1788
|
-
status.inHead = false;
|
|
1789
|
-
b.append("");
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
// src/compile/build/client/buildSlotNode.ts
|
|
1793
|
-
function buildSlotNode(node, status, b) {
|
|
1794
|
-
let slotName = node.attributes.find((a) => a.name === "name")?.value;
|
|
1795
|
-
slotName = slotName ? trimQuotes(slotName) : "_";
|
|
1796
|
-
const propsName = nextVarName("sprops", status);
|
|
1797
|
-
const slotAttributes = node.attributes.filter((a) => a.name !== "name");
|
|
1798
|
-
const slotHasProps = slotAttributes.length;
|
|
1799
|
-
if (slotHasProps) {
|
|
1800
|
-
status.imports.add("$watch");
|
|
1801
|
-
b.append(`const ${propsName} = $watch({});`);
|
|
1802
|
-
for (let { name, value } of slotAttributes) {
|
|
1803
|
-
if (name.startsWith("{") && name.endsWith("}")) {
|
|
1804
|
-
name = name.substring(1, name.length - 1);
|
|
1805
|
-
const propName = name.split(".").at(-1);
|
|
1806
|
-
buildRun("setProp", `${propsName}["${propName}"] = ${name};`, status, b);
|
|
1807
|
-
} else if (value != null) {
|
|
1808
|
-
let fullyReactive = isFullyReactive(value);
|
|
1809
|
-
let partlyReactive = isReactive(value);
|
|
1810
|
-
if (fullyReactive) {
|
|
1811
|
-
value = value.substring(1, value.length - 1);
|
|
1812
|
-
} else if (partlyReactive) {
|
|
1813
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
1814
|
-
}
|
|
1815
|
-
const setProp = `${propsName}["${name}"] = ${value}`;
|
|
1816
|
-
if (fullyReactive || partlyReactive) {
|
|
1817
|
-
buildRun("setProp", `${setProp};`, status, b);
|
|
1818
|
-
} else {
|
|
1819
|
-
b.append(`${setProp};`);
|
|
1820
|
-
}
|
|
1821
|
-
} else {
|
|
1822
|
-
b.append(`${propsName}["${name}"] = true;`);
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
const slotParentName = node.parentName;
|
|
1827
|
-
const slotAnchorName = node.varName;
|
|
1828
|
-
b.append(`if ($slots && $slots["${slotName}"]) {`);
|
|
1829
|
-
let params = [slotParentName, slotAnchorName, slotHasProps ? propsName : "undefined", "$context"];
|
|
1830
|
-
b.append(`$slots["${slotName}"](${params.join(", ")})`);
|
|
1831
|
-
const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === ":fill");
|
|
1832
|
-
if (fill && isSpecialNode(fill) && fill.children.length) {
|
|
1833
|
-
b.append(`} else {`);
|
|
1834
|
-
buildFragment(fill, status, b, slotParentName, slotAnchorName);
|
|
1835
|
-
status.fragmentStack.push({
|
|
1836
|
-
fragment: fill.fragment,
|
|
1837
|
-
path: "0:ch/"
|
|
1838
|
-
});
|
|
1839
|
-
for (let child of fill.children) {
|
|
1840
|
-
buildNode(child, status, b, slotParentName, slotAnchorName);
|
|
1841
|
-
}
|
|
1842
|
-
status.fragmentStack.pop();
|
|
1843
|
-
buildAddFragment(fill, status, b, slotParentName, slotAnchorName);
|
|
1844
|
-
}
|
|
1845
|
-
b.append(`}`);
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
// src/compile/build/client/buildSpecialNode.ts
|
|
1849
|
-
function buildSpecialNode(node, status, b, parentName, root = false) {
|
|
1850
|
-
switch (node.tagName) {
|
|
1851
|
-
case ":slot": {
|
|
1852
|
-
buildSlotNode(node, status, b);
|
|
1853
|
-
break;
|
|
1854
|
-
}
|
|
1855
|
-
case ":element": {
|
|
1856
|
-
buildElementNode(node, status, b, parentName, root);
|
|
1857
|
-
break;
|
|
1858
|
-
}
|
|
1859
|
-
case ":component": {
|
|
1860
|
-
buildComponentNode(node, status, b, root);
|
|
1861
|
-
break;
|
|
1862
|
-
}
|
|
1863
|
-
case ":head": {
|
|
1864
|
-
buildHeadNode2(node, status, b);
|
|
1865
|
-
break;
|
|
1866
|
-
}
|
|
1867
|
-
case ":fill": {
|
|
1868
|
-
break;
|
|
1869
|
-
}
|
|
1870
|
-
default: {
|
|
1871
|
-
throw new Error(`Invalid special node: ${node.tagName}`);
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
return "";
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
// src/compile/build/client/buildTextNode.ts
|
|
1878
|
-
function buildTextNode(node, status, b) {
|
|
1879
|
-
let content = node.content || "";
|
|
1880
|
-
if (!status.preserveWhitespace) {
|
|
1881
|
-
content = content.replaceAll(/\s+/g, " ");
|
|
1882
|
-
}
|
|
1883
|
-
let textContent = "";
|
|
1884
|
-
let reactiveCount = 0;
|
|
1885
|
-
let level = 0;
|
|
1886
|
-
let maxLevel = 0;
|
|
1887
|
-
for (let i = 0; i < content.length; i++) {
|
|
1888
|
-
const char = content[i];
|
|
1889
|
-
const nextChar = content[i + 1];
|
|
1890
|
-
if (char === "{") {
|
|
1891
|
-
level++;
|
|
1892
|
-
maxLevel = Math.max(level, maxLevel);
|
|
1893
|
-
if (level === 1) {
|
|
1894
|
-
reactiveCount += 1;
|
|
1895
|
-
textContent += "${t_fmt(";
|
|
1896
|
-
continue;
|
|
1897
|
-
}
|
|
1898
|
-
} else if (char === "}") {
|
|
1899
|
-
level--;
|
|
1900
|
-
if (level === 0) {
|
|
1901
|
-
textContent += ")";
|
|
1902
|
-
}
|
|
1903
|
-
} else if (char === "`" && level === 0) {
|
|
1904
|
-
textContent += "\\";
|
|
1905
|
-
} else if (level > 0) {
|
|
1906
|
-
if (char === "/" && nextChar === "/") {
|
|
1907
|
-
let start = i;
|
|
1908
|
-
i = content.indexOf("\n", i);
|
|
1909
|
-
textContent += content.substring(start, i + 1);
|
|
1910
|
-
continue;
|
|
1911
|
-
} else if (char === "/" && nextChar === "*") {
|
|
1912
|
-
let start = i;
|
|
1913
|
-
i = content.indexOf("*/", i) + 1;
|
|
1914
|
-
textContent += content.substring(start, i + 1);
|
|
1915
|
-
continue;
|
|
1916
|
-
} else if (char === '"' || char === "'") {
|
|
1917
|
-
let start = i;
|
|
1918
|
-
for (let j = i + 1; j < content.length; j++) {
|
|
1919
|
-
if (content[j] === char && content[j - 1] !== "\\") {
|
|
1920
|
-
i = j;
|
|
1921
|
-
textContent += content.substring(start, i + 1);
|
|
1922
|
-
break;
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
continue;
|
|
1926
|
-
} else if (char === "`") {
|
|
1927
|
-
let start = i;
|
|
1928
|
-
let level2 = 0;
|
|
1929
|
-
for (let j = i + 1; j < content.length; j++) {
|
|
1930
|
-
if (content[j] === char && content[j - 1] !== "\\" && level2 === 0) {
|
|
1931
|
-
i = j;
|
|
1932
|
-
textContent += content.substring(start, i + 1);
|
|
1933
|
-
break;
|
|
1934
|
-
} else if (content[j] === "{" && (level2 > 0 || content[j - 1] === "$")) {
|
|
1935
|
-
level2 += 1;
|
|
1936
|
-
} else if (content[j] === "}" && level2 > 0) {
|
|
1937
|
-
level2 -= 1;
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
continue;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
textContent += content[i];
|
|
1944
|
-
}
|
|
1945
|
-
if (maxLevel) {
|
|
1946
|
-
if (reactiveCount === 1 && content.startsWith("{") && content.endsWith("}")) {
|
|
1947
|
-
textContent = textContent.substring(2, textContent.length - 1);
|
|
1948
|
-
} else {
|
|
1949
|
-
textContent = `\`${textContent}\``;
|
|
1950
|
-
}
|
|
1951
|
-
status.imports.add("t_fmt");
|
|
1952
|
-
buildRun("setTextContent", `${node.varName}.textContent = ${textContent};`, status, b);
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
// src/compile/build/client/buildNode.ts
|
|
1957
|
-
function buildNode(node, status, b, parentName, anchorName, root = false) {
|
|
1958
|
-
if (node.handled) {
|
|
1959
|
-
node.handled = false;
|
|
1960
|
-
return;
|
|
1961
|
-
}
|
|
1962
|
-
switch (node.type) {
|
|
1963
|
-
case "root": {
|
|
1964
|
-
buildRootNode(node, status, b, parentName, anchorName);
|
|
1965
|
-
break;
|
|
1966
|
-
}
|
|
1967
|
-
case "control": {
|
|
1968
|
-
buildControlNode(node, status, b);
|
|
1969
|
-
break;
|
|
1970
|
-
}
|
|
1971
|
-
case "component": {
|
|
1972
|
-
buildComponentNode(node, status, b, root);
|
|
1973
|
-
break;
|
|
1974
|
-
}
|
|
1975
|
-
case "element": {
|
|
1976
|
-
buildElementNode(node, status, b, parentName, root);
|
|
1977
|
-
break;
|
|
1978
|
-
}
|
|
1979
|
-
case "text": {
|
|
1980
|
-
buildTextNode(node, status, b);
|
|
1981
|
-
break;
|
|
1982
|
-
}
|
|
1983
|
-
case "special": {
|
|
1984
|
-
buildSpecialNode(node, status, b, parentName, root);
|
|
1985
|
-
break;
|
|
1986
|
-
}
|
|
1987
|
-
default: {
|
|
1988
|
-
throw new Error(`Invalid node type: ${node.type}`);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
// src/compile/build/client/buildCode.ts
|
|
1994
|
-
var importsMap = {
|
|
1995
|
-
$watch: 'import { $watch } from "${folder}";',
|
|
1996
|
-
$unwrap: 'import { $unwrap } from "${folder}";',
|
|
1997
|
-
$run: 'import { $run } from "${folder}";',
|
|
1998
|
-
$mount: 'import { $mount } from "${folder}";',
|
|
1999
|
-
t_range: 'import { t_range } from "${folder}";',
|
|
2000
|
-
t_push_range: 'import { t_push_range } from "${folder}";',
|
|
2001
|
-
t_pop_range: 'import { t_pop_range } from "${folder}";',
|
|
2002
|
-
t_run_control: 'import { t_run_control } from "${folder}";',
|
|
2003
|
-
t_run_branch: 'import { t_run_branch } from "${folder}";',
|
|
2004
|
-
t_list_item: 'import { t_list_item } from "${folder}";',
|
|
2005
|
-
t_run_list: 'import { t_run_list } from "${folder}";',
|
|
2006
|
-
t_add_fragment: 'import { t_add_fragment } from "${folder}";',
|
|
2007
|
-
t_apply_props: 'import { t_apply_props } from "${folder}";',
|
|
2008
|
-
t_class: 'import { t_class } from "${folder}";',
|
|
2009
|
-
t_style: 'import { t_style } from "${folder}";',
|
|
2010
|
-
t_attribute: 'import { t_attribute } from "${folder}";',
|
|
2011
|
-
t_dynamic: 'import { t_dynamic } from "${folder}";',
|
|
2012
|
-
t_fmt: 'import { t_fmt } from "${folder}";',
|
|
2013
|
-
t_fragment: 'import { t_fragment } from "${folder}";',
|
|
2014
|
-
t_event: 'import { t_event } from "${folder}";',
|
|
2015
|
-
t_animate: 'import { t_animate } from "${folder}";',
|
|
2016
|
-
t_root: 'import { t_root } from "${folder}";',
|
|
2017
|
-
t_anchor: 'import { t_anchor } from "${folder}";',
|
|
2018
|
-
t_child: 'import { t_child } from "${folder}";',
|
|
2019
|
-
t_next: 'import { t_next } from "${folder}";',
|
|
2020
|
-
t_skip: 'import { t_skip } from "${folder}";',
|
|
2021
|
-
t_frg: 'import { t_frg } from "${folder}";',
|
|
2022
|
-
t_elm: 'import { t_elm } from "${folder}";',
|
|
2023
|
-
t_txt: 'import { t_txt } from "${folder}";',
|
|
2024
|
-
t_cmt: 'import { t_cmt } from "${folder}";',
|
|
2025
|
-
t_print: 'import { t_print } from "${folder}";',
|
|
2026
|
-
ListItem: 'import { type ListItem } from "${folder}";',
|
|
2027
|
-
SlotRender: 'import { type SlotRender } from "${folder}";'
|
|
2028
|
-
};
|
|
2029
|
-
function buildCode(template, options) {
|
|
2030
|
-
let b = new Builder();
|
|
2031
|
-
let imports = /* @__PURE__ */ new Set();
|
|
2032
|
-
imports.add("SlotRender");
|
|
2033
|
-
buildTemplate(template, imports, b);
|
|
2034
|
-
if (imports.size) {
|
|
2035
|
-
b.prepend("");
|
|
2036
|
-
for (let imp of Array.from(imports).sort().reverse()) {
|
|
2037
|
-
imp = importsMap[imp] || imp;
|
|
2038
|
-
b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view"));
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
return b.toString();
|
|
2042
|
-
}
|
|
2043
|
-
function buildTemplate(template, imports, b) {
|
|
2044
|
-
let script = template.script || "";
|
|
2045
|
-
if (/\$watch\b/.test(script)) imports.add("$watch");
|
|
2046
|
-
if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
|
|
2047
|
-
if (/\$run\b/.test(script)) imports.add("$run");
|
|
2048
|
-
if (/\$mount\b/.test(script)) imports.add("$mount");
|
|
2049
|
-
let currentIndex = 0;
|
|
2050
|
-
let current = template.components[0];
|
|
2051
|
-
let marker = 0;
|
|
2052
|
-
for (let i = 0; i < script.length; i++) {
|
|
2053
|
-
if (script.substring(i, i + "/* @params */".length) === "/* @params */") {
|
|
2054
|
-
b.append(script.substring(marker, i));
|
|
2055
|
-
let params = [
|
|
2056
|
-
"$parent: ParentNode",
|
|
2057
|
-
"$anchor: Node | null",
|
|
2058
|
-
current.params ?? `${current.props?.length ? "$props" : "// @ts-ignore\n$props?"}: Record<PropertyKey, any>`,
|
|
2059
|
-
`${current.contextProps?.length ? "" : "// @ts-ignore\n"}$context?: Record<PropertyKey, any>`,
|
|
2060
|
-
`${current.slotProps?.length ? "" : "// @ts-ignore\n"}$slots?: Record<string, SlotRender>`
|
|
2061
|
-
];
|
|
2062
|
-
b.append(params.join(",\n"));
|
|
2063
|
-
marker = i + "/* @params */".length;
|
|
2064
|
-
} else if (script.substring(i, i + "/* @start */".length) === "/* @start */") {
|
|
2065
|
-
b.append(script.substring(marker, i));
|
|
2066
|
-
if (current.props?.length) {
|
|
2067
|
-
imports.add("$watch");
|
|
2068
|
-
b.append(`$props ??= $watch({});`);
|
|
2069
|
-
}
|
|
2070
|
-
if (current.contextProps?.length) {
|
|
2071
|
-
b.append(`$context = Object.assign({}, $context);`);
|
|
2072
|
-
}
|
|
2073
|
-
b.append("");
|
|
2074
|
-
marker = i + "/* @start */".length;
|
|
2075
|
-
} else if (script.substring(i, i + "/* @render */".length) === "/* @render */") {
|
|
2076
|
-
b.append(script.substring(marker, i));
|
|
2077
|
-
if (current.markup) {
|
|
2078
|
-
const status = {
|
|
2079
|
-
imports,
|
|
2080
|
-
props: current.props || [],
|
|
2081
|
-
contextProps: current.contextProps || [],
|
|
2082
|
-
slotProps: current.slotProps || [],
|
|
2083
|
-
styleHash: current.style?.hash || "",
|
|
2084
|
-
varNames: {},
|
|
2085
|
-
fragmentStack: [],
|
|
2086
|
-
forVarNames: [],
|
|
2087
|
-
ns: false,
|
|
2088
|
-
preserveWhitespace: false
|
|
2089
|
-
};
|
|
2090
|
-
b.append("");
|
|
2091
|
-
b.append("/* User interface */");
|
|
2092
|
-
buildFragmentText(current.markup, status, b);
|
|
2093
|
-
b.append("");
|
|
2094
|
-
buildNode(current.markup, status, b, "$parent", "$anchor", true);
|
|
2095
|
-
}
|
|
2096
|
-
marker = i + "/* @render */".length;
|
|
2097
|
-
} else if (script.substring(i, i + "/* @end */".length) === "/* @end */") {
|
|
2098
|
-
b.append(script.substring(marker, i));
|
|
2099
|
-
currentIndex += 1;
|
|
2100
|
-
current = template.components[currentIndex];
|
|
2101
|
-
marker = i + "/* @end */".length;
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
b.append(script.substring(marker));
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
// src/compile/build/client/buildStyles.ts
|
|
2108
|
-
function buildStyles(style, styleHash) {
|
|
2109
|
-
const b = new Builder();
|
|
2110
|
-
for (let block of style.blocks) {
|
|
2111
|
-
buildStyleBlock(block, b, styleHash);
|
|
2112
|
-
}
|
|
2113
|
-
return b.toString();
|
|
2114
|
-
}
|
|
2115
|
-
var globalStyleRegex = /\:global\((.+)\)/;
|
|
2116
|
-
function buildStyleBlock(block, b, styleHash) {
|
|
2117
|
-
if (block.selector.startsWith("@")) {
|
|
2118
|
-
b.append(`${block.selector} {`);
|
|
2119
|
-
} else {
|
|
2120
|
-
const selectors = block.selector.split(/([\s*,>+~])/).filter((s) => !!s.trim()).map((s) => {
|
|
2121
|
-
if (s.length === 1 && "*,>+~".includes(s)) {
|
|
2122
|
-
return s;
|
|
2123
|
-
} else if (globalStyleRegex.test(s)) {
|
|
2124
|
-
return s.match(globalStyleRegex)[1];
|
|
2125
|
-
} else {
|
|
2126
|
-
return `${s}.torp-${styleHash}`;
|
|
2127
|
-
}
|
|
2128
|
-
});
|
|
2129
|
-
b.append(`${selectors.join(" ")} {`);
|
|
2130
|
-
}
|
|
2131
|
-
for (let attribute of block.attributes) {
|
|
2132
|
-
buildStyleAttribute(attribute, b);
|
|
2133
|
-
}
|
|
2134
|
-
for (let child of block.children) {
|
|
2135
|
-
buildStyleBlock(child, b, styleHash);
|
|
2136
|
-
}
|
|
2137
|
-
b.append(`}`);
|
|
2138
|
-
}
|
|
2139
|
-
function buildStyleAttribute(attribute, b) {
|
|
2140
|
-
b.append(`${attribute.name}: ${attribute.value};`);
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
// src/compile/build/server/buildServerComponentNode.ts
|
|
2144
|
-
function buildServerComponentNode(node, status, b) {
|
|
2145
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2146
|
-
if (status.output) {
|
|
2147
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2148
|
-
status.output = "";
|
|
2149
|
-
}
|
|
2150
|
-
const componentHasProps = node.attributes.length;
|
|
2151
|
-
const propsName = componentHasProps ? nextVarName("props", status) : "undefined";
|
|
2152
|
-
if (componentHasProps) {
|
|
2153
|
-
b.append(`const ${propsName}: any = {};`);
|
|
2154
|
-
for (let { name, value } of node.attributes) {
|
|
2155
|
-
if (name.startsWith("{") && name.endsWith("}")) {
|
|
2156
|
-
name = name.substring(1, name.length - 1);
|
|
2157
|
-
const propName = name.split(".").at(-1);
|
|
2158
|
-
b.append(`${propsName}["${propName}"] = ${name};`);
|
|
2159
|
-
} else if (name === ":class" && value != null && isFullyReactive(value)) {
|
|
2160
|
-
status.imports.add("t_class");
|
|
2161
|
-
value = value.substring(1, value.length - 1);
|
|
2162
|
-
if (node.scopeStyles) {
|
|
2163
|
-
value += `, "torp-${status.styleHash}"`;
|
|
2164
|
-
}
|
|
2165
|
-
b.append(`${propsName}["class"] = t_class(${value});`);
|
|
2166
|
-
} else if (name === ":style" && value != null && isFullyReactive(value)) {
|
|
2167
|
-
status.imports.add("t_style");
|
|
2168
|
-
value = value.substring(1, value.length - 1);
|
|
2169
|
-
b.append(`${propsName}["style"] = t_style(${value});`);
|
|
2170
|
-
} else if (value != null) {
|
|
2171
|
-
let fullyReactive = isFullyReactive(value);
|
|
2172
|
-
let partlyReactive = isReactive(value);
|
|
2173
|
-
if (fullyReactive) {
|
|
2174
|
-
value = value.substring(1, value.length - 1);
|
|
2175
|
-
} else if (partlyReactive) {
|
|
2176
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
2177
|
-
}
|
|
2178
|
-
if (name === "class") {
|
|
2179
|
-
b.append(`"${trimQuotes(value)} torp-${status.styleHash}"`);
|
|
2180
|
-
}
|
|
2181
|
-
b.append(`${propsName}["${name}"] = ${value};`);
|
|
2182
|
-
} else {
|
|
2183
|
-
b.append(`${propsName}["${name}"] = true;`);
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
const componentHasSlots = node.children.length;
|
|
2188
|
-
const slotsName = componentHasSlots ? nextVarName("slots", status) : "undefined";
|
|
2189
|
-
if (componentHasSlots) {
|
|
2190
|
-
b.append(`const ${slotsName}: Record<string, ServerSlotRender> = {};`);
|
|
2191
|
-
for (let slot of node.children) {
|
|
2192
|
-
if (isSpecialNode(slot)) {
|
|
2193
|
-
const nameAttribute = slot.attributes.find((a) => a.name === "name");
|
|
2194
|
-
const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
|
|
2195
|
-
const slotParams = [
|
|
2196
|
-
"// @ts-ignore\n$sprops?: Record<PropertyKey, any>",
|
|
2197
|
-
"// @ts-ignore\n$context?: Record<PropertyKey, any>"
|
|
2198
|
-
];
|
|
2199
|
-
b.append(`${slotsName}["${slotName}"] = (
|
|
2200
|
-
${slotParams.join(",\n")}
|
|
2201
|
-
) => {`);
|
|
2202
|
-
b.append(`let $output = "";`);
|
|
2203
|
-
for (let child of slot.children) {
|
|
2204
|
-
buildServerNode(child, status, b);
|
|
2205
|
-
}
|
|
2206
|
-
if (status.output) {
|
|
2207
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2208
|
-
status.output = "";
|
|
2209
|
-
}
|
|
2210
|
-
b.append("return $output;");
|
|
2211
|
-
b.append(`}`);
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
let componentName = node.tagName;
|
|
2216
|
-
if (componentName === ":component") {
|
|
2217
|
-
let selfAttribute = node.attributes.find((a) => a.name === "self");
|
|
2218
|
-
if (selfAttribute && selfAttribute.value) {
|
|
2219
|
-
componentName = trimMatched(selfAttribute.value, "{", "}");
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
let renderParams = `${propsName}, $context`;
|
|
2223
|
-
if (slotsName !== "undefined") {
|
|
2224
|
-
renderParams += `, ${slotsName}`;
|
|
2225
|
-
}
|
|
2226
|
-
b.append("");
|
|
2227
|
-
b.append(`$output += ${componentName}(${renderParams})`);
|
|
2228
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2229
|
-
status.output += ANCHOR_COMMENT;
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
|
-
// src/compile/build/server/buildServerAwaitNode.ts
|
|
2233
|
-
function buildServerAwaitNode(node, status, b) {
|
|
2234
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2235
|
-
if (status.output) {
|
|
2236
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2237
|
-
status.output = "";
|
|
2238
|
-
}
|
|
2239
|
-
for (let branch of node.children) {
|
|
2240
|
-
if (isControlNode(branch) && branch.operation === "@await") {
|
|
2241
|
-
buildServerAwaitBranch(branch, status, b);
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2245
|
-
status.output += ANCHOR_COMMENT;
|
|
2246
|
-
}
|
|
2247
|
-
function buildServerAwaitBranch(node, status, b) {
|
|
2248
|
-
for (let child of node.children) {
|
|
2249
|
-
buildServerNode(child, status, b);
|
|
2250
|
-
}
|
|
2251
|
-
if (status.output) {
|
|
2252
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2253
|
-
status.output = "";
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
// src/compile/build/server/buildServerForNode.ts
|
|
2258
|
-
function buildServerForNode(node, status, b) {
|
|
2259
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2260
|
-
if (status.output) {
|
|
2261
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2262
|
-
status.output = "";
|
|
2263
|
-
}
|
|
2264
|
-
for (let branch of node.children) {
|
|
2265
|
-
if (isControlNode(branch)) {
|
|
2266
|
-
buildServerForBranch(branch, status, b);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2270
|
-
status.output += ANCHOR_COMMENT;
|
|
2271
|
-
}
|
|
2272
|
-
function buildServerForBranch(node, status, b) {
|
|
2273
|
-
b.append(`${node.statement} {`);
|
|
2274
|
-
status.output += HYDRATION_BREAK_COMMENT;
|
|
2275
|
-
for (let child of node.children) {
|
|
2276
|
-
buildServerNode(child, status, b);
|
|
2277
|
-
}
|
|
2278
|
-
if (status.output) {
|
|
2279
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2280
|
-
status.output = "";
|
|
2281
|
-
}
|
|
2282
|
-
b.append("}");
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
// src/compile/build/server/buildServerHtmlNode.ts
|
|
2286
|
-
function buildServerHtmlNode(node, status) {
|
|
2287
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2288
|
-
for (let branch of node.children) {
|
|
2289
|
-
if (isControlNode(branch)) {
|
|
2290
|
-
status.output += `\${${branch.statement}}`;
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2294
|
-
status.output += ANCHOR_COMMENT;
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
// src/compile/build/server/buildServerIfNode.ts
|
|
2298
|
-
function buildServerIfNode(node, status, b) {
|
|
2299
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2300
|
-
if (status.output) {
|
|
2301
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2302
|
-
status.output = "";
|
|
2303
|
-
}
|
|
2304
|
-
for (let branch of node.children) {
|
|
2305
|
-
if (isControlNode(branch)) {
|
|
2306
|
-
buildServerIfBranch(branch, status, b);
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2310
|
-
status.output += ANCHOR_COMMENT;
|
|
2311
|
-
}
|
|
2312
|
-
function buildServerIfBranch(node, status, b) {
|
|
2313
|
-
b.append(`${node.statement} {`);
|
|
2314
|
-
status.output += HYDRATION_BREAK_COMMENT;
|
|
2315
|
-
for (let child of node.children) {
|
|
2316
|
-
buildServerNode(child, status, b);
|
|
2317
|
-
}
|
|
2318
|
-
if (status.output) {
|
|
2319
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2320
|
-
status.output = "";
|
|
2321
|
-
}
|
|
2322
|
-
b.append("}");
|
|
2323
|
-
}
|
|
2324
|
-
|
|
2325
|
-
// src/compile/build/server/buildServerReplaceNode.ts
|
|
2326
|
-
function buildServerReplaceNode(node, status, b) {
|
|
2327
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2328
|
-
if (status.output) {
|
|
2329
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2330
|
-
status.output = "";
|
|
2331
|
-
}
|
|
2332
|
-
for (let branch of node.children) {
|
|
2333
|
-
if (isControlNode(branch)) {
|
|
2334
|
-
buildServerReplaceBranch(branch, status, b);
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2338
|
-
status.output += ANCHOR_COMMENT;
|
|
2339
|
-
}
|
|
2340
|
-
function buildServerReplaceBranch(node, status, b) {
|
|
2341
|
-
b.append(`${node.statement};`);
|
|
2342
|
-
for (let child of node.children) {
|
|
2343
|
-
buildServerNode(child, status, b);
|
|
2344
|
-
}
|
|
2345
|
-
if (status.output) {
|
|
2346
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2347
|
-
status.output = "";
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
// src/compile/build/server/buildServerScriptNode.ts
|
|
2352
|
-
function buildServerScriptNode(node, b) {
|
|
2353
|
-
b.append(`${maybeAppend2(node.statement, ";")}`);
|
|
2354
|
-
}
|
|
2355
|
-
function maybeAppend2(text, end) {
|
|
2356
|
-
if (!text.endsWith(end)) {
|
|
2357
|
-
text += end;
|
|
2358
|
-
}
|
|
2359
|
-
return text;
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
// src/compile/build/server/buildServerSwitchNode.ts
|
|
2363
|
-
function buildServerSwitchNode(node, status, b) {
|
|
2364
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2365
|
-
if (status.output) {
|
|
2366
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2367
|
-
status.output = "";
|
|
2368
|
-
}
|
|
2369
|
-
b.append(`${node.statement} {`);
|
|
2370
|
-
for (let branch of node.children.filter((c) => isControlNode(c))) {
|
|
2371
|
-
if (isControlNode(branch)) {
|
|
2372
|
-
buildServerSwitchBranch(branch, status, b);
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
|
-
b.append("}");
|
|
2376
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2377
|
-
status.output += ANCHOR_COMMENT;
|
|
2378
|
-
}
|
|
2379
|
-
function buildServerSwitchBranch(node, status, b) {
|
|
2380
|
-
b.append(`${node.statement} {`);
|
|
2381
|
-
status.output += HYDRATION_BREAK_COMMENT;
|
|
2382
|
-
for (let child of node.children) {
|
|
2383
|
-
buildServerNode(child, status, b);
|
|
2384
|
-
}
|
|
2385
|
-
if (status.output) {
|
|
2386
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2387
|
-
status.output = "";
|
|
2388
|
-
}
|
|
2389
|
-
b.append("break;");
|
|
2390
|
-
b.append("}");
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
// src/compile/build/server/buildServerControlNode.ts
|
|
2394
|
-
function buildServerControlNode(node, status, b) {
|
|
2395
|
-
switch (node.operation) {
|
|
2396
|
-
case "@if group": {
|
|
2397
|
-
buildServerIfNode(node, status, b);
|
|
2398
|
-
break;
|
|
2399
|
-
}
|
|
2400
|
-
case "@if":
|
|
2401
|
-
case "@else if":
|
|
2402
|
-
case "@else": {
|
|
2403
|
-
break;
|
|
2404
|
-
}
|
|
2405
|
-
case "@switch group": {
|
|
2406
|
-
buildServerSwitchNode(node, status, b);
|
|
2407
|
-
break;
|
|
2408
|
-
}
|
|
2409
|
-
case "@case":
|
|
2410
|
-
case "@default": {
|
|
2411
|
-
break;
|
|
2412
|
-
}
|
|
2413
|
-
case "@for group": {
|
|
2414
|
-
buildServerForNode(node, status, b);
|
|
2415
|
-
break;
|
|
2416
|
-
}
|
|
2417
|
-
case "@for":
|
|
2418
|
-
case "@key": {
|
|
2419
|
-
break;
|
|
2420
|
-
}
|
|
2421
|
-
case "@await group": {
|
|
2422
|
-
buildServerAwaitNode(node, status, b);
|
|
2423
|
-
break;
|
|
2424
|
-
}
|
|
2425
|
-
case "@await":
|
|
2426
|
-
case "@then":
|
|
2427
|
-
case "@catch": {
|
|
2428
|
-
break;
|
|
2429
|
-
}
|
|
2430
|
-
case "@replace group": {
|
|
2431
|
-
buildServerReplaceNode(node, status, b);
|
|
2432
|
-
break;
|
|
2433
|
-
}
|
|
2434
|
-
case "@replace": {
|
|
2435
|
-
break;
|
|
2436
|
-
}
|
|
2437
|
-
case "@html group": {
|
|
2438
|
-
buildServerHtmlNode(node, status);
|
|
2439
|
-
break;
|
|
2440
|
-
}
|
|
2441
|
-
case "@html": {
|
|
2442
|
-
break;
|
|
2443
|
-
}
|
|
2444
|
-
case "@const": {
|
|
2445
|
-
if (status.output) {
|
|
2446
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2447
|
-
status.output = "";
|
|
2448
|
-
}
|
|
2449
|
-
buildServerScriptNode(node, b);
|
|
2450
|
-
break;
|
|
2451
|
-
}
|
|
2452
|
-
case "@function":
|
|
2453
|
-
case "@async function": {
|
|
2454
|
-
if (status.output) {
|
|
2455
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2456
|
-
status.output = "";
|
|
2457
|
-
}
|
|
2458
|
-
b.append("");
|
|
2459
|
-
buildServerScriptNode(node, b);
|
|
2460
|
-
b.append("");
|
|
2461
|
-
break;
|
|
2462
|
-
}
|
|
2463
|
-
case "@console":
|
|
2464
|
-
case "@debugger": {
|
|
2465
|
-
break;
|
|
2466
|
-
}
|
|
2467
|
-
default: {
|
|
2468
|
-
throw new Error(`Invalid operation: ${node.operation}`);
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
// src/compile/utils/voidTags.ts
|
|
2474
|
-
var voidTags = [
|
|
2475
|
-
"area",
|
|
2476
|
-
"base",
|
|
2477
|
-
"br",
|
|
2478
|
-
"col",
|
|
2479
|
-
"embed",
|
|
2480
|
-
"hr",
|
|
2481
|
-
"img",
|
|
2482
|
-
"input",
|
|
2483
|
-
"link",
|
|
2484
|
-
"meta",
|
|
2485
|
-
"param",
|
|
2486
|
-
"source",
|
|
2487
|
-
"track",
|
|
2488
|
-
"wbr"
|
|
2489
|
-
];
|
|
2490
|
-
var voidTags_default = voidTags;
|
|
2491
|
-
|
|
2492
|
-
// src/compile/build/server/buildServerElementNode.ts
|
|
2493
|
-
function buildServerElementNode(node, status, b) {
|
|
2494
|
-
let attributes = buildElementAttributes2(node, status);
|
|
2495
|
-
if (attributes.length) {
|
|
2496
|
-
attributes = " " + attributes;
|
|
2497
|
-
}
|
|
2498
|
-
let tagName = node.tagName;
|
|
2499
|
-
if (tagName === ":element") {
|
|
2500
|
-
let selfAttribute = node.attributes.find((a) => a.name === "self");
|
|
2501
|
-
if (selfAttribute) {
|
|
2502
|
-
tagName = `$${selfAttribute.value}`;
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
status.output += `<${tagName}${attributes}>`;
|
|
2506
|
-
if (!voidTags_default.includes(tagName)) {
|
|
2507
|
-
const oldPreserveWhitespace = status.preserveWhitespace;
|
|
2508
|
-
status.preserveWhitespace = ["pre", "code"].includes(tagName);
|
|
2509
|
-
for (let child of node.children) {
|
|
2510
|
-
buildServerNode(child, status, b);
|
|
2511
|
-
}
|
|
2512
|
-
status.preserveWhitespace = oldPreserveWhitespace;
|
|
2513
|
-
status.output += `</${tagName}>`;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
function buildElementAttributes2(node, status) {
|
|
2517
|
-
let needsClass = node.scopeStyles;
|
|
2518
|
-
let attributes = [];
|
|
2519
|
-
for (let { name, value } of node.attributes) {
|
|
2520
|
-
if (name === "self" && node.tagName === ":element") {
|
|
2521
|
-
} else if (name.startsWith("on") || name.startsWith(":on")) {
|
|
2522
|
-
} else if (name.startsWith(":transition") && value) {
|
|
2523
|
-
value = value.substring(1, value.length - 1).trim();
|
|
2524
|
-
value = value.split(",")[0].trim();
|
|
2525
|
-
if (value.startsWith("[")) {
|
|
2526
|
-
value = value.substring(1);
|
|
2527
|
-
} else {
|
|
2528
|
-
value = value + "[0]";
|
|
2529
|
-
}
|
|
2530
|
-
attributes.push(
|
|
2531
|
-
`style="\${Object.entries(${value}).map(([k, v]) => \`\${k}: \${v}\`).join("; ")}"`
|
|
2532
|
-
);
|
|
2533
|
-
} else if (name.startsWith("{") && name.endsWith("}")) {
|
|
2534
|
-
name = name.substring(1, name.length - 1);
|
|
2535
|
-
const propName = name.split(".").at(-1);
|
|
2536
|
-
status.imports.add("t_attr");
|
|
2537
|
-
attributes.push(`${propName}="\${t_attr(${name})}"`);
|
|
2538
|
-
} else if (value != null && isFullyReactive(value)) {
|
|
2539
|
-
value = value.substring(1, value.length - 1);
|
|
2540
|
-
if (name === "&ref" || name === "&value" || name === "&checked" || name === "&group") {
|
|
2541
|
-
let defaultValue = "";
|
|
2542
|
-
let typeAttribute = node.attributes.find((a) => a.name === "type");
|
|
2543
|
-
if (typeAttribute && typeAttribute.value) {
|
|
2544
|
-
switch (trimQuotes(typeAttribute.value)) {
|
|
2545
|
-
case "number": {
|
|
2546
|
-
defaultValue = "0";
|
|
2547
|
-
break;
|
|
2548
|
-
}
|
|
2549
|
-
case "checkbox": {
|
|
2550
|
-
defaultValue = "false";
|
|
2551
|
-
break;
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
if (!defaultValue) {
|
|
2556
|
-
status.imports.add("t_attr");
|
|
2557
|
-
value = `t_attr(${value})`;
|
|
2558
|
-
defaultValue = '""';
|
|
2559
|
-
}
|
|
2560
|
-
let valueOrDefault = `${value} || ${defaultValue}`;
|
|
2561
|
-
const propName = name.substring(1);
|
|
2562
|
-
attributes.push(`${propName}="\${${valueOrDefault}}"`);
|
|
2563
|
-
} else if (name === ":class") {
|
|
2564
|
-
status.imports.add("t_class");
|
|
2565
|
-
if (node.scopeStyles) {
|
|
2566
|
-
value += `, "torp-${status.styleHash}"`;
|
|
2567
|
-
needsClass = false;
|
|
2568
|
-
}
|
|
2569
|
-
attributes.push(`class="\${t_class(${value})}"`);
|
|
2570
|
-
} else if (name === ":style") {
|
|
2571
|
-
status.imports.add("t_style");
|
|
2572
|
-
attributes.push(`style="\${t_style(${value})}"`);
|
|
2573
|
-
} else {
|
|
2574
|
-
status.imports.add("t_attr");
|
|
2575
|
-
attributes.push(`\${${value} ? \`${name}="\${t_attr(${value})}"\` : ''}`);
|
|
2576
|
-
}
|
|
2577
|
-
} else if (value != null && isReactive(value)) {
|
|
2578
|
-
status.imports.add("t_attr");
|
|
2579
|
-
attributes.push(
|
|
2580
|
-
`${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`
|
|
2581
|
-
);
|
|
2582
|
-
} else if (name === "class" && node.scopeStyles) {
|
|
2583
|
-
value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
2584
|
-
attributes.push(`${name}="${trimQuotes(value).replaceAll('"', """)}"`);
|
|
2585
|
-
needsClass = false;
|
|
2586
|
-
} else if (value != null) {
|
|
2587
|
-
attributes.push(`${name}="${trimQuotes(value).replaceAll('"', """)}"`);
|
|
2588
|
-
} else {
|
|
2589
|
-
attributes.push(`${name}`);
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
if (needsClass) {
|
|
2593
|
-
attributes.push(`class="torp-${status.styleHash}"`);
|
|
2594
|
-
}
|
|
2595
|
-
return attributes.join(" ");
|
|
2596
|
-
}
|
|
2597
|
-
|
|
2598
|
-
// src/compile/build/server/buildServerRootNode.ts
|
|
2599
|
-
function buildServerRootNode(node, status, b) {
|
|
2600
|
-
for (let child of node.children) {
|
|
2601
|
-
buildServerNode(child, status, b);
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
// src/compile/build/server/buildServerSlotNode.ts
|
|
2606
|
-
function buildServerSlotNode(node, status, b) {
|
|
2607
|
-
status.output += HYDRATION_START_COMMENT;
|
|
2608
|
-
if (status.output) {
|
|
2609
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2610
|
-
status.output = "";
|
|
2611
|
-
}
|
|
2612
|
-
let slotName = node.attributes.find((a) => a.name === "name")?.value;
|
|
2613
|
-
slotName = slotName ? trimQuotes(slotName) : "_";
|
|
2614
|
-
const propsName = nextVarName("sprops", status);
|
|
2615
|
-
const slotAttributes = node.attributes.filter((a) => a.name !== "name");
|
|
2616
|
-
const slotHasProps = slotAttributes.length;
|
|
2617
|
-
if (slotHasProps) {
|
|
2618
|
-
b.append(`const ${propsName}: any = {};`);
|
|
2619
|
-
for (let { name, value } of slotAttributes) {
|
|
2620
|
-
if (name.startsWith("{") && name.endsWith("}")) {
|
|
2621
|
-
name = name.substring(1, name.length - 1);
|
|
2622
|
-
const propName = name.split(".").at(-1);
|
|
2623
|
-
b.append(`${propsName}["${propName}"] = ${name};`);
|
|
2624
|
-
} else if (value != null) {
|
|
2625
|
-
let fullyReactive = isFullyReactive(value);
|
|
2626
|
-
let partlyReactive = isReactive(value);
|
|
2627
|
-
if (fullyReactive) {
|
|
2628
|
-
value = value.substring(1, value.length - 1);
|
|
2629
|
-
} else if (partlyReactive) {
|
|
2630
|
-
value = `\`${trimQuotes(value).replaceAll("{", "${")}\``;
|
|
2631
|
-
}
|
|
2632
|
-
b.append(`${propsName}["${name}"] = ${value};`);
|
|
2633
|
-
} else {
|
|
2634
|
-
b.append(`${propsName}["${name}"] = true;`);
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
b.append(`if ($slots && $slots["${slotName}"]) {`);
|
|
2639
|
-
b.append(
|
|
2640
|
-
`$output += $slots["${slotName}"](${slotHasProps ? propsName : "undefined"}, $context);`
|
|
2641
|
-
);
|
|
2642
|
-
const fill = node.children.find((c) => isSpecialNode(c) && c.tagName === ":fill");
|
|
2643
|
-
if (fill && isSpecialNode(fill) && fill.children.length) {
|
|
2644
|
-
b.append(`} else {`);
|
|
2645
|
-
for (let child of fill.children) {
|
|
2646
|
-
buildServerNode(child, status, b);
|
|
2647
|
-
}
|
|
2648
|
-
if (status.output) {
|
|
2649
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2650
|
-
status.output = "";
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
b.append(`}`);
|
|
2654
|
-
status.output += HYDRATION_END_COMMENT;
|
|
2655
|
-
status.output += ANCHOR_COMMENT;
|
|
2656
|
-
}
|
|
2657
|
-
|
|
2658
|
-
// src/compile/build/server/buildServerSpecialNode.ts
|
|
2659
|
-
function buildServerSpecialNode(node, status, b) {
|
|
2660
|
-
switch (node.tagName) {
|
|
2661
|
-
case ":slot": {
|
|
2662
|
-
buildServerSlotNode(node, status, b);
|
|
2663
|
-
break;
|
|
2664
|
-
}
|
|
2665
|
-
case ":element": {
|
|
2666
|
-
buildServerElementNode(node, status, b);
|
|
2667
|
-
break;
|
|
2668
|
-
}
|
|
2669
|
-
case ":component": {
|
|
2670
|
-
buildServerComponentNode(node, status, b);
|
|
2671
|
-
break;
|
|
2672
|
-
}
|
|
2673
|
-
case ":head": {
|
|
2674
|
-
break;
|
|
2675
|
-
}
|
|
2676
|
-
case ":fill": {
|
|
2677
|
-
break;
|
|
2678
|
-
}
|
|
2679
|
-
default: {
|
|
2680
|
-
throw new Error(`Invalid special node: ${node.tagName}`);
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
|
|
2685
|
-
// src/compile/build/server/buildServerTextNode.ts
|
|
2686
|
-
function buildServerTextNode(node, status) {
|
|
2687
|
-
let content = node.content || "";
|
|
2688
|
-
if (!status.preserveWhitespace) {
|
|
2689
|
-
content = content.replaceAll(/\s+/g, " ");
|
|
2690
|
-
}
|
|
2691
|
-
let level = 0;
|
|
2692
|
-
for (let i = 0; i < content.length; i++) {
|
|
2693
|
-
const char = content[i];
|
|
2694
|
-
const nextChar = content[i + 1];
|
|
2695
|
-
if (char === "{") {
|
|
2696
|
-
level++;
|
|
2697
|
-
if (level === 1) {
|
|
2698
|
-
status.imports.add("t_fmt");
|
|
2699
|
-
status.output += "${t_fmt(";
|
|
2700
|
-
continue;
|
|
2701
|
-
}
|
|
2702
|
-
} else if (char === "}") {
|
|
2703
|
-
level--;
|
|
2704
|
-
if (level === 0) {
|
|
2705
|
-
status.output += ")";
|
|
2706
|
-
}
|
|
2707
|
-
} else if (char === "`" && level === 0) {
|
|
2708
|
-
status.output += "\\";
|
|
2709
|
-
} else if (level > 0) {
|
|
2710
|
-
if (char === "/" && nextChar === "/") {
|
|
2711
|
-
let start = i;
|
|
2712
|
-
i = content.indexOf("\n", i);
|
|
2713
|
-
status.output += escapeHtml(content.substring(start, i + 1));
|
|
2714
|
-
continue;
|
|
2715
|
-
} else if (char === "/" && nextChar === "*") {
|
|
2716
|
-
let start = i;
|
|
2717
|
-
i = content.indexOf("*/", i) + 1;
|
|
2718
|
-
status.output += escapeHtml(content.substring(start, i + 1));
|
|
2719
|
-
continue;
|
|
2720
|
-
} else if (char === '"' || char === "'") {
|
|
2721
|
-
let start = i;
|
|
2722
|
-
for (let j = i + 1; j < content.length; j++) {
|
|
2723
|
-
if (content[j] === char && content[j - 1] !== "\\") {
|
|
2724
|
-
i = j;
|
|
2725
|
-
status.output += escapeHtml(content.substring(start, i + 1));
|
|
2726
|
-
break;
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
continue;
|
|
2730
|
-
} else if (char === "`") {
|
|
2731
|
-
let start = i;
|
|
2732
|
-
let level2 = 0;
|
|
2733
|
-
for (let j = i + 1; j < content.length; j++) {
|
|
2734
|
-
if (content[j] === char && content[j - 1] !== "\\" && level2 === 0) {
|
|
2735
|
-
i = j;
|
|
2736
|
-
status.output += escapeHtml(content.substring(start, i + 1));
|
|
2737
|
-
break;
|
|
2738
|
-
} else if (content[j] === "{" && (level2 > 0 || content[j - 1] === "$")) {
|
|
2739
|
-
level2 += 1;
|
|
2740
|
-
} else if (content[j] === "}" && level2 > 0) {
|
|
2741
|
-
level2 -= 1;
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
continue;
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
status.output += char;
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
function escapeHtml(text) {
|
|
2751
|
-
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
2752
|
-
}
|
|
2753
|
-
|
|
2754
|
-
// src/compile/build/server/buildServerNode.ts
|
|
2755
|
-
function buildServerNode(node, status, b) {
|
|
2756
|
-
switch (node.type) {
|
|
2757
|
-
case "root": {
|
|
2758
|
-
buildServerRootNode(node, status, b);
|
|
2759
|
-
break;
|
|
2760
|
-
}
|
|
2761
|
-
case "control": {
|
|
2762
|
-
buildServerControlNode(node, status, b);
|
|
2763
|
-
break;
|
|
2764
|
-
}
|
|
2765
|
-
case "component": {
|
|
2766
|
-
buildServerComponentNode(node, status, b);
|
|
2767
|
-
break;
|
|
2768
|
-
}
|
|
2769
|
-
case "element": {
|
|
2770
|
-
buildServerElementNode(node, status, b);
|
|
2771
|
-
break;
|
|
2772
|
-
}
|
|
2773
|
-
case "text": {
|
|
2774
|
-
buildServerTextNode(node, status);
|
|
2775
|
-
break;
|
|
2776
|
-
}
|
|
2777
|
-
case "special": {
|
|
2778
|
-
buildServerSpecialNode(node, status, b);
|
|
2779
|
-
break;
|
|
2780
|
-
}
|
|
2781
|
-
default: {
|
|
2782
|
-
throw new Error(`Invalid node type: ${node.type}`);
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
|
|
2787
|
-
// src/compile/build/server/buildServerCode.ts
|
|
2788
|
-
var importsMap2 = {
|
|
2789
|
-
$watch: 'import { $watch } from "${folder}";',
|
|
2790
|
-
$unwrap: 'import { $unwrap } from "${folder}";',
|
|
2791
|
-
$run: 'import { $run } from "${folder}";',
|
|
2792
|
-
$mount: 'import { $mount } from "${folder}";',
|
|
2793
|
-
t_fmt: 'import { t_fmt } from "${folder}";',
|
|
2794
|
-
t_attr: 'import { t_attr } from "${folder}";',
|
|
2795
|
-
t_class: 'import { t_class } from "${folder}";',
|
|
2796
|
-
t_style: 'import { t_style } from "${folder}";',
|
|
2797
|
-
ServerSlotRender: 'import { type ServerSlotRender } from "${folder}";'
|
|
2798
|
-
};
|
|
2799
|
-
function buildServerCode(template, options) {
|
|
2800
|
-
let b = new Builder();
|
|
2801
|
-
let imports = /* @__PURE__ */ new Set();
|
|
2802
|
-
imports.add("ServerSlotRender");
|
|
2803
|
-
buildServerTemplate(template, imports, b, options);
|
|
2804
|
-
if (imports.size) {
|
|
2805
|
-
b.prepend("");
|
|
2806
|
-
for (let imp of Array.from(imports).sort().reverse()) {
|
|
2807
|
-
imp = importsMap2[imp] || imp;
|
|
2808
|
-
b.prepend(imp.replace("${folder}", options?.renderFolder || "@torpor/view/ssr"));
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
return b.toString();
|
|
2812
|
-
}
|
|
2813
|
-
function buildServerTemplate(template, imports, b, options) {
|
|
2814
|
-
let script = template.script || "";
|
|
2815
|
-
if (/\$watch\b/.test(script)) imports.add("$watch");
|
|
2816
|
-
if (/\$unwrap\b/.test(script)) imports.add("$unwrap");
|
|
2817
|
-
if (/\$run\b/.test(script)) imports.add("$run");
|
|
2818
|
-
if (/\$mount\b/.test(script)) imports.add("$mount");
|
|
2819
|
-
let currentIndex = 0;
|
|
2820
|
-
let current = template.components[0];
|
|
2821
|
-
let marker = 0;
|
|
2822
|
-
for (let i = 0; i < script.length; i++) {
|
|
2823
|
-
if (script.substring(i, i + "/* @params */".length) === "/* @params */") {
|
|
2824
|
-
b.append(script.substring(marker, i));
|
|
2825
|
-
let params = [
|
|
2826
|
-
current.params ?? `${current.props?.length ? "$props" : "// @ts-ignore\n$props?"}: Record<PropertyKey, any>`,
|
|
2827
|
-
`${current.contextProps?.length ? "" : "// @ts-ignore\n"}$context?: Record<PropertyKey, any>`,
|
|
2828
|
-
`${current.slotProps?.length ? "" : "// @ts-ignore\n"}$slots?: Record<string, ServerSlotRender>`
|
|
2829
|
-
];
|
|
2830
|
-
b.append(params.join(",\n"));
|
|
2831
|
-
marker = i + "/* @params */".length;
|
|
2832
|
-
} else if (script.substring(i, i + "/* @start */".length) === "/* @start */") {
|
|
2833
|
-
b.append(script.substring(marker, i));
|
|
2834
|
-
if (current.props?.length) {
|
|
2835
|
-
b.append(`$props ??= {};`);
|
|
2836
|
-
}
|
|
2837
|
-
if (current.contextProps?.length) {
|
|
2838
|
-
b.append(`$context = Object.assign({}, $context);`);
|
|
2839
|
-
}
|
|
2840
|
-
marker = i + "/* @start */".length;
|
|
2841
|
-
} else if (script.substring(i, i + "/* @render */".length) === "/* @render */") {
|
|
2842
|
-
b.append(script.substring(marker, i));
|
|
2843
|
-
if (current.markup) {
|
|
2844
|
-
const status = {
|
|
2845
|
-
imports,
|
|
2846
|
-
output: "",
|
|
2847
|
-
styleHash: current.style?.hash || "",
|
|
2848
|
-
varNames: {},
|
|
2849
|
-
preserveWhitespace: false,
|
|
2850
|
-
options
|
|
2851
|
-
};
|
|
2852
|
-
b.append("");
|
|
2853
|
-
b.append("/* User interface */");
|
|
2854
|
-
b.append(`let $output = "";`);
|
|
2855
|
-
buildServerNode(current.markup, status, b);
|
|
2856
|
-
if (status.output) {
|
|
2857
|
-
b.append(`$output += \`${status.output}\`;`);
|
|
2858
|
-
status.output = "";
|
|
2859
|
-
}
|
|
2860
|
-
}
|
|
2861
|
-
marker = i + "/* @render */".length;
|
|
2862
|
-
} else if (script.substring(i, i + "/* @end */".length) === "/* @end */") {
|
|
2863
|
-
b.append(script.substring(marker, i));
|
|
2864
|
-
b.append("return $output;");
|
|
2865
|
-
currentIndex += 1;
|
|
2866
|
-
current = template.components[currentIndex];
|
|
2867
|
-
marker = i + "/* @end */".length;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
b.append(script.substring(marker));
|
|
2871
|
-
}
|
|
2872
|
-
|
|
2873
|
-
// src/compile/build.ts
|
|
2874
|
-
function build(template, options) {
|
|
2875
|
-
let code = options?.server ? buildServerCode(template, options) : buildCode(template, options);
|
|
2876
|
-
let styles = template.components.map(
|
|
2877
|
-
(c) => c.style ? { style: buildStyles(c.style, c.style.hash), hash: c.style.hash } : void 0
|
|
2878
|
-
).filter((c) => c !== void 0);
|
|
2879
|
-
return {
|
|
2880
|
-
code,
|
|
2881
|
-
styles
|
|
2882
|
-
};
|
|
2883
|
-
}
|
|
2884
|
-
|
|
2885
|
-
// src/compile/buildType.ts
|
|
2886
|
-
function buildType(template, options) {
|
|
2887
|
-
let b = new Builder();
|
|
2888
|
-
b.append(`import { type SlotRender } from "${options?.renderFolder || "@torpor/view"}";`);
|
|
2889
|
-
for (let component of template.components) {
|
|
2890
|
-
b.append("");
|
|
2891
|
-
b.append(`
|
|
2892
|
-
/**
|
|
2893
|
-
* Mounts or hydrates the component into the supplied parent node.
|
|
2894
|
-
* @param $parent -- The parent node.
|
|
2895
|
-
* @param $anchor -- The node to mount the component before.
|
|
2896
|
-
* @param $props -- The values that have been passed into the component as properties.
|
|
2897
|
-
* @param $context -- Values that have been passed into the component from its ancestors.
|
|
2898
|
-
* @param $slots -- Functions for rendering children into slot nodes within the component.
|
|
2899
|
-
*/
|
|
2900
|
-
${component.default ? "declare" : "export declare"} function ${component.name}(
|
|
2901
|
-
$parent: ParentNode,
|
|
2902
|
-
$anchor: Node | null,
|
|
2903
|
-
${component.params || "$props?: Record<PropertyKey, any>"},
|
|
2904
|
-
$context?: Record<PropertyKey, any>,
|
|
2905
|
-
$slots?: Record<string, SlotRender>,
|
|
2906
|
-
): void;
|
|
2907
|
-
`);
|
|
2908
|
-
if (component.default) {
|
|
2909
|
-
b.append(`export default ${component.name};`);
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
return b.toString();
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
// src/compile/types/nodes/isSpaceNode.ts
|
|
2916
|
-
function isSpaceNode(node) {
|
|
2917
|
-
return isTextNode(node) && isSpace(node.content);
|
|
2918
|
-
}
|
|
2919
|
-
|
|
2920
|
-
// src/compile/utils/trimStart.ts
|
|
2921
|
-
function trimStart(text, char) {
|
|
2922
|
-
let start = 0;
|
|
2923
|
-
while (text[start] === char) {
|
|
2924
|
-
start += 1;
|
|
2925
|
-
}
|
|
2926
|
-
return text.substring(start);
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
// src/compile/parse/utils/consumeSpace.ts
|
|
2930
|
-
function consumeSpace(status) {
|
|
2931
|
-
const start = status.i;
|
|
2932
|
-
for (status.i; status.i < status.source.length; status.i++) {
|
|
2933
|
-
if (!isSpaceChar(status.source, status.i)) {
|
|
2934
|
-
return status.source.substring(start, status.i);
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
return "";
|
|
2938
|
-
}
|
|
2939
|
-
|
|
2940
|
-
// src/compile/parse/addSpaceElement.ts
|
|
2941
|
-
function addSpaceElement(parent, status) {
|
|
2942
|
-
const content = consumeSpace(status);
|
|
2943
|
-
if (content) {
|
|
2944
|
-
const previousNode = parent.children[parent.children.length - 1];
|
|
2945
|
-
if (previousNode && isTextNode(previousNode)) {
|
|
2946
|
-
previousNode.content += content;
|
|
2947
|
-
} else {
|
|
2948
|
-
const space = {
|
|
2949
|
-
type: "text",
|
|
2950
|
-
content
|
|
2951
|
-
};
|
|
2952
|
-
parent.children.push(space);
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
// src/compile/parse/utils/accept.ts
|
|
2958
|
-
function accept(value, status, advance = true) {
|
|
2959
|
-
const check = status.source.substring(status.i, status.i + value.length);
|
|
2960
|
-
if (check == value) {
|
|
2961
|
-
status.i += advance ? value.length : 0;
|
|
2962
|
-
return true;
|
|
2963
|
-
}
|
|
2964
|
-
return false;
|
|
2965
|
-
}
|
|
2966
|
-
|
|
2967
|
-
// src/compile/parse/parseInlineScript.ts
|
|
2968
|
-
function parseInlineScript(status) {
|
|
2969
|
-
const start = status.i;
|
|
2970
|
-
let braceCount = 0;
|
|
2971
|
-
while (status.i < status.source.length) {
|
|
2972
|
-
if (accept("{", status)) {
|
|
2973
|
-
braceCount += 1;
|
|
2974
|
-
} else if (accept("}", status)) {
|
|
2975
|
-
if (braceCount > 0) {
|
|
2976
|
-
braceCount -= 1;
|
|
2977
|
-
} else {
|
|
2978
|
-
return status.source.substring(start, status.i - 1);
|
|
2979
|
-
}
|
|
2980
|
-
} else if (accept('"', status) || accept("'", status)) {
|
|
2981
|
-
const char = status.source[status.i - 1];
|
|
2982
|
-
for (let j = status.i; j < status.source.length; j++) {
|
|
2983
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\") {
|
|
2984
|
-
status.i = j + 1;
|
|
2985
|
-
break;
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
} else if (accept("`", status)) {
|
|
2989
|
-
const char = status.source[status.i - 1];
|
|
2990
|
-
let level2 = 0;
|
|
2991
|
-
for (let j = status.i; j < status.source.length; j++) {
|
|
2992
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
|
|
2993
|
-
status.i = j + 1;
|
|
2994
|
-
break;
|
|
2995
|
-
} else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
|
|
2996
|
-
level2 += 1;
|
|
2997
|
-
} else if (status.source[j] === "}" && level2 > 0) {
|
|
2998
|
-
level2 -= 1;
|
|
2999
|
-
}
|
|
3000
|
-
}
|
|
3001
|
-
} else if (accept("//", status)) {
|
|
3002
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3003
|
-
} else if (accept("/*", status)) {
|
|
3004
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3005
|
-
} else {
|
|
3006
|
-
status.i += 1;
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
return "";
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
// src/compile/parse/utils/isAlphaNumericChar.ts
|
|
3013
|
-
function isAlphaNumericChar(text, index) {
|
|
3014
|
-
let code = text.charCodeAt(index);
|
|
3015
|
-
return (
|
|
3016
|
-
// 0-9
|
|
3017
|
-
code > 47 && code < 58 || // A-Z
|
|
3018
|
-
code > 64 && code < 91 || // a-z
|
|
3019
|
-
code > 96 && code < 123
|
|
3020
|
-
);
|
|
3021
|
-
}
|
|
3022
|
-
|
|
3023
|
-
// src/compile/parse/utils/consumeAlphaNumeric.ts
|
|
3024
|
-
function consumeAlphaNumeric(status) {
|
|
3025
|
-
const start = status.i;
|
|
3026
|
-
for (status.i; status.i < status.source.length; status.i++) {
|
|
3027
|
-
if (!isAlphaNumericChar(status.source, status.i)) {
|
|
3028
|
-
return status.source.substring(start, status.i);
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
return "";
|
|
3032
|
-
}
|
|
3033
|
-
|
|
3034
|
-
// src/compile/parse/utils/consumeUntil.ts
|
|
3035
|
-
function consumeUntil(chars, status) {
|
|
3036
|
-
const start = status.i;
|
|
3037
|
-
for (status.i; status.i < status.source.length; status.i++) {
|
|
3038
|
-
if (chars.includes(status.source[status.i])) {
|
|
3039
|
-
return status.source.substring(start, status.i);
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3042
|
-
return "";
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
|
-
// src/compile/parse/parseTag.ts
|
|
3046
|
-
function parseTag(status) {
|
|
3047
|
-
accept("<", status);
|
|
3048
|
-
let closeTag = accept("/", status);
|
|
3049
|
-
consumeSpace(status);
|
|
3050
|
-
let special = accept(":", status);
|
|
3051
|
-
let tagName = consumeAlphaNumeric(status);
|
|
3052
|
-
if (special) {
|
|
3053
|
-
tagName = ":" + tagName;
|
|
3054
|
-
}
|
|
3055
|
-
if (closeTag) {
|
|
3056
|
-
tagName = "/" + tagName;
|
|
3057
|
-
}
|
|
3058
|
-
consumeSpace(status);
|
|
3059
|
-
let attributes = parseTagAttributes(status);
|
|
3060
|
-
let selfClosed = false;
|
|
3061
|
-
if (accept("/>", status)) {
|
|
3062
|
-
selfClosed = true;
|
|
3063
|
-
} else {
|
|
3064
|
-
accept(">", status);
|
|
3065
|
-
}
|
|
3066
|
-
if (closeTag) {
|
|
3067
|
-
selfClosed = true;
|
|
3068
|
-
}
|
|
3069
|
-
return {
|
|
3070
|
-
type: special ? "special" : "element",
|
|
3071
|
-
tagName,
|
|
3072
|
-
selfClosed: selfClosed || void 0,
|
|
3073
|
-
closed: selfClosed || void 0,
|
|
3074
|
-
attributes,
|
|
3075
|
-
children: []
|
|
3076
|
-
};
|
|
3077
|
-
}
|
|
3078
|
-
function parseTagAttributes(status) {
|
|
3079
|
-
let attributes = [];
|
|
3080
|
-
while (status.i < status.source.length) {
|
|
3081
|
-
consumeSpace(status);
|
|
3082
|
-
if (accept("@//", status)) {
|
|
3083
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3084
|
-
} else if (accept("@/*", status)) {
|
|
3085
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3086
|
-
} else if (accept("/>", status, false) || accept(">", status, false)) {
|
|
3087
|
-
break;
|
|
3088
|
-
} else {
|
|
3089
|
-
const attribute = parseAttribute(status);
|
|
3090
|
-
attributes.push(attribute);
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
return attributes;
|
|
3094
|
-
}
|
|
3095
|
-
function parseAttribute(status) {
|
|
3096
|
-
let name = consumeUntil("= \r\n/>", status);
|
|
3097
|
-
let value = void 0;
|
|
3098
|
-
consumeSpace(status);
|
|
3099
|
-
if (accept("=", status)) {
|
|
3100
|
-
consumeSpace(status);
|
|
3101
|
-
value = parseAttributeValue(status);
|
|
3102
|
-
}
|
|
3103
|
-
return { name, value };
|
|
3104
|
-
}
|
|
3105
|
-
function parseAttributeValue(status) {
|
|
3106
|
-
if (accept('"', status)) {
|
|
3107
|
-
const value = consumeUntil('"', status);
|
|
3108
|
-
accept('"', status);
|
|
3109
|
-
return `"${value}"`;
|
|
3110
|
-
} else if (accept("'", status)) {
|
|
3111
|
-
const value = consumeUntil("'", status);
|
|
3112
|
-
accept("'", status);
|
|
3113
|
-
return `'${value}'`;
|
|
3114
|
-
} else if (accept("{", status)) {
|
|
3115
|
-
const value = parseInlineScript(status);
|
|
3116
|
-
return `{${value}}`;
|
|
3117
|
-
} else {
|
|
3118
|
-
let value = consumeUntil(" \r\n>", status);
|
|
3119
|
-
if (status.source.substring(status.i - 1, status.i + 1) === "/>") {
|
|
3120
|
-
value = value.substring(0, value.length - 1);
|
|
3121
|
-
status.i -= 1;
|
|
3122
|
-
}
|
|
3123
|
-
return value;
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
// src/compile/parse/slottifyChildNodes.ts
|
|
3128
|
-
function slottifyChildNodes(node) {
|
|
3129
|
-
const nonFillNodes = node.children.filter((c) => !isFillNode(c));
|
|
3130
|
-
if (nonFillNodes.length) {
|
|
3131
|
-
let defaultFillNode = node.children.find(
|
|
3132
|
-
(n) => isFillNode(n) && !n.attributes.find((a) => a.name === "name")
|
|
3133
|
-
);
|
|
3134
|
-
if (!defaultFillNode) {
|
|
3135
|
-
defaultFillNode = {
|
|
3136
|
-
type: "special",
|
|
3137
|
-
tagName: ":fill",
|
|
3138
|
-
attributes: [],
|
|
3139
|
-
children: nonFillNodes
|
|
3140
|
-
};
|
|
3141
|
-
node.children.unshift(defaultFillNode);
|
|
3142
|
-
}
|
|
3143
|
-
}
|
|
3144
|
-
node.children = node.children.filter((c) => isFillNode(c));
|
|
3145
|
-
}
|
|
3146
|
-
function isFillNode(n) {
|
|
3147
|
-
return isSpecialNode(n) && n.tagName === ":fill";
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
// src/compile/parse/utils/addError.ts
|
|
3151
|
-
function addError(status, message, start = status.i) {
|
|
3152
|
-
let line = 1;
|
|
3153
|
-
let lastLineStart = 0;
|
|
3154
|
-
for (let i = 0; i < start; i++) {
|
|
3155
|
-
if (status.source[i] === "\n") {
|
|
3156
|
-
line += 1;
|
|
3157
|
-
lastLineStart = i + 1;
|
|
3158
|
-
}
|
|
3159
|
-
}
|
|
3160
|
-
let column = start - lastLineStart;
|
|
3161
|
-
status.errors.push({ message, start, line, column });
|
|
3162
|
-
}
|
|
3163
|
-
|
|
3164
|
-
// src/compile/parse/parseElement.ts
|
|
3165
|
-
function parseElement(status) {
|
|
3166
|
-
const start = status.i;
|
|
3167
|
-
const element = parseTag(status);
|
|
3168
|
-
if (element.tagName.startsWith("/")) {
|
|
3169
|
-
addError(status, `Non matching close tag: ${element.tagName.substring(1)}`, start);
|
|
3170
|
-
return element;
|
|
3171
|
-
}
|
|
3172
|
-
if (voidTags_default.includes(element.tagName)) {
|
|
3173
|
-
checkVoidElement(status, element);
|
|
3174
|
-
}
|
|
3175
|
-
if (!element.selfClosed && !voidTags_default.includes(element.tagName)) {
|
|
3176
|
-
const current = status.components[status.components.length - 1];
|
|
3177
|
-
current.stack ??= [];
|
|
3178
|
-
current.stack.push(element);
|
|
3179
|
-
while (status.i < status.source.length) {
|
|
3180
|
-
addSpaceElement(element, status);
|
|
3181
|
-
if (accept("}", status, false)) {
|
|
3182
|
-
break;
|
|
3183
|
-
} else if (accept("<!--", status)) {
|
|
3184
|
-
status.i = status.source.indexOf("-->", status.i) + 3;
|
|
3185
|
-
} else if (accept("@//", status)) {
|
|
3186
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3187
|
-
} else if (accept("@/*", status)) {
|
|
3188
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3189
|
-
} else if (accept("</", status, false)) {
|
|
3190
|
-
if (checkCloseTag(status, element, current)) {
|
|
3191
|
-
break;
|
|
3192
|
-
}
|
|
3193
|
-
} else if (accept("<", status, false)) {
|
|
3194
|
-
const child = parseElement(status);
|
|
3195
|
-
element.children.push(child);
|
|
3196
|
-
} else if (accept("@", status, false)) {
|
|
3197
|
-
parseControl(status, element);
|
|
3198
|
-
} else {
|
|
3199
|
-
parseText(status, element);
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
current.stack.pop();
|
|
3203
|
-
}
|
|
3204
|
-
if (!element.tagName.startsWith(":") && /[A-Z]/.test(element.tagName[0])) {
|
|
3205
|
-
element.type = "component";
|
|
3206
|
-
slottifyChildNodes(element);
|
|
3207
|
-
}
|
|
3208
|
-
if (isSpecialNode(element)) {
|
|
3209
|
-
if (element.tagName === ":slot") {
|
|
3210
|
-
slottifyChildNodes(element);
|
|
3211
|
-
const current = status.components[status.components.length - 1];
|
|
3212
|
-
current.slotProps ??= [];
|
|
3213
|
-
current.slotProps.push(element.attributes.find((a) => a.name === "name")?.name ?? "default");
|
|
3214
|
-
} else if (element.tagName === ":component") {
|
|
3215
|
-
const selfAttribute = element.attributes.find((a) => a.name === "self");
|
|
3216
|
-
if (selfAttribute && selfAttribute.value) {
|
|
3217
|
-
element.type = "component";
|
|
3218
|
-
slottifyChildNodes(element);
|
|
3219
|
-
const selfValue = trimMatched(selfAttribute.value, "{", "}");
|
|
3220
|
-
const replace = {
|
|
3221
|
-
type: "control",
|
|
3222
|
-
operation: "@replace",
|
|
3223
|
-
statement: selfValue,
|
|
3224
|
-
children: [element]
|
|
3225
|
-
};
|
|
3226
|
-
const replaceGroup = {
|
|
3227
|
-
type: "control",
|
|
3228
|
-
operation: "@replace group",
|
|
3229
|
-
statement: selfValue,
|
|
3230
|
-
children: [replace]
|
|
3231
|
-
};
|
|
3232
|
-
return replaceGroup;
|
|
3233
|
-
} else {
|
|
3234
|
-
addError(status, ":component element must have a self attribute", start);
|
|
3235
|
-
}
|
|
3236
|
-
}
|
|
3237
|
-
}
|
|
3238
|
-
if (!element.closed && !voidTags_default.includes(element.tagName)) {
|
|
3239
|
-
addError(status, `Unclosed non-void element: ${element.tagName}`, start);
|
|
3240
|
-
}
|
|
3241
|
-
return element;
|
|
3242
|
-
}
|
|
3243
|
-
function parseText(status, element) {
|
|
3244
|
-
const start = status.i;
|
|
3245
|
-
let end = -1;
|
|
3246
|
-
for (let j = status.i; j < status.source.length; j++) {
|
|
3247
|
-
if (status.source[j] === "}") {
|
|
3248
|
-
end = j;
|
|
3249
|
-
} else if (status.source[j] === "{") {
|
|
3250
|
-
let level = 0;
|
|
3251
|
-
for (let k = j; k < status.source.length; k++) {
|
|
3252
|
-
const char = status.source[k];
|
|
3253
|
-
const nextChar = status.source[k + 1];
|
|
3254
|
-
if (char === "/" && nextChar === "/") {
|
|
3255
|
-
k = status.source.indexOf("\n", k);
|
|
3256
|
-
} else if (char === "/" && nextChar === "*") {
|
|
3257
|
-
k = status.source.indexOf("*/", k) + 1;
|
|
3258
|
-
} else if (char === '"' || char === "'") {
|
|
3259
|
-
for (let l = k + 1; l < status.source.length; l++) {
|
|
3260
|
-
if (status.source[l] === char && status.source[l - 1] !== "\\") {
|
|
3261
|
-
k = l;
|
|
3262
|
-
break;
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
} else if (char === "`") {
|
|
3266
|
-
let level2 = 0;
|
|
3267
|
-
for (let l = k + 1; l < status.source.length; l++) {
|
|
3268
|
-
if (status.source[l] === char && status.source[l - 1] !== "\\" && level2 === 0) {
|
|
3269
|
-
k = l;
|
|
3270
|
-
break;
|
|
3271
|
-
} else if (status.source[l] === "{" && (level2 > 0 || status.source[l - 1] === "$")) {
|
|
3272
|
-
level2 += 1;
|
|
3273
|
-
} else if (status.source[l] === "}" && level2 > 0) {
|
|
3274
|
-
level2 -= 1;
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
|
-
} else if (char === "{") {
|
|
3278
|
-
level += 1;
|
|
3279
|
-
} else if (char === "}") {
|
|
3280
|
-
level -= 1;
|
|
3281
|
-
if (level === 0) {
|
|
3282
|
-
j = k;
|
|
3283
|
-
break;
|
|
3284
|
-
}
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
} else if (status.source[j] === "<") {
|
|
3288
|
-
end = j;
|
|
3289
|
-
} else if (status.source[j] === "@") {
|
|
3290
|
-
for (let k = j - 1; k > status.i; k--) {
|
|
3291
|
-
if (status.source[k] === "\n") {
|
|
3292
|
-
end = j;
|
|
3293
|
-
break;
|
|
3294
|
-
} else if (!isSpaceChar(status.source, k)) {
|
|
3295
|
-
break;
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3298
|
-
}
|
|
3299
|
-
if (end !== -1) {
|
|
3300
|
-
break;
|
|
3301
|
-
}
|
|
3302
|
-
}
|
|
3303
|
-
if (end !== -1) {
|
|
3304
|
-
const content = status.source.substring(start, end).trimEnd();
|
|
3305
|
-
const spaceContent = status.source.substring(start + content.length, end);
|
|
3306
|
-
if (content || spaceContent) {
|
|
3307
|
-
const previousNode = element.children[element.children.length - 1];
|
|
3308
|
-
if (previousNode && isTextNode(previousNode)) {
|
|
3309
|
-
previousNode.content += content + spaceContent;
|
|
3310
|
-
} else {
|
|
3311
|
-
const text = {
|
|
3312
|
-
type: "text",
|
|
3313
|
-
content: content + spaceContent
|
|
3314
|
-
};
|
|
3315
|
-
element.children.push(text);
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
status.i = end;
|
|
3319
|
-
} else {
|
|
3320
|
-
status.i += 1;
|
|
3321
|
-
}
|
|
3322
|
-
}
|
|
3323
|
-
function checkVoidElement(status, element) {
|
|
3324
|
-
let i = status.i;
|
|
3325
|
-
consumeSpace(status);
|
|
3326
|
-
if (accept("</", status)) {
|
|
3327
|
-
consumeSpace(status);
|
|
3328
|
-
if (accept(element.tagName, status)) {
|
|
3329
|
-
addError(status, `Closed void element: ${element.tagName}`, i);
|
|
3330
|
-
consumeSpace(status);
|
|
3331
|
-
accept(">", status);
|
|
3332
|
-
return;
|
|
3333
|
-
}
|
|
3334
|
-
}
|
|
3335
|
-
status.i = i;
|
|
3336
|
-
}
|
|
3337
|
-
function checkCloseTag(status, element, current) {
|
|
3338
|
-
const start = status.i;
|
|
3339
|
-
accept("</", status);
|
|
3340
|
-
consumeSpace(status);
|
|
3341
|
-
let special = accept(":", status);
|
|
3342
|
-
let closingTagName = consumeAlphaNumeric(status);
|
|
3343
|
-
if (special) {
|
|
3344
|
-
closingTagName = ":" + closingTagName;
|
|
3345
|
-
}
|
|
3346
|
-
consumeSpace(status);
|
|
3347
|
-
accept(">", status);
|
|
3348
|
-
let found = false;
|
|
3349
|
-
if (current.stack) {
|
|
3350
|
-
for (let i = current.stack.length - 1; i >= 0; i--) {
|
|
3351
|
-
if (closingTagName === current.stack[i].tagName) {
|
|
3352
|
-
current.stack[i].closed = true;
|
|
3353
|
-
found = true;
|
|
3354
|
-
break;
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
}
|
|
3358
|
-
if (!found) {
|
|
3359
|
-
addError(
|
|
3360
|
-
status,
|
|
3361
|
-
`Non matching close tag: ${closingTagName} (expected ${element.tagName})`,
|
|
3362
|
-
start
|
|
3363
|
-
);
|
|
3364
|
-
}
|
|
3365
|
-
return found;
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
// src/compile/parse/parseControl.ts
|
|
3369
|
-
var controlOperations = [
|
|
3370
|
-
"@if",
|
|
3371
|
-
"@else",
|
|
3372
|
-
"@for",
|
|
3373
|
-
"@key",
|
|
3374
|
-
"@switch",
|
|
3375
|
-
"@case",
|
|
3376
|
-
"@default",
|
|
3377
|
-
"@await",
|
|
3378
|
-
"@then",
|
|
3379
|
-
"@catch",
|
|
3380
|
-
"@replace",
|
|
3381
|
-
"@html",
|
|
3382
|
-
"@const",
|
|
3383
|
-
"@console",
|
|
3384
|
-
"@debugger",
|
|
3385
|
-
"@function",
|
|
3386
|
-
"@async function"
|
|
3387
|
-
];
|
|
3388
|
-
var standaloneOperations = [
|
|
3389
|
-
"@key",
|
|
3390
|
-
"@html",
|
|
3391
|
-
"@const",
|
|
3392
|
-
"@console",
|
|
3393
|
-
"@debugger",
|
|
3394
|
-
"@function",
|
|
3395
|
-
"@async function"
|
|
3396
|
-
];
|
|
3397
|
-
function parseControl(status, parentNode) {
|
|
3398
|
-
const node = parseControlOpen(status);
|
|
3399
|
-
if (!node) {
|
|
3400
|
-
return;
|
|
3401
|
-
}
|
|
3402
|
-
if (standaloneOperations.includes(node.operation)) {
|
|
3403
|
-
wrangleControlNode(node, parentNode);
|
|
3404
|
-
return;
|
|
3405
|
-
}
|
|
3406
|
-
while (status.i < status.source.length) {
|
|
3407
|
-
addSpaceElement(node, status);
|
|
3408
|
-
if (accept("}", status)) {
|
|
3409
|
-
break;
|
|
3410
|
-
} else if (accept("<", status, false)) {
|
|
3411
|
-
const child = parseElement(status);
|
|
3412
|
-
node.children.push(child);
|
|
3413
|
-
} else if (accept("@//", status)) {
|
|
3414
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3415
|
-
} else if (accept("@/*", status)) {
|
|
3416
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3417
|
-
} else if (accept("@", status, false)) {
|
|
3418
|
-
parseControl(status, node);
|
|
3419
|
-
} else if (accept("case", status, false) || accept("key", status, false)) {
|
|
3420
|
-
parseControl(status, node);
|
|
3421
|
-
} else {
|
|
3422
|
-
const char = status.source[status.i];
|
|
3423
|
-
addError(status, `Unexpected token in control block: ${char}`, status.i);
|
|
3424
|
-
break;
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
wrangleControlNode(node, parentNode);
|
|
3428
|
-
parseControlBranches(status, parentNode);
|
|
3429
|
-
}
|
|
3430
|
-
function parseControlOpen(status) {
|
|
3431
|
-
const start = status.i;
|
|
3432
|
-
let operation = "";
|
|
3433
|
-
for (status.i; status.i < status.source.length; status.i++) {
|
|
3434
|
-
const char = status.source[status.i];
|
|
3435
|
-
if (isSpaceChar(status.source, status.i) && operation !== "@async" || accept(":", status) && operation === "default" || accept(".", status) && operation === "@console" || accept("(", status, false) && operation === "@html") {
|
|
3436
|
-
break;
|
|
3437
|
-
}
|
|
3438
|
-
operation += char;
|
|
3439
|
-
}
|
|
3440
|
-
if (!operation.startsWith("@")) {
|
|
3441
|
-
operation = "@" + operation;
|
|
3442
|
-
}
|
|
3443
|
-
let statement = "";
|
|
3444
|
-
if (controlOperations.includes(operation)) {
|
|
3445
|
-
statement = parseControlStatement(start, operation, status);
|
|
3446
|
-
if (operation === "@function" || operation === "@async function") {
|
|
3447
|
-
statement += ` {${parseInlineScript(status)}}`;
|
|
3448
|
-
accept("}", status);
|
|
3449
|
-
}
|
|
3450
|
-
if (operation === "@replace" || operation === "@html") {
|
|
3451
|
-
statement = trimMatched(statement.substring(statement.indexOf("(")).trim(), "(", ")");
|
|
3452
|
-
}
|
|
3453
|
-
} else {
|
|
3454
|
-
addError(status, `Unknown operation: ${operation}`, status.i);
|
|
3455
|
-
return null;
|
|
3456
|
-
}
|
|
3457
|
-
return {
|
|
3458
|
-
type: "control",
|
|
3459
|
-
operation,
|
|
3460
|
-
statement,
|
|
3461
|
-
children: []
|
|
3462
|
-
};
|
|
3463
|
-
}
|
|
3464
|
-
function parseControlStatement(start, operation, status) {
|
|
3465
|
-
let parenCount = 0;
|
|
3466
|
-
while (status.i < status.source.length) {
|
|
3467
|
-
if (accept("(", status)) {
|
|
3468
|
-
parenCount += 1;
|
|
3469
|
-
} else if (accept(")", status)) {
|
|
3470
|
-
parenCount -= 1;
|
|
3471
|
-
} else if (accept("{", status) || accept("\n", status) && standaloneOperations.includes(operation)) {
|
|
3472
|
-
if (parenCount === 0) {
|
|
3473
|
-
return trimStart(status.source.substring(start, status.i - 1).trim(), "@");
|
|
3474
|
-
}
|
|
3475
|
-
} else if (accept('"', status) || accept("'", status)) {
|
|
3476
|
-
const char = status.source[status.i - 1];
|
|
3477
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
3478
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\") {
|
|
3479
|
-
status.i = j + 1;
|
|
3480
|
-
break;
|
|
3481
|
-
}
|
|
3482
|
-
}
|
|
3483
|
-
} else if (accept("`", status)) {
|
|
3484
|
-
let level2 = 0;
|
|
3485
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
3486
|
-
if (status.source[j] === "`" && status.source[j - 1] !== "\\" && level2 === 0) {
|
|
3487
|
-
status.i = j + 1;
|
|
3488
|
-
break;
|
|
3489
|
-
} else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
|
|
3490
|
-
level2 += 1;
|
|
3491
|
-
} else if (status.source[j] === "}" && level2 > 0) {
|
|
3492
|
-
level2 -= 1;
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
} else if (accept("//", status)) {
|
|
3496
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3497
|
-
} else if (accept("/*", status)) {
|
|
3498
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3499
|
-
} else {
|
|
3500
|
-
status.i += 1;
|
|
3501
|
-
}
|
|
3502
|
-
}
|
|
3503
|
-
return "";
|
|
3504
|
-
}
|
|
3505
|
-
function wrangleControlNode(node, parentNode) {
|
|
3506
|
-
if (node.operation === "@if") {
|
|
3507
|
-
const ifGroup = {
|
|
3508
|
-
type: "control",
|
|
3509
|
-
operation: "@if group",
|
|
3510
|
-
statement: "",
|
|
3511
|
-
children: [node]
|
|
3512
|
-
};
|
|
3513
|
-
parentNode.children.push(ifGroup);
|
|
3514
|
-
} else if (node.operation === "@else") {
|
|
3515
|
-
if (/^else\s+if/.test(node.statement)) {
|
|
3516
|
-
node.operation = "@else if";
|
|
3517
|
-
}
|
|
3518
|
-
for (let i = parentNode.children.length - 1; i >= 0; i--) {
|
|
3519
|
-
const lastChild = parentNode.children[i];
|
|
3520
|
-
if (isControlNode(lastChild) && lastChild.operation === "@if group") {
|
|
3521
|
-
lastChild.children.push(node);
|
|
3522
|
-
break;
|
|
3523
|
-
}
|
|
3524
|
-
}
|
|
3525
|
-
} else if (node.operation === "@for") {
|
|
3526
|
-
const forGroup = {
|
|
3527
|
-
type: "control",
|
|
3528
|
-
operation: "@for group",
|
|
3529
|
-
statement: "",
|
|
3530
|
-
children: [node]
|
|
3531
|
-
};
|
|
3532
|
-
parentNode.children.push(forGroup);
|
|
3533
|
-
} else if (node.operation === "@switch") {
|
|
3534
|
-
node.operation = "@switch group";
|
|
3535
|
-
parentNode.children.push(node);
|
|
3536
|
-
} else if (node.operation === "@await") {
|
|
3537
|
-
const awaitGroup = {
|
|
3538
|
-
type: "control",
|
|
3539
|
-
operation: "@await group",
|
|
3540
|
-
statement: "",
|
|
3541
|
-
children: [node]
|
|
3542
|
-
};
|
|
3543
|
-
parentNode.children.push(awaitGroup);
|
|
3544
|
-
} else if (node.operation === "@then" || node.operation === "@catch") {
|
|
3545
|
-
for (let i = parentNode.children.length - 1; i >= 0; i--) {
|
|
3546
|
-
const lastChild = parentNode.children[i];
|
|
3547
|
-
if (isControlNode(lastChild) && lastChild.operation === "@await group") {
|
|
3548
|
-
lastChild.children.push(node);
|
|
3549
|
-
break;
|
|
3550
|
-
}
|
|
3551
|
-
}
|
|
3552
|
-
} else if (node.operation === "@replace") {
|
|
3553
|
-
const replaceGroup = {
|
|
3554
|
-
type: "control",
|
|
3555
|
-
operation: "@replace group",
|
|
3556
|
-
statement: "",
|
|
3557
|
-
children: [node]
|
|
3558
|
-
};
|
|
3559
|
-
parentNode.children.push(replaceGroup);
|
|
3560
|
-
} else if (node.operation === "@html") {
|
|
3561
|
-
const htmlGroup = {
|
|
3562
|
-
type: "control",
|
|
3563
|
-
operation: "@html group",
|
|
3564
|
-
statement: "",
|
|
3565
|
-
children: [node]
|
|
3566
|
-
};
|
|
3567
|
-
parentNode.children.push(htmlGroup);
|
|
3568
|
-
} else {
|
|
3569
|
-
parentNode.children.push(node);
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
function parseControlBranches(status, parentNode) {
|
|
3573
|
-
let gotAnotherBranch = true;
|
|
3574
|
-
while (gotAnotherBranch) {
|
|
3575
|
-
let start = status.i;
|
|
3576
|
-
status.i += 1;
|
|
3577
|
-
consumeSpace(status);
|
|
3578
|
-
if (accept("else", status, false) || accept("case", status, false) || accept("default", status, false) || accept("then", status, false) || accept("catch", status, false)) {
|
|
3579
|
-
parseControl(status, parentNode);
|
|
3580
|
-
} else {
|
|
3581
|
-
gotAnotherBranch = false;
|
|
3582
|
-
status.i = start;
|
|
3583
|
-
}
|
|
3584
|
-
}
|
|
3585
|
-
}
|
|
3586
|
-
|
|
3587
|
-
// src/compile/parse/parseMarkup.ts
|
|
3588
|
-
function parseMarkup(status, source) {
|
|
3589
|
-
const current = status.components.at(-1);
|
|
3590
|
-
if (!current) return;
|
|
3591
|
-
while (status.i < source.length) {
|
|
3592
|
-
if (accept("}", status, false)) {
|
|
3593
|
-
return;
|
|
3594
|
-
} else if (accept("<!--", status)) {
|
|
3595
|
-
status.i = status.source.indexOf("-->", status.i) + 3;
|
|
3596
|
-
} else if (accept("@//", status)) {
|
|
3597
|
-
status.i = status.source.indexOf("\n", status.i) + 1;
|
|
3598
|
-
} else if (accept("@/*", status)) {
|
|
3599
|
-
status.i = status.source.indexOf("*/", status.i) + 2;
|
|
3600
|
-
} else if (isSpaceChar(status.source, status.i)) {
|
|
3601
|
-
current.markup ??= { type: "root", children: [] };
|
|
3602
|
-
const text = { type: "text", content: consumeSpace(status) };
|
|
3603
|
-
current.markup.children.push(text);
|
|
3604
|
-
} else if (accept("<", status, false)) {
|
|
3605
|
-
current.markup ??= { type: "root", children: [] };
|
|
3606
|
-
const element = parseElement(status);
|
|
3607
|
-
current.markup.children.push(element);
|
|
3608
|
-
} else if (accept("@", status, false)) {
|
|
3609
|
-
current.markup ??= { type: "root", children: [] };
|
|
3610
|
-
parseControl(status, current.markup);
|
|
3611
|
-
} else {
|
|
3612
|
-
status.i += 1;
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
|
|
3617
|
-
// src/compile/utils/hash.ts
|
|
3618
|
-
var returnRegex = /\r/g;
|
|
3619
|
-
function hash(input) {
|
|
3620
|
-
input = input.replace(returnRegex, "");
|
|
3621
|
-
let hash2 = 5381;
|
|
3622
|
-
let i = input.length;
|
|
3623
|
-
while (i--) {
|
|
3624
|
-
hash2 = (hash2 << 5) - hash2 ^ input.charCodeAt(i);
|
|
3625
|
-
}
|
|
3626
|
-
return (hash2 >>> 0).toString(36);
|
|
3627
|
-
}
|
|
3628
|
-
|
|
3629
|
-
// src/compile/parse/utils/expect.ts
|
|
3630
|
-
function expect(value, status, advance = true) {
|
|
3631
|
-
if (status.i < status.source.length) {
|
|
3632
|
-
if (status.source.substring(status.i, status.i + value.length) == value) {
|
|
3633
|
-
status.i += advance ? value.length : 0;
|
|
3634
|
-
return true;
|
|
3635
|
-
} else {
|
|
3636
|
-
addError(status, `Expected ${value}`);
|
|
3637
|
-
}
|
|
3638
|
-
} else {
|
|
3639
|
-
addError(status, "Expected token");
|
|
3640
|
-
}
|
|
3641
|
-
return false;
|
|
3642
|
-
}
|
|
3643
|
-
|
|
3644
|
-
// src/compile/parse/parseStyles.ts
|
|
3645
|
-
function parseStyles(source, status) {
|
|
3646
|
-
const current = status.components.at(-1);
|
|
3647
|
-
if (!current) return;
|
|
3648
|
-
current.style = {
|
|
3649
|
-
global: false,
|
|
3650
|
-
blocks: [],
|
|
3651
|
-
hash: hash(source)
|
|
3652
|
-
};
|
|
3653
|
-
const styleStatus = {
|
|
3654
|
-
source,
|
|
3655
|
-
i: 0,
|
|
3656
|
-
marker: 0,
|
|
3657
|
-
level: 0,
|
|
3658
|
-
imports: [],
|
|
3659
|
-
script: "",
|
|
3660
|
-
components: [],
|
|
3661
|
-
errors: []
|
|
3662
|
-
};
|
|
3663
|
-
while (styleStatus.i < styleStatus.source.length) {
|
|
3664
|
-
if (isSpaceChar(styleStatus.source, styleStatus.i)) {
|
|
3665
|
-
consumeSpace(styleStatus);
|
|
3666
|
-
} else {
|
|
3667
|
-
const block = parseStyleBlock(styleStatus);
|
|
3668
|
-
if (block) {
|
|
3669
|
-
current.style.blocks.push(block);
|
|
3670
|
-
} else {
|
|
3671
|
-
break;
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
status.errors = status.errors.concat(styleStatus.errors);
|
|
3676
|
-
}
|
|
3677
|
-
function parseStyleBlock(status) {
|
|
3678
|
-
const selector = consumeUntil("{", status).trim();
|
|
3679
|
-
if (expect("{", status)) {
|
|
3680
|
-
const block = {
|
|
3681
|
-
selector,
|
|
3682
|
-
attributes: [],
|
|
3683
|
-
children: []
|
|
3684
|
-
};
|
|
3685
|
-
consumeSpace(status);
|
|
3686
|
-
while (status.source[status.i] !== "}") {
|
|
3687
|
-
let nextColon = status.source.indexOf(":", status.i);
|
|
3688
|
-
if (nextColon === -1) nextColon = status.source.length;
|
|
3689
|
-
let nextOpenBrace = status.source.indexOf("{", status.i);
|
|
3690
|
-
if (nextOpenBrace === -1) nextOpenBrace = status.source.length;
|
|
3691
|
-
if (nextColon < nextOpenBrace) {
|
|
3692
|
-
const attribute = parseStyleAttribute(status);
|
|
3693
|
-
block.attributes.push(attribute);
|
|
3694
|
-
} else if (nextOpenBrace < nextColon) {
|
|
3695
|
-
const child = parseStyleBlock(status);
|
|
3696
|
-
if (child) {
|
|
3697
|
-
block.children.push(child);
|
|
3698
|
-
} else {
|
|
3699
|
-
break;
|
|
3700
|
-
}
|
|
3701
|
-
} else {
|
|
3702
|
-
return block;
|
|
3703
|
-
}
|
|
3704
|
-
consumeSpace(status);
|
|
3705
|
-
}
|
|
3706
|
-
accept("}", status);
|
|
3707
|
-
return block;
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
function parseStyleAttribute(status) {
|
|
3711
|
-
const name = consumeUntil(":", status).trim();
|
|
3712
|
-
accept(":", status);
|
|
3713
|
-
const value = consumeUntil(";", status).trim();
|
|
3714
|
-
accept(";", status);
|
|
3715
|
-
return {
|
|
3716
|
-
name,
|
|
3717
|
-
value
|
|
3718
|
-
};
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
|
-
// src/compile/types/nodes/isComponentNode.ts
|
|
3722
|
-
function isComponentNode(node) {
|
|
3723
|
-
return node.type === "component";
|
|
3724
|
-
}
|
|
3725
|
-
|
|
3726
|
-
// src/compile/types/nodes/isParentNode.ts
|
|
3727
|
-
function isParentNode(node) {
|
|
3728
|
-
return "children" in node;
|
|
3729
|
-
}
|
|
3730
|
-
|
|
3731
|
-
// src/compile/parse/scopeStyles.ts
|
|
3732
|
-
function scopeStyles(status) {
|
|
3733
|
-
let selectors = [];
|
|
3734
|
-
for (let component of status.components) {
|
|
3735
|
-
if (component.style && component.markup) {
|
|
3736
|
-
for (let block of component.style.blocks) {
|
|
3737
|
-
collectStyleSelectors(block, selectors);
|
|
3738
|
-
}
|
|
3739
|
-
scopeStylesOnNode(component.markup, selectors);
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
}
|
|
3743
|
-
function scopeStylesOnNode(node, selectors) {
|
|
3744
|
-
if (isElementNode(node) || isComponentNode(node)) {
|
|
3745
|
-
let scopeStyles2 = selectors.includes(node.tagName);
|
|
3746
|
-
if (!scopeStyles2) {
|
|
3747
|
-
for (let a of node.attributes) {
|
|
3748
|
-
if (a.name === "class" || a.name === ":class") {
|
|
3749
|
-
scopeStyles2 = true;
|
|
3750
|
-
} else if (a.name === "id" && a.value) {
|
|
3751
|
-
scopeStyles2 = selectors.includes(`#${trimQuotes(a.value)}`);
|
|
3752
|
-
} else if (a.name === "class" && a.value) {
|
|
3753
|
-
scopeStyles2 = selectors.includes(`.${trimQuotes(a.value)}`);
|
|
3754
|
-
}
|
|
3755
|
-
if (scopeStyles2) {
|
|
3756
|
-
break;
|
|
3757
|
-
}
|
|
3758
|
-
}
|
|
3759
|
-
}
|
|
3760
|
-
node.scopeStyles = scopeStyles2;
|
|
3761
|
-
}
|
|
3762
|
-
if (isParentNode(node)) {
|
|
3763
|
-
for (let child of node.children) {
|
|
3764
|
-
scopeStylesOnNode(child, selectors);
|
|
3765
|
-
}
|
|
3766
|
-
}
|
|
3767
|
-
}
|
|
3768
|
-
function collectStyleSelectors(block, selectors) {
|
|
3769
|
-
for (let s of block.selector.split(/[\s*,>+~]/)) {
|
|
3770
|
-
selectors.push(s);
|
|
3771
|
-
}
|
|
3772
|
-
}
|
|
3773
|
-
|
|
3774
|
-
// src/compile/parse/parseCode.ts
|
|
3775
|
-
function parseCode(source) {
|
|
3776
|
-
const status = {
|
|
3777
|
-
source,
|
|
3778
|
-
i: 0,
|
|
3779
|
-
marker: 0,
|
|
3780
|
-
level: 0,
|
|
3781
|
-
imports: [],
|
|
3782
|
-
script: "",
|
|
3783
|
-
components: [],
|
|
3784
|
-
errors: []
|
|
3785
|
-
};
|
|
3786
|
-
for (status.i; status.i < source.length; status.i++) {
|
|
3787
|
-
if (consumeScriptComments(status)) {
|
|
3788
|
-
} else if (status.source[status.i] === "{") {
|
|
3789
|
-
status.level += 1;
|
|
3790
|
-
} else if (status.source[status.i] === "}") {
|
|
3791
|
-
status.level -= 1;
|
|
3792
|
-
if (status.level === 0) {
|
|
3793
|
-
parseComponentEnd(status);
|
|
3794
|
-
}
|
|
3795
|
-
} else if (accept("function", status)) {
|
|
3796
|
-
if (consumeSpace(status)) {
|
|
3797
|
-
if (/[A-Z]/.test(source[status.i])) {
|
|
3798
|
-
parseComponentStart(status);
|
|
3799
|
-
} else {
|
|
3800
|
-
status.i--;
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
3803
|
-
} else if (accept("const", status)) {
|
|
3804
|
-
if (consumeSpace(status)) {
|
|
3805
|
-
if (/[A-Z]/.test(source[status.i])) {
|
|
3806
|
-
const start = status.i;
|
|
3807
|
-
consumeAlphaNumeric(status);
|
|
3808
|
-
consumeSpace(status);
|
|
3809
|
-
if (accept("=", status)) {
|
|
3810
|
-
consumeSpace(status);
|
|
3811
|
-
if (accept("(", status, false)) {
|
|
3812
|
-
status.i = start;
|
|
3813
|
-
parseComponentStart(status);
|
|
3814
|
-
}
|
|
3815
|
-
}
|
|
3816
|
-
} else {
|
|
3817
|
-
status.i--;
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
} else if (accept("export", status)) {
|
|
3821
|
-
const start = status.i;
|
|
3822
|
-
if (consumeSpace(status) && accept("default", status) && consumeSpace(status) && accept("(", status, false)) {
|
|
3823
|
-
parseComponentStart(status);
|
|
3824
|
-
} else {
|
|
3825
|
-
status.i = start;
|
|
3826
|
-
}
|
|
3827
|
-
} else if (accept("@render", status, false)) {
|
|
3828
|
-
parseComponentRender(status);
|
|
3829
|
-
} else if (accept("@style", status, false)) {
|
|
3830
|
-
parseComponentStyle(status);
|
|
3831
|
-
}
|
|
3832
|
-
}
|
|
3833
|
-
status.script += source.substring(status.marker, source.length);
|
|
3834
|
-
scopeStyles(status);
|
|
3835
|
-
const ok = !status.errors.length;
|
|
3836
|
-
if (!ok) {
|
|
3837
|
-
status.errors = status.errors.sort((a, b) => a.start - b.start);
|
|
3838
|
-
}
|
|
3839
|
-
return {
|
|
3840
|
-
ok,
|
|
3841
|
-
errors: status.errors,
|
|
3842
|
-
template: ok ? {
|
|
3843
|
-
imports: status.imports,
|
|
3844
|
-
script: status.script,
|
|
3845
|
-
components: status.components.map((c) => {
|
|
3846
|
-
return {
|
|
3847
|
-
start: c.start,
|
|
3848
|
-
name: c.name,
|
|
3849
|
-
default: c.default,
|
|
3850
|
-
params: c.params,
|
|
3851
|
-
markup: c.markup,
|
|
3852
|
-
style: c.style,
|
|
3853
|
-
props: c.props,
|
|
3854
|
-
contextProps: c.contextProps,
|
|
3855
|
-
slotProps: c.slotProps
|
|
3856
|
-
};
|
|
3857
|
-
})
|
|
3858
|
-
} : void 0
|
|
3859
|
-
};
|
|
3860
|
-
}
|
|
3861
|
-
function parseComponentStart(status) {
|
|
3862
|
-
let source = status.source.substring(0, status.i);
|
|
3863
|
-
let def = /export\s+default\s+(function\s+|const\s+)*$/.test(source);
|
|
3864
|
-
let isConst = /const\s+$/.test(source);
|
|
3865
|
-
let isAnon = /export default\s+$/.test(source);
|
|
3866
|
-
status.components.push({
|
|
3867
|
-
start: status.i,
|
|
3868
|
-
name: consumeAlphaNumeric(status),
|
|
3869
|
-
default: def
|
|
3870
|
-
});
|
|
3871
|
-
const current = status.components.at(-1);
|
|
3872
|
-
if (!current) return;
|
|
3873
|
-
let start = -1;
|
|
3874
|
-
let end = -1;
|
|
3875
|
-
let level = 0;
|
|
3876
|
-
for (status.i; status.i < status.source.length; status.i++) {
|
|
3877
|
-
const char = status.source[status.i];
|
|
3878
|
-
if (consumeScriptComments(status)) {
|
|
3879
|
-
} else if (char === "(") {
|
|
3880
|
-
level += 1;
|
|
3881
|
-
if (start === -1) {
|
|
3882
|
-
start = status.i + 1;
|
|
3883
|
-
}
|
|
3884
|
-
} else if (char === ")") {
|
|
3885
|
-
level -= 1;
|
|
3886
|
-
if (level === 0) {
|
|
3887
|
-
end = status.i;
|
|
3888
|
-
break;
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
}
|
|
3892
|
-
status.script += status.source.substring(status.marker, start) + "/* @params */";
|
|
3893
|
-
current.params = status.source.substring(start, end).trim() || void 0;
|
|
3894
|
-
status.marker = end;
|
|
3895
|
-
status.i = status.marker;
|
|
3896
|
-
accept(")", status);
|
|
3897
|
-
consumeSpace(status);
|
|
3898
|
-
if (isConst || isAnon) {
|
|
3899
|
-
accept("=>", status);
|
|
3900
|
-
consumeSpace(status);
|
|
3901
|
-
}
|
|
3902
|
-
accept("{", status);
|
|
3903
|
-
status.level += 1;
|
|
3904
|
-
const space = consumeSpace(status);
|
|
3905
|
-
status.script += status.source.substring(status.marker, status.i) + "/* @start */" + space;
|
|
3906
|
-
status.marker = status.i;
|
|
3907
|
-
status.i -= 1;
|
|
3908
|
-
}
|
|
3909
|
-
function parseComponentRender(status) {
|
|
3910
|
-
const current = status.components.at(-1);
|
|
3911
|
-
if (!current) return;
|
|
3912
|
-
if (current.markup) {
|
|
3913
|
-
addError(status, `Multiple @render sections`, status.i);
|
|
3914
|
-
}
|
|
3915
|
-
status.script += status.source.substring(status.marker, status.i) + "/* @render */";
|
|
3916
|
-
accept("@render", status);
|
|
3917
|
-
consumeSpace(status);
|
|
3918
|
-
if (accept("{", status)) {
|
|
3919
|
-
parseMarkup(status, status.source);
|
|
3920
|
-
accept("}", status);
|
|
3921
|
-
}
|
|
3922
|
-
status.marker = status.i;
|
|
3923
|
-
}
|
|
3924
|
-
function parseComponentStyle(status) {
|
|
3925
|
-
const current = status.components.at(-1);
|
|
3926
|
-
if (!current) return;
|
|
3927
|
-
if (current.style) {
|
|
3928
|
-
addError(status, `Multiple @style sections`, status.i);
|
|
3929
|
-
}
|
|
3930
|
-
status.script += status.source.substring(status.marker, status.i);
|
|
3931
|
-
let start = -1;
|
|
3932
|
-
let end = status.source.length;
|
|
3933
|
-
let level = 0;
|
|
3934
|
-
let styleSource = "";
|
|
3935
|
-
for (; status.i < status.source.length; status.i++) {
|
|
3936
|
-
const char = status.source[status.i];
|
|
3937
|
-
const nextChar = status.source[status.i + 1];
|
|
3938
|
-
if (char === "/" && nextChar === "/") {
|
|
3939
|
-
status.i = status.source.indexOf("\n", status.i);
|
|
3940
|
-
} else if (char === "/" && nextChar === "*") {
|
|
3941
|
-
status.i = status.source.indexOf("*/", status.i) + 1;
|
|
3942
|
-
} else if (char === '"' || char === "'") {
|
|
3943
|
-
styleSource += char;
|
|
3944
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
3945
|
-
styleSource += status.source[j];
|
|
3946
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\") {
|
|
3947
|
-
status.i = j;
|
|
3948
|
-
break;
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
} else if (char === "`") {
|
|
3952
|
-
styleSource += char;
|
|
3953
|
-
let level2 = 0;
|
|
3954
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
3955
|
-
styleSource += status.source[j];
|
|
3956
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
|
|
3957
|
-
status.i = j;
|
|
3958
|
-
break;
|
|
3959
|
-
} else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
|
|
3960
|
-
level2 += 1;
|
|
3961
|
-
} else if (status.source[j] === "}" && level2 > 0) {
|
|
3962
|
-
level2 -= 1;
|
|
3963
|
-
}
|
|
3964
|
-
}
|
|
3965
|
-
} else if (char === "{") {
|
|
3966
|
-
level += 1;
|
|
3967
|
-
if (start === -1) {
|
|
3968
|
-
start = status.i + 1;
|
|
3969
|
-
} else {
|
|
3970
|
-
styleSource += char;
|
|
3971
|
-
}
|
|
3972
|
-
} else if (char === "}") {
|
|
3973
|
-
level -= 1;
|
|
3974
|
-
if (level === 0) {
|
|
3975
|
-
end = status.i - 1;
|
|
3976
|
-
break;
|
|
3977
|
-
} else {
|
|
3978
|
-
styleSource += char;
|
|
3979
|
-
}
|
|
3980
|
-
} else {
|
|
3981
|
-
if (start !== -1) {
|
|
3982
|
-
styleSource += char;
|
|
3983
|
-
}
|
|
3984
|
-
}
|
|
3985
|
-
}
|
|
3986
|
-
status.i = start;
|
|
3987
|
-
parseStyles(styleSource.trim(), status);
|
|
3988
|
-
status.i = end + 2;
|
|
3989
|
-
status.marker = status.i;
|
|
3990
|
-
}
|
|
3991
|
-
function parseComponentEnd(status) {
|
|
3992
|
-
const current = status.components.at(-1);
|
|
3993
|
-
if (!current) return;
|
|
3994
|
-
status.script += status.source.substring(status.marker, status.i);
|
|
3995
|
-
if (status.script.endsWith("\n")) {
|
|
3996
|
-
status.script += " /* @end */\n";
|
|
3997
|
-
} else {
|
|
3998
|
-
status.script += "/* @end */";
|
|
3999
|
-
}
|
|
4000
|
-
const componentSource = status.source.substring(current.start || 0, status.i);
|
|
4001
|
-
current.props = getPropsUsage(componentSource);
|
|
4002
|
-
current.contextProps = getContextUsage(componentSource);
|
|
4003
|
-
if (current.markup && isElementNode(current.markup.children[0]) && current.markup.children[0].tagName === "html" && isSpaceNode(current.markup.children[0].children[0])) {
|
|
4004
|
-
current.markup.children.splice(1, 1);
|
|
4005
|
-
}
|
|
4006
|
-
status.marker = status.i;
|
|
4007
|
-
}
|
|
4008
|
-
function getPropsUsage(source) {
|
|
4009
|
-
const propsMatches = source.matchAll(/\$props\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
|
|
4010
|
-
const props = [];
|
|
4011
|
-
for (let match of propsMatches) {
|
|
4012
|
-
const name = trimQuotes(match[1] || match[2]);
|
|
4013
|
-
if (!props.includes(name)) {
|
|
4014
|
-
props.push(name);
|
|
4015
|
-
}
|
|
4016
|
-
}
|
|
4017
|
-
return props.length ? props : void 0;
|
|
4018
|
-
}
|
|
4019
|
-
function getContextUsage(source) {
|
|
4020
|
-
const contextsMatches = source.matchAll(/\$context\s*(?:\.([\d\w]+)|\[([^\]]+)\])/g);
|
|
4021
|
-
const contexts = [];
|
|
4022
|
-
for (let match of contextsMatches) {
|
|
4023
|
-
const name = trimQuotes(match[1] || match[2]);
|
|
4024
|
-
if (!contexts.includes(name)) {
|
|
4025
|
-
contexts.push(name);
|
|
4026
|
-
}
|
|
4027
|
-
}
|
|
4028
|
-
return contexts.length ? contexts : void 0;
|
|
4029
|
-
}
|
|
4030
|
-
function consumeScriptComments(status) {
|
|
4031
|
-
const char = status.source[status.i];
|
|
4032
|
-
const nextChar = status.source[status.i + 1];
|
|
4033
|
-
if (char === "/" && nextChar === "/") {
|
|
4034
|
-
status.i = status.source.indexOf("\n", status.i);
|
|
4035
|
-
return true;
|
|
4036
|
-
} else if (char === "/" && nextChar === "*") {
|
|
4037
|
-
status.i = status.source.indexOf("*/", status.i) + 1;
|
|
4038
|
-
return true;
|
|
4039
|
-
} else if (char === '"' || char === "'") {
|
|
4040
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
4041
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\") {
|
|
4042
|
-
status.i = j;
|
|
4043
|
-
break;
|
|
4044
|
-
}
|
|
4045
|
-
}
|
|
4046
|
-
return true;
|
|
4047
|
-
} else if (char === "`") {
|
|
4048
|
-
let level2 = 0;
|
|
4049
|
-
for (let j = status.i + 1; j < status.source.length; j++) {
|
|
4050
|
-
if (status.source[j] === char && status.source[j - 1] !== "\\" && level2 === 0) {
|
|
4051
|
-
status.i = j;
|
|
4052
|
-
break;
|
|
4053
|
-
} else if (status.source[j] === "{" && (level2 > 0 || status.source[j - 1] === "$")) {
|
|
4054
|
-
level2 += 1;
|
|
4055
|
-
} else if (status.source[j] === "}" && level2 > 0) {
|
|
4056
|
-
level2 -= 1;
|
|
4057
|
-
}
|
|
4058
|
-
}
|
|
4059
|
-
return true;
|
|
4060
|
-
}
|
|
4061
|
-
return false;
|
|
4062
|
-
}
|
|
4063
|
-
|
|
4064
|
-
// src/compile/parse.ts
|
|
4065
|
-
function parse(source) {
|
|
4066
|
-
return parseCode(source);
|
|
4067
|
-
}
|
|
4068
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4069
|
-
0 && (module.exports = {
|
|
4070
|
-
build,
|
|
4071
|
-
buildType,
|
|
4072
|
-
parse
|
|
4073
|
-
});
|
|
4074
|
-
//# sourceMappingURL=compile.cjs.map
|