From 803d1d2746c164615eba15f5eae00e03003dbcd8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Apr 2017 12:05:54 -0400 Subject: [PATCH 01/31] move test/generator to test/runtime, and have separate input -> output tests for codegen. add test for #433 --- .eslintignore | 4 +- test/js/README.md | 1 + test/js/index.js | 28 +++ .../samples/event-handlers-custom/expected.js | 205 ++++++++++++++++++ .../samples/event-handlers-custom/input.html | 17 ++ test/{generator => runtime}/index.js | 8 +- .../attribute-dynamic-multiple/_config.js | 0 .../attribute-dynamic-multiple/main.html | 0 .../attribute-dynamic-reserved/_config.js | 0 .../attribute-dynamic-reserved/main.html | 0 .../attribute-dynamic-shorthand/_config.js | 0 .../attribute-dynamic-shorthand/main.html | 0 .../samples/attribute-dynamic/_config.js | 0 .../samples/attribute-dynamic/main.html | 0 .../samples/attribute-empty-svg/_config.js | 0 .../samples/attribute-empty-svg/main.html | 0 .../samples/attribute-empty/_config.js | 0 .../samples/attribute-empty/main.html | 0 .../attribute-partial-number/Component.html | 0 .../attribute-partial-number/_config.js | 0 .../attribute-partial-number/main.html | 0 .../attribute-prefer-expression/_config.js | 0 .../attribute-prefer-expression/main.html | 0 .../attribute-static-boolean/_config.js | 0 .../attribute-static-boolean/main.html | 0 .../samples/attribute-static/_config.js | 0 .../samples/attribute-static/main.html | 0 .../samples/autofocus/_config.js | 0 .../samples/autofocus/main.html | 0 .../_config.js | 0 .../main.html | 0 .../binding-input-checkbox-group/_config.js | 0 .../binding-input-checkbox-group/main.html | 0 .../samples/binding-input-checkbox/_config.js | 0 .../samples/binding-input-checkbox/main.html | 0 .../samples/binding-input-number/_config.js | 0 .../samples/binding-input-number/main.html | 0 .../binding-input-radio-group/_config.js | 0 .../binding-input-radio-group/main.html | 0 .../samples/binding-input-range/_config.js | 0 .../samples/binding-input-range/main.html | 0 .../binding-input-text-contextual/_config.js | 0 .../binding-input-text-contextual/main.html | 0 .../_config.js | 0 .../main.html | 0 .../binding-input-text-deep/_config.js | 0 .../samples/binding-input-text-deep/main.html | 0 .../samples/binding-input-text/_config.js | 0 .../samples/binding-input-text/main.html | 0 .../binding-select-initial-value/_config.js | 0 .../binding-select-initial-value/main.html | 0 .../binding-select-multiple/_config.js | 0 .../samples/binding-select-multiple/main.html | 0 .../samples/binding-select/_config.js | 0 .../samples/binding-select/main.html | 0 .../samples/binding-textarea/_config.js | 0 .../samples/binding-textarea/main.html | 0 .../component-binding-conditional-b/Bar.html | 0 .../component-binding-conditional-b/Baz.html | 0 .../component-binding-conditional-b/Foo.html | 0 .../_config.js | 0 .../component-binding-conditional-b/main.html | 0 .../component-binding-conditional/Bar.html | 0 .../component-binding-conditional/Baz.html | 0 .../component-binding-conditional/Foo.html | 0 .../component-binding-conditional/_config.js | 0 .../component-binding-conditional/main.html | 0 .../ComponentSelector.html | 0 .../component-binding-deep-b/Editor.html | 0 .../component-binding-deep-b/_config.js | 0 .../component-binding-deep-b/main.html | 0 .../component-binding-deep/Widget.html | 0 .../samples/component-binding-deep/_config.js | 0 .../samples/component-binding-deep/main.html | 0 .../component-binding-each-nested/Widget.html | 0 .../component-binding-each-nested/_config.js | 0 .../component-binding-each-nested/main.html | 0 .../component-binding-each-object/Widget.html | 0 .../component-binding-each-object/_config.js | 0 .../component-binding-each-object/main.html | 0 .../component-binding-each/Widget.html | 0 .../samples/component-binding-each/_config.js | 0 .../samples/component-binding-each/main.html | 0 .../component-binding-infinite-loop/A.html | 0 .../component-binding-infinite-loop/B.html | 0 .../component-binding-infinite-loop/C.html | 0 .../_config.js | 0 .../component-binding-infinite-loop/main.html | 0 .../samples/component-binding-nested/Bar.html | 0 .../samples/component-binding-nested/Baz.html | 0 .../samples/component-binding-nested/Foo.html | 0 .../component-binding-nested/_config.js | 0 .../component-binding-nested/main.html | 0 .../Counter.html | 0 .../_config.js | 0 .../main.html | 0 .../samples/component-binding/Counter.html | 0 .../samples/component-binding/_config.js | 0 .../samples/component-binding/main.html | 0 .../component-data-dynamic-late/Widget.html | 0 .../component-data-dynamic-late/_config.js | 0 .../component-data-dynamic-late/main.html | 0 .../Widget.html | 0 .../_config.js | 0 .../main.html | 0 .../component-data-dynamic/Widget.html | 0 .../samples/component-data-dynamic/_config.js | 0 .../samples/component-data-dynamic/main.html | 0 .../samples/component-data-empty/Widget.html | 0 .../samples/component-data-empty/_config.js | 0 .../samples/component-data-empty/main.html | 0 .../component-data-static-boolean/Foo.html | 0 .../component-data-static-boolean/_config.js | 0 .../component-data-static-boolean/main.html | 0 .../samples/component-data-static/Widget.html | 0 .../samples/component-data-static/_config.js | 0 .../samples/component-data-static/main.html | 0 .../samples/component-events-data/Widget.html | 0 .../samples/component-events-data/_config.js | 0 .../samples/component-events-data/main.html | 0 .../samples/component-events-each/Widget.html | 0 .../samples/component-events-each/_config.js | 0 .../samples/component-events-each/main.html | 0 .../samples/component-events/Widget.html | 0 .../samples/component-events/_config.js | 0 .../samples/component-events/main.html | 0 .../samples/component-not-void/Link.html | 0 .../samples/component-not-void/_config.js | 0 .../samples/component-not-void/main.html | 0 .../samples/component-ref/Widget.html | 0 .../samples/component-ref/_config.js | 0 .../samples/component-ref/main.html | 0 .../samples/component-yield-if/Widget.html | 0 .../samples/component-yield-if/_config.js | 0 .../samples/component-yield-if/main.html | 0 .../Widget.html | 0 .../_config.js | 0 .../main.html | 0 .../Widget.html | 0 .../component-yield-multiple-in-if/_config.js | 0 .../component-yield-multiple-in-if/main.html | 0 .../component-yield-parent/Widget.html | 0 .../samples/component-yield-parent/_config.js | 0 .../samples/component-yield-parent/main.html | 0 .../samples/component-yield/_config.js | 0 .../samples/component-yield/main.html | 0 .../samples/component/Widget.html | 0 .../samples/component/_config.js | 0 .../samples/component/main.html | 0 .../samples/computed-function/_config.js | 0 .../samples/computed-function/main.html | 0 .../computed-values-default/_config.js | 0 .../samples/computed-values-default/main.html | 0 .../_config.js | 0 .../main.html | 0 .../samples/computed-values/_config.js | 0 .../samples/computed-values/main.html | 0 .../samples/css-comments/_config.js | 0 .../samples/css-comments/main.html | 0 .../samples/css-false/Widget.html | 0 .../samples/css-false/_config.js | 0 .../samples/css-false/main.html | 0 .../css-space-in-attribute/Widget.html | 0 .../samples/css-space-in-attribute/_config.js | 0 .../samples/css-space-in-attribute/main.html | 0 .../samples/css/Widget.html | 0 .../samples/css/_config.js | 0 .../samples/css/main.html | 0 .../samples/custom-method/_config.js | 0 .../samples/custom-method/main.html | 0 .../samples/deconflict-builtins/_config.js | 0 .../samples/deconflict-builtins/get.js | 0 .../samples/deconflict-builtins/main.html | 0 .../samples/deconflict-contexts/_config.js | 0 .../samples/deconflict-contexts/main.html | 0 .../samples/deconflict-non-helpers/_config.js | 0 .../samples/deconflict-non-helpers/main.html | 0 .../samples/deconflict-non-helpers/module.js | 0 .../samples/deconflict-template-1/_config.js | 0 .../samples/deconflict-template-1/main.html | 0 .../samples/deconflict-template-1/module.js | 0 .../samples/deconflict-template-2/_config.js | 0 .../samples/deconflict-template-2/main.html | 0 .../samples/default-data-function/_config.js | 0 .../samples/default-data-function/main.html | 0 .../samples/default-data-override/_config.js | 0 .../samples/default-data-override/main.html | 0 .../samples/default-data/_config.js | 0 .../samples/default-data/main.html | 0 .../samples/destructuring/_config.js | 0 .../samples/destructuring/main.html | 0 .../_config.js | 0 .../main.html | 0 .../_config.js | 0 .../main.html | 0 .../_config.js | 0 .../main.html | 0 .../dev-warning-missing-data/_config.js | 0 .../dev-warning-missing-data/main.html | 0 .../each-block-containing-if/_config.js | 0 .../each-block-containing-if/main.html | 0 .../samples/each-block-else/_config.js | 0 .../samples/each-block-else/main.html | 0 .../samples/each-block-indexed/_config.js | 0 .../samples/each-block-indexed/main.html | 0 .../samples/each-block-keyed/_config.js | 0 .../samples/each-block-keyed/main.html | 0 .../each-block-random-permute/_config.js | 0 .../each-block-random-permute/main.html | 0 .../samples/each-block-text-node/_config.js | 0 .../samples/each-block-text-node/main.html | 0 .../samples/each-block/_config.js | 0 .../samples/each-block/main.html | 0 .../samples/each-blocks-expression/_config.js | 0 .../samples/each-blocks-expression/main.html | 0 .../samples/each-blocks-nested-b/_config.js | 0 .../samples/each-blocks-nested-b/main.html | 0 .../samples/each-blocks-nested/_config.js | 0 .../samples/each-blocks-nested/main.html | 0 .../event-handler-custom-context/_config.js | 0 .../event-handler-custom-context/main.html | 0 .../_config.js | 0 .../main.html | 0 .../samples/event-handler-custom/_config.js | 0 .../samples/event-handler-custom/main.html | 0 .../event-handler-event-methods/_config.js | 0 .../event-handler-event-methods/main.html | 0 .../samples/event-handler-removal/_config.js | 0 .../samples/event-handler-removal/main.html | 0 .../event-handler-this-methods/_config.js | 0 .../event-handler-this-methods/main.html | 0 .../samples/event-handler/_config.js | 0 .../samples/event-handler/main.html | 0 .../samples/events-custom/_config.js | 0 .../samples/events-custom/main.html | 0 .../samples/events-lifecycle/_config.js | 0 .../samples/events-lifecycle/main.html | 0 .../samples/function-in-expression/_config.js | 0 .../samples/function-in-expression/main.html | 0 .../samples/get-state/_config.js | 0 .../samples/get-state/main.html | 0 .../globals-accessible-directly/_config.js | 0 .../globals-accessible-directly/main.html | 0 .../globals-not-dereferenced/_config.js | 0 .../globals-not-dereferenced/main.html | 0 .../globals-shadowed-by-data/_config.js | 0 .../globals-shadowed-by-data/main.html | 0 .../globals-shadowed-by-helpers/_config.js | 0 .../globals-shadowed-by-helpers/main.html | 0 .../samples/hello-world/_config.js | 0 .../samples/hello-world/main.html | 0 .../samples/helpers/_config.js | 0 .../samples/helpers/main.html | 0 .../samples/if-block-else/_config.js | 0 .../samples/if-block-else/main.html | 0 .../samples/if-block-elseif-text/_config.js | 0 .../samples/if-block-elseif-text/main.html | 0 .../samples/if-block-elseif/_config.js | 0 .../samples/if-block-elseif/main.html | 0 .../samples/if-block-expression/_config.js | 0 .../samples/if-block-expression/main.html | 0 .../samples/if-block-widget/Widget.html | 0 .../samples/if-block-widget/_config.js | 0 .../samples/if-block-widget/main.html | 0 .../samples/if-block/_config.js | 0 .../samples/if-block/main.html | 0 .../ComponentOne.html | 0 .../ComponentTwo.html | 0 .../imported-renamed-components/_config.js | 0 .../imported-renamed-components/main.html | 0 .../samples/inline-expressions/_config.js | 0 .../samples/inline-expressions/main.html | 0 .../samples/input-list/_config.js | 0 .../samples/input-list/main.html | 0 .../samples/lifecycle-events/_config.js | 0 .../samples/lifecycle-events/main.html | 0 .../names-deconflicted-nested/_config.js | 0 .../names-deconflicted-nested/main.html | 0 .../samples/names-deconflicted/Widget.html | 0 .../samples/names-deconflicted/_config.js | 0 .../samples/names-deconflicted/main.html | 0 .../samples/nbsp/_config.js | 0 .../samples/nbsp/main.html | 0 .../Foo.html | 0 .../_config.js | 0 .../main.html | 0 .../samples/observe-prevents-loop/_config.js | 0 .../samples/observe-prevents-loop/main.html | 0 .../samples/onrender-chain/Item.html | 0 .../samples/onrender-chain/List.html | 0 .../samples/onrender-chain/_config.js | 0 .../samples/onrender-chain/main.html | 0 .../ParentWidget.html | 0 .../Widget.html | 0 .../_config.js | 0 .../main.html | 0 .../onrender-fires-when-ready/Widget.html | 0 .../onrender-fires-when-ready/_config.js | 0 .../onrender-fires-when-ready/main.html | 0 .../samples/pass-no-options/_config.js | 0 .../samples/pass-no-options/main.html | 0 .../raw-mustaches-preserved/_config.js | 0 .../samples/raw-mustaches-preserved/main.html | 0 .../samples/raw-mustaches/_config.js | 0 .../samples/raw-mustaches/main.html | 0 .../samples/refs-unset/_config.js | 0 .../samples/refs-unset/main.html | 0 .../samples/refs/_config.js | 0 .../samples/refs/main.html | 0 .../samples/select-one-way-bind/_config.js | 0 .../samples/select-one-way-bind/main.html | 0 .../samples/select/_config.js | 0 .../samples/select/main.html | 0 .../samples/self-reference-tree/_config.js | 0 .../samples/self-reference-tree/main.html | 0 .../samples/self-reference/_config.js | 0 .../samples/self-reference/main.html | 0 .../Widget.html | 0 .../set-in-observe-dedupes-renders/_config.js | 0 .../set-in-observe-dedupes-renders/main.html | 0 .../samples/set-in-observe/_config.js | 0 .../samples/set-in-observe/main.html | 0 .../samples/set-in-onrender/_config.js | 0 .../samples/set-in-onrender/main.html | 0 .../samples/set-prevents-loop/Foo.html | 0 .../samples/set-prevents-loop/_config.js | 0 .../samples/set-prevents-loop/main.html | 0 .../samples/single-static-element/_config.js | 0 .../samples/single-static-element/main.html | 0 .../samples/single-text-node/_config.js | 0 .../samples/single-text-node/main.html | 0 .../samples/svg-attributes/_config.js | 0 .../samples/svg-attributes/main.html | 0 .../Rect.html | 0 .../_config.js | 0 .../main.html | 0 .../Rect.html | 0 .../_config.js | 0 .../main.html | 0 .../samples/svg-class/_config.js | 0 .../samples/svg-class/main.html | 0 .../svg-each-block-namespace/_config.js | 0 .../svg-each-block-namespace/main.html | 0 .../samples/svg-multiple/_config.js | 0 .../samples/svg-multiple/main.html | 0 .../samples/svg-no-whitespace/_config.js | 0 .../samples/svg-no-whitespace/main.html | 0 .../samples/svg-xlink/_config.js | 0 .../samples/svg-xlink/main.html | 0 .../samples/svg-xmlns/_config.js | 0 .../samples/svg-xmlns/main.html | 0 .../samples/svg/_config.js | 0 .../samples/svg/main.html | 0 .../samples/window-binding-resize/_config.js | 0 .../samples/window-binding-resize/main.html | 0 .../samples/window-event/_config.js | 0 .../samples/window-event/main.html | 0 test/server-side-rendering/index.js | 8 +- 358 files changed, 262 insertions(+), 9 deletions(-) create mode 100644 test/js/README.md create mode 100644 test/js/index.js create mode 100644 test/js/samples/event-handlers-custom/expected.js create mode 100644 test/js/samples/event-handlers-custom/input.html rename test/{generator => runtime}/index.js (94%) rename test/{generator => runtime}/samples/attribute-dynamic-multiple/_config.js (100%) rename test/{generator => runtime}/samples/attribute-dynamic-multiple/main.html (100%) rename test/{generator => runtime}/samples/attribute-dynamic-reserved/_config.js (100%) rename test/{generator => runtime}/samples/attribute-dynamic-reserved/main.html (100%) rename test/{generator => runtime}/samples/attribute-dynamic-shorthand/_config.js (100%) rename test/{generator => runtime}/samples/attribute-dynamic-shorthand/main.html (100%) rename test/{generator => runtime}/samples/attribute-dynamic/_config.js (100%) rename test/{generator => runtime}/samples/attribute-dynamic/main.html (100%) rename test/{generator => runtime}/samples/attribute-empty-svg/_config.js (100%) rename test/{generator => runtime}/samples/attribute-empty-svg/main.html (100%) rename test/{generator => runtime}/samples/attribute-empty/_config.js (100%) rename test/{generator => runtime}/samples/attribute-empty/main.html (100%) rename test/{generator => runtime}/samples/attribute-partial-number/Component.html (100%) rename test/{generator => runtime}/samples/attribute-partial-number/_config.js (100%) rename test/{generator => runtime}/samples/attribute-partial-number/main.html (100%) rename test/{generator => runtime}/samples/attribute-prefer-expression/_config.js (100%) rename test/{generator => runtime}/samples/attribute-prefer-expression/main.html (100%) rename test/{generator => runtime}/samples/attribute-static-boolean/_config.js (100%) rename test/{generator => runtime}/samples/attribute-static-boolean/main.html (100%) rename test/{generator => runtime}/samples/attribute-static/_config.js (100%) rename test/{generator => runtime}/samples/attribute-static/main.html (100%) rename test/{generator => runtime}/samples/autofocus/_config.js (100%) rename test/{generator => runtime}/samples/autofocus/main.html (100%) rename test/{generator => runtime}/samples/binding-input-checkbox-deep-contextual/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-checkbox-deep-contextual/main.html (100%) rename test/{generator => runtime}/samples/binding-input-checkbox-group/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-checkbox-group/main.html (100%) rename test/{generator => runtime}/samples/binding-input-checkbox/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-checkbox/main.html (100%) rename test/{generator => runtime}/samples/binding-input-number/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-number/main.html (100%) rename test/{generator => runtime}/samples/binding-input-radio-group/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-radio-group/main.html (100%) rename test/{generator => runtime}/samples/binding-input-range/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-range/main.html (100%) rename test/{generator => runtime}/samples/binding-input-text-contextual/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-text-contextual/main.html (100%) rename test/{generator => runtime}/samples/binding-input-text-deep-contextual/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-text-deep-contextual/main.html (100%) rename test/{generator => runtime}/samples/binding-input-text-deep/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-text-deep/main.html (100%) rename test/{generator => runtime}/samples/binding-input-text/_config.js (100%) rename test/{generator => runtime}/samples/binding-input-text/main.html (100%) rename test/{generator => runtime}/samples/binding-select-initial-value/_config.js (100%) rename test/{generator => runtime}/samples/binding-select-initial-value/main.html (100%) rename test/{generator => runtime}/samples/binding-select-multiple/_config.js (100%) rename test/{generator => runtime}/samples/binding-select-multiple/main.html (100%) rename test/{generator => runtime}/samples/binding-select/_config.js (100%) rename test/{generator => runtime}/samples/binding-select/main.html (100%) rename test/{generator => runtime}/samples/binding-textarea/_config.js (100%) rename test/{generator => runtime}/samples/binding-textarea/main.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional-b/Bar.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional-b/Baz.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional-b/Foo.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional-b/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-conditional-b/main.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional/Bar.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional/Baz.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional/Foo.html (100%) rename test/{generator => runtime}/samples/component-binding-conditional/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-conditional/main.html (100%) rename test/{generator => runtime}/samples/component-binding-deep-b/ComponentSelector.html (100%) rename test/{generator => runtime}/samples/component-binding-deep-b/Editor.html (100%) rename test/{generator => runtime}/samples/component-binding-deep-b/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-deep-b/main.html (100%) rename test/{generator => runtime}/samples/component-binding-deep/Widget.html (100%) rename test/{generator => runtime}/samples/component-binding-deep/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-deep/main.html (100%) rename test/{generator => runtime}/samples/component-binding-each-nested/Widget.html (100%) rename test/{generator => runtime}/samples/component-binding-each-nested/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-each-nested/main.html (100%) rename test/{generator => runtime}/samples/component-binding-each-object/Widget.html (100%) rename test/{generator => runtime}/samples/component-binding-each-object/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-each-object/main.html (100%) rename test/{generator => runtime}/samples/component-binding-each/Widget.html (100%) rename test/{generator => runtime}/samples/component-binding-each/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-each/main.html (100%) rename test/{generator => runtime}/samples/component-binding-infinite-loop/A.html (100%) rename test/{generator => runtime}/samples/component-binding-infinite-loop/B.html (100%) rename test/{generator => runtime}/samples/component-binding-infinite-loop/C.html (100%) rename test/{generator => runtime}/samples/component-binding-infinite-loop/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-infinite-loop/main.html (100%) rename test/{generator => runtime}/samples/component-binding-nested/Bar.html (100%) rename test/{generator => runtime}/samples/component-binding-nested/Baz.html (100%) rename test/{generator => runtime}/samples/component-binding-nested/Foo.html (100%) rename test/{generator => runtime}/samples/component-binding-nested/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-nested/main.html (100%) rename test/{generator => runtime}/samples/component-binding-parent-supercedes-child/Counter.html (100%) rename test/{generator => runtime}/samples/component-binding-parent-supercedes-child/_config.js (100%) rename test/{generator => runtime}/samples/component-binding-parent-supercedes-child/main.html (100%) rename test/{generator => runtime}/samples/component-binding/Counter.html (100%) rename test/{generator => runtime}/samples/component-binding/_config.js (100%) rename test/{generator => runtime}/samples/component-binding/main.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic-late/Widget.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic-late/_config.js (100%) rename test/{generator => runtime}/samples/component-data-dynamic-late/main.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic-shorthand/Widget.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic-shorthand/_config.js (100%) rename test/{generator => runtime}/samples/component-data-dynamic-shorthand/main.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic/Widget.html (100%) rename test/{generator => runtime}/samples/component-data-dynamic/_config.js (100%) rename test/{generator => runtime}/samples/component-data-dynamic/main.html (100%) rename test/{generator => runtime}/samples/component-data-empty/Widget.html (100%) rename test/{generator => runtime}/samples/component-data-empty/_config.js (100%) rename test/{generator => runtime}/samples/component-data-empty/main.html (100%) rename test/{generator => runtime}/samples/component-data-static-boolean/Foo.html (100%) rename test/{generator => runtime}/samples/component-data-static-boolean/_config.js (100%) rename test/{generator => runtime}/samples/component-data-static-boolean/main.html (100%) rename test/{generator => runtime}/samples/component-data-static/Widget.html (100%) rename test/{generator => runtime}/samples/component-data-static/_config.js (100%) rename test/{generator => runtime}/samples/component-data-static/main.html (100%) rename test/{generator => runtime}/samples/component-events-data/Widget.html (100%) rename test/{generator => runtime}/samples/component-events-data/_config.js (100%) rename test/{generator => runtime}/samples/component-events-data/main.html (100%) rename test/{generator => runtime}/samples/component-events-each/Widget.html (100%) rename test/{generator => runtime}/samples/component-events-each/_config.js (100%) rename test/{generator => runtime}/samples/component-events-each/main.html (100%) rename test/{generator => runtime}/samples/component-events/Widget.html (100%) rename test/{generator => runtime}/samples/component-events/_config.js (100%) rename test/{generator => runtime}/samples/component-events/main.html (100%) rename test/{generator => runtime}/samples/component-not-void/Link.html (100%) rename test/{generator => runtime}/samples/component-not-void/_config.js (100%) rename test/{generator => runtime}/samples/component-not-void/main.html (100%) rename test/{generator => runtime}/samples/component-ref/Widget.html (100%) rename test/{generator => runtime}/samples/component-ref/_config.js (100%) rename test/{generator => runtime}/samples/component-ref/main.html (100%) rename test/{generator => runtime}/samples/component-yield-if/Widget.html (100%) rename test/{generator => runtime}/samples/component-yield-if/_config.js (100%) rename test/{generator => runtime}/samples/component-yield-if/main.html (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-each/Widget.html (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-each/_config.js (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-each/main.html (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-if/Widget.html (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-if/_config.js (100%) rename test/{generator => runtime}/samples/component-yield-multiple-in-if/main.html (100%) rename test/{generator => runtime}/samples/component-yield-parent/Widget.html (100%) rename test/{generator => runtime}/samples/component-yield-parent/_config.js (100%) rename test/{generator => runtime}/samples/component-yield-parent/main.html (100%) rename test/{generator => runtime}/samples/component-yield/_config.js (100%) rename test/{generator => runtime}/samples/component-yield/main.html (100%) rename test/{generator => runtime}/samples/component/Widget.html (100%) rename test/{generator => runtime}/samples/component/_config.js (100%) rename test/{generator => runtime}/samples/component/main.html (100%) rename test/{generator => runtime}/samples/computed-function/_config.js (100%) rename test/{generator => runtime}/samples/computed-function/main.html (100%) rename test/{generator => runtime}/samples/computed-values-default/_config.js (100%) rename test/{generator => runtime}/samples/computed-values-default/main.html (100%) rename test/{generator => runtime}/samples/computed-values-function-dependency/_config.js (100%) rename test/{generator => runtime}/samples/computed-values-function-dependency/main.html (100%) rename test/{generator => runtime}/samples/computed-values/_config.js (100%) rename test/{generator => runtime}/samples/computed-values/main.html (100%) rename test/{generator => runtime}/samples/css-comments/_config.js (100%) rename test/{generator => runtime}/samples/css-comments/main.html (100%) rename test/{generator => runtime}/samples/css-false/Widget.html (100%) rename test/{generator => runtime}/samples/css-false/_config.js (100%) rename test/{generator => runtime}/samples/css-false/main.html (100%) rename test/{generator => runtime}/samples/css-space-in-attribute/Widget.html (100%) rename test/{generator => runtime}/samples/css-space-in-attribute/_config.js (100%) rename test/{generator => runtime}/samples/css-space-in-attribute/main.html (100%) rename test/{generator => runtime}/samples/css/Widget.html (100%) rename test/{generator => runtime}/samples/css/_config.js (100%) rename test/{generator => runtime}/samples/css/main.html (100%) rename test/{generator => runtime}/samples/custom-method/_config.js (100%) rename test/{generator => runtime}/samples/custom-method/main.html (100%) rename test/{generator => runtime}/samples/deconflict-builtins/_config.js (100%) rename test/{generator => runtime}/samples/deconflict-builtins/get.js (100%) rename test/{generator => runtime}/samples/deconflict-builtins/main.html (100%) rename test/{generator => runtime}/samples/deconflict-contexts/_config.js (100%) rename test/{generator => runtime}/samples/deconflict-contexts/main.html (100%) rename test/{generator => runtime}/samples/deconflict-non-helpers/_config.js (100%) rename test/{generator => runtime}/samples/deconflict-non-helpers/main.html (100%) rename test/{generator => runtime}/samples/deconflict-non-helpers/module.js (100%) rename test/{generator => runtime}/samples/deconflict-template-1/_config.js (100%) rename test/{generator => runtime}/samples/deconflict-template-1/main.html (100%) rename test/{generator => runtime}/samples/deconflict-template-1/module.js (100%) rename test/{generator => runtime}/samples/deconflict-template-2/_config.js (100%) rename test/{generator => runtime}/samples/deconflict-template-2/main.html (100%) rename test/{generator => runtime}/samples/default-data-function/_config.js (100%) rename test/{generator => runtime}/samples/default-data-function/main.html (100%) rename test/{generator => runtime}/samples/default-data-override/_config.js (100%) rename test/{generator => runtime}/samples/default-data-override/main.html (100%) rename test/{generator => runtime}/samples/default-data/_config.js (100%) rename test/{generator => runtime}/samples/default-data/main.html (100%) rename test/{generator => runtime}/samples/destructuring/_config.js (100%) rename test/{generator => runtime}/samples/destructuring/main.html (100%) rename test/{generator => runtime}/samples/dev-warning-bad-observe-arguments/_config.js (100%) rename test/{generator => runtime}/samples/dev-warning-bad-observe-arguments/main.html (100%) rename test/{generator => runtime}/samples/dev-warning-destroy-not-teardown/_config.js (100%) rename test/{generator => runtime}/samples/dev-warning-destroy-not-teardown/main.html (100%) rename test/{generator => runtime}/samples/dev-warning-missing-data-binding/_config.js (100%) rename test/{generator => runtime}/samples/dev-warning-missing-data-binding/main.html (100%) rename test/{generator => runtime}/samples/dev-warning-missing-data/_config.js (100%) rename test/{generator => runtime}/samples/dev-warning-missing-data/main.html (100%) rename test/{generator => runtime}/samples/each-block-containing-if/_config.js (100%) rename test/{generator => runtime}/samples/each-block-containing-if/main.html (100%) rename test/{generator => runtime}/samples/each-block-else/_config.js (100%) rename test/{generator => runtime}/samples/each-block-else/main.html (100%) rename test/{generator => runtime}/samples/each-block-indexed/_config.js (100%) rename test/{generator => runtime}/samples/each-block-indexed/main.html (100%) rename test/{generator => runtime}/samples/each-block-keyed/_config.js (100%) rename test/{generator => runtime}/samples/each-block-keyed/main.html (100%) rename test/{generator => runtime}/samples/each-block-random-permute/_config.js (100%) rename test/{generator => runtime}/samples/each-block-random-permute/main.html (100%) rename test/{generator => runtime}/samples/each-block-text-node/_config.js (100%) rename test/{generator => runtime}/samples/each-block-text-node/main.html (100%) rename test/{generator => runtime}/samples/each-block/_config.js (100%) rename test/{generator => runtime}/samples/each-block/main.html (100%) rename test/{generator => runtime}/samples/each-blocks-expression/_config.js (100%) rename test/{generator => runtime}/samples/each-blocks-expression/main.html (100%) rename test/{generator => runtime}/samples/each-blocks-nested-b/_config.js (100%) rename test/{generator => runtime}/samples/each-blocks-nested-b/main.html (100%) rename test/{generator => runtime}/samples/each-blocks-nested/_config.js (100%) rename test/{generator => runtime}/samples/each-blocks-nested/main.html (100%) rename test/{generator => runtime}/samples/event-handler-custom-context/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-custom-context/main.html (100%) rename test/{generator => runtime}/samples/event-handler-custom-node-context/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-custom-node-context/main.html (100%) rename test/{generator => runtime}/samples/event-handler-custom/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-custom/main.html (100%) rename test/{generator => runtime}/samples/event-handler-event-methods/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-event-methods/main.html (100%) rename test/{generator => runtime}/samples/event-handler-removal/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-removal/main.html (100%) rename test/{generator => runtime}/samples/event-handler-this-methods/_config.js (100%) rename test/{generator => runtime}/samples/event-handler-this-methods/main.html (100%) rename test/{generator => runtime}/samples/event-handler/_config.js (100%) rename test/{generator => runtime}/samples/event-handler/main.html (100%) rename test/{generator => runtime}/samples/events-custom/_config.js (100%) rename test/{generator => runtime}/samples/events-custom/main.html (100%) rename test/{generator => runtime}/samples/events-lifecycle/_config.js (100%) rename test/{generator => runtime}/samples/events-lifecycle/main.html (100%) rename test/{generator => runtime}/samples/function-in-expression/_config.js (100%) rename test/{generator => runtime}/samples/function-in-expression/main.html (100%) rename test/{generator => runtime}/samples/get-state/_config.js (100%) rename test/{generator => runtime}/samples/get-state/main.html (100%) rename test/{generator => runtime}/samples/globals-accessible-directly/_config.js (100%) rename test/{generator => runtime}/samples/globals-accessible-directly/main.html (100%) rename test/{generator => runtime}/samples/globals-not-dereferenced/_config.js (100%) rename test/{generator => runtime}/samples/globals-not-dereferenced/main.html (100%) rename test/{generator => runtime}/samples/globals-shadowed-by-data/_config.js (100%) rename test/{generator => runtime}/samples/globals-shadowed-by-data/main.html (100%) rename test/{generator => runtime}/samples/globals-shadowed-by-helpers/_config.js (100%) rename test/{generator => runtime}/samples/globals-shadowed-by-helpers/main.html (100%) rename test/{generator => runtime}/samples/hello-world/_config.js (100%) rename test/{generator => runtime}/samples/hello-world/main.html (100%) rename test/{generator => runtime}/samples/helpers/_config.js (100%) rename test/{generator => runtime}/samples/helpers/main.html (100%) rename test/{generator => runtime}/samples/if-block-else/_config.js (100%) rename test/{generator => runtime}/samples/if-block-else/main.html (100%) rename test/{generator => runtime}/samples/if-block-elseif-text/_config.js (100%) rename test/{generator => runtime}/samples/if-block-elseif-text/main.html (100%) rename test/{generator => runtime}/samples/if-block-elseif/_config.js (100%) rename test/{generator => runtime}/samples/if-block-elseif/main.html (100%) rename test/{generator => runtime}/samples/if-block-expression/_config.js (100%) rename test/{generator => runtime}/samples/if-block-expression/main.html (100%) rename test/{generator => runtime}/samples/if-block-widget/Widget.html (100%) rename test/{generator => runtime}/samples/if-block-widget/_config.js (100%) rename test/{generator => runtime}/samples/if-block-widget/main.html (100%) rename test/{generator => runtime}/samples/if-block/_config.js (100%) rename test/{generator => runtime}/samples/if-block/main.html (100%) rename test/{generator => runtime}/samples/imported-renamed-components/ComponentOne.html (100%) rename test/{generator => runtime}/samples/imported-renamed-components/ComponentTwo.html (100%) rename test/{generator => runtime}/samples/imported-renamed-components/_config.js (100%) rename test/{generator => runtime}/samples/imported-renamed-components/main.html (100%) rename test/{generator => runtime}/samples/inline-expressions/_config.js (100%) rename test/{generator => runtime}/samples/inline-expressions/main.html (100%) rename test/{generator => runtime}/samples/input-list/_config.js (100%) rename test/{generator => runtime}/samples/input-list/main.html (100%) rename test/{generator => runtime}/samples/lifecycle-events/_config.js (100%) rename test/{generator => runtime}/samples/lifecycle-events/main.html (100%) rename test/{generator => runtime}/samples/names-deconflicted-nested/_config.js (100%) rename test/{generator => runtime}/samples/names-deconflicted-nested/main.html (100%) rename test/{generator => runtime}/samples/names-deconflicted/Widget.html (100%) rename test/{generator => runtime}/samples/names-deconflicted/_config.js (100%) rename test/{generator => runtime}/samples/names-deconflicted/main.html (100%) rename test/{generator => runtime}/samples/nbsp/_config.js (100%) rename test/{generator => runtime}/samples/nbsp/main.html (100%) rename test/{generator => runtime}/samples/observe-component-ignores-irrelevant-changes/Foo.html (100%) rename test/{generator => runtime}/samples/observe-component-ignores-irrelevant-changes/_config.js (100%) rename test/{generator => runtime}/samples/observe-component-ignores-irrelevant-changes/main.html (100%) rename test/{generator => runtime}/samples/observe-prevents-loop/_config.js (100%) rename test/{generator => runtime}/samples/observe-prevents-loop/main.html (100%) rename test/{generator => runtime}/samples/onrender-chain/Item.html (100%) rename test/{generator => runtime}/samples/onrender-chain/List.html (100%) rename test/{generator => runtime}/samples/onrender-chain/_config.js (100%) rename test/{generator => runtime}/samples/onrender-chain/main.html (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready-nested/ParentWidget.html (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready-nested/Widget.html (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready-nested/_config.js (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready-nested/main.html (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready/Widget.html (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready/_config.js (100%) rename test/{generator => runtime}/samples/onrender-fires-when-ready/main.html (100%) rename test/{generator => runtime}/samples/pass-no-options/_config.js (100%) rename test/{generator => runtime}/samples/pass-no-options/main.html (100%) rename test/{generator => runtime}/samples/raw-mustaches-preserved/_config.js (100%) rename test/{generator => runtime}/samples/raw-mustaches-preserved/main.html (100%) rename test/{generator => runtime}/samples/raw-mustaches/_config.js (100%) rename test/{generator => runtime}/samples/raw-mustaches/main.html (100%) rename test/{generator => runtime}/samples/refs-unset/_config.js (100%) rename test/{generator => runtime}/samples/refs-unset/main.html (100%) rename test/{generator => runtime}/samples/refs/_config.js (100%) rename test/{generator => runtime}/samples/refs/main.html (100%) rename test/{generator => runtime}/samples/select-one-way-bind/_config.js (100%) rename test/{generator => runtime}/samples/select-one-way-bind/main.html (100%) rename test/{generator => runtime}/samples/select/_config.js (100%) rename test/{generator => runtime}/samples/select/main.html (100%) rename test/{generator => runtime}/samples/self-reference-tree/_config.js (100%) rename test/{generator => runtime}/samples/self-reference-tree/main.html (100%) rename test/{generator => runtime}/samples/self-reference/_config.js (100%) rename test/{generator => runtime}/samples/self-reference/main.html (100%) rename test/{generator => runtime}/samples/set-in-observe-dedupes-renders/Widget.html (100%) rename test/{generator => runtime}/samples/set-in-observe-dedupes-renders/_config.js (100%) rename test/{generator => runtime}/samples/set-in-observe-dedupes-renders/main.html (100%) rename test/{generator => runtime}/samples/set-in-observe/_config.js (100%) rename test/{generator => runtime}/samples/set-in-observe/main.html (100%) rename test/{generator => runtime}/samples/set-in-onrender/_config.js (100%) rename test/{generator => runtime}/samples/set-in-onrender/main.html (100%) rename test/{generator => runtime}/samples/set-prevents-loop/Foo.html (100%) rename test/{generator => runtime}/samples/set-prevents-loop/_config.js (100%) rename test/{generator => runtime}/samples/set-prevents-loop/main.html (100%) rename test/{generator => runtime}/samples/single-static-element/_config.js (100%) rename test/{generator => runtime}/samples/single-static-element/main.html (100%) rename test/{generator => runtime}/samples/single-text-node/_config.js (100%) rename test/{generator => runtime}/samples/single-text-node/main.html (100%) rename test/{generator => runtime}/samples/svg-attributes/_config.js (100%) rename test/{generator => runtime}/samples/svg-attributes/main.html (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace-shorthand/Rect.html (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace-shorthand/_config.js (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace-shorthand/main.html (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace/Rect.html (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace/_config.js (100%) rename test/{generator => runtime}/samples/svg-child-component-declared-namespace/main.html (100%) rename test/{generator => runtime}/samples/svg-class/_config.js (100%) rename test/{generator => runtime}/samples/svg-class/main.html (100%) rename test/{generator => runtime}/samples/svg-each-block-namespace/_config.js (100%) rename test/{generator => runtime}/samples/svg-each-block-namespace/main.html (100%) rename test/{generator => runtime}/samples/svg-multiple/_config.js (100%) rename test/{generator => runtime}/samples/svg-multiple/main.html (100%) rename test/{generator => runtime}/samples/svg-no-whitespace/_config.js (100%) rename test/{generator => runtime}/samples/svg-no-whitespace/main.html (100%) rename test/{generator => runtime}/samples/svg-xlink/_config.js (100%) rename test/{generator => runtime}/samples/svg-xlink/main.html (100%) rename test/{generator => runtime}/samples/svg-xmlns/_config.js (100%) rename test/{generator => runtime}/samples/svg-xmlns/main.html (100%) rename test/{generator => runtime}/samples/svg/_config.js (100%) rename test/{generator => runtime}/samples/svg/main.html (100%) rename test/{generator => runtime}/samples/window-binding-resize/_config.js (100%) rename test/{generator => runtime}/samples/window-binding-resize/main.html (100%) rename test/{generator => runtime}/samples/window-event/_config.js (100%) rename test/{generator => runtime}/samples/window-event/main.html (100%) diff --git a/.eslintignore b/.eslintignore index a84efdafe36f..effb19af4547 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,5 @@ src/shared shared.js -test/test.js \ No newline at end of file +test/test.js +**/_actual.js +**/expected.js \ No newline at end of file diff --git a/test/js/README.md b/test/js/README.md new file mode 100644 index 000000000000..c43905123ea8 --- /dev/null +++ b/test/js/README.md @@ -0,0 +1 @@ +Use these tests sparingly, as they will need to be updated frequently as the code generation changes. \ No newline at end of file diff --git a/test/js/index.js b/test/js/index.js new file mode 100644 index 000000000000..cf8ab54bbd3a --- /dev/null +++ b/test/js/index.js @@ -0,0 +1,28 @@ +import assert from 'assert'; +import * as fs from 'fs'; +import * as path from 'path'; +import { svelte } from '../helpers.js'; + +describe( 'js', () => { + fs.readdirSync( 'test/js/samples' ).forEach( dir => { + if ( dir[0] === '.' ) return; + + // add .solo to a sample directory name to only run that test + const solo = /\.solo/.test( dir ); + + if ( solo && process.env.CI ) { + throw new Error( 'Forgot to remove `solo: true` from test' ); + } + + ( solo ? it.only : it )( dir, () => { + dir = path.resolve( 'test/js/samples', dir ); + const input = fs.readFileSync( `${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' ); + + const actual = svelte.compile( input ).code; + fs.writeFileSync( `${dir}/_actual.js`, actual ); + const expected = fs.readFileSync( `${dir}/expected.js`, 'utf-8' ); + + assert.equal( actual.trim(), expected.trim() ); + }); + }); +}); diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js new file mode 100644 index 000000000000..71e633d752f2 --- /dev/null +++ b/test/js/samples/event-handlers-custom/expected.js @@ -0,0 +1,205 @@ +var template = (function () { + return { + methods: { + foo ( bar ) { + console.log( bar ); + } + }, + + events: { + foo ( node, callback ) { + // code goes here + } + } + }; +}()); + +function render_main_fragment ( root, component ) { + var button = createElement( 'button' ); + + var foo_handler = template.events.foo.call( component, button, function ( event ) { + var root = component.get(); + + component.foo( root.bar ); + }.bind( button ) ); + + appendNode( createText( "foo" ), button ); + + return { + mount: function ( target, anchor ) { + insertNode( button, target, anchor ); + }, + + update: noop, + + teardown: function ( detach ) { + foo_handler.teardown(); + + if ( detach ) { + detachNode( button ); + } + } + }; +} + +function SvelteComponent ( options ) { + options = options || {}; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root; + this._yield = options._yield; + + this._torndown = false; + + this._fragment = render_main_fragment( this._state, this ); + if ( options.target ) this._fragment.mount( options.target, null ); +} + +assign( SvelteComponent.prototype, template.methods, { + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + _flush: _flush +}); + +SvelteComponent.prototype._set = function _set ( newState ) { + var oldState = this._state; + this._state = assign( {}, oldState, newState ); + + dispatchObservers( this, this._observers.pre, newState, oldState ); + if ( this._fragment ) this._fragment.update( newState, this._state ); + dispatchObservers( this, this._observers.post, newState, oldState ); +}; + +SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { + this.fire( 'destroy' ); + + this._fragment.teardown( detach !== false ); + this._fragment = null; + + this._state = {}; + this._torndown = true; +}; + +function createElement( name ) { + return document.createElement( name ); +} + +function detachNode( node ) { + node.parentNode.removeChild( node ); +} + +function insertNode( node, target, anchor ) { + target.insertBefore( node, anchor ); +} + +function createText( data ) { + return document.createTextNode( data ); +} + +function appendNode( node, target ) { + target.appendChild( node ); +} + +function assign( target ) { + for ( var i = 1; i < arguments.length; i += 1 ) { + var source = arguments[i]; + for ( var k in source ) target[k] = source[k]; + } + + return target; +} + +function dispatchObservers( component, group, newState, oldState ) { + for ( var key in group ) { + if ( !( key in newState ) ) continue; + + var newValue = newState[ key ]; + var oldValue = oldState[ key ]; + + if ( newValue === oldValue && typeof newValue !== 'object' ) continue; + + var callbacks = group[ key ]; + if ( !callbacks ) continue; + + for ( var i = 0; i < callbacks.length; i += 1 ) { + var callback = callbacks[i]; + if ( callback.__calling ) continue; + + callback.__calling = true; + callback.call( component, newValue, oldValue ); + callback.__calling = false; + } + } +} + +function get( key ) { + return key ? this._state[ key ] : this._state; +} + +function fire( eventName, data ) { + var handlers = eventName in this._handlers && this._handlers[ eventName ].slice(); + if ( !handlers ) return; + + for ( var i = 0; i < handlers.length; i += 1 ) { + handlers[i].call( this, data ); + } +} + +function observe( key, callback, options ) { + var group = ( options && options.defer ) ? this._observers.pre : this._observers.post; + + ( group[ key ] || ( group[ key ] = [] ) ).push( callback ); + + if ( !options || options.init !== false ) { + callback.__calling = true; + callback.call( this, this._state[ key ] ); + callback.__calling = false; + } + + return { + cancel: function () { + var index = group[ key ].indexOf( callback ); + if ( ~index ) group[ key ].splice( index, 1 ); + } + }; +} + +function on( eventName, handler ) { + if ( eventName === 'teardown' ) return this.on( 'destroy', handler ); + + var handlers = this._handlers[ eventName ] || ( this._handlers[ eventName ] = [] ); + handlers.push( handler ); + + return { + cancel: function () { + var index = handlers.indexOf( handler ); + if ( ~index ) handlers.splice( index, 1 ); + } + }; +} + +function set( newState ) { + this._set( newState ); + ( this._root || this )._flush(); +} + +function _flush() { + if ( !this._renderHooks ) return; + + while ( this._renderHooks.length ) { + var hook = this._renderHooks.pop(); + hook.fn.call( hook.context ); + } +} + +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/input.html b/test/js/samples/event-handlers-custom/input.html new file mode 100644 index 000000000000..77c530fcf632 --- /dev/null +++ b/test/js/samples/event-handlers-custom/input.html @@ -0,0 +1,17 @@ + + + \ No newline at end of file diff --git a/test/generator/index.js b/test/runtime/index.js similarity index 94% rename from test/generator/index.js rename to test/runtime/index.js index 6ca442623b42..0d74c6db45e9 100644 --- a/test/generator/index.js +++ b/test/runtime/index.js @@ -38,7 +38,7 @@ describe( 'generate', () => { function runTest ( dir, shared ) { if ( dir[0] === '.' ) return; - const config = loadConfig( `./generator/samples/${dir}/_config.js` ); + const config = loadConfig( `./runtime/samples/${dir}/_config.js` ); if ( config.solo && process.env.CI ) { throw new Error( 'Forgot to remove `solo: true` from test' ); @@ -53,7 +53,7 @@ describe( 'generate', () => { compileOptions.dev = config.dev; try { - const source = fs.readFileSync( `test/generator/samples/${dir}/main.html`, 'utf-8' ); + const source = fs.readFileSync( `test/runtime/samples/${dir}/main.html`, 'utf-8' ); compiled = svelte.compile( source, compileOptions ); } catch ( err ) { if ( config.compileError ) { @@ -160,13 +160,13 @@ describe( 'generate', () => { } describe( 'inline helpers', () => { - fs.readdirSync( 'test/generator/samples' ).forEach( dir => { + fs.readdirSync( 'test/runtime/samples' ).forEach( dir => { runTest( dir, null ); }); }); describe( 'shared helpers', () => { - fs.readdirSync( 'test/generator/samples' ).forEach( dir => { + fs.readdirSync( 'test/runtime/samples' ).forEach( dir => { runTest( dir, path.resolve( 'shared.js' ) ); }); }); diff --git a/test/generator/samples/attribute-dynamic-multiple/_config.js b/test/runtime/samples/attribute-dynamic-multiple/_config.js similarity index 100% rename from test/generator/samples/attribute-dynamic-multiple/_config.js rename to test/runtime/samples/attribute-dynamic-multiple/_config.js diff --git a/test/generator/samples/attribute-dynamic-multiple/main.html b/test/runtime/samples/attribute-dynamic-multiple/main.html similarity index 100% rename from test/generator/samples/attribute-dynamic-multiple/main.html rename to test/runtime/samples/attribute-dynamic-multiple/main.html diff --git a/test/generator/samples/attribute-dynamic-reserved/_config.js b/test/runtime/samples/attribute-dynamic-reserved/_config.js similarity index 100% rename from test/generator/samples/attribute-dynamic-reserved/_config.js rename to test/runtime/samples/attribute-dynamic-reserved/_config.js diff --git a/test/generator/samples/attribute-dynamic-reserved/main.html b/test/runtime/samples/attribute-dynamic-reserved/main.html similarity index 100% rename from test/generator/samples/attribute-dynamic-reserved/main.html rename to test/runtime/samples/attribute-dynamic-reserved/main.html diff --git a/test/generator/samples/attribute-dynamic-shorthand/_config.js b/test/runtime/samples/attribute-dynamic-shorthand/_config.js similarity index 100% rename from test/generator/samples/attribute-dynamic-shorthand/_config.js rename to test/runtime/samples/attribute-dynamic-shorthand/_config.js diff --git a/test/generator/samples/attribute-dynamic-shorthand/main.html b/test/runtime/samples/attribute-dynamic-shorthand/main.html similarity index 100% rename from test/generator/samples/attribute-dynamic-shorthand/main.html rename to test/runtime/samples/attribute-dynamic-shorthand/main.html diff --git a/test/generator/samples/attribute-dynamic/_config.js b/test/runtime/samples/attribute-dynamic/_config.js similarity index 100% rename from test/generator/samples/attribute-dynamic/_config.js rename to test/runtime/samples/attribute-dynamic/_config.js diff --git a/test/generator/samples/attribute-dynamic/main.html b/test/runtime/samples/attribute-dynamic/main.html similarity index 100% rename from test/generator/samples/attribute-dynamic/main.html rename to test/runtime/samples/attribute-dynamic/main.html diff --git a/test/generator/samples/attribute-empty-svg/_config.js b/test/runtime/samples/attribute-empty-svg/_config.js similarity index 100% rename from test/generator/samples/attribute-empty-svg/_config.js rename to test/runtime/samples/attribute-empty-svg/_config.js diff --git a/test/generator/samples/attribute-empty-svg/main.html b/test/runtime/samples/attribute-empty-svg/main.html similarity index 100% rename from test/generator/samples/attribute-empty-svg/main.html rename to test/runtime/samples/attribute-empty-svg/main.html diff --git a/test/generator/samples/attribute-empty/_config.js b/test/runtime/samples/attribute-empty/_config.js similarity index 100% rename from test/generator/samples/attribute-empty/_config.js rename to test/runtime/samples/attribute-empty/_config.js diff --git a/test/generator/samples/attribute-empty/main.html b/test/runtime/samples/attribute-empty/main.html similarity index 100% rename from test/generator/samples/attribute-empty/main.html rename to test/runtime/samples/attribute-empty/main.html diff --git a/test/generator/samples/attribute-partial-number/Component.html b/test/runtime/samples/attribute-partial-number/Component.html similarity index 100% rename from test/generator/samples/attribute-partial-number/Component.html rename to test/runtime/samples/attribute-partial-number/Component.html diff --git a/test/generator/samples/attribute-partial-number/_config.js b/test/runtime/samples/attribute-partial-number/_config.js similarity index 100% rename from test/generator/samples/attribute-partial-number/_config.js rename to test/runtime/samples/attribute-partial-number/_config.js diff --git a/test/generator/samples/attribute-partial-number/main.html b/test/runtime/samples/attribute-partial-number/main.html similarity index 100% rename from test/generator/samples/attribute-partial-number/main.html rename to test/runtime/samples/attribute-partial-number/main.html diff --git a/test/generator/samples/attribute-prefer-expression/_config.js b/test/runtime/samples/attribute-prefer-expression/_config.js similarity index 100% rename from test/generator/samples/attribute-prefer-expression/_config.js rename to test/runtime/samples/attribute-prefer-expression/_config.js diff --git a/test/generator/samples/attribute-prefer-expression/main.html b/test/runtime/samples/attribute-prefer-expression/main.html similarity index 100% rename from test/generator/samples/attribute-prefer-expression/main.html rename to test/runtime/samples/attribute-prefer-expression/main.html diff --git a/test/generator/samples/attribute-static-boolean/_config.js b/test/runtime/samples/attribute-static-boolean/_config.js similarity index 100% rename from test/generator/samples/attribute-static-boolean/_config.js rename to test/runtime/samples/attribute-static-boolean/_config.js diff --git a/test/generator/samples/attribute-static-boolean/main.html b/test/runtime/samples/attribute-static-boolean/main.html similarity index 100% rename from test/generator/samples/attribute-static-boolean/main.html rename to test/runtime/samples/attribute-static-boolean/main.html diff --git a/test/generator/samples/attribute-static/_config.js b/test/runtime/samples/attribute-static/_config.js similarity index 100% rename from test/generator/samples/attribute-static/_config.js rename to test/runtime/samples/attribute-static/_config.js diff --git a/test/generator/samples/attribute-static/main.html b/test/runtime/samples/attribute-static/main.html similarity index 100% rename from test/generator/samples/attribute-static/main.html rename to test/runtime/samples/attribute-static/main.html diff --git a/test/generator/samples/autofocus/_config.js b/test/runtime/samples/autofocus/_config.js similarity index 100% rename from test/generator/samples/autofocus/_config.js rename to test/runtime/samples/autofocus/_config.js diff --git a/test/generator/samples/autofocus/main.html b/test/runtime/samples/autofocus/main.html similarity index 100% rename from test/generator/samples/autofocus/main.html rename to test/runtime/samples/autofocus/main.html diff --git a/test/generator/samples/binding-input-checkbox-deep-contextual/_config.js b/test/runtime/samples/binding-input-checkbox-deep-contextual/_config.js similarity index 100% rename from test/generator/samples/binding-input-checkbox-deep-contextual/_config.js rename to test/runtime/samples/binding-input-checkbox-deep-contextual/_config.js diff --git a/test/generator/samples/binding-input-checkbox-deep-contextual/main.html b/test/runtime/samples/binding-input-checkbox-deep-contextual/main.html similarity index 100% rename from test/generator/samples/binding-input-checkbox-deep-contextual/main.html rename to test/runtime/samples/binding-input-checkbox-deep-contextual/main.html diff --git a/test/generator/samples/binding-input-checkbox-group/_config.js b/test/runtime/samples/binding-input-checkbox-group/_config.js similarity index 100% rename from test/generator/samples/binding-input-checkbox-group/_config.js rename to test/runtime/samples/binding-input-checkbox-group/_config.js diff --git a/test/generator/samples/binding-input-checkbox-group/main.html b/test/runtime/samples/binding-input-checkbox-group/main.html similarity index 100% rename from test/generator/samples/binding-input-checkbox-group/main.html rename to test/runtime/samples/binding-input-checkbox-group/main.html diff --git a/test/generator/samples/binding-input-checkbox/_config.js b/test/runtime/samples/binding-input-checkbox/_config.js similarity index 100% rename from test/generator/samples/binding-input-checkbox/_config.js rename to test/runtime/samples/binding-input-checkbox/_config.js diff --git a/test/generator/samples/binding-input-checkbox/main.html b/test/runtime/samples/binding-input-checkbox/main.html similarity index 100% rename from test/generator/samples/binding-input-checkbox/main.html rename to test/runtime/samples/binding-input-checkbox/main.html diff --git a/test/generator/samples/binding-input-number/_config.js b/test/runtime/samples/binding-input-number/_config.js similarity index 100% rename from test/generator/samples/binding-input-number/_config.js rename to test/runtime/samples/binding-input-number/_config.js diff --git a/test/generator/samples/binding-input-number/main.html b/test/runtime/samples/binding-input-number/main.html similarity index 100% rename from test/generator/samples/binding-input-number/main.html rename to test/runtime/samples/binding-input-number/main.html diff --git a/test/generator/samples/binding-input-radio-group/_config.js b/test/runtime/samples/binding-input-radio-group/_config.js similarity index 100% rename from test/generator/samples/binding-input-radio-group/_config.js rename to test/runtime/samples/binding-input-radio-group/_config.js diff --git a/test/generator/samples/binding-input-radio-group/main.html b/test/runtime/samples/binding-input-radio-group/main.html similarity index 100% rename from test/generator/samples/binding-input-radio-group/main.html rename to test/runtime/samples/binding-input-radio-group/main.html diff --git a/test/generator/samples/binding-input-range/_config.js b/test/runtime/samples/binding-input-range/_config.js similarity index 100% rename from test/generator/samples/binding-input-range/_config.js rename to test/runtime/samples/binding-input-range/_config.js diff --git a/test/generator/samples/binding-input-range/main.html b/test/runtime/samples/binding-input-range/main.html similarity index 100% rename from test/generator/samples/binding-input-range/main.html rename to test/runtime/samples/binding-input-range/main.html diff --git a/test/generator/samples/binding-input-text-contextual/_config.js b/test/runtime/samples/binding-input-text-contextual/_config.js similarity index 100% rename from test/generator/samples/binding-input-text-contextual/_config.js rename to test/runtime/samples/binding-input-text-contextual/_config.js diff --git a/test/generator/samples/binding-input-text-contextual/main.html b/test/runtime/samples/binding-input-text-contextual/main.html similarity index 100% rename from test/generator/samples/binding-input-text-contextual/main.html rename to test/runtime/samples/binding-input-text-contextual/main.html diff --git a/test/generator/samples/binding-input-text-deep-contextual/_config.js b/test/runtime/samples/binding-input-text-deep-contextual/_config.js similarity index 100% rename from test/generator/samples/binding-input-text-deep-contextual/_config.js rename to test/runtime/samples/binding-input-text-deep-contextual/_config.js diff --git a/test/generator/samples/binding-input-text-deep-contextual/main.html b/test/runtime/samples/binding-input-text-deep-contextual/main.html similarity index 100% rename from test/generator/samples/binding-input-text-deep-contextual/main.html rename to test/runtime/samples/binding-input-text-deep-contextual/main.html diff --git a/test/generator/samples/binding-input-text-deep/_config.js b/test/runtime/samples/binding-input-text-deep/_config.js similarity index 100% rename from test/generator/samples/binding-input-text-deep/_config.js rename to test/runtime/samples/binding-input-text-deep/_config.js diff --git a/test/generator/samples/binding-input-text-deep/main.html b/test/runtime/samples/binding-input-text-deep/main.html similarity index 100% rename from test/generator/samples/binding-input-text-deep/main.html rename to test/runtime/samples/binding-input-text-deep/main.html diff --git a/test/generator/samples/binding-input-text/_config.js b/test/runtime/samples/binding-input-text/_config.js similarity index 100% rename from test/generator/samples/binding-input-text/_config.js rename to test/runtime/samples/binding-input-text/_config.js diff --git a/test/generator/samples/binding-input-text/main.html b/test/runtime/samples/binding-input-text/main.html similarity index 100% rename from test/generator/samples/binding-input-text/main.html rename to test/runtime/samples/binding-input-text/main.html diff --git a/test/generator/samples/binding-select-initial-value/_config.js b/test/runtime/samples/binding-select-initial-value/_config.js similarity index 100% rename from test/generator/samples/binding-select-initial-value/_config.js rename to test/runtime/samples/binding-select-initial-value/_config.js diff --git a/test/generator/samples/binding-select-initial-value/main.html b/test/runtime/samples/binding-select-initial-value/main.html similarity index 100% rename from test/generator/samples/binding-select-initial-value/main.html rename to test/runtime/samples/binding-select-initial-value/main.html diff --git a/test/generator/samples/binding-select-multiple/_config.js b/test/runtime/samples/binding-select-multiple/_config.js similarity index 100% rename from test/generator/samples/binding-select-multiple/_config.js rename to test/runtime/samples/binding-select-multiple/_config.js diff --git a/test/generator/samples/binding-select-multiple/main.html b/test/runtime/samples/binding-select-multiple/main.html similarity index 100% rename from test/generator/samples/binding-select-multiple/main.html rename to test/runtime/samples/binding-select-multiple/main.html diff --git a/test/generator/samples/binding-select/_config.js b/test/runtime/samples/binding-select/_config.js similarity index 100% rename from test/generator/samples/binding-select/_config.js rename to test/runtime/samples/binding-select/_config.js diff --git a/test/generator/samples/binding-select/main.html b/test/runtime/samples/binding-select/main.html similarity index 100% rename from test/generator/samples/binding-select/main.html rename to test/runtime/samples/binding-select/main.html diff --git a/test/generator/samples/binding-textarea/_config.js b/test/runtime/samples/binding-textarea/_config.js similarity index 100% rename from test/generator/samples/binding-textarea/_config.js rename to test/runtime/samples/binding-textarea/_config.js diff --git a/test/generator/samples/binding-textarea/main.html b/test/runtime/samples/binding-textarea/main.html similarity index 100% rename from test/generator/samples/binding-textarea/main.html rename to test/runtime/samples/binding-textarea/main.html diff --git a/test/generator/samples/component-binding-conditional-b/Bar.html b/test/runtime/samples/component-binding-conditional-b/Bar.html similarity index 100% rename from test/generator/samples/component-binding-conditional-b/Bar.html rename to test/runtime/samples/component-binding-conditional-b/Bar.html diff --git a/test/generator/samples/component-binding-conditional-b/Baz.html b/test/runtime/samples/component-binding-conditional-b/Baz.html similarity index 100% rename from test/generator/samples/component-binding-conditional-b/Baz.html rename to test/runtime/samples/component-binding-conditional-b/Baz.html diff --git a/test/generator/samples/component-binding-conditional-b/Foo.html b/test/runtime/samples/component-binding-conditional-b/Foo.html similarity index 100% rename from test/generator/samples/component-binding-conditional-b/Foo.html rename to test/runtime/samples/component-binding-conditional-b/Foo.html diff --git a/test/generator/samples/component-binding-conditional-b/_config.js b/test/runtime/samples/component-binding-conditional-b/_config.js similarity index 100% rename from test/generator/samples/component-binding-conditional-b/_config.js rename to test/runtime/samples/component-binding-conditional-b/_config.js diff --git a/test/generator/samples/component-binding-conditional-b/main.html b/test/runtime/samples/component-binding-conditional-b/main.html similarity index 100% rename from test/generator/samples/component-binding-conditional-b/main.html rename to test/runtime/samples/component-binding-conditional-b/main.html diff --git a/test/generator/samples/component-binding-conditional/Bar.html b/test/runtime/samples/component-binding-conditional/Bar.html similarity index 100% rename from test/generator/samples/component-binding-conditional/Bar.html rename to test/runtime/samples/component-binding-conditional/Bar.html diff --git a/test/generator/samples/component-binding-conditional/Baz.html b/test/runtime/samples/component-binding-conditional/Baz.html similarity index 100% rename from test/generator/samples/component-binding-conditional/Baz.html rename to test/runtime/samples/component-binding-conditional/Baz.html diff --git a/test/generator/samples/component-binding-conditional/Foo.html b/test/runtime/samples/component-binding-conditional/Foo.html similarity index 100% rename from test/generator/samples/component-binding-conditional/Foo.html rename to test/runtime/samples/component-binding-conditional/Foo.html diff --git a/test/generator/samples/component-binding-conditional/_config.js b/test/runtime/samples/component-binding-conditional/_config.js similarity index 100% rename from test/generator/samples/component-binding-conditional/_config.js rename to test/runtime/samples/component-binding-conditional/_config.js diff --git a/test/generator/samples/component-binding-conditional/main.html b/test/runtime/samples/component-binding-conditional/main.html similarity index 100% rename from test/generator/samples/component-binding-conditional/main.html rename to test/runtime/samples/component-binding-conditional/main.html diff --git a/test/generator/samples/component-binding-deep-b/ComponentSelector.html b/test/runtime/samples/component-binding-deep-b/ComponentSelector.html similarity index 100% rename from test/generator/samples/component-binding-deep-b/ComponentSelector.html rename to test/runtime/samples/component-binding-deep-b/ComponentSelector.html diff --git a/test/generator/samples/component-binding-deep-b/Editor.html b/test/runtime/samples/component-binding-deep-b/Editor.html similarity index 100% rename from test/generator/samples/component-binding-deep-b/Editor.html rename to test/runtime/samples/component-binding-deep-b/Editor.html diff --git a/test/generator/samples/component-binding-deep-b/_config.js b/test/runtime/samples/component-binding-deep-b/_config.js similarity index 100% rename from test/generator/samples/component-binding-deep-b/_config.js rename to test/runtime/samples/component-binding-deep-b/_config.js diff --git a/test/generator/samples/component-binding-deep-b/main.html b/test/runtime/samples/component-binding-deep-b/main.html similarity index 100% rename from test/generator/samples/component-binding-deep-b/main.html rename to test/runtime/samples/component-binding-deep-b/main.html diff --git a/test/generator/samples/component-binding-deep/Widget.html b/test/runtime/samples/component-binding-deep/Widget.html similarity index 100% rename from test/generator/samples/component-binding-deep/Widget.html rename to test/runtime/samples/component-binding-deep/Widget.html diff --git a/test/generator/samples/component-binding-deep/_config.js b/test/runtime/samples/component-binding-deep/_config.js similarity index 100% rename from test/generator/samples/component-binding-deep/_config.js rename to test/runtime/samples/component-binding-deep/_config.js diff --git a/test/generator/samples/component-binding-deep/main.html b/test/runtime/samples/component-binding-deep/main.html similarity index 100% rename from test/generator/samples/component-binding-deep/main.html rename to test/runtime/samples/component-binding-deep/main.html diff --git a/test/generator/samples/component-binding-each-nested/Widget.html b/test/runtime/samples/component-binding-each-nested/Widget.html similarity index 100% rename from test/generator/samples/component-binding-each-nested/Widget.html rename to test/runtime/samples/component-binding-each-nested/Widget.html diff --git a/test/generator/samples/component-binding-each-nested/_config.js b/test/runtime/samples/component-binding-each-nested/_config.js similarity index 100% rename from test/generator/samples/component-binding-each-nested/_config.js rename to test/runtime/samples/component-binding-each-nested/_config.js diff --git a/test/generator/samples/component-binding-each-nested/main.html b/test/runtime/samples/component-binding-each-nested/main.html similarity index 100% rename from test/generator/samples/component-binding-each-nested/main.html rename to test/runtime/samples/component-binding-each-nested/main.html diff --git a/test/generator/samples/component-binding-each-object/Widget.html b/test/runtime/samples/component-binding-each-object/Widget.html similarity index 100% rename from test/generator/samples/component-binding-each-object/Widget.html rename to test/runtime/samples/component-binding-each-object/Widget.html diff --git a/test/generator/samples/component-binding-each-object/_config.js b/test/runtime/samples/component-binding-each-object/_config.js similarity index 100% rename from test/generator/samples/component-binding-each-object/_config.js rename to test/runtime/samples/component-binding-each-object/_config.js diff --git a/test/generator/samples/component-binding-each-object/main.html b/test/runtime/samples/component-binding-each-object/main.html similarity index 100% rename from test/generator/samples/component-binding-each-object/main.html rename to test/runtime/samples/component-binding-each-object/main.html diff --git a/test/generator/samples/component-binding-each/Widget.html b/test/runtime/samples/component-binding-each/Widget.html similarity index 100% rename from test/generator/samples/component-binding-each/Widget.html rename to test/runtime/samples/component-binding-each/Widget.html diff --git a/test/generator/samples/component-binding-each/_config.js b/test/runtime/samples/component-binding-each/_config.js similarity index 100% rename from test/generator/samples/component-binding-each/_config.js rename to test/runtime/samples/component-binding-each/_config.js diff --git a/test/generator/samples/component-binding-each/main.html b/test/runtime/samples/component-binding-each/main.html similarity index 100% rename from test/generator/samples/component-binding-each/main.html rename to test/runtime/samples/component-binding-each/main.html diff --git a/test/generator/samples/component-binding-infinite-loop/A.html b/test/runtime/samples/component-binding-infinite-loop/A.html similarity index 100% rename from test/generator/samples/component-binding-infinite-loop/A.html rename to test/runtime/samples/component-binding-infinite-loop/A.html diff --git a/test/generator/samples/component-binding-infinite-loop/B.html b/test/runtime/samples/component-binding-infinite-loop/B.html similarity index 100% rename from test/generator/samples/component-binding-infinite-loop/B.html rename to test/runtime/samples/component-binding-infinite-loop/B.html diff --git a/test/generator/samples/component-binding-infinite-loop/C.html b/test/runtime/samples/component-binding-infinite-loop/C.html similarity index 100% rename from test/generator/samples/component-binding-infinite-loop/C.html rename to test/runtime/samples/component-binding-infinite-loop/C.html diff --git a/test/generator/samples/component-binding-infinite-loop/_config.js b/test/runtime/samples/component-binding-infinite-loop/_config.js similarity index 100% rename from test/generator/samples/component-binding-infinite-loop/_config.js rename to test/runtime/samples/component-binding-infinite-loop/_config.js diff --git a/test/generator/samples/component-binding-infinite-loop/main.html b/test/runtime/samples/component-binding-infinite-loop/main.html similarity index 100% rename from test/generator/samples/component-binding-infinite-loop/main.html rename to test/runtime/samples/component-binding-infinite-loop/main.html diff --git a/test/generator/samples/component-binding-nested/Bar.html b/test/runtime/samples/component-binding-nested/Bar.html similarity index 100% rename from test/generator/samples/component-binding-nested/Bar.html rename to test/runtime/samples/component-binding-nested/Bar.html diff --git a/test/generator/samples/component-binding-nested/Baz.html b/test/runtime/samples/component-binding-nested/Baz.html similarity index 100% rename from test/generator/samples/component-binding-nested/Baz.html rename to test/runtime/samples/component-binding-nested/Baz.html diff --git a/test/generator/samples/component-binding-nested/Foo.html b/test/runtime/samples/component-binding-nested/Foo.html similarity index 100% rename from test/generator/samples/component-binding-nested/Foo.html rename to test/runtime/samples/component-binding-nested/Foo.html diff --git a/test/generator/samples/component-binding-nested/_config.js b/test/runtime/samples/component-binding-nested/_config.js similarity index 100% rename from test/generator/samples/component-binding-nested/_config.js rename to test/runtime/samples/component-binding-nested/_config.js diff --git a/test/generator/samples/component-binding-nested/main.html b/test/runtime/samples/component-binding-nested/main.html similarity index 100% rename from test/generator/samples/component-binding-nested/main.html rename to test/runtime/samples/component-binding-nested/main.html diff --git a/test/generator/samples/component-binding-parent-supercedes-child/Counter.html b/test/runtime/samples/component-binding-parent-supercedes-child/Counter.html similarity index 100% rename from test/generator/samples/component-binding-parent-supercedes-child/Counter.html rename to test/runtime/samples/component-binding-parent-supercedes-child/Counter.html diff --git a/test/generator/samples/component-binding-parent-supercedes-child/_config.js b/test/runtime/samples/component-binding-parent-supercedes-child/_config.js similarity index 100% rename from test/generator/samples/component-binding-parent-supercedes-child/_config.js rename to test/runtime/samples/component-binding-parent-supercedes-child/_config.js diff --git a/test/generator/samples/component-binding-parent-supercedes-child/main.html b/test/runtime/samples/component-binding-parent-supercedes-child/main.html similarity index 100% rename from test/generator/samples/component-binding-parent-supercedes-child/main.html rename to test/runtime/samples/component-binding-parent-supercedes-child/main.html diff --git a/test/generator/samples/component-binding/Counter.html b/test/runtime/samples/component-binding/Counter.html similarity index 100% rename from test/generator/samples/component-binding/Counter.html rename to test/runtime/samples/component-binding/Counter.html diff --git a/test/generator/samples/component-binding/_config.js b/test/runtime/samples/component-binding/_config.js similarity index 100% rename from test/generator/samples/component-binding/_config.js rename to test/runtime/samples/component-binding/_config.js diff --git a/test/generator/samples/component-binding/main.html b/test/runtime/samples/component-binding/main.html similarity index 100% rename from test/generator/samples/component-binding/main.html rename to test/runtime/samples/component-binding/main.html diff --git a/test/generator/samples/component-data-dynamic-late/Widget.html b/test/runtime/samples/component-data-dynamic-late/Widget.html similarity index 100% rename from test/generator/samples/component-data-dynamic-late/Widget.html rename to test/runtime/samples/component-data-dynamic-late/Widget.html diff --git a/test/generator/samples/component-data-dynamic-late/_config.js b/test/runtime/samples/component-data-dynamic-late/_config.js similarity index 100% rename from test/generator/samples/component-data-dynamic-late/_config.js rename to test/runtime/samples/component-data-dynamic-late/_config.js diff --git a/test/generator/samples/component-data-dynamic-late/main.html b/test/runtime/samples/component-data-dynamic-late/main.html similarity index 100% rename from test/generator/samples/component-data-dynamic-late/main.html rename to test/runtime/samples/component-data-dynamic-late/main.html diff --git a/test/generator/samples/component-data-dynamic-shorthand/Widget.html b/test/runtime/samples/component-data-dynamic-shorthand/Widget.html similarity index 100% rename from test/generator/samples/component-data-dynamic-shorthand/Widget.html rename to test/runtime/samples/component-data-dynamic-shorthand/Widget.html diff --git a/test/generator/samples/component-data-dynamic-shorthand/_config.js b/test/runtime/samples/component-data-dynamic-shorthand/_config.js similarity index 100% rename from test/generator/samples/component-data-dynamic-shorthand/_config.js rename to test/runtime/samples/component-data-dynamic-shorthand/_config.js diff --git a/test/generator/samples/component-data-dynamic-shorthand/main.html b/test/runtime/samples/component-data-dynamic-shorthand/main.html similarity index 100% rename from test/generator/samples/component-data-dynamic-shorthand/main.html rename to test/runtime/samples/component-data-dynamic-shorthand/main.html diff --git a/test/generator/samples/component-data-dynamic/Widget.html b/test/runtime/samples/component-data-dynamic/Widget.html similarity index 100% rename from test/generator/samples/component-data-dynamic/Widget.html rename to test/runtime/samples/component-data-dynamic/Widget.html diff --git a/test/generator/samples/component-data-dynamic/_config.js b/test/runtime/samples/component-data-dynamic/_config.js similarity index 100% rename from test/generator/samples/component-data-dynamic/_config.js rename to test/runtime/samples/component-data-dynamic/_config.js diff --git a/test/generator/samples/component-data-dynamic/main.html b/test/runtime/samples/component-data-dynamic/main.html similarity index 100% rename from test/generator/samples/component-data-dynamic/main.html rename to test/runtime/samples/component-data-dynamic/main.html diff --git a/test/generator/samples/component-data-empty/Widget.html b/test/runtime/samples/component-data-empty/Widget.html similarity index 100% rename from test/generator/samples/component-data-empty/Widget.html rename to test/runtime/samples/component-data-empty/Widget.html diff --git a/test/generator/samples/component-data-empty/_config.js b/test/runtime/samples/component-data-empty/_config.js similarity index 100% rename from test/generator/samples/component-data-empty/_config.js rename to test/runtime/samples/component-data-empty/_config.js diff --git a/test/generator/samples/component-data-empty/main.html b/test/runtime/samples/component-data-empty/main.html similarity index 100% rename from test/generator/samples/component-data-empty/main.html rename to test/runtime/samples/component-data-empty/main.html diff --git a/test/generator/samples/component-data-static-boolean/Foo.html b/test/runtime/samples/component-data-static-boolean/Foo.html similarity index 100% rename from test/generator/samples/component-data-static-boolean/Foo.html rename to test/runtime/samples/component-data-static-boolean/Foo.html diff --git a/test/generator/samples/component-data-static-boolean/_config.js b/test/runtime/samples/component-data-static-boolean/_config.js similarity index 100% rename from test/generator/samples/component-data-static-boolean/_config.js rename to test/runtime/samples/component-data-static-boolean/_config.js diff --git a/test/generator/samples/component-data-static-boolean/main.html b/test/runtime/samples/component-data-static-boolean/main.html similarity index 100% rename from test/generator/samples/component-data-static-boolean/main.html rename to test/runtime/samples/component-data-static-boolean/main.html diff --git a/test/generator/samples/component-data-static/Widget.html b/test/runtime/samples/component-data-static/Widget.html similarity index 100% rename from test/generator/samples/component-data-static/Widget.html rename to test/runtime/samples/component-data-static/Widget.html diff --git a/test/generator/samples/component-data-static/_config.js b/test/runtime/samples/component-data-static/_config.js similarity index 100% rename from test/generator/samples/component-data-static/_config.js rename to test/runtime/samples/component-data-static/_config.js diff --git a/test/generator/samples/component-data-static/main.html b/test/runtime/samples/component-data-static/main.html similarity index 100% rename from test/generator/samples/component-data-static/main.html rename to test/runtime/samples/component-data-static/main.html diff --git a/test/generator/samples/component-events-data/Widget.html b/test/runtime/samples/component-events-data/Widget.html similarity index 100% rename from test/generator/samples/component-events-data/Widget.html rename to test/runtime/samples/component-events-data/Widget.html diff --git a/test/generator/samples/component-events-data/_config.js b/test/runtime/samples/component-events-data/_config.js similarity index 100% rename from test/generator/samples/component-events-data/_config.js rename to test/runtime/samples/component-events-data/_config.js diff --git a/test/generator/samples/component-events-data/main.html b/test/runtime/samples/component-events-data/main.html similarity index 100% rename from test/generator/samples/component-events-data/main.html rename to test/runtime/samples/component-events-data/main.html diff --git a/test/generator/samples/component-events-each/Widget.html b/test/runtime/samples/component-events-each/Widget.html similarity index 100% rename from test/generator/samples/component-events-each/Widget.html rename to test/runtime/samples/component-events-each/Widget.html diff --git a/test/generator/samples/component-events-each/_config.js b/test/runtime/samples/component-events-each/_config.js similarity index 100% rename from test/generator/samples/component-events-each/_config.js rename to test/runtime/samples/component-events-each/_config.js diff --git a/test/generator/samples/component-events-each/main.html b/test/runtime/samples/component-events-each/main.html similarity index 100% rename from test/generator/samples/component-events-each/main.html rename to test/runtime/samples/component-events-each/main.html diff --git a/test/generator/samples/component-events/Widget.html b/test/runtime/samples/component-events/Widget.html similarity index 100% rename from test/generator/samples/component-events/Widget.html rename to test/runtime/samples/component-events/Widget.html diff --git a/test/generator/samples/component-events/_config.js b/test/runtime/samples/component-events/_config.js similarity index 100% rename from test/generator/samples/component-events/_config.js rename to test/runtime/samples/component-events/_config.js diff --git a/test/generator/samples/component-events/main.html b/test/runtime/samples/component-events/main.html similarity index 100% rename from test/generator/samples/component-events/main.html rename to test/runtime/samples/component-events/main.html diff --git a/test/generator/samples/component-not-void/Link.html b/test/runtime/samples/component-not-void/Link.html similarity index 100% rename from test/generator/samples/component-not-void/Link.html rename to test/runtime/samples/component-not-void/Link.html diff --git a/test/generator/samples/component-not-void/_config.js b/test/runtime/samples/component-not-void/_config.js similarity index 100% rename from test/generator/samples/component-not-void/_config.js rename to test/runtime/samples/component-not-void/_config.js diff --git a/test/generator/samples/component-not-void/main.html b/test/runtime/samples/component-not-void/main.html similarity index 100% rename from test/generator/samples/component-not-void/main.html rename to test/runtime/samples/component-not-void/main.html diff --git a/test/generator/samples/component-ref/Widget.html b/test/runtime/samples/component-ref/Widget.html similarity index 100% rename from test/generator/samples/component-ref/Widget.html rename to test/runtime/samples/component-ref/Widget.html diff --git a/test/generator/samples/component-ref/_config.js b/test/runtime/samples/component-ref/_config.js similarity index 100% rename from test/generator/samples/component-ref/_config.js rename to test/runtime/samples/component-ref/_config.js diff --git a/test/generator/samples/component-ref/main.html b/test/runtime/samples/component-ref/main.html similarity index 100% rename from test/generator/samples/component-ref/main.html rename to test/runtime/samples/component-ref/main.html diff --git a/test/generator/samples/component-yield-if/Widget.html b/test/runtime/samples/component-yield-if/Widget.html similarity index 100% rename from test/generator/samples/component-yield-if/Widget.html rename to test/runtime/samples/component-yield-if/Widget.html diff --git a/test/generator/samples/component-yield-if/_config.js b/test/runtime/samples/component-yield-if/_config.js similarity index 100% rename from test/generator/samples/component-yield-if/_config.js rename to test/runtime/samples/component-yield-if/_config.js diff --git a/test/generator/samples/component-yield-if/main.html b/test/runtime/samples/component-yield-if/main.html similarity index 100% rename from test/generator/samples/component-yield-if/main.html rename to test/runtime/samples/component-yield-if/main.html diff --git a/test/generator/samples/component-yield-multiple-in-each/Widget.html b/test/runtime/samples/component-yield-multiple-in-each/Widget.html similarity index 100% rename from test/generator/samples/component-yield-multiple-in-each/Widget.html rename to test/runtime/samples/component-yield-multiple-in-each/Widget.html diff --git a/test/generator/samples/component-yield-multiple-in-each/_config.js b/test/runtime/samples/component-yield-multiple-in-each/_config.js similarity index 100% rename from test/generator/samples/component-yield-multiple-in-each/_config.js rename to test/runtime/samples/component-yield-multiple-in-each/_config.js diff --git a/test/generator/samples/component-yield-multiple-in-each/main.html b/test/runtime/samples/component-yield-multiple-in-each/main.html similarity index 100% rename from test/generator/samples/component-yield-multiple-in-each/main.html rename to test/runtime/samples/component-yield-multiple-in-each/main.html diff --git a/test/generator/samples/component-yield-multiple-in-if/Widget.html b/test/runtime/samples/component-yield-multiple-in-if/Widget.html similarity index 100% rename from test/generator/samples/component-yield-multiple-in-if/Widget.html rename to test/runtime/samples/component-yield-multiple-in-if/Widget.html diff --git a/test/generator/samples/component-yield-multiple-in-if/_config.js b/test/runtime/samples/component-yield-multiple-in-if/_config.js similarity index 100% rename from test/generator/samples/component-yield-multiple-in-if/_config.js rename to test/runtime/samples/component-yield-multiple-in-if/_config.js diff --git a/test/generator/samples/component-yield-multiple-in-if/main.html b/test/runtime/samples/component-yield-multiple-in-if/main.html similarity index 100% rename from test/generator/samples/component-yield-multiple-in-if/main.html rename to test/runtime/samples/component-yield-multiple-in-if/main.html diff --git a/test/generator/samples/component-yield-parent/Widget.html b/test/runtime/samples/component-yield-parent/Widget.html similarity index 100% rename from test/generator/samples/component-yield-parent/Widget.html rename to test/runtime/samples/component-yield-parent/Widget.html diff --git a/test/generator/samples/component-yield-parent/_config.js b/test/runtime/samples/component-yield-parent/_config.js similarity index 100% rename from test/generator/samples/component-yield-parent/_config.js rename to test/runtime/samples/component-yield-parent/_config.js diff --git a/test/generator/samples/component-yield-parent/main.html b/test/runtime/samples/component-yield-parent/main.html similarity index 100% rename from test/generator/samples/component-yield-parent/main.html rename to test/runtime/samples/component-yield-parent/main.html diff --git a/test/generator/samples/component-yield/_config.js b/test/runtime/samples/component-yield/_config.js similarity index 100% rename from test/generator/samples/component-yield/_config.js rename to test/runtime/samples/component-yield/_config.js diff --git a/test/generator/samples/component-yield/main.html b/test/runtime/samples/component-yield/main.html similarity index 100% rename from test/generator/samples/component-yield/main.html rename to test/runtime/samples/component-yield/main.html diff --git a/test/generator/samples/component/Widget.html b/test/runtime/samples/component/Widget.html similarity index 100% rename from test/generator/samples/component/Widget.html rename to test/runtime/samples/component/Widget.html diff --git a/test/generator/samples/component/_config.js b/test/runtime/samples/component/_config.js similarity index 100% rename from test/generator/samples/component/_config.js rename to test/runtime/samples/component/_config.js diff --git a/test/generator/samples/component/main.html b/test/runtime/samples/component/main.html similarity index 100% rename from test/generator/samples/component/main.html rename to test/runtime/samples/component/main.html diff --git a/test/generator/samples/computed-function/_config.js b/test/runtime/samples/computed-function/_config.js similarity index 100% rename from test/generator/samples/computed-function/_config.js rename to test/runtime/samples/computed-function/_config.js diff --git a/test/generator/samples/computed-function/main.html b/test/runtime/samples/computed-function/main.html similarity index 100% rename from test/generator/samples/computed-function/main.html rename to test/runtime/samples/computed-function/main.html diff --git a/test/generator/samples/computed-values-default/_config.js b/test/runtime/samples/computed-values-default/_config.js similarity index 100% rename from test/generator/samples/computed-values-default/_config.js rename to test/runtime/samples/computed-values-default/_config.js diff --git a/test/generator/samples/computed-values-default/main.html b/test/runtime/samples/computed-values-default/main.html similarity index 100% rename from test/generator/samples/computed-values-default/main.html rename to test/runtime/samples/computed-values-default/main.html diff --git a/test/generator/samples/computed-values-function-dependency/_config.js b/test/runtime/samples/computed-values-function-dependency/_config.js similarity index 100% rename from test/generator/samples/computed-values-function-dependency/_config.js rename to test/runtime/samples/computed-values-function-dependency/_config.js diff --git a/test/generator/samples/computed-values-function-dependency/main.html b/test/runtime/samples/computed-values-function-dependency/main.html similarity index 100% rename from test/generator/samples/computed-values-function-dependency/main.html rename to test/runtime/samples/computed-values-function-dependency/main.html diff --git a/test/generator/samples/computed-values/_config.js b/test/runtime/samples/computed-values/_config.js similarity index 100% rename from test/generator/samples/computed-values/_config.js rename to test/runtime/samples/computed-values/_config.js diff --git a/test/generator/samples/computed-values/main.html b/test/runtime/samples/computed-values/main.html similarity index 100% rename from test/generator/samples/computed-values/main.html rename to test/runtime/samples/computed-values/main.html diff --git a/test/generator/samples/css-comments/_config.js b/test/runtime/samples/css-comments/_config.js similarity index 100% rename from test/generator/samples/css-comments/_config.js rename to test/runtime/samples/css-comments/_config.js diff --git a/test/generator/samples/css-comments/main.html b/test/runtime/samples/css-comments/main.html similarity index 100% rename from test/generator/samples/css-comments/main.html rename to test/runtime/samples/css-comments/main.html diff --git a/test/generator/samples/css-false/Widget.html b/test/runtime/samples/css-false/Widget.html similarity index 100% rename from test/generator/samples/css-false/Widget.html rename to test/runtime/samples/css-false/Widget.html diff --git a/test/generator/samples/css-false/_config.js b/test/runtime/samples/css-false/_config.js similarity index 100% rename from test/generator/samples/css-false/_config.js rename to test/runtime/samples/css-false/_config.js diff --git a/test/generator/samples/css-false/main.html b/test/runtime/samples/css-false/main.html similarity index 100% rename from test/generator/samples/css-false/main.html rename to test/runtime/samples/css-false/main.html diff --git a/test/generator/samples/css-space-in-attribute/Widget.html b/test/runtime/samples/css-space-in-attribute/Widget.html similarity index 100% rename from test/generator/samples/css-space-in-attribute/Widget.html rename to test/runtime/samples/css-space-in-attribute/Widget.html diff --git a/test/generator/samples/css-space-in-attribute/_config.js b/test/runtime/samples/css-space-in-attribute/_config.js similarity index 100% rename from test/generator/samples/css-space-in-attribute/_config.js rename to test/runtime/samples/css-space-in-attribute/_config.js diff --git a/test/generator/samples/css-space-in-attribute/main.html b/test/runtime/samples/css-space-in-attribute/main.html similarity index 100% rename from test/generator/samples/css-space-in-attribute/main.html rename to test/runtime/samples/css-space-in-attribute/main.html diff --git a/test/generator/samples/css/Widget.html b/test/runtime/samples/css/Widget.html similarity index 100% rename from test/generator/samples/css/Widget.html rename to test/runtime/samples/css/Widget.html diff --git a/test/generator/samples/css/_config.js b/test/runtime/samples/css/_config.js similarity index 100% rename from test/generator/samples/css/_config.js rename to test/runtime/samples/css/_config.js diff --git a/test/generator/samples/css/main.html b/test/runtime/samples/css/main.html similarity index 100% rename from test/generator/samples/css/main.html rename to test/runtime/samples/css/main.html diff --git a/test/generator/samples/custom-method/_config.js b/test/runtime/samples/custom-method/_config.js similarity index 100% rename from test/generator/samples/custom-method/_config.js rename to test/runtime/samples/custom-method/_config.js diff --git a/test/generator/samples/custom-method/main.html b/test/runtime/samples/custom-method/main.html similarity index 100% rename from test/generator/samples/custom-method/main.html rename to test/runtime/samples/custom-method/main.html diff --git a/test/generator/samples/deconflict-builtins/_config.js b/test/runtime/samples/deconflict-builtins/_config.js similarity index 100% rename from test/generator/samples/deconflict-builtins/_config.js rename to test/runtime/samples/deconflict-builtins/_config.js diff --git a/test/generator/samples/deconflict-builtins/get.js b/test/runtime/samples/deconflict-builtins/get.js similarity index 100% rename from test/generator/samples/deconflict-builtins/get.js rename to test/runtime/samples/deconflict-builtins/get.js diff --git a/test/generator/samples/deconflict-builtins/main.html b/test/runtime/samples/deconflict-builtins/main.html similarity index 100% rename from test/generator/samples/deconflict-builtins/main.html rename to test/runtime/samples/deconflict-builtins/main.html diff --git a/test/generator/samples/deconflict-contexts/_config.js b/test/runtime/samples/deconflict-contexts/_config.js similarity index 100% rename from test/generator/samples/deconflict-contexts/_config.js rename to test/runtime/samples/deconflict-contexts/_config.js diff --git a/test/generator/samples/deconflict-contexts/main.html b/test/runtime/samples/deconflict-contexts/main.html similarity index 100% rename from test/generator/samples/deconflict-contexts/main.html rename to test/runtime/samples/deconflict-contexts/main.html diff --git a/test/generator/samples/deconflict-non-helpers/_config.js b/test/runtime/samples/deconflict-non-helpers/_config.js similarity index 100% rename from test/generator/samples/deconflict-non-helpers/_config.js rename to test/runtime/samples/deconflict-non-helpers/_config.js diff --git a/test/generator/samples/deconflict-non-helpers/main.html b/test/runtime/samples/deconflict-non-helpers/main.html similarity index 100% rename from test/generator/samples/deconflict-non-helpers/main.html rename to test/runtime/samples/deconflict-non-helpers/main.html diff --git a/test/generator/samples/deconflict-non-helpers/module.js b/test/runtime/samples/deconflict-non-helpers/module.js similarity index 100% rename from test/generator/samples/deconflict-non-helpers/module.js rename to test/runtime/samples/deconflict-non-helpers/module.js diff --git a/test/generator/samples/deconflict-template-1/_config.js b/test/runtime/samples/deconflict-template-1/_config.js similarity index 100% rename from test/generator/samples/deconflict-template-1/_config.js rename to test/runtime/samples/deconflict-template-1/_config.js diff --git a/test/generator/samples/deconflict-template-1/main.html b/test/runtime/samples/deconflict-template-1/main.html similarity index 100% rename from test/generator/samples/deconflict-template-1/main.html rename to test/runtime/samples/deconflict-template-1/main.html diff --git a/test/generator/samples/deconflict-template-1/module.js b/test/runtime/samples/deconflict-template-1/module.js similarity index 100% rename from test/generator/samples/deconflict-template-1/module.js rename to test/runtime/samples/deconflict-template-1/module.js diff --git a/test/generator/samples/deconflict-template-2/_config.js b/test/runtime/samples/deconflict-template-2/_config.js similarity index 100% rename from test/generator/samples/deconflict-template-2/_config.js rename to test/runtime/samples/deconflict-template-2/_config.js diff --git a/test/generator/samples/deconflict-template-2/main.html b/test/runtime/samples/deconflict-template-2/main.html similarity index 100% rename from test/generator/samples/deconflict-template-2/main.html rename to test/runtime/samples/deconflict-template-2/main.html diff --git a/test/generator/samples/default-data-function/_config.js b/test/runtime/samples/default-data-function/_config.js similarity index 100% rename from test/generator/samples/default-data-function/_config.js rename to test/runtime/samples/default-data-function/_config.js diff --git a/test/generator/samples/default-data-function/main.html b/test/runtime/samples/default-data-function/main.html similarity index 100% rename from test/generator/samples/default-data-function/main.html rename to test/runtime/samples/default-data-function/main.html diff --git a/test/generator/samples/default-data-override/_config.js b/test/runtime/samples/default-data-override/_config.js similarity index 100% rename from test/generator/samples/default-data-override/_config.js rename to test/runtime/samples/default-data-override/_config.js diff --git a/test/generator/samples/default-data-override/main.html b/test/runtime/samples/default-data-override/main.html similarity index 100% rename from test/generator/samples/default-data-override/main.html rename to test/runtime/samples/default-data-override/main.html diff --git a/test/generator/samples/default-data/_config.js b/test/runtime/samples/default-data/_config.js similarity index 100% rename from test/generator/samples/default-data/_config.js rename to test/runtime/samples/default-data/_config.js diff --git a/test/generator/samples/default-data/main.html b/test/runtime/samples/default-data/main.html similarity index 100% rename from test/generator/samples/default-data/main.html rename to test/runtime/samples/default-data/main.html diff --git a/test/generator/samples/destructuring/_config.js b/test/runtime/samples/destructuring/_config.js similarity index 100% rename from test/generator/samples/destructuring/_config.js rename to test/runtime/samples/destructuring/_config.js diff --git a/test/generator/samples/destructuring/main.html b/test/runtime/samples/destructuring/main.html similarity index 100% rename from test/generator/samples/destructuring/main.html rename to test/runtime/samples/destructuring/main.html diff --git a/test/generator/samples/dev-warning-bad-observe-arguments/_config.js b/test/runtime/samples/dev-warning-bad-observe-arguments/_config.js similarity index 100% rename from test/generator/samples/dev-warning-bad-observe-arguments/_config.js rename to test/runtime/samples/dev-warning-bad-observe-arguments/_config.js diff --git a/test/generator/samples/dev-warning-bad-observe-arguments/main.html b/test/runtime/samples/dev-warning-bad-observe-arguments/main.html similarity index 100% rename from test/generator/samples/dev-warning-bad-observe-arguments/main.html rename to test/runtime/samples/dev-warning-bad-observe-arguments/main.html diff --git a/test/generator/samples/dev-warning-destroy-not-teardown/_config.js b/test/runtime/samples/dev-warning-destroy-not-teardown/_config.js similarity index 100% rename from test/generator/samples/dev-warning-destroy-not-teardown/_config.js rename to test/runtime/samples/dev-warning-destroy-not-teardown/_config.js diff --git a/test/generator/samples/dev-warning-destroy-not-teardown/main.html b/test/runtime/samples/dev-warning-destroy-not-teardown/main.html similarity index 100% rename from test/generator/samples/dev-warning-destroy-not-teardown/main.html rename to test/runtime/samples/dev-warning-destroy-not-teardown/main.html diff --git a/test/generator/samples/dev-warning-missing-data-binding/_config.js b/test/runtime/samples/dev-warning-missing-data-binding/_config.js similarity index 100% rename from test/generator/samples/dev-warning-missing-data-binding/_config.js rename to test/runtime/samples/dev-warning-missing-data-binding/_config.js diff --git a/test/generator/samples/dev-warning-missing-data-binding/main.html b/test/runtime/samples/dev-warning-missing-data-binding/main.html similarity index 100% rename from test/generator/samples/dev-warning-missing-data-binding/main.html rename to test/runtime/samples/dev-warning-missing-data-binding/main.html diff --git a/test/generator/samples/dev-warning-missing-data/_config.js b/test/runtime/samples/dev-warning-missing-data/_config.js similarity index 100% rename from test/generator/samples/dev-warning-missing-data/_config.js rename to test/runtime/samples/dev-warning-missing-data/_config.js diff --git a/test/generator/samples/dev-warning-missing-data/main.html b/test/runtime/samples/dev-warning-missing-data/main.html similarity index 100% rename from test/generator/samples/dev-warning-missing-data/main.html rename to test/runtime/samples/dev-warning-missing-data/main.html diff --git a/test/generator/samples/each-block-containing-if/_config.js b/test/runtime/samples/each-block-containing-if/_config.js similarity index 100% rename from test/generator/samples/each-block-containing-if/_config.js rename to test/runtime/samples/each-block-containing-if/_config.js diff --git a/test/generator/samples/each-block-containing-if/main.html b/test/runtime/samples/each-block-containing-if/main.html similarity index 100% rename from test/generator/samples/each-block-containing-if/main.html rename to test/runtime/samples/each-block-containing-if/main.html diff --git a/test/generator/samples/each-block-else/_config.js b/test/runtime/samples/each-block-else/_config.js similarity index 100% rename from test/generator/samples/each-block-else/_config.js rename to test/runtime/samples/each-block-else/_config.js diff --git a/test/generator/samples/each-block-else/main.html b/test/runtime/samples/each-block-else/main.html similarity index 100% rename from test/generator/samples/each-block-else/main.html rename to test/runtime/samples/each-block-else/main.html diff --git a/test/generator/samples/each-block-indexed/_config.js b/test/runtime/samples/each-block-indexed/_config.js similarity index 100% rename from test/generator/samples/each-block-indexed/_config.js rename to test/runtime/samples/each-block-indexed/_config.js diff --git a/test/generator/samples/each-block-indexed/main.html b/test/runtime/samples/each-block-indexed/main.html similarity index 100% rename from test/generator/samples/each-block-indexed/main.html rename to test/runtime/samples/each-block-indexed/main.html diff --git a/test/generator/samples/each-block-keyed/_config.js b/test/runtime/samples/each-block-keyed/_config.js similarity index 100% rename from test/generator/samples/each-block-keyed/_config.js rename to test/runtime/samples/each-block-keyed/_config.js diff --git a/test/generator/samples/each-block-keyed/main.html b/test/runtime/samples/each-block-keyed/main.html similarity index 100% rename from test/generator/samples/each-block-keyed/main.html rename to test/runtime/samples/each-block-keyed/main.html diff --git a/test/generator/samples/each-block-random-permute/_config.js b/test/runtime/samples/each-block-random-permute/_config.js similarity index 100% rename from test/generator/samples/each-block-random-permute/_config.js rename to test/runtime/samples/each-block-random-permute/_config.js diff --git a/test/generator/samples/each-block-random-permute/main.html b/test/runtime/samples/each-block-random-permute/main.html similarity index 100% rename from test/generator/samples/each-block-random-permute/main.html rename to test/runtime/samples/each-block-random-permute/main.html diff --git a/test/generator/samples/each-block-text-node/_config.js b/test/runtime/samples/each-block-text-node/_config.js similarity index 100% rename from test/generator/samples/each-block-text-node/_config.js rename to test/runtime/samples/each-block-text-node/_config.js diff --git a/test/generator/samples/each-block-text-node/main.html b/test/runtime/samples/each-block-text-node/main.html similarity index 100% rename from test/generator/samples/each-block-text-node/main.html rename to test/runtime/samples/each-block-text-node/main.html diff --git a/test/generator/samples/each-block/_config.js b/test/runtime/samples/each-block/_config.js similarity index 100% rename from test/generator/samples/each-block/_config.js rename to test/runtime/samples/each-block/_config.js diff --git a/test/generator/samples/each-block/main.html b/test/runtime/samples/each-block/main.html similarity index 100% rename from test/generator/samples/each-block/main.html rename to test/runtime/samples/each-block/main.html diff --git a/test/generator/samples/each-blocks-expression/_config.js b/test/runtime/samples/each-blocks-expression/_config.js similarity index 100% rename from test/generator/samples/each-blocks-expression/_config.js rename to test/runtime/samples/each-blocks-expression/_config.js diff --git a/test/generator/samples/each-blocks-expression/main.html b/test/runtime/samples/each-blocks-expression/main.html similarity index 100% rename from test/generator/samples/each-blocks-expression/main.html rename to test/runtime/samples/each-blocks-expression/main.html diff --git a/test/generator/samples/each-blocks-nested-b/_config.js b/test/runtime/samples/each-blocks-nested-b/_config.js similarity index 100% rename from test/generator/samples/each-blocks-nested-b/_config.js rename to test/runtime/samples/each-blocks-nested-b/_config.js diff --git a/test/generator/samples/each-blocks-nested-b/main.html b/test/runtime/samples/each-blocks-nested-b/main.html similarity index 100% rename from test/generator/samples/each-blocks-nested-b/main.html rename to test/runtime/samples/each-blocks-nested-b/main.html diff --git a/test/generator/samples/each-blocks-nested/_config.js b/test/runtime/samples/each-blocks-nested/_config.js similarity index 100% rename from test/generator/samples/each-blocks-nested/_config.js rename to test/runtime/samples/each-blocks-nested/_config.js diff --git a/test/generator/samples/each-blocks-nested/main.html b/test/runtime/samples/each-blocks-nested/main.html similarity index 100% rename from test/generator/samples/each-blocks-nested/main.html rename to test/runtime/samples/each-blocks-nested/main.html diff --git a/test/generator/samples/event-handler-custom-context/_config.js b/test/runtime/samples/event-handler-custom-context/_config.js similarity index 100% rename from test/generator/samples/event-handler-custom-context/_config.js rename to test/runtime/samples/event-handler-custom-context/_config.js diff --git a/test/generator/samples/event-handler-custom-context/main.html b/test/runtime/samples/event-handler-custom-context/main.html similarity index 100% rename from test/generator/samples/event-handler-custom-context/main.html rename to test/runtime/samples/event-handler-custom-context/main.html diff --git a/test/generator/samples/event-handler-custom-node-context/_config.js b/test/runtime/samples/event-handler-custom-node-context/_config.js similarity index 100% rename from test/generator/samples/event-handler-custom-node-context/_config.js rename to test/runtime/samples/event-handler-custom-node-context/_config.js diff --git a/test/generator/samples/event-handler-custom-node-context/main.html b/test/runtime/samples/event-handler-custom-node-context/main.html similarity index 100% rename from test/generator/samples/event-handler-custom-node-context/main.html rename to test/runtime/samples/event-handler-custom-node-context/main.html diff --git a/test/generator/samples/event-handler-custom/_config.js b/test/runtime/samples/event-handler-custom/_config.js similarity index 100% rename from test/generator/samples/event-handler-custom/_config.js rename to test/runtime/samples/event-handler-custom/_config.js diff --git a/test/generator/samples/event-handler-custom/main.html b/test/runtime/samples/event-handler-custom/main.html similarity index 100% rename from test/generator/samples/event-handler-custom/main.html rename to test/runtime/samples/event-handler-custom/main.html diff --git a/test/generator/samples/event-handler-event-methods/_config.js b/test/runtime/samples/event-handler-event-methods/_config.js similarity index 100% rename from test/generator/samples/event-handler-event-methods/_config.js rename to test/runtime/samples/event-handler-event-methods/_config.js diff --git a/test/generator/samples/event-handler-event-methods/main.html b/test/runtime/samples/event-handler-event-methods/main.html similarity index 100% rename from test/generator/samples/event-handler-event-methods/main.html rename to test/runtime/samples/event-handler-event-methods/main.html diff --git a/test/generator/samples/event-handler-removal/_config.js b/test/runtime/samples/event-handler-removal/_config.js similarity index 100% rename from test/generator/samples/event-handler-removal/_config.js rename to test/runtime/samples/event-handler-removal/_config.js diff --git a/test/generator/samples/event-handler-removal/main.html b/test/runtime/samples/event-handler-removal/main.html similarity index 100% rename from test/generator/samples/event-handler-removal/main.html rename to test/runtime/samples/event-handler-removal/main.html diff --git a/test/generator/samples/event-handler-this-methods/_config.js b/test/runtime/samples/event-handler-this-methods/_config.js similarity index 100% rename from test/generator/samples/event-handler-this-methods/_config.js rename to test/runtime/samples/event-handler-this-methods/_config.js diff --git a/test/generator/samples/event-handler-this-methods/main.html b/test/runtime/samples/event-handler-this-methods/main.html similarity index 100% rename from test/generator/samples/event-handler-this-methods/main.html rename to test/runtime/samples/event-handler-this-methods/main.html diff --git a/test/generator/samples/event-handler/_config.js b/test/runtime/samples/event-handler/_config.js similarity index 100% rename from test/generator/samples/event-handler/_config.js rename to test/runtime/samples/event-handler/_config.js diff --git a/test/generator/samples/event-handler/main.html b/test/runtime/samples/event-handler/main.html similarity index 100% rename from test/generator/samples/event-handler/main.html rename to test/runtime/samples/event-handler/main.html diff --git a/test/generator/samples/events-custom/_config.js b/test/runtime/samples/events-custom/_config.js similarity index 100% rename from test/generator/samples/events-custom/_config.js rename to test/runtime/samples/events-custom/_config.js diff --git a/test/generator/samples/events-custom/main.html b/test/runtime/samples/events-custom/main.html similarity index 100% rename from test/generator/samples/events-custom/main.html rename to test/runtime/samples/events-custom/main.html diff --git a/test/generator/samples/events-lifecycle/_config.js b/test/runtime/samples/events-lifecycle/_config.js similarity index 100% rename from test/generator/samples/events-lifecycle/_config.js rename to test/runtime/samples/events-lifecycle/_config.js diff --git a/test/generator/samples/events-lifecycle/main.html b/test/runtime/samples/events-lifecycle/main.html similarity index 100% rename from test/generator/samples/events-lifecycle/main.html rename to test/runtime/samples/events-lifecycle/main.html diff --git a/test/generator/samples/function-in-expression/_config.js b/test/runtime/samples/function-in-expression/_config.js similarity index 100% rename from test/generator/samples/function-in-expression/_config.js rename to test/runtime/samples/function-in-expression/_config.js diff --git a/test/generator/samples/function-in-expression/main.html b/test/runtime/samples/function-in-expression/main.html similarity index 100% rename from test/generator/samples/function-in-expression/main.html rename to test/runtime/samples/function-in-expression/main.html diff --git a/test/generator/samples/get-state/_config.js b/test/runtime/samples/get-state/_config.js similarity index 100% rename from test/generator/samples/get-state/_config.js rename to test/runtime/samples/get-state/_config.js diff --git a/test/generator/samples/get-state/main.html b/test/runtime/samples/get-state/main.html similarity index 100% rename from test/generator/samples/get-state/main.html rename to test/runtime/samples/get-state/main.html diff --git a/test/generator/samples/globals-accessible-directly/_config.js b/test/runtime/samples/globals-accessible-directly/_config.js similarity index 100% rename from test/generator/samples/globals-accessible-directly/_config.js rename to test/runtime/samples/globals-accessible-directly/_config.js diff --git a/test/generator/samples/globals-accessible-directly/main.html b/test/runtime/samples/globals-accessible-directly/main.html similarity index 100% rename from test/generator/samples/globals-accessible-directly/main.html rename to test/runtime/samples/globals-accessible-directly/main.html diff --git a/test/generator/samples/globals-not-dereferenced/_config.js b/test/runtime/samples/globals-not-dereferenced/_config.js similarity index 100% rename from test/generator/samples/globals-not-dereferenced/_config.js rename to test/runtime/samples/globals-not-dereferenced/_config.js diff --git a/test/generator/samples/globals-not-dereferenced/main.html b/test/runtime/samples/globals-not-dereferenced/main.html similarity index 100% rename from test/generator/samples/globals-not-dereferenced/main.html rename to test/runtime/samples/globals-not-dereferenced/main.html diff --git a/test/generator/samples/globals-shadowed-by-data/_config.js b/test/runtime/samples/globals-shadowed-by-data/_config.js similarity index 100% rename from test/generator/samples/globals-shadowed-by-data/_config.js rename to test/runtime/samples/globals-shadowed-by-data/_config.js diff --git a/test/generator/samples/globals-shadowed-by-data/main.html b/test/runtime/samples/globals-shadowed-by-data/main.html similarity index 100% rename from test/generator/samples/globals-shadowed-by-data/main.html rename to test/runtime/samples/globals-shadowed-by-data/main.html diff --git a/test/generator/samples/globals-shadowed-by-helpers/_config.js b/test/runtime/samples/globals-shadowed-by-helpers/_config.js similarity index 100% rename from test/generator/samples/globals-shadowed-by-helpers/_config.js rename to test/runtime/samples/globals-shadowed-by-helpers/_config.js diff --git a/test/generator/samples/globals-shadowed-by-helpers/main.html b/test/runtime/samples/globals-shadowed-by-helpers/main.html similarity index 100% rename from test/generator/samples/globals-shadowed-by-helpers/main.html rename to test/runtime/samples/globals-shadowed-by-helpers/main.html diff --git a/test/generator/samples/hello-world/_config.js b/test/runtime/samples/hello-world/_config.js similarity index 100% rename from test/generator/samples/hello-world/_config.js rename to test/runtime/samples/hello-world/_config.js diff --git a/test/generator/samples/hello-world/main.html b/test/runtime/samples/hello-world/main.html similarity index 100% rename from test/generator/samples/hello-world/main.html rename to test/runtime/samples/hello-world/main.html diff --git a/test/generator/samples/helpers/_config.js b/test/runtime/samples/helpers/_config.js similarity index 100% rename from test/generator/samples/helpers/_config.js rename to test/runtime/samples/helpers/_config.js diff --git a/test/generator/samples/helpers/main.html b/test/runtime/samples/helpers/main.html similarity index 100% rename from test/generator/samples/helpers/main.html rename to test/runtime/samples/helpers/main.html diff --git a/test/generator/samples/if-block-else/_config.js b/test/runtime/samples/if-block-else/_config.js similarity index 100% rename from test/generator/samples/if-block-else/_config.js rename to test/runtime/samples/if-block-else/_config.js diff --git a/test/generator/samples/if-block-else/main.html b/test/runtime/samples/if-block-else/main.html similarity index 100% rename from test/generator/samples/if-block-else/main.html rename to test/runtime/samples/if-block-else/main.html diff --git a/test/generator/samples/if-block-elseif-text/_config.js b/test/runtime/samples/if-block-elseif-text/_config.js similarity index 100% rename from test/generator/samples/if-block-elseif-text/_config.js rename to test/runtime/samples/if-block-elseif-text/_config.js diff --git a/test/generator/samples/if-block-elseif-text/main.html b/test/runtime/samples/if-block-elseif-text/main.html similarity index 100% rename from test/generator/samples/if-block-elseif-text/main.html rename to test/runtime/samples/if-block-elseif-text/main.html diff --git a/test/generator/samples/if-block-elseif/_config.js b/test/runtime/samples/if-block-elseif/_config.js similarity index 100% rename from test/generator/samples/if-block-elseif/_config.js rename to test/runtime/samples/if-block-elseif/_config.js diff --git a/test/generator/samples/if-block-elseif/main.html b/test/runtime/samples/if-block-elseif/main.html similarity index 100% rename from test/generator/samples/if-block-elseif/main.html rename to test/runtime/samples/if-block-elseif/main.html diff --git a/test/generator/samples/if-block-expression/_config.js b/test/runtime/samples/if-block-expression/_config.js similarity index 100% rename from test/generator/samples/if-block-expression/_config.js rename to test/runtime/samples/if-block-expression/_config.js diff --git a/test/generator/samples/if-block-expression/main.html b/test/runtime/samples/if-block-expression/main.html similarity index 100% rename from test/generator/samples/if-block-expression/main.html rename to test/runtime/samples/if-block-expression/main.html diff --git a/test/generator/samples/if-block-widget/Widget.html b/test/runtime/samples/if-block-widget/Widget.html similarity index 100% rename from test/generator/samples/if-block-widget/Widget.html rename to test/runtime/samples/if-block-widget/Widget.html diff --git a/test/generator/samples/if-block-widget/_config.js b/test/runtime/samples/if-block-widget/_config.js similarity index 100% rename from test/generator/samples/if-block-widget/_config.js rename to test/runtime/samples/if-block-widget/_config.js diff --git a/test/generator/samples/if-block-widget/main.html b/test/runtime/samples/if-block-widget/main.html similarity index 100% rename from test/generator/samples/if-block-widget/main.html rename to test/runtime/samples/if-block-widget/main.html diff --git a/test/generator/samples/if-block/_config.js b/test/runtime/samples/if-block/_config.js similarity index 100% rename from test/generator/samples/if-block/_config.js rename to test/runtime/samples/if-block/_config.js diff --git a/test/generator/samples/if-block/main.html b/test/runtime/samples/if-block/main.html similarity index 100% rename from test/generator/samples/if-block/main.html rename to test/runtime/samples/if-block/main.html diff --git a/test/generator/samples/imported-renamed-components/ComponentOne.html b/test/runtime/samples/imported-renamed-components/ComponentOne.html similarity index 100% rename from test/generator/samples/imported-renamed-components/ComponentOne.html rename to test/runtime/samples/imported-renamed-components/ComponentOne.html diff --git a/test/generator/samples/imported-renamed-components/ComponentTwo.html b/test/runtime/samples/imported-renamed-components/ComponentTwo.html similarity index 100% rename from test/generator/samples/imported-renamed-components/ComponentTwo.html rename to test/runtime/samples/imported-renamed-components/ComponentTwo.html diff --git a/test/generator/samples/imported-renamed-components/_config.js b/test/runtime/samples/imported-renamed-components/_config.js similarity index 100% rename from test/generator/samples/imported-renamed-components/_config.js rename to test/runtime/samples/imported-renamed-components/_config.js diff --git a/test/generator/samples/imported-renamed-components/main.html b/test/runtime/samples/imported-renamed-components/main.html similarity index 100% rename from test/generator/samples/imported-renamed-components/main.html rename to test/runtime/samples/imported-renamed-components/main.html diff --git a/test/generator/samples/inline-expressions/_config.js b/test/runtime/samples/inline-expressions/_config.js similarity index 100% rename from test/generator/samples/inline-expressions/_config.js rename to test/runtime/samples/inline-expressions/_config.js diff --git a/test/generator/samples/inline-expressions/main.html b/test/runtime/samples/inline-expressions/main.html similarity index 100% rename from test/generator/samples/inline-expressions/main.html rename to test/runtime/samples/inline-expressions/main.html diff --git a/test/generator/samples/input-list/_config.js b/test/runtime/samples/input-list/_config.js similarity index 100% rename from test/generator/samples/input-list/_config.js rename to test/runtime/samples/input-list/_config.js diff --git a/test/generator/samples/input-list/main.html b/test/runtime/samples/input-list/main.html similarity index 100% rename from test/generator/samples/input-list/main.html rename to test/runtime/samples/input-list/main.html diff --git a/test/generator/samples/lifecycle-events/_config.js b/test/runtime/samples/lifecycle-events/_config.js similarity index 100% rename from test/generator/samples/lifecycle-events/_config.js rename to test/runtime/samples/lifecycle-events/_config.js diff --git a/test/generator/samples/lifecycle-events/main.html b/test/runtime/samples/lifecycle-events/main.html similarity index 100% rename from test/generator/samples/lifecycle-events/main.html rename to test/runtime/samples/lifecycle-events/main.html diff --git a/test/generator/samples/names-deconflicted-nested/_config.js b/test/runtime/samples/names-deconflicted-nested/_config.js similarity index 100% rename from test/generator/samples/names-deconflicted-nested/_config.js rename to test/runtime/samples/names-deconflicted-nested/_config.js diff --git a/test/generator/samples/names-deconflicted-nested/main.html b/test/runtime/samples/names-deconflicted-nested/main.html similarity index 100% rename from test/generator/samples/names-deconflicted-nested/main.html rename to test/runtime/samples/names-deconflicted-nested/main.html diff --git a/test/generator/samples/names-deconflicted/Widget.html b/test/runtime/samples/names-deconflicted/Widget.html similarity index 100% rename from test/generator/samples/names-deconflicted/Widget.html rename to test/runtime/samples/names-deconflicted/Widget.html diff --git a/test/generator/samples/names-deconflicted/_config.js b/test/runtime/samples/names-deconflicted/_config.js similarity index 100% rename from test/generator/samples/names-deconflicted/_config.js rename to test/runtime/samples/names-deconflicted/_config.js diff --git a/test/generator/samples/names-deconflicted/main.html b/test/runtime/samples/names-deconflicted/main.html similarity index 100% rename from test/generator/samples/names-deconflicted/main.html rename to test/runtime/samples/names-deconflicted/main.html diff --git a/test/generator/samples/nbsp/_config.js b/test/runtime/samples/nbsp/_config.js similarity index 100% rename from test/generator/samples/nbsp/_config.js rename to test/runtime/samples/nbsp/_config.js diff --git a/test/generator/samples/nbsp/main.html b/test/runtime/samples/nbsp/main.html similarity index 100% rename from test/generator/samples/nbsp/main.html rename to test/runtime/samples/nbsp/main.html diff --git a/test/generator/samples/observe-component-ignores-irrelevant-changes/Foo.html b/test/runtime/samples/observe-component-ignores-irrelevant-changes/Foo.html similarity index 100% rename from test/generator/samples/observe-component-ignores-irrelevant-changes/Foo.html rename to test/runtime/samples/observe-component-ignores-irrelevant-changes/Foo.html diff --git a/test/generator/samples/observe-component-ignores-irrelevant-changes/_config.js b/test/runtime/samples/observe-component-ignores-irrelevant-changes/_config.js similarity index 100% rename from test/generator/samples/observe-component-ignores-irrelevant-changes/_config.js rename to test/runtime/samples/observe-component-ignores-irrelevant-changes/_config.js diff --git a/test/generator/samples/observe-component-ignores-irrelevant-changes/main.html b/test/runtime/samples/observe-component-ignores-irrelevant-changes/main.html similarity index 100% rename from test/generator/samples/observe-component-ignores-irrelevant-changes/main.html rename to test/runtime/samples/observe-component-ignores-irrelevant-changes/main.html diff --git a/test/generator/samples/observe-prevents-loop/_config.js b/test/runtime/samples/observe-prevents-loop/_config.js similarity index 100% rename from test/generator/samples/observe-prevents-loop/_config.js rename to test/runtime/samples/observe-prevents-loop/_config.js diff --git a/test/generator/samples/observe-prevents-loop/main.html b/test/runtime/samples/observe-prevents-loop/main.html similarity index 100% rename from test/generator/samples/observe-prevents-loop/main.html rename to test/runtime/samples/observe-prevents-loop/main.html diff --git a/test/generator/samples/onrender-chain/Item.html b/test/runtime/samples/onrender-chain/Item.html similarity index 100% rename from test/generator/samples/onrender-chain/Item.html rename to test/runtime/samples/onrender-chain/Item.html diff --git a/test/generator/samples/onrender-chain/List.html b/test/runtime/samples/onrender-chain/List.html similarity index 100% rename from test/generator/samples/onrender-chain/List.html rename to test/runtime/samples/onrender-chain/List.html diff --git a/test/generator/samples/onrender-chain/_config.js b/test/runtime/samples/onrender-chain/_config.js similarity index 100% rename from test/generator/samples/onrender-chain/_config.js rename to test/runtime/samples/onrender-chain/_config.js diff --git a/test/generator/samples/onrender-chain/main.html b/test/runtime/samples/onrender-chain/main.html similarity index 100% rename from test/generator/samples/onrender-chain/main.html rename to test/runtime/samples/onrender-chain/main.html diff --git a/test/generator/samples/onrender-fires-when-ready-nested/ParentWidget.html b/test/runtime/samples/onrender-fires-when-ready-nested/ParentWidget.html similarity index 100% rename from test/generator/samples/onrender-fires-when-ready-nested/ParentWidget.html rename to test/runtime/samples/onrender-fires-when-ready-nested/ParentWidget.html diff --git a/test/generator/samples/onrender-fires-when-ready-nested/Widget.html b/test/runtime/samples/onrender-fires-when-ready-nested/Widget.html similarity index 100% rename from test/generator/samples/onrender-fires-when-ready-nested/Widget.html rename to test/runtime/samples/onrender-fires-when-ready-nested/Widget.html diff --git a/test/generator/samples/onrender-fires-when-ready-nested/_config.js b/test/runtime/samples/onrender-fires-when-ready-nested/_config.js similarity index 100% rename from test/generator/samples/onrender-fires-when-ready-nested/_config.js rename to test/runtime/samples/onrender-fires-when-ready-nested/_config.js diff --git a/test/generator/samples/onrender-fires-when-ready-nested/main.html b/test/runtime/samples/onrender-fires-when-ready-nested/main.html similarity index 100% rename from test/generator/samples/onrender-fires-when-ready-nested/main.html rename to test/runtime/samples/onrender-fires-when-ready-nested/main.html diff --git a/test/generator/samples/onrender-fires-when-ready/Widget.html b/test/runtime/samples/onrender-fires-when-ready/Widget.html similarity index 100% rename from test/generator/samples/onrender-fires-when-ready/Widget.html rename to test/runtime/samples/onrender-fires-when-ready/Widget.html diff --git a/test/generator/samples/onrender-fires-when-ready/_config.js b/test/runtime/samples/onrender-fires-when-ready/_config.js similarity index 100% rename from test/generator/samples/onrender-fires-when-ready/_config.js rename to test/runtime/samples/onrender-fires-when-ready/_config.js diff --git a/test/generator/samples/onrender-fires-when-ready/main.html b/test/runtime/samples/onrender-fires-when-ready/main.html similarity index 100% rename from test/generator/samples/onrender-fires-when-ready/main.html rename to test/runtime/samples/onrender-fires-when-ready/main.html diff --git a/test/generator/samples/pass-no-options/_config.js b/test/runtime/samples/pass-no-options/_config.js similarity index 100% rename from test/generator/samples/pass-no-options/_config.js rename to test/runtime/samples/pass-no-options/_config.js diff --git a/test/generator/samples/pass-no-options/main.html b/test/runtime/samples/pass-no-options/main.html similarity index 100% rename from test/generator/samples/pass-no-options/main.html rename to test/runtime/samples/pass-no-options/main.html diff --git a/test/generator/samples/raw-mustaches-preserved/_config.js b/test/runtime/samples/raw-mustaches-preserved/_config.js similarity index 100% rename from test/generator/samples/raw-mustaches-preserved/_config.js rename to test/runtime/samples/raw-mustaches-preserved/_config.js diff --git a/test/generator/samples/raw-mustaches-preserved/main.html b/test/runtime/samples/raw-mustaches-preserved/main.html similarity index 100% rename from test/generator/samples/raw-mustaches-preserved/main.html rename to test/runtime/samples/raw-mustaches-preserved/main.html diff --git a/test/generator/samples/raw-mustaches/_config.js b/test/runtime/samples/raw-mustaches/_config.js similarity index 100% rename from test/generator/samples/raw-mustaches/_config.js rename to test/runtime/samples/raw-mustaches/_config.js diff --git a/test/generator/samples/raw-mustaches/main.html b/test/runtime/samples/raw-mustaches/main.html similarity index 100% rename from test/generator/samples/raw-mustaches/main.html rename to test/runtime/samples/raw-mustaches/main.html diff --git a/test/generator/samples/refs-unset/_config.js b/test/runtime/samples/refs-unset/_config.js similarity index 100% rename from test/generator/samples/refs-unset/_config.js rename to test/runtime/samples/refs-unset/_config.js diff --git a/test/generator/samples/refs-unset/main.html b/test/runtime/samples/refs-unset/main.html similarity index 100% rename from test/generator/samples/refs-unset/main.html rename to test/runtime/samples/refs-unset/main.html diff --git a/test/generator/samples/refs/_config.js b/test/runtime/samples/refs/_config.js similarity index 100% rename from test/generator/samples/refs/_config.js rename to test/runtime/samples/refs/_config.js diff --git a/test/generator/samples/refs/main.html b/test/runtime/samples/refs/main.html similarity index 100% rename from test/generator/samples/refs/main.html rename to test/runtime/samples/refs/main.html diff --git a/test/generator/samples/select-one-way-bind/_config.js b/test/runtime/samples/select-one-way-bind/_config.js similarity index 100% rename from test/generator/samples/select-one-way-bind/_config.js rename to test/runtime/samples/select-one-way-bind/_config.js diff --git a/test/generator/samples/select-one-way-bind/main.html b/test/runtime/samples/select-one-way-bind/main.html similarity index 100% rename from test/generator/samples/select-one-way-bind/main.html rename to test/runtime/samples/select-one-way-bind/main.html diff --git a/test/generator/samples/select/_config.js b/test/runtime/samples/select/_config.js similarity index 100% rename from test/generator/samples/select/_config.js rename to test/runtime/samples/select/_config.js diff --git a/test/generator/samples/select/main.html b/test/runtime/samples/select/main.html similarity index 100% rename from test/generator/samples/select/main.html rename to test/runtime/samples/select/main.html diff --git a/test/generator/samples/self-reference-tree/_config.js b/test/runtime/samples/self-reference-tree/_config.js similarity index 100% rename from test/generator/samples/self-reference-tree/_config.js rename to test/runtime/samples/self-reference-tree/_config.js diff --git a/test/generator/samples/self-reference-tree/main.html b/test/runtime/samples/self-reference-tree/main.html similarity index 100% rename from test/generator/samples/self-reference-tree/main.html rename to test/runtime/samples/self-reference-tree/main.html diff --git a/test/generator/samples/self-reference/_config.js b/test/runtime/samples/self-reference/_config.js similarity index 100% rename from test/generator/samples/self-reference/_config.js rename to test/runtime/samples/self-reference/_config.js diff --git a/test/generator/samples/self-reference/main.html b/test/runtime/samples/self-reference/main.html similarity index 100% rename from test/generator/samples/self-reference/main.html rename to test/runtime/samples/self-reference/main.html diff --git a/test/generator/samples/set-in-observe-dedupes-renders/Widget.html b/test/runtime/samples/set-in-observe-dedupes-renders/Widget.html similarity index 100% rename from test/generator/samples/set-in-observe-dedupes-renders/Widget.html rename to test/runtime/samples/set-in-observe-dedupes-renders/Widget.html diff --git a/test/generator/samples/set-in-observe-dedupes-renders/_config.js b/test/runtime/samples/set-in-observe-dedupes-renders/_config.js similarity index 100% rename from test/generator/samples/set-in-observe-dedupes-renders/_config.js rename to test/runtime/samples/set-in-observe-dedupes-renders/_config.js diff --git a/test/generator/samples/set-in-observe-dedupes-renders/main.html b/test/runtime/samples/set-in-observe-dedupes-renders/main.html similarity index 100% rename from test/generator/samples/set-in-observe-dedupes-renders/main.html rename to test/runtime/samples/set-in-observe-dedupes-renders/main.html diff --git a/test/generator/samples/set-in-observe/_config.js b/test/runtime/samples/set-in-observe/_config.js similarity index 100% rename from test/generator/samples/set-in-observe/_config.js rename to test/runtime/samples/set-in-observe/_config.js diff --git a/test/generator/samples/set-in-observe/main.html b/test/runtime/samples/set-in-observe/main.html similarity index 100% rename from test/generator/samples/set-in-observe/main.html rename to test/runtime/samples/set-in-observe/main.html diff --git a/test/generator/samples/set-in-onrender/_config.js b/test/runtime/samples/set-in-onrender/_config.js similarity index 100% rename from test/generator/samples/set-in-onrender/_config.js rename to test/runtime/samples/set-in-onrender/_config.js diff --git a/test/generator/samples/set-in-onrender/main.html b/test/runtime/samples/set-in-onrender/main.html similarity index 100% rename from test/generator/samples/set-in-onrender/main.html rename to test/runtime/samples/set-in-onrender/main.html diff --git a/test/generator/samples/set-prevents-loop/Foo.html b/test/runtime/samples/set-prevents-loop/Foo.html similarity index 100% rename from test/generator/samples/set-prevents-loop/Foo.html rename to test/runtime/samples/set-prevents-loop/Foo.html diff --git a/test/generator/samples/set-prevents-loop/_config.js b/test/runtime/samples/set-prevents-loop/_config.js similarity index 100% rename from test/generator/samples/set-prevents-loop/_config.js rename to test/runtime/samples/set-prevents-loop/_config.js diff --git a/test/generator/samples/set-prevents-loop/main.html b/test/runtime/samples/set-prevents-loop/main.html similarity index 100% rename from test/generator/samples/set-prevents-loop/main.html rename to test/runtime/samples/set-prevents-loop/main.html diff --git a/test/generator/samples/single-static-element/_config.js b/test/runtime/samples/single-static-element/_config.js similarity index 100% rename from test/generator/samples/single-static-element/_config.js rename to test/runtime/samples/single-static-element/_config.js diff --git a/test/generator/samples/single-static-element/main.html b/test/runtime/samples/single-static-element/main.html similarity index 100% rename from test/generator/samples/single-static-element/main.html rename to test/runtime/samples/single-static-element/main.html diff --git a/test/generator/samples/single-text-node/_config.js b/test/runtime/samples/single-text-node/_config.js similarity index 100% rename from test/generator/samples/single-text-node/_config.js rename to test/runtime/samples/single-text-node/_config.js diff --git a/test/generator/samples/single-text-node/main.html b/test/runtime/samples/single-text-node/main.html similarity index 100% rename from test/generator/samples/single-text-node/main.html rename to test/runtime/samples/single-text-node/main.html diff --git a/test/generator/samples/svg-attributes/_config.js b/test/runtime/samples/svg-attributes/_config.js similarity index 100% rename from test/generator/samples/svg-attributes/_config.js rename to test/runtime/samples/svg-attributes/_config.js diff --git a/test/generator/samples/svg-attributes/main.html b/test/runtime/samples/svg-attributes/main.html similarity index 100% rename from test/generator/samples/svg-attributes/main.html rename to test/runtime/samples/svg-attributes/main.html diff --git a/test/generator/samples/svg-child-component-declared-namespace-shorthand/Rect.html b/test/runtime/samples/svg-child-component-declared-namespace-shorthand/Rect.html similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace-shorthand/Rect.html rename to test/runtime/samples/svg-child-component-declared-namespace-shorthand/Rect.html diff --git a/test/generator/samples/svg-child-component-declared-namespace-shorthand/_config.js b/test/runtime/samples/svg-child-component-declared-namespace-shorthand/_config.js similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace-shorthand/_config.js rename to test/runtime/samples/svg-child-component-declared-namespace-shorthand/_config.js diff --git a/test/generator/samples/svg-child-component-declared-namespace-shorthand/main.html b/test/runtime/samples/svg-child-component-declared-namespace-shorthand/main.html similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace-shorthand/main.html rename to test/runtime/samples/svg-child-component-declared-namespace-shorthand/main.html diff --git a/test/generator/samples/svg-child-component-declared-namespace/Rect.html b/test/runtime/samples/svg-child-component-declared-namespace/Rect.html similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace/Rect.html rename to test/runtime/samples/svg-child-component-declared-namespace/Rect.html diff --git a/test/generator/samples/svg-child-component-declared-namespace/_config.js b/test/runtime/samples/svg-child-component-declared-namespace/_config.js similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace/_config.js rename to test/runtime/samples/svg-child-component-declared-namespace/_config.js diff --git a/test/generator/samples/svg-child-component-declared-namespace/main.html b/test/runtime/samples/svg-child-component-declared-namespace/main.html similarity index 100% rename from test/generator/samples/svg-child-component-declared-namespace/main.html rename to test/runtime/samples/svg-child-component-declared-namespace/main.html diff --git a/test/generator/samples/svg-class/_config.js b/test/runtime/samples/svg-class/_config.js similarity index 100% rename from test/generator/samples/svg-class/_config.js rename to test/runtime/samples/svg-class/_config.js diff --git a/test/generator/samples/svg-class/main.html b/test/runtime/samples/svg-class/main.html similarity index 100% rename from test/generator/samples/svg-class/main.html rename to test/runtime/samples/svg-class/main.html diff --git a/test/generator/samples/svg-each-block-namespace/_config.js b/test/runtime/samples/svg-each-block-namespace/_config.js similarity index 100% rename from test/generator/samples/svg-each-block-namespace/_config.js rename to test/runtime/samples/svg-each-block-namespace/_config.js diff --git a/test/generator/samples/svg-each-block-namespace/main.html b/test/runtime/samples/svg-each-block-namespace/main.html similarity index 100% rename from test/generator/samples/svg-each-block-namespace/main.html rename to test/runtime/samples/svg-each-block-namespace/main.html diff --git a/test/generator/samples/svg-multiple/_config.js b/test/runtime/samples/svg-multiple/_config.js similarity index 100% rename from test/generator/samples/svg-multiple/_config.js rename to test/runtime/samples/svg-multiple/_config.js diff --git a/test/generator/samples/svg-multiple/main.html b/test/runtime/samples/svg-multiple/main.html similarity index 100% rename from test/generator/samples/svg-multiple/main.html rename to test/runtime/samples/svg-multiple/main.html diff --git a/test/generator/samples/svg-no-whitespace/_config.js b/test/runtime/samples/svg-no-whitespace/_config.js similarity index 100% rename from test/generator/samples/svg-no-whitespace/_config.js rename to test/runtime/samples/svg-no-whitespace/_config.js diff --git a/test/generator/samples/svg-no-whitespace/main.html b/test/runtime/samples/svg-no-whitespace/main.html similarity index 100% rename from test/generator/samples/svg-no-whitespace/main.html rename to test/runtime/samples/svg-no-whitespace/main.html diff --git a/test/generator/samples/svg-xlink/_config.js b/test/runtime/samples/svg-xlink/_config.js similarity index 100% rename from test/generator/samples/svg-xlink/_config.js rename to test/runtime/samples/svg-xlink/_config.js diff --git a/test/generator/samples/svg-xlink/main.html b/test/runtime/samples/svg-xlink/main.html similarity index 100% rename from test/generator/samples/svg-xlink/main.html rename to test/runtime/samples/svg-xlink/main.html diff --git a/test/generator/samples/svg-xmlns/_config.js b/test/runtime/samples/svg-xmlns/_config.js similarity index 100% rename from test/generator/samples/svg-xmlns/_config.js rename to test/runtime/samples/svg-xmlns/_config.js diff --git a/test/generator/samples/svg-xmlns/main.html b/test/runtime/samples/svg-xmlns/main.html similarity index 100% rename from test/generator/samples/svg-xmlns/main.html rename to test/runtime/samples/svg-xmlns/main.html diff --git a/test/generator/samples/svg/_config.js b/test/runtime/samples/svg/_config.js similarity index 100% rename from test/generator/samples/svg/_config.js rename to test/runtime/samples/svg/_config.js diff --git a/test/generator/samples/svg/main.html b/test/runtime/samples/svg/main.html similarity index 100% rename from test/generator/samples/svg/main.html rename to test/runtime/samples/svg/main.html diff --git a/test/generator/samples/window-binding-resize/_config.js b/test/runtime/samples/window-binding-resize/_config.js similarity index 100% rename from test/generator/samples/window-binding-resize/_config.js rename to test/runtime/samples/window-binding-resize/_config.js diff --git a/test/generator/samples/window-binding-resize/main.html b/test/runtime/samples/window-binding-resize/main.html similarity index 100% rename from test/generator/samples/window-binding-resize/main.html rename to test/runtime/samples/window-binding-resize/main.html diff --git a/test/generator/samples/window-event/_config.js b/test/runtime/samples/window-event/_config.js similarity index 100% rename from test/generator/samples/window-event/_config.js rename to test/runtime/samples/window-event/_config.js diff --git a/test/generator/samples/window-event/main.html b/test/runtime/samples/window-event/main.html similarity index 100% rename from test/generator/samples/window-event/main.html rename to test/runtime/samples/window-event/main.html diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.js index 8fa6f74e0a89..d9ac917e54c6 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.js @@ -81,10 +81,10 @@ describe( 'ssr', () => { }); // duplicate client-side tests, as far as possible - fs.readdirSync( 'test/generator/samples' ).forEach( dir => { + fs.readdirSync( 'test/runtime/samples' ).forEach( dir => { if ( dir[0] === '.' ) return; - const config = loadConfig( `./generator/samples/${dir}/_config.js` ); + const config = loadConfig( `./runtime/samples/${dir}/_config.js` ); if ( config.solo && process.env.CI ) { throw new Error( 'Forgot to remove `solo: true` from test' ); @@ -96,7 +96,7 @@ describe( 'ssr', () => { let compiled; try { - const source = fs.readFileSync( `test/generator/samples/${dir}/main.html`, 'utf-8' ); + const source = fs.readFileSync( `test/runtime/samples/${dir}/main.html`, 'utf-8' ); compiled = svelte.compile( source, { generate: 'ssr' }); } catch ( err ) { if ( config.compileError ) { @@ -107,7 +107,7 @@ describe( 'ssr', () => { } } - const component = require( `../generator/samples/${dir}/main.html` ); + const component = require( `../runtime/samples/${dir}/main.html` ); let html; try { From f43e71b959bf83d39e789c898e7ad63ac5e600e2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Apr 2017 17:55:31 -0400 Subject: [PATCH 02/31] remove #433 test for now --- .../samples/event-handlers-custom/expected.js | 205 ------------------ .../samples/event-handlers-custom/input.html | 17 -- 2 files changed, 222 deletions(-) delete mode 100644 test/js/samples/event-handlers-custom/expected.js delete mode 100644 test/js/samples/event-handlers-custom/input.html diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js deleted file mode 100644 index 71e633d752f2..000000000000 --- a/test/js/samples/event-handlers-custom/expected.js +++ /dev/null @@ -1,205 +0,0 @@ -var template = (function () { - return { - methods: { - foo ( bar ) { - console.log( bar ); - } - }, - - events: { - foo ( node, callback ) { - // code goes here - } - } - }; -}()); - -function render_main_fragment ( root, component ) { - var button = createElement( 'button' ); - - var foo_handler = template.events.foo.call( component, button, function ( event ) { - var root = component.get(); - - component.foo( root.bar ); - }.bind( button ) ); - - appendNode( createText( "foo" ), button ); - - return { - mount: function ( target, anchor ) { - insertNode( button, target, anchor ); - }, - - update: noop, - - teardown: function ( detach ) { - foo_handler.teardown(); - - if ( detach ) { - detachNode( button ); - } - } - }; -} - -function SvelteComponent ( options ) { - options = options || {}; - this._state = options.data || {}; - - this._observers = { - pre: Object.create( null ), - post: Object.create( null ) - }; - - this._handlers = Object.create( null ); - - this._root = options._root; - this._yield = options._yield; - - this._torndown = false; - - this._fragment = render_main_fragment( this._state, this ); - if ( options.target ) this._fragment.mount( options.target, null ); -} - -assign( SvelteComponent.prototype, template.methods, { - get: get, - fire: fire, - observe: observe, - on: on, - set: set, - _flush: _flush -}); - -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - - dispatchObservers( this, this._observers.pre, newState, oldState ); - if ( this._fragment ) this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - this.fire( 'destroy' ); - - this._fragment.teardown( detach !== false ); - this._fragment = null; - - this._state = {}; - this._torndown = true; -}; - -function createElement( name ) { - return document.createElement( name ); -} - -function detachNode( node ) { - node.parentNode.removeChild( node ); -} - -function insertNode( node, target, anchor ) { - target.insertBefore( node, anchor ); -} - -function createText( data ) { - return document.createTextNode( data ); -} - -function appendNode( node, target ) { - target.appendChild( node ); -} - -function assign( target ) { - for ( var i = 1; i < arguments.length; i += 1 ) { - var source = arguments[i]; - for ( var k in source ) target[k] = source[k]; - } - - return target; -} - -function dispatchObservers( component, group, newState, oldState ) { - for ( var key in group ) { - if ( !( key in newState ) ) continue; - - var newValue = newState[ key ]; - var oldValue = oldState[ key ]; - - if ( newValue === oldValue && typeof newValue !== 'object' ) continue; - - var callbacks = group[ key ]; - if ( !callbacks ) continue; - - for ( var i = 0; i < callbacks.length; i += 1 ) { - var callback = callbacks[i]; - if ( callback.__calling ) continue; - - callback.__calling = true; - callback.call( component, newValue, oldValue ); - callback.__calling = false; - } - } -} - -function get( key ) { - return key ? this._state[ key ] : this._state; -} - -function fire( eventName, data ) { - var handlers = eventName in this._handlers && this._handlers[ eventName ].slice(); - if ( !handlers ) return; - - for ( var i = 0; i < handlers.length; i += 1 ) { - handlers[i].call( this, data ); - } -} - -function observe( key, callback, options ) { - var group = ( options && options.defer ) ? this._observers.pre : this._observers.post; - - ( group[ key ] || ( group[ key ] = [] ) ).push( callback ); - - if ( !options || options.init !== false ) { - callback.__calling = true; - callback.call( this, this._state[ key ] ); - callback.__calling = false; - } - - return { - cancel: function () { - var index = group[ key ].indexOf( callback ); - if ( ~index ) group[ key ].splice( index, 1 ); - } - }; -} - -function on( eventName, handler ) { - if ( eventName === 'teardown' ) return this.on( 'destroy', handler ); - - var handlers = this._handlers[ eventName ] || ( this._handlers[ eventName ] = [] ); - handlers.push( handler ); - - return { - cancel: function () { - var index = handlers.indexOf( handler ); - if ( ~index ) handlers.splice( index, 1 ); - } - }; -} - -function set( newState ) { - this._set( newState ); - ( this._root || this )._flush(); -} - -function _flush() { - if ( !this._renderHooks ) return; - - while ( this._renderHooks.length ) { - var hook = this._renderHooks.pop(); - hook.fn.call( hook.context ); - } -} - -export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/input.html b/test/js/samples/event-handlers-custom/input.html deleted file mode 100644 index 77c530fcf632..000000000000 --- a/test/js/samples/event-handlers-custom/input.html +++ /dev/null @@ -1,17 +0,0 @@ - - - \ No newline at end of file From 77eee8602d623d2db0a28878266e7c17410f011e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Apr 2017 17:55:44 -0400 Subject: [PATCH 03/31] remove some long-since obsolete generator code --- src/generators/Generator.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/generators/Generator.js b/src/generators/Generator.js index 65b391d20b8c..0f73292b91cb 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -154,15 +154,6 @@ export default class Generator { }; } - fire ( eventName, data ) { - const handlers = this._callbacks.has( eventName ) && this._callbacks.get( eventName ).slice(); - if ( !handlers ) return; - - for ( let i = 0; i < handlers.length; i += 1 ) { - handlers[i].call( this, data ); - } - } - generate ( result, options, { name, format } ) { if ( this.imports.length ) { const statements = []; @@ -431,14 +422,6 @@ export default class Generator { }; } - on ( eventName, handler ) { - if ( this._callbacks.has( eventName ) ) { - this._callbacks.get( eventName ).push( handler ); - } else { - this._callbacks.set( eventName, [ handler ] ); - } - } - pop () { const tail = this.current; this.current = tail.parent; From 00f1eaee12162142c1fcc05d03df892ac2d69887 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Apr 2017 18:15:07 -0400 Subject: [PATCH 04/31] remove this._callbacks --- src/generators/Generator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/generators/Generator.js b/src/generators/Generator.js index 0f73292b91cb..ddd2dec79746 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -43,8 +43,6 @@ export default class Generator { this.importedNames = new Set(); this._aliases = new Map(); this._usedNames = new Set(); - - this._callbacks = new Map(); } addSourcemapLocations ( node ) { From 2d4f9eac00fce55b56b1de50d231f79e904b9fa4 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 4 Apr 2017 22:55:30 -0400 Subject: [PATCH 05/31] make visitors responsible for visiting their own children --- src/generators/Generator.js | 26 +------------------ src/generators/dom/index.js | 14 +++++----- src/generators/dom/visit.js | 8 ++++++ src/generators/dom/visitors/Component.js | 11 ++++++-- src/generators/dom/visitors/EachBlock.js | 7 +++-- src/generators/dom/visitors/Element.js | 17 ++++++------ src/generators/server-side-rendering/index.js | 12 +++++---- src/generators/server-side-rendering/visit.js | 8 ++++++ .../visitors/Component.js | 11 ++++++-- .../visitors/EachBlock.js | 8 ++++-- .../server-side-rendering/visitors/Element.js | 11 ++++++-- .../server-side-rendering/visitors/IfBlock.js | 16 +++++++++--- 12 files changed, 92 insertions(+), 57 deletions(-) create mode 100644 src/generators/dom/visit.js create mode 100644 src/generators/server-side-rendering/visit.js diff --git a/src/generators/Generator.js b/src/generators/Generator.js index ddd2dec79746..d1956ed73460 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -12,11 +12,10 @@ import processCss from './shared/processCss.js'; import annotateWithScopes from './annotateWithScopes.js'; export default class Generator { - constructor ( parsed, source, name, visitors, options ) { + constructor ( parsed, source, name, options ) { this.parsed = parsed; this.source = source; this.name = name; - this.visitors = visitors; this.options = options; this.imports = []; @@ -434,27 +433,4 @@ export default class Generator { this.current = newFragment; } - - visit ( node ) { - const visitor = this.visitors[ node.type ]; - if ( !visitor ) throw new Error( `Not implemented: ${node.type}` ); - - if ( visitor.enter ) visitor.enter( this, node ); - - if ( visitor.type === 'Element' ) { - this.elementDepth += 1; - } - - if ( node.children ) { - node.children.forEach( child => { - this.visit( child ); - }); - } - - if ( visitor.type === 'Element' ) { - this.elementDepth -= 1; - } - - if ( visitor.leave ) visitor.leave( this, node ); - } } diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 4f829776fdf7..3e86ead4352c 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -1,13 +1,13 @@ import deindent from '../../utils/deindent.js'; import getBuilders from './utils/getBuilders.js'; import CodeBuilder from '../../utils/CodeBuilder.js'; -import visitors from './visitors/index.js'; +import visit from './visit.js'; import Generator from '../Generator.js'; import * as shared from '../../shared/index.js'; class DomGenerator extends Generator { - constructor ( parsed, source, name, visitors, options ) { - super( parsed, source, name, visitors, options ); + constructor ( parsed, source, name, options ) { + super( parsed, source, name, options ); this.renderers = []; this.uses = new Set(); @@ -126,7 +126,7 @@ class DomGenerator extends Generator { }); // walk the children here - node.children.forEach( node => this.visit( node ) ); + node.children.forEach( node => visit( node, this ) ); this.addRenderer( this.current ); this.pop(); @@ -149,7 +149,7 @@ export default function dom ( parsed, source, options ) { const format = options.format || 'es'; const name = options.name || 'SvelteComponent'; - const generator = new DomGenerator( parsed, source, name, visitors, options ); + const generator = new DomGenerator( parsed, source, name, options ); const { computations, hasJs, templateProperties, namespace } = generator.parseJs(); @@ -177,7 +177,9 @@ export default function dom ( parsed, source, options ) { getUniqueName, }); - parsed.html.children.forEach( node => generator.visit( node ) ); + parsed.html.children.forEach( node => { + visit( node, generator ); + }); generator.addRenderer( generator.pop() ); diff --git a/src/generators/dom/visit.js b/src/generators/dom/visit.js new file mode 100644 index 000000000000..5f688e76acc1 --- /dev/null +++ b/src/generators/dom/visit.js @@ -0,0 +1,8 @@ +import visitors from './visitors/index.js'; + +export default function visit ( node, generator ) { + const visitor = visitors[ node.type ]; + + if ( visitor.enter ) visitor.enter( generator, node ); + if ( visitor.leave ) visitor.leave( generator, node ); +} \ No newline at end of file diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index 69e2e3c2acf0..ed9cae89218d 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -1,5 +1,6 @@ import deindent from '../../../utils/deindent.js'; import CodeBuilder from '../../../utils/CodeBuilder.js'; +import visit from '../visit.js'; import addComponentAttributes from './attributes/addComponentAttributes.js'; function capDown ( name ) { @@ -166,9 +167,15 @@ export default { localElementDepth: current.localElementDepth + 1, key: null }); - }, - leave ( generator ) { + this.elementDepth += 1; + + node.children.forEach( child => { + visit( child, generator ); + }); + + this.elementDepth -= 1; + generator.pop(); } }; diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index df9936197fc4..716c5c1e34cf 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -1,6 +1,7 @@ import CodeBuilder from '../../../utils/CodeBuilder.js'; import deindent from '../../../utils/deindent.js'; import getBuilders from '../utils/getBuilders.js'; +import visit from '../visit.js'; export default { enter ( generator, node ) { @@ -214,9 +215,11 @@ export default { builders: getBuilders(), getUniqueName, }); - }, - leave ( generator ) { + node.children.forEach( child => { + visit( child, generator ); + }); + generator.addRenderer( generator.current ); generator.pop(); } diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element.js index 566a535bab7b..a056c2957f39 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element.js @@ -1,5 +1,6 @@ import CodeBuilder from '../../../utils/CodeBuilder.js'; import deindent from '../../../utils/deindent.js'; +import visit from '../visit.js'; import addElementAttributes from './attributes/addElementAttributes.js'; import Component from './Component.js'; import Window from './meta/Window.js'; @@ -108,20 +109,20 @@ export default { localElementDepth: generator.current.localElementDepth + 1, key: null }); - }, - leave ( generator, node ) { + this.elementDepth += 1; + + node.children.forEach( child => { + visit( child, generator ); + }); + + this.elementDepth -= 1; + if ( node.name in meta ) { if ( meta[ node.name ].leave ) meta[ node.name ].leave( generator, node ); return; } - const isComponent = generator.components.has( node.name ); - - if ( isComponent ) { - return Component.leave( generator, node ); - } - if ( node.initialUpdate ) { generator.current.builders.init.addBlock( node.initialUpdate ); } diff --git a/src/generators/server-side-rendering/index.js b/src/generators/server-side-rendering/index.js index c28b4aeef9cb..3189fdd583b9 100644 --- a/src/generators/server-side-rendering/index.js +++ b/src/generators/server-side-rendering/index.js @@ -1,12 +1,12 @@ import deindent from '../../utils/deindent.js'; import CodeBuilder from '../../utils/CodeBuilder.js'; import flattenReference from '../../utils/flattenReference.js'; -import visitors from './visitors/index.js'; import Generator from '../Generator.js'; +import visit from './visit.js'; class SsrGenerator extends Generator { - constructor ( parsed, source, name, visitors, options ) { - super( parsed, source, name, visitors, options ); + constructor ( parsed, source, name, options ) { + super( parsed, source, name, options ); this.bindings = []; this.renderCode = ''; } @@ -38,7 +38,7 @@ export default function ssr ( parsed, source, options ) { const format = options.format || 'cjs'; const name = options.name || 'SvelteComponent'; - const generator = new SsrGenerator( parsed, source, name, visitors, options ); + const generator = new SsrGenerator( parsed, source, name, options ); const { computations, hasJs, templateProperties } = generator.parseJs( true ); @@ -56,7 +56,9 @@ export default function ssr ( parsed, source, options ) { conditions: [] }); - parsed.html.children.forEach( node => generator.visit( node ) ); + parsed.html.children.forEach( node => { + visit( node, generator ); + }); builders.render.addLine( templateProperties.data ? `root = Object.assign( ${generator.alias( 'template' )}.data(), root || {} );` : `root = root || {};` diff --git a/src/generators/server-side-rendering/visit.js b/src/generators/server-side-rendering/visit.js new file mode 100644 index 000000000000..5f688e76acc1 --- /dev/null +++ b/src/generators/server-side-rendering/visit.js @@ -0,0 +1,8 @@ +import visitors from './visitors/index.js'; + +export default function visit ( node, generator ) { + const visitor = visitors[ node.type ]; + + if ( visitor.enter ) visitor.enter( generator, node ); + if ( visitor.leave ) visitor.leave( generator, node ); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/Component.js b/src/generators/server-side-rendering/visitors/Component.js index aef098a02455..688f70f6146b 100644 --- a/src/generators/server-side-rendering/visitors/Component.js +++ b/src/generators/server-side-rendering/visitors/Component.js @@ -1,4 +1,5 @@ import flattenReference from '../../../utils/flattenReference.js'; +import visit from '../visit.js'; export default { enter ( generator, node ) { @@ -63,9 +64,15 @@ export default { } generator.append( open ); - }, - leave ( generator, node ) { + this.elementDepth += 1; + + node.children.forEach( child => { + visit( child, generator ); + }); + + this.elementDepth -= 1; + const close = node.children.length ? `\` })}` : ')}'; generator.append( close ); } diff --git a/src/generators/server-side-rendering/visitors/EachBlock.js b/src/generators/server-side-rendering/visitors/EachBlock.js index 0fbe3ee9958f..da97500a4357 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.js +++ b/src/generators/server-side-rendering/visitors/EachBlock.js @@ -1,3 +1,5 @@ +import visit from '../visit.js'; + export default { enter ( generator, node ) { const { dependencies, snippet } = generator.contextualise( node.expression ); @@ -21,9 +23,11 @@ export default { indexes, contextDependencies }); - }, - leave ( generator ) { + node.children.forEach( child => { + visit( child, generator ); + }); + const close = `\` ).join( '' )}`; generator.append( close ); diff --git a/src/generators/server-side-rendering/visitors/Element.js b/src/generators/server-side-rendering/visitors/Element.js index d50f795b6c10..f452a37e075e 100644 --- a/src/generators/server-side-rendering/visitors/Element.js +++ b/src/generators/server-side-rendering/visitors/Element.js @@ -1,5 +1,6 @@ import Component from './Component.js'; import isVoidElementName from '../../../utils/isVoidElementName.js'; +import visit from '../visit.js'; import Window from './meta/Window.js'; const meta = { @@ -45,9 +46,15 @@ export default { openingTag += '>'; generator.append( openingTag ); - }, - leave ( generator, node ) { + this.elementDepth += 1; + + node.children.forEach( child => { + visit( child, generator ); + }); + + this.elementDepth -= 1; + if ( node.name in meta ) { if ( meta[ node.name ].leave ) meta[ node.name ].leave( generator, node ); return; diff --git a/src/generators/server-side-rendering/visitors/IfBlock.js b/src/generators/server-side-rendering/visitors/IfBlock.js index dd21ff8b4f10..1d093db3588b 100644 --- a/src/generators/server-side-rendering/visitors/IfBlock.js +++ b/src/generators/server-side-rendering/visitors/IfBlock.js @@ -1,3 +1,5 @@ +import visit from '../visit.js'; + export default { enter ( generator, node ) { const { snippet } = generator.contextualise( node.expression ); @@ -7,11 +9,19 @@ export default { generator.push({ conditions: generator.current.conditions.concat( snippet ) }); - }, - leave ( generator, node ) { + node.children.forEach( child => { + visit( child, generator ); + }); + generator.append( '` : `' ); - if ( node.else ) node.else.children.forEach( child => generator.visit( child ) ); + + if ( node.else ) { + node.else.children.forEach( child => { + visit( child, generator ); + }); + } + generator.append( '` }' ); generator.pop(); From e7d324f305024625abb5bd5ab714beee91e01706 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 4 Apr 2017 23:10:52 -0400 Subject: [PATCH 06/31] visitors can just be functions now --- src/generators/dom/visitors/Component.js | 4 +- src/generators/dom/visitors/Element.js | 4 +- src/generators/server-side-rendering/visit.js | 4 +- .../server-side-rendering/visitors/Comment.js | 4 +- .../visitors/Component.js | 116 +++++++++--------- .../visitors/EachBlock.js | 50 ++++---- .../server-side-rendering/visitors/Element.js | 88 ++++++------- .../server-side-rendering/visitors/IfBlock.js | 38 +++--- .../visitors/MustacheTag.js | 10 +- .../visitors/RawMustacheTag.js | 10 +- .../server-side-rendering/visitors/Text.js | 8 +- .../visitors/YieldTag.js | 8 +- .../visitors/meta/Window.js | 12 +- 13 files changed, 161 insertions(+), 195 deletions(-) diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index ed9cae89218d..d9a8e0daa54b 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -168,13 +168,13 @@ export default { key: null }); - this.elementDepth += 1; + generator.elementDepth += 1; node.children.forEach( child => { visit( child, generator ); }); - this.elementDepth -= 1; + generator.elementDepth -= 1; generator.pop(); } diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element.js index a056c2957f39..a224f0ffce35 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element.js @@ -110,13 +110,13 @@ export default { key: null }); - this.elementDepth += 1; + generator.elementDepth += 1; node.children.forEach( child => { visit( child, generator ); }); - this.elementDepth -= 1; + generator.elementDepth -= 1; if ( node.name in meta ) { if ( meta[ node.name ].leave ) meta[ node.name ].leave( generator, node ); diff --git a/src/generators/server-side-rendering/visit.js b/src/generators/server-side-rendering/visit.js index 5f688e76acc1..e9837098c4cd 100644 --- a/src/generators/server-side-rendering/visit.js +++ b/src/generators/server-side-rendering/visit.js @@ -2,7 +2,5 @@ import visitors from './visitors/index.js'; export default function visit ( node, generator ) { const visitor = visitors[ node.type ]; - - if ( visitor.enter ) visitor.enter( generator, node ); - if ( visitor.leave ) visitor.leave( generator, node ); + visitor( generator, node ); } \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/Comment.js b/src/generators/server-side-rendering/visitors/Comment.js index f32a1e64a8bd..4d3477d7ef0d 100644 --- a/src/generators/server-side-rendering/visitors/Comment.js +++ b/src/generators/server-side-rendering/visitors/Comment.js @@ -1,3 +1,3 @@ -export default { +export default function visitComment () { // do nothing -}; +} diff --git a/src/generators/server-side-rendering/visitors/Component.js b/src/generators/server-side-rendering/visitors/Component.js index 688f70f6146b..4b1793f047f6 100644 --- a/src/generators/server-side-rendering/visitors/Component.js +++ b/src/generators/server-side-rendering/visitors/Component.js @@ -1,79 +1,77 @@ import flattenReference from '../../../utils/flattenReference.js'; import visit from '../visit.js'; -export default { - enter ( generator, node ) { - function stringify ( chunk ) { - if ( chunk.type === 'Text' ) return chunk.data; - if ( chunk.type === 'MustacheTag' ) { - const { snippet } = generator.contextualise( chunk.expression ); - return '${__escape( ' + snippet + ')}'; - } +export default function visitComponent ( generator, node ) { + function stringify ( chunk ) { + if ( chunk.type === 'Text' ) return chunk.data; + if ( chunk.type === 'MustacheTag' ) { + const { snippet } = generator.contextualise( chunk.expression ); + return '${__escape( ' + snippet + ')}'; } + } - const attributes = []; - const bindings = []; + const attributes = []; + const bindings = []; - node.attributes.forEach( attribute => { - if ( attribute.type === 'Attribute' ) { - attributes.push( attribute ); - } else if ( attribute.type === 'Binding' ) { - bindings.push( attribute ); - } - }); + node.attributes.forEach( attribute => { + if ( attribute.type === 'Attribute' ) { + attributes.push( attribute ); + } else if ( attribute.type === 'Binding' ) { + bindings.push( attribute ); + } + }); - const props = attributes - .map( attribute => { - let value; + const props = attributes + .map( attribute => { + let value; - if ( attribute.value === true ) { - value = `true`; - } else if ( attribute.value.length === 0 ) { - value = `''`; - } else if ( attribute.value.length === 1 ) { - const chunk = attribute.value[0]; - if ( chunk.type === 'Text' ) { - value = isNaN( chunk.data ) ? JSON.stringify( chunk.data ) : chunk.data; - } else { - const { snippet } = generator.contextualise( chunk.expression ); - value = snippet; - } + if ( attribute.value === true ) { + value = `true`; + } else if ( attribute.value.length === 0 ) { + value = `''`; + } else if ( attribute.value.length === 1 ) { + const chunk = attribute.value[0]; + if ( chunk.type === 'Text' ) { + value = isNaN( chunk.data ) ? JSON.stringify( chunk.data ) : chunk.data; } else { - value = '`' + attribute.value.map( stringify ).join( '' ) + '`'; + const { snippet } = generator.contextualise( chunk.expression ); + value = snippet; } + } else { + value = '`' + attribute.value.map( stringify ).join( '' ) + '`'; + } - return `${attribute.name}: ${value}`; - }) - .concat( bindings.map( binding => { - const { name, keypath } = flattenReference( binding.value ); - const value = generator.current.contexts.has( name ) ? keypath : `root.${keypath}`; - return `${binding.name}: ${value}`; - })) - .join( ', ' ); + return `${attribute.name}: ${value}`; + }) + .concat( bindings.map( binding => { + const { name, keypath } = flattenReference( binding.value ); + const value = generator.current.contexts.has( name ) ? keypath : `root.${keypath}`; + return `${binding.name}: ${value}`; + })) + .join( ', ' ); - const expression = node.name === ':Self' ? generator.name : generator.importedComponents.get( node.name ) || `${generator.alias( 'template' )}.components.${node.name}`; + const expression = node.name === ':Self' ? generator.name : generator.importedComponents.get( node.name ) || `${generator.alias( 'template' )}.components.${node.name}`; - bindings.forEach( binding => { - generator.addBinding( binding, expression ); - }); + bindings.forEach( binding => { + generator.addBinding( binding, expression ); + }); - let open = `\${${expression}.render({${props}}`; + let open = `\${${expression}.render({${props}}`; - if ( node.children.length ) { - open += `, { yield: () => \``; - } + if ( node.children.length ) { + open += `, { yield: () => \``; + } - generator.append( open ); + generator.append( open ); - this.elementDepth += 1; + generator.elementDepth += 1; - node.children.forEach( child => { - visit( child, generator ); - }); + node.children.forEach( child => { + visit( child, generator ); + }); - this.elementDepth -= 1; + generator.elementDepth -= 1; - const close = node.children.length ? `\` })}` : ')}'; - generator.append( close ); - } -}; + const close = node.children.length ? `\` })}` : ')}'; + generator.append( close ); +} diff --git a/src/generators/server-side-rendering/visitors/EachBlock.js b/src/generators/server-side-rendering/visitors/EachBlock.js index da97500a4357..93cca86df9c2 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.js +++ b/src/generators/server-side-rendering/visitors/EachBlock.js @@ -1,36 +1,34 @@ import visit from '../visit.js'; -export default { - enter ( generator, node ) { - const { dependencies, snippet } = generator.contextualise( node.expression ); +export default function visitEachBlock ( generator, node ) { + const { dependencies, snippet } = generator.contextualise( node.expression ); - const open = `\${ ${snippet}.map( ${ node.index ? `( ${node.context}, ${node.index} )` : node.context} => \``; - generator.append( open ); + const open = `\${ ${snippet}.map( ${ node.index ? `( ${node.context}, ${node.index} )` : node.context} => \``; + generator.append( open ); - // TODO should this be the generator's job? It's duplicated between - // here and the equivalent DOM compiler visitor - const contexts = new Map( generator.current.contexts ); - contexts.set( node.context, node.context ); + // TODO should this be the generator's job? It's duplicated between + // here and the equivalent DOM compiler visitor + const contexts = new Map( generator.current.contexts ); + contexts.set( node.context, node.context ); - const indexes = new Map( generator.current.indexes ); - if ( node.index ) indexes.set( node.index, node.context ); + const indexes = new Map( generator.current.indexes ); + if ( node.index ) indexes.set( node.index, node.context ); - const contextDependencies = new Map( generator.current.contextDependencies ); - contextDependencies.set( node.context, dependencies ); + const contextDependencies = new Map( generator.current.contextDependencies ); + contextDependencies.set( node.context, dependencies ); - generator.push({ - contexts, - indexes, - contextDependencies - }); + generator.push({ + contexts, + indexes, + contextDependencies + }); - node.children.forEach( child => { - visit( child, generator ); - }); + node.children.forEach( child => { + visit( child, generator ); + }); - const close = `\` ).join( '' )}`; - generator.append( close ); + const close = `\` ).join( '' )}`; + generator.append( close ); - generator.pop(); - } -}; + generator.pop(); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/Element.js b/src/generators/server-side-rendering/visitors/Element.js index f452a37e075e..97bc489ec987 100644 --- a/src/generators/server-side-rendering/visitors/Element.js +++ b/src/generators/server-side-rendering/visitors/Element.js @@ -1,72 +1,60 @@ -import Component from './Component.js'; +import visitComponent from './Component.js'; import isVoidElementName from '../../../utils/isVoidElementName.js'; import visit from '../visit.js'; -import Window from './meta/Window.js'; +import visitWindow from './meta/Window.js'; const meta = { - ':Window': Window + ':Window': visitWindow }; -export default { - enter ( generator, node ) { - if ( node.name in meta ) { - return meta[ node.name ].enter( generator, node ); - } - - if ( generator.components.has( node.name ) || node.name === ':Self' ) { - Component.enter( generator, node ); - return; - } - - let openingTag = `<${node.name}`; +export default function visitElement ( generator, node ) { + if ( node.name in meta ) { + return meta[ node.name ]( generator, node ); + } - node.attributes.forEach( attribute => { - if ( attribute.type !== 'Attribute' ) return; + if ( generator.components.has( node.name ) || node.name === ':Self' ) { + visitComponent( generator, node ); + return; + } - let str = ` ${attribute.name}`; + let openingTag = `<${node.name}`; - if ( attribute.value !== true ) { - str += `="` + attribute.value.map( chunk => { - if ( chunk.type === 'Text' ) { - return chunk.data; - } + node.attributes.forEach( attribute => { + if ( attribute.type !== 'Attribute' ) return; - const { snippet } = generator.contextualise( chunk.expression ); - return '${' + snippet + '}'; - }).join( '' ) + `"`; - } + let str = ` ${attribute.name}`; - openingTag += str; - }); + if ( attribute.value !== true ) { + str += `="` + attribute.value.map( chunk => { + if ( chunk.type === 'Text' ) { + return chunk.data; + } - if ( generator.cssId && !generator.elementDepth ) { - openingTag += ` ${generator.cssId}`; + const { snippet } = generator.contextualise( chunk.expression ); + return '${' + snippet + '}'; + }).join( '' ) + `"`; } - openingTag += '>'; + openingTag += str; + }); - generator.append( openingTag ); + if ( generator.cssId && !generator.elementDepth ) { + openingTag += ` ${generator.cssId}`; + } - this.elementDepth += 1; + openingTag += '>'; - node.children.forEach( child => { - visit( child, generator ); - }); + generator.append( openingTag ); - this.elementDepth -= 1; + generator.elementDepth += 1; - if ( node.name in meta ) { - if ( meta[ node.name ].leave ) meta[ node.name ].leave( generator, node ); - return; - } + node.children.forEach( child => { + visit( child, generator ); + }); - if ( generator.components.has( node.name ) || node.name === ':Self' ) { - Component.leave( generator, node ); - return; - } + generator.elementDepth -= 1; - if ( !isVoidElementName( node.name ) ) { - generator.append( `` ); - } + if ( !isVoidElementName( node.name ) ) { + generator.append( `` ); } -}; +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/IfBlock.js b/src/generators/server-side-rendering/visitors/IfBlock.js index 1d093db3588b..f024f04ec3f0 100644 --- a/src/generators/server-side-rendering/visitors/IfBlock.js +++ b/src/generators/server-side-rendering/visitors/IfBlock.js @@ -1,29 +1,27 @@ import visit from '../visit.js'; -export default { - enter ( generator, node ) { - const { snippet } = generator.contextualise( node.expression ); +export default function visitIfBlock ( generator, node ) { + const { snippet } = generator.contextualise( node.expression ); - generator.append( '${ ' + snippet + ' ? `' ); + generator.append( '${ ' + snippet + ' ? `' ); - generator.push({ - conditions: generator.current.conditions.concat( snippet ) - }); + generator.push({ + conditions: generator.current.conditions.concat( snippet ) + }); - node.children.forEach( child => { - visit( child, generator ); - }); + node.children.forEach( child => { + visit( child, generator ); + }); - generator.append( '` : `' ); + generator.append( '` : `' ); - if ( node.else ) { - node.else.children.forEach( child => { - visit( child, generator ); - }); - } + if ( node.else ) { + node.else.children.forEach( child => { + visit( child, generator ); + }); + } - generator.append( '` }' ); + generator.append( '` }' ); - generator.pop(); - } -}; + generator.pop(); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/MustacheTag.js b/src/generators/server-side-rendering/visitors/MustacheTag.js index 9052e2627fc3..99102a7ccb2e 100644 --- a/src/generators/server-side-rendering/visitors/MustacheTag.js +++ b/src/generators/server-side-rendering/visitors/MustacheTag.js @@ -1,6 +1,4 @@ -export default { - enter ( generator, node ) { - const { snippet } = generator.contextualise( node.expression ); - generator.append( '${__escape( ' + snippet + ' )}' ); - } -}; +export default function visitMustacheTag ( generator, node ) { + const { snippet } = generator.contextualise( node.expression ); + generator.append( '${__escape( ' + snippet + ' )}' ); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/RawMustacheTag.js b/src/generators/server-side-rendering/visitors/RawMustacheTag.js index c84de16e2acb..0c70f363e380 100644 --- a/src/generators/server-side-rendering/visitors/RawMustacheTag.js +++ b/src/generators/server-side-rendering/visitors/RawMustacheTag.js @@ -1,6 +1,4 @@ -export default { - enter ( generator, node ) { - const { snippet } = generator.contextualise( node.expression ); - generator.append( '${' + snippet + '}' ); - } -}; +export default function visitRawMustacheTag ( generator, node ) { + const { snippet } = generator.contextualise( node.expression ); + generator.append( '${' + snippet + '}' ); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/Text.js b/src/generators/server-side-rendering/visitors/Text.js index 16630a709d3d..d8510d839300 100644 --- a/src/generators/server-side-rendering/visitors/Text.js +++ b/src/generators/server-side-rendering/visitors/Text.js @@ -1,5 +1,3 @@ -export default { - enter ( generator, node ) { - generator.append( node.data.replace( /\${/g, '\\${' ) ); - } -}; +export default function visitText ( generator, node ) { + generator.append( node.data.replace( /\${/g, '\\${' ) ); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/YieldTag.js b/src/generators/server-side-rendering/visitors/YieldTag.js index a9b35f777edf..bde5ab1a00b2 100644 --- a/src/generators/server-side-rendering/visitors/YieldTag.js +++ b/src/generators/server-side-rendering/visitors/YieldTag.js @@ -1,5 +1,3 @@ -export default { - enter ( generator ) { - generator.append( `\${options && options.yield ? options.yield() : ''}` ); - } -}; +export default function visitYieldTag ( generator ) { + generator.append( `\${options && options.yield ? options.yield() : ''}` ); +} \ No newline at end of file diff --git a/src/generators/server-side-rendering/visitors/meta/Window.js b/src/generators/server-side-rendering/visitors/meta/Window.js index 7df7d8bdaf61..4b4bf67ccce2 100644 --- a/src/generators/server-side-rendering/visitors/meta/Window.js +++ b/src/generators/server-side-rendering/visitors/meta/Window.js @@ -1,9 +1,3 @@ -export default { - enter () { - // noop - }, - - leave () { - // noop - } -}; +export default function visitWindow () { + // noop +} \ No newline at end of file From b8705a5b0c0f54699b2cf596c2abb2e8207468cb Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 4 Apr 2017 23:17:02 -0400 Subject: [PATCH 07/31] turn dom generator visitors into functions --- src/generators/dom/visit.js | 4 +- src/generators/dom/visitors/Comment.js | 4 +- src/generators/dom/visitors/Component.js | 232 ++++++------ src/generators/dom/visitors/EachBlock.js | 334 +++++++++--------- src/generators/dom/visitors/Element.js | 179 +++++----- src/generators/dom/visitors/IfBlock.js | 80 ++--- src/generators/dom/visitors/MustacheTag.js | 28 +- src/generators/dom/visitors/RawMustacheTag.js | 60 ++-- src/generators/dom/visitors/Text.js | 16 +- src/generators/dom/visitors/YieldTag.js | 22 +- src/generators/dom/visitors/meta/Window.js | 120 ++++--- 11 files changed, 526 insertions(+), 553 deletions(-) diff --git a/src/generators/dom/visit.js b/src/generators/dom/visit.js index 5f688e76acc1..e9837098c4cd 100644 --- a/src/generators/dom/visit.js +++ b/src/generators/dom/visit.js @@ -2,7 +2,5 @@ import visitors from './visitors/index.js'; export default function visit ( node, generator ) { const visitor = visitors[ node.type ]; - - if ( visitor.enter ) visitor.enter( generator, node ); - if ( visitor.leave ) visitor.leave( generator, node ); + visitor( generator, node ); } \ No newline at end of file diff --git a/src/generators/dom/visitors/Comment.js b/src/generators/dom/visitors/Comment.js index f32a1e64a8bd..4d3477d7ef0d 100644 --- a/src/generators/dom/visitors/Comment.js +++ b/src/generators/dom/visitors/Comment.js @@ -1,3 +1,3 @@ -export default { +export default function visitComment () { // do nothing -}; +} diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index d9a8e0daa54b..1733886fda5f 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -19,163 +19,161 @@ function stringifyProps ( props ) { return `{ ${joined} }`; } -export default { - enter ( generator, node ) { - const hasChildren = node.children.length > 0; - const { current } = generator; - const name = current.getUniqueName( capDown( node.name === ':Self' ? generator.name : node.name ) ); +export default function visitComponent ( generator, node ) { + const hasChildren = node.children.length > 0; + const { current } = generator; + const name = current.getUniqueName( capDown( node.name === ':Self' ? generator.name : node.name ) ); - const local = { - name, - namespace: current.namespace, - isComponent: true, + const local = { + name, + namespace: current.namespace, + isComponent: true, - allUsedContexts: [], + allUsedContexts: [], - init: new CodeBuilder(), - update: new CodeBuilder() - }; + init: new CodeBuilder(), + update: new CodeBuilder() + }; - const isToplevel = current.localElementDepth === 0; + const isToplevel = current.localElementDepth === 0; - generator.hasComponents = true; + generator.hasComponents = true; - addComponentAttributes( generator, node, local ); + addComponentAttributes( generator, node, local ); - if ( local.allUsedContexts.length ) { - const initialProps = local.allUsedContexts.map( contextName => { - if ( contextName === 'root' ) return `root: root`; + if ( local.allUsedContexts.length ) { + const initialProps = local.allUsedContexts.map( contextName => { + if ( contextName === 'root' ) return `root: root`; - const listName = current.listNames.get( contextName ); - const indexName = current.indexNames.get( contextName ); + const listName = current.listNames.get( contextName ); + const indexName = current.indexNames.get( contextName ); - return `${listName}: ${listName},\n${indexName}: ${indexName}`; - }).join( ',\n' ); + return `${listName}: ${listName},\n${indexName}: ${indexName}`; + }).join( ',\n' ); - const updates = local.allUsedContexts.map( contextName => { - if ( contextName === 'root' ) return `${name}._context.root = root;`; + const updates = local.allUsedContexts.map( contextName => { + if ( contextName === 'root' ) return `${name}._context.root = root;`; - const listName = current.listNames.get( contextName ); - const indexName = current.indexNames.get( contextName ); + const listName = current.listNames.get( contextName ); + const indexName = current.indexNames.get( contextName ); - return `${name}._context.${listName} = ${listName};\n${name}._context.${indexName} = ${indexName};`; - }).join( '\n' ); + return `${name}._context.${listName} = ${listName};\n${name}._context.${indexName} = ${indexName};`; + }).join( '\n' ); - local.init.addBlock( deindent` - ${name}._context = { - ${initialProps} - }; - ` ); + local.init.addBlock( deindent` + ${name}._context = { + ${initialProps} + }; + ` ); - local.update.addBlock( updates ); - } + local.update.addBlock( updates ); + } - const componentInitProperties = [ - `target: ${!isToplevel ? current.target: 'null'}`, - `_root: ${current.component}._root || ${current.component}` - ]; + const componentInitProperties = [ + `target: ${!isToplevel ? current.target: 'null'}`, + `_root: ${current.component}._root || ${current.component}` + ]; - // Component has children, put them in a separate {{yield}} block - if ( hasChildren ) { - const yieldName = generator.getUniqueName( `render_${name}_yield_fragment` ); - const params = current.params.join( ', ' ); + // Component has children, put them in a separate {{yield}} block + if ( hasChildren ) { + const yieldName = generator.getUniqueName( `render_${name}_yield_fragment` ); + const params = current.params.join( ', ' ); - generator.generateBlock( node, yieldName, 'block' ); + generator.generateBlock( node, yieldName, 'block' ); - const yieldFragment = current.getUniqueName( `${name}_yield_fragment` ); + const yieldFragment = current.getUniqueName( `${name}_yield_fragment` ); - current.builders.init.addLine( - `var ${yieldFragment} = ${yieldName}( ${params}, ${current.component} );` - ); + current.builders.init.addLine( + `var ${yieldFragment} = ${yieldName}( ${params}, ${current.component} );` + ); - current.builders.update.addLine( - `${yieldFragment}.update( changed, ${params} );` - ); + current.builders.update.addLine( + `${yieldFragment}.update( changed, ${params} );` + ); - componentInitProperties.push( `_yield: ${yieldFragment}`); - } + componentInitProperties.push( `_yield: ${yieldFragment}`); + } - const statements = []; + const statements = []; - if ( local.staticAttributes.length || local.dynamicAttributes.length || local.bindings.length ) { - const initialProps = local.staticAttributes - .concat( local.dynamicAttributes ) - .map( attribute => `${attribute.name}: ${attribute.value}` ); + if ( local.staticAttributes.length || local.dynamicAttributes.length || local.bindings.length ) { + const initialProps = local.staticAttributes + .concat( local.dynamicAttributes ) + .map( attribute => `${attribute.name}: ${attribute.value}` ); - const initialPropString = stringifyProps( initialProps ); + const initialPropString = stringifyProps( initialProps ); - if ( local.bindings.length ) { - const initialData = current.getUniqueName( `${name}_initial_data` ); + if ( local.bindings.length ) { + const initialData = current.getUniqueName( `${name}_initial_data` ); - statements.push( `var ${name}_initial_data = ${initialPropString};` ); + statements.push( `var ${name}_initial_data = ${initialPropString};` ); - local.bindings.forEach( binding => { - statements.push( `if ( ${binding.prop} in ${binding.obj} ) ${initialData}.${binding.name} = ${binding.value};` ); - }); + local.bindings.forEach( binding => { + statements.push( `if ( ${binding.prop} in ${binding.obj} ) ${initialData}.${binding.name} = ${binding.value};` ); + }); - componentInitProperties.push( `data: ${initialData}` ); - } else if ( initialProps.length ) { - componentInitProperties.push( `data: ${initialPropString}` ); - } + componentInitProperties.push( `data: ${initialData}` ); + } else if ( initialProps.length ) { + componentInitProperties.push( `data: ${initialPropString}` ); } + } - const expression = node.name === ':Self' ? generator.name : generator.importedComponents.get( node.name ) || `${generator.alias( 'template' )}.components.${node.name}`; + const expression = node.name === ':Self' ? generator.name : generator.importedComponents.get( node.name ) || `${generator.alias( 'template' )}.components.${node.name}`; - local.init.addBlockAtStart( deindent` - ${statements.join( '\n' )} - var ${name} = new ${expression}({ - ${componentInitProperties.join(',\n')} - }); - ` ); + local.init.addBlockAtStart( deindent` + ${statements.join( '\n' )} + var ${name} = new ${expression}({ + ${componentInitProperties.join(',\n')} + }); + ` ); - if ( isToplevel ) { - current.builders.mount.addLine( `${name}._fragment.mount( target, anchor );` ); - } + if ( isToplevel ) { + current.builders.mount.addLine( `${name}._fragment.mount( target, anchor );` ); + } - if ( local.dynamicAttributes.length ) { - const updates = local.dynamicAttributes.map( attribute => { - if ( attribute.dependencies.length ) { - return deindent` - if ( ${attribute.dependencies.map( dependency => `'${dependency}' in changed` ).join( '||' )} ) ${name}_changes.${attribute.name} = ${attribute.value}; - `; - } - - // TODO this is an odd situation to encounter – I *think* it should only happen with - // each block indices, in which case it may be possible to optimise this - return `${name}_changes.${attribute.name} = ${attribute.value};`; - }); + if ( local.dynamicAttributes.length ) { + const updates = local.dynamicAttributes.map( attribute => { + if ( attribute.dependencies.length ) { + return deindent` + if ( ${attribute.dependencies.map( dependency => `'${dependency}' in changed` ).join( '||' )} ) ${name}_changes.${attribute.name} = ${attribute.value}; + `; + } - local.update.addBlock( deindent` - var ${name}_changes = {}; + // TODO this is an odd situation to encounter – I *think* it should only happen with + // each block indices, in which case it may be possible to optimise this + return `${name}_changes.${attribute.name} = ${attribute.value};`; + }); - ${updates.join( '\n' )} + local.update.addBlock( deindent` + var ${name}_changes = {}; - if ( Object.keys( ${name}_changes ).length ) ${name}.set( ${name}_changes ); - ` ); - } + ${updates.join( '\n' )} - current.builders.teardown.addLine( `${name}.destroy( ${isToplevel ? 'detach' : 'false'} );` ); + if ( Object.keys( ${name}_changes ).length ) ${name}.set( ${name}_changes ); + ` ); + } - current.builders.init.addBlock( local.init ); - if ( !local.update.isEmpty() ) current.builders.update.addBlock( local.update ); + current.builders.teardown.addLine( `${name}.destroy( ${isToplevel ? 'detach' : 'false'} );` ); - generator.push({ - type: 'component', - namespace: local.namespace, - target: name, - parent: current, - localElementDepth: current.localElementDepth + 1, - key: null - }); + current.builders.init.addBlock( local.init ); + if ( !local.update.isEmpty() ) current.builders.update.addBlock( local.update ); - generator.elementDepth += 1; + generator.push({ + type: 'component', + namespace: local.namespace, + target: name, + parent: current, + localElementDepth: current.localElementDepth + 1, + key: null + }); - node.children.forEach( child => { - visit( child, generator ); - }); + generator.elementDepth += 1; - generator.elementDepth -= 1; + node.children.forEach( child => { + visit( child, generator ); + }); - generator.pop(); - } -}; + generator.elementDepth -= 1; + + generator.pop(); +} \ No newline at end of file diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index 716c5c1e34cf..d60c69ec8b92 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -3,224 +3,222 @@ import deindent from '../../../utils/deindent.js'; import getBuilders from '../utils/getBuilders.js'; import visit from '../visit.js'; -export default { - enter ( generator, node ) { - const name = generator.getUniqueName( `each_block` ); - const renderer = generator.getUniqueName( `render_each_block` ); - const elseName = generator.getUniqueName( `${name}_else` ); - const renderElse = generator.getUniqueName( `${renderer}_else` ); - const i = generator.current.getUniqueName( `i` ); - const params = generator.current.params.join( ', ' ); +export default function visitEachBlock ( generator, node ) { + const name = generator.getUniqueName( `each_block` ); + const renderer = generator.getUniqueName( `render_each_block` ); + const elseName = generator.getUniqueName( `${name}_else` ); + const renderElse = generator.getUniqueName( `${renderer}_else` ); + const i = generator.current.getUniqueName( `i` ); + const params = generator.current.params.join( ', ' ); - const listName = generator.current.getUniqueName( `${name}_value` ); + const listName = generator.current.getUniqueName( `${name}_value` ); - const isToplevel = generator.current.localElementDepth === 0; + const isToplevel = generator.current.localElementDepth === 0; - generator.addSourcemapLocations( node.expression ); + generator.addSourcemapLocations( node.expression ); - const { dependencies, snippet } = generator.contextualise( node.expression ); + const { dependencies, snippet } = generator.contextualise( node.expression ); - const anchor = generator.current.getUniqueName( `${name}_anchor` ); - generator.createAnchor( anchor ); + const anchor = generator.current.getUniqueName( `${name}_anchor` ); + generator.createAnchor( anchor ); - const localVars = {}; + const localVars = {}; - localVars.iteration = generator.current.getUniqueName( `${name}_iteration` ); - localVars.iterations = generator.current.getUniqueName( `${name}_iterations` ); - localVars._iterations = generator.current.getUniqueName( `_${name}_iterations` ); - localVars.lookup = generator.current.getUniqueName( `${name}_lookup` ); - localVars._lookup = generator.current.getUniqueName( `_${name}_lookup` ); + localVars.iteration = generator.current.getUniqueName( `${name}_iteration` ); + localVars.iterations = generator.current.getUniqueName( `${name}_iterations` ); + localVars._iterations = generator.current.getUniqueName( `_${name}_iterations` ); + localVars.lookup = generator.current.getUniqueName( `${name}_lookup` ); + localVars._lookup = generator.current.getUniqueName( `_${name}_lookup` ); - generator.current.builders.init.addLine( `var ${listName} = ${snippet};` ); - generator.current.builders.init.addLine( `var ${localVars.iterations} = [];` ); - if ( node.key ) generator.current.builders.init.addLine( `var ${localVars.lookup} = Object.create( null );` ); - if ( node.else ) generator.current.builders.init.addLine( `var ${elseName} = null;` ); + generator.current.builders.init.addLine( `var ${listName} = ${snippet};` ); + generator.current.builders.init.addLine( `var ${localVars.iterations} = [];` ); + if ( node.key ) generator.current.builders.init.addLine( `var ${localVars.lookup} = Object.create( null );` ); + if ( node.else ) generator.current.builders.init.addLine( `var ${elseName} = null;` ); - const initialRender = new CodeBuilder(); + const initialRender = new CodeBuilder(); - if ( node.key ) { - localVars.fragment = generator.current.getUniqueName( 'fragment' ); - localVars.value = generator.current.getUniqueName( 'value' ); - localVars.key = generator.current.getUniqueName( 'key' ); + if ( node.key ) { + localVars.fragment = generator.current.getUniqueName( 'fragment' ); + localVars.value = generator.current.getUniqueName( 'value' ); + localVars.key = generator.current.getUniqueName( 'key' ); - initialRender.addBlock( deindent` - var ${localVars.key} = ${listName}[${i}].${node.key}; - ${localVars.iterations}[${i}] = ${localVars.lookup}[ ${localVars.key} ] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component}${node.key ? `, ${localVars.key}` : `` } ); - ` ); - } else { - initialRender.addLine( - `${localVars.iterations}[${i}] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component} );` - ); - } + initialRender.addBlock( deindent` + var ${localVars.key} = ${listName}[${i}].${node.key}; + ${localVars.iterations}[${i}] = ${localVars.lookup}[ ${localVars.key} ] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component}${node.key ? `, ${localVars.key}` : `` } ); + ` ); + } else { + initialRender.addLine( + `${localVars.iterations}[${i}] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component} );` + ); + } - if ( !isToplevel ) { - initialRender.addLine( - `${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} );` - ); + if ( !isToplevel ) { + initialRender.addLine( + `${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} );` + ); + } + + generator.current.builders.init.addBlock( deindent` + for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { + ${initialRender} } + ` ); + if ( node.else ) { generator.current.builders.init.addBlock( deindent` - for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { - ${initialRender} + if ( !${listName}.length ) { + ${elseName} = ${renderElse}( ${params}, ${generator.current.component} ); + ${!isToplevel ? `${elseName}.mount( ${anchor}.parentNode, ${anchor} );` : ''} } ` ); + } + if ( isToplevel ) { + generator.current.builders.mount.addBlock( deindent` + for ( var ${i} = 0; ${i} < ${localVars.iterations}.length; ${i} += 1 ) { + ${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} ); + } + ` ); if ( node.else ) { - generator.current.builders.init.addBlock( deindent` - if ( !${listName}.length ) { - ${elseName} = ${renderElse}( ${params}, ${generator.current.component} ); - ${!isToplevel ? `${elseName}.mount( ${anchor}.parentNode, ${anchor} );` : ''} - } - ` ); - } - - if ( isToplevel ) { generator.current.builders.mount.addBlock( deindent` - for ( var ${i} = 0; ${i} < ${localVars.iterations}.length; ${i} += 1 ) { - ${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} ); + if ( ${elseName} ) { + ${elseName}.mount( ${anchor}.parentNode, ${anchor} ); } ` ); - if ( node.else ) { - generator.current.builders.mount.addBlock( deindent` - if ( ${elseName} ) { - ${elseName}.mount( ${anchor}.parentNode, ${anchor} ); - } - ` ); - } } + } - if ( node.key ) { - generator.current.builders.update.addBlock( deindent` - var ${listName} = ${snippet}; - var ${localVars._iterations} = []; - var ${localVars._lookup} = Object.create( null ); + if ( node.key ) { + generator.current.builders.update.addBlock( deindent` + var ${listName} = ${snippet}; + var ${localVars._iterations} = []; + var ${localVars._lookup} = Object.create( null ); - var ${localVars.fragment} = document.createDocumentFragment(); + var ${localVars.fragment} = document.createDocumentFragment(); - // create new iterations as necessary - for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { - var ${localVars.value} = ${listName}[${i}]; - var ${localVars.key} = ${localVars.value}.${node.key}; + // create new iterations as necessary + for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { + var ${localVars.value} = ${listName}[${i}]; + var ${localVars.key} = ${localVars.value}.${node.key}; + + if ( ${localVars.lookup}[ ${localVars.key} ] ) { + ${localVars._iterations}[${i}] = ${localVars._lookup}[ ${localVars.key} ] = ${localVars.lookup}[ ${localVars.key} ]; + ${localVars._lookup}[ ${localVars.key} ].update( changed, ${params}, ${listName}, ${listName}[${i}], ${i} ); + } else { + ${localVars._iterations}[${i}] = ${localVars._lookup}[ ${localVars.key} ] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component}${node.key ? `, ${localVars.key}` : `` } ); + } - if ( ${localVars.lookup}[ ${localVars.key} ] ) { - ${localVars._iterations}[${i}] = ${localVars._lookup}[ ${localVars.key} ] = ${localVars.lookup}[ ${localVars.key} ]; - ${localVars._lookup}[ ${localVars.key} ].update( changed, ${params}, ${listName}, ${listName}[${i}], ${i} ); - } else { - ${localVars._iterations}[${i}] = ${localVars._lookup}[ ${localVars.key} ] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component}${node.key ? `, ${localVars.key}` : `` } ); - } + ${localVars._iterations}[${i}].mount( ${localVars.fragment}, null ); + } - ${localVars._iterations}[${i}].mount( ${localVars.fragment}, null ); + // remove old iterations + for ( var ${i} = 0; ${i} < ${localVars.iterations}.length; ${i} += 1 ) { + var ${localVars.iteration} = ${localVars.iterations}[${i}]; + if ( !${localVars._lookup}[ ${localVars.iteration}.key ] ) { + ${localVars.iteration}.teardown( true ); } + } - // remove old iterations - for ( var ${i} = 0; ${i} < ${localVars.iterations}.length; ${i} += 1 ) { - var ${localVars.iteration} = ${localVars.iterations}[${i}]; - if ( !${localVars._lookup}[ ${localVars.iteration}.key ] ) { - ${localVars.iteration}.teardown( true ); - } - } + ${anchor}.parentNode.insertBefore( ${localVars.fragment}, ${anchor} ); - ${anchor}.parentNode.insertBefore( ${localVars.fragment}, ${anchor} ); + ${localVars.iterations} = ${localVars._iterations}; + ${localVars.lookup} = ${localVars._lookup}; + ` ); + } else { + generator.current.builders.update.addBlock( deindent` + var ${listName} = ${snippet}; - ${localVars.iterations} = ${localVars._iterations}; - ${localVars.lookup} = ${localVars._lookup}; - ` ); - } else { - generator.current.builders.update.addBlock( deindent` - var ${listName} = ${snippet}; - - for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { - if ( !${localVars.iterations}[${i}] ) { - ${localVars.iterations}[${i}] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component} ); - ${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} ); - } else { - ${localVars.iterations}[${i}].update( changed, ${params}, ${listName}, ${listName}[${i}], ${i} ); - } + for ( var ${i} = 0; ${i} < ${listName}.length; ${i} += 1 ) { + if ( !${localVars.iterations}[${i}] ) { + ${localVars.iterations}[${i}] = ${renderer}( ${params}, ${listName}, ${listName}[${i}], ${i}, ${generator.current.component} ); + ${localVars.iterations}[${i}].mount( ${anchor}.parentNode, ${anchor} ); + } else { + ${localVars.iterations}[${i}].update( changed, ${params}, ${listName}, ${listName}[${i}], ${i} ); } + } - teardownEach( ${localVars.iterations}, true, ${listName}.length ); + teardownEach( ${localVars.iterations}, true, ${listName}.length ); - ${localVars.iterations}.length = ${listName}.length; - ` ); - } + ${localVars.iterations}.length = ${listName}.length; + ` ); + } - if ( node.else ) { - generator.current.builders.update.addBlock( deindent` - if ( !${listName}.length && ${elseName} ) { - ${elseName}.update( changed, ${params} ); - } else if ( !${listName}.length ) { - ${elseName} = ${renderElse}( ${params}, ${generator.current.component} ); - ${elseName}.mount( ${anchor}.parentNode, ${anchor} ); - } else if ( ${elseName} ) { - ${elseName}.teardown( true ); - } - ` ); - } + if ( node.else ) { + generator.current.builders.update.addBlock( deindent` + if ( !${listName}.length && ${elseName} ) { + ${elseName}.update( changed, ${params} ); + } else if ( !${listName}.length ) { + ${elseName} = ${renderElse}( ${params}, ${generator.current.component} ); + ${elseName}.mount( ${anchor}.parentNode, ${anchor} ); + } else if ( ${elseName} ) { + ${elseName}.teardown( true ); + } + ` ); + } - generator.current.builders.teardown.addBlock( - `${generator.helper( 'teardownEach' )}( ${localVars.iterations}, ${isToplevel ? 'detach' : 'false'} );` ); + generator.current.builders.teardown.addBlock( + `${generator.helper( 'teardownEach' )}( ${localVars.iterations}, ${isToplevel ? 'detach' : 'false'} );` ); - if ( node.else ) { - generator.current.builders.teardown.addBlock( deindent` - if ( ${elseName} ) { - ${elseName}.teardown( ${isToplevel ? 'detach' : 'false'} ); - } - ` ); - } + if ( node.else ) { + generator.current.builders.teardown.addBlock( deindent` + if ( ${elseName} ) { + ${elseName}.teardown( ${isToplevel ? 'detach' : 'false'} ); + } + ` ); + } - if ( node.else ) { - generator.generateBlock( node.else, renderElse, 'block' ); - } + if ( node.else ) { + generator.generateBlock( node.else, renderElse, 'block' ); + } - const indexNames = new Map( generator.current.indexNames ); - const indexName = node.index || generator.current.getUniqueName( `${node.context}_index` ); - indexNames.set( node.context, indexName ); + const indexNames = new Map( generator.current.indexNames ); + const indexName = node.index || generator.current.getUniqueName( `${node.context}_index` ); + indexNames.set( node.context, indexName ); - const listNames = new Map( generator.current.listNames ); - listNames.set( node.context, listName ); + const listNames = new Map( generator.current.listNames ); + listNames.set( node.context, listName ); - const context = generator.getUniqueName( node.context ); - const contexts = new Map( generator.current.contexts ); - contexts.set( node.context, context ); + const context = generator.getUniqueName( node.context ); + const contexts = new Map( generator.current.contexts ); + contexts.set( node.context, context ); - const indexes = new Map( generator.current.indexes ); - if ( node.index ) indexes.set( indexName, node.context ); + const indexes = new Map( generator.current.indexes ); + if ( node.index ) indexes.set( indexName, node.context ); - const contextDependencies = new Map( generator.current.contextDependencies ); - contextDependencies.set( node.context, dependencies ); + const contextDependencies = new Map( generator.current.contextDependencies ); + contextDependencies.set( node.context, dependencies ); - const blockParams = generator.current.params.concat( listName, context, indexName ); + const blockParams = generator.current.params.concat( listName, context, indexName ); - const getUniqueName = generator.getUniqueNameMaker( blockParams ); + const getUniqueName = generator.getUniqueNameMaker( blockParams ); - generator.push({ - type: 'block', - name: renderer, - target: 'target', - expression: node.expression, - context: node.context, - key: node.key, - localElementDepth: 0, + generator.push({ + type: 'block', + name: renderer, + target: 'target', + expression: node.expression, + context: node.context, + key: node.key, + localElementDepth: 0, - component: getUniqueName( 'component' ), + component: getUniqueName( 'component' ), - contextDependencies, - contexts, - indexes, + contextDependencies, + contexts, + indexes, - indexNames, - listNames, - params: blockParams, + indexNames, + listNames, + params: blockParams, - builders: getBuilders(), - getUniqueName, - }); + builders: getBuilders(), + getUniqueName, + }); - node.children.forEach( child => { - visit( child, generator ); - }); + node.children.forEach( child => { + visit( child, generator ); + }); - generator.addRenderer( generator.current ); - generator.pop(); - } -}; + generator.addRenderer( generator.current ); + generator.pop(); +} \ No newline at end of file diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element.js index a224f0ffce35..21f81c8eb9d6 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element.js @@ -2,131 +2,122 @@ import CodeBuilder from '../../../utils/CodeBuilder.js'; import deindent from '../../../utils/deindent.js'; import visit from '../visit.js'; import addElementAttributes from './attributes/addElementAttributes.js'; -import Component from './Component.js'; -import Window from './meta/Window.js'; +import visitComponent from './Component.js'; +import visitWindow from './meta/Window.js'; const meta = { - ':Window': Window + ':Window': visitWindow }; -export default { - enter ( generator, node ) { - if ( node.name in meta ) { - return meta[ node.name ].enter( generator, node ); - } - - const isComponent = generator.components.has( node.name ) || node.name === ':Self'; +export default function visitElement ( generator, node ) { + if ( node.name in meta ) { + return meta[ node.name ]( generator, node ); + } - if ( isComponent ) { - return Component.enter( generator, node ); - } + if ( generator.components.has( node.name ) || node.name === ':Self' ) { + return visitComponent( generator, node ); + } - const name = generator.current.getUniqueName( node.name ); + const name = generator.current.getUniqueName( node.name ); - const local = { - name, - namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace, - isComponent: false, + const local = { + name, + namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace, + isComponent: false, - allUsedContexts: [], + allUsedContexts: [], - init: new CodeBuilder(), - update: new CodeBuilder(), - teardown: new CodeBuilder() - }; + init: new CodeBuilder(), + update: new CodeBuilder(), + teardown: new CodeBuilder() + }; - const isToplevel = generator.current.localElementDepth === 0; + const isToplevel = generator.current.localElementDepth === 0; - addElementAttributes( generator, node, local ); + addElementAttributes( generator, node, local ); - if ( local.allUsedContexts.length ) { - const initialProps = local.allUsedContexts.map( contextName => { - if ( contextName === 'root' ) return `root: root`; + if ( local.allUsedContexts.length ) { + const initialProps = local.allUsedContexts.map( contextName => { + if ( contextName === 'root' ) return `root: root`; - const listName = generator.current.listNames.get( contextName ); - const indexName = generator.current.indexNames.get( contextName ); + const listName = generator.current.listNames.get( contextName ); + const indexName = generator.current.indexNames.get( contextName ); - return `${listName}: ${listName},\n${indexName}: ${indexName}`; - }).join( ',\n' ); + return `${listName}: ${listName},\n${indexName}: ${indexName}`; + }).join( ',\n' ); - const updates = local.allUsedContexts.map( contextName => { - if ( contextName === 'root' ) return `${name}.__svelte.root = root;`; + const updates = local.allUsedContexts.map( contextName => { + if ( contextName === 'root' ) return `${name}.__svelte.root = root;`; - const listName = generator.current.listNames.get( contextName ); - const indexName = generator.current.indexNames.get( contextName ); + const listName = generator.current.listNames.get( contextName ); + const indexName = generator.current.indexNames.get( contextName ); - return `${name}.__svelte.${listName} = ${listName};\n${name}.__svelte.${indexName} = ${indexName};`; - }).join( '\n' ); + return `${name}.__svelte.${listName} = ${listName};\n${name}.__svelte.${indexName} = ${indexName};`; + }).join( '\n' ); - local.init.addBlock( deindent` - ${name}.__svelte = { - ${initialProps} - }; - ` ); + local.init.addBlock( deindent` + ${name}.__svelte = { + ${initialProps} + }; + ` ); - local.update.addBlock( updates ); - } + local.update.addBlock( updates ); + } - let render; + let render; - if ( local.namespace ) { - if ( local.namespace === 'http://www.w3.org/2000/svg' ) { - render = `var ${name} = ${generator.helper( 'createSvgElement' )}( '${node.name}' )`; - } else { - render = `var ${name} = document.createElementNS( '${local.namespace}', '${node.name}' );`; - } + if ( local.namespace ) { + if ( local.namespace === 'http://www.w3.org/2000/svg' ) { + render = `var ${name} = ${generator.helper( 'createSvgElement' )}( '${node.name}' )`; } else { - render = `var ${name} = ${generator.helper( 'createElement' )}( '${node.name}' );`; - } - - if ( generator.cssId && !generator.elementDepth ) { - render += `\n${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );`; - } - - local.init.addLineAtStart( render ); - if ( isToplevel ) { - generator.current.builders.detach.addLine( `${generator.helper( 'detachNode' )}( ${name} );` ); + render = `var ${name} = document.createElementNS( '${local.namespace}', '${node.name}' );`; } + } else { + render = `var ${name} = ${generator.helper( 'createElement' )}( '${node.name}' );`; + } - // special case – bound