From eebd47d02b504ce34ca440ca00ad3aea70451344 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 8 Apr 2018 11:25:02 -0700 Subject: [PATCH 01/15] add v2 parser tests, handle single curly tags --- src/interfaces.ts | 2 + src/parse/index.ts | 4 + src/parse/state/fragment.ts | 2 +- src/parse/state/mustache.ts | 4 +- src/parse/state/text.ts | 2 +- test/parser/index.js | 22 ++- .../samples/action-with-call/_actual-v2.json | 47 +++++ .../samples/action-with-call/input-v2.html | 1 + .../samples/action-with-call/output-v2.json | 47 +++++ .../action-with-identifier/_actual-v2.json | 33 ++++ .../action-with-identifier/input-v2.html | 1 + .../action-with-identifier/output-v2.json | 33 ++++ .../action-with-literal/_actual-v2.json | 34 ++++ .../samples/action-with-literal/input-v2.html | 1 + .../action-with-literal/output-v2.json | 34 ++++ test/parser/samples/action/_actual-v2.json | 28 +++ test/parser/samples/action/input-v2.html | 1 + test/parser/samples/action/output-v2.json | 28 +++ .../attribute-dynamic-boolean/_actual-v2.json | 35 ++++ .../attribute-dynamic-boolean/input-v2.html | 1 + .../attribute-dynamic-boolean/output-v2.json | 40 ++++ .../_actual-v2.json | 35 ++++ .../attribute-dynamic-reserved/input-v2.html | 1 + .../attribute-dynamic-reserved/output-v2.json | 40 ++++ .../samples/attribute-dynamic/_actual-v2.json | 42 ++++ .../samples/attribute-dynamic/input-v2.html | 1 + .../samples/attribute-dynamic/output-v2.json | 64 ++++++ .../samples/attribute-escaped/_actual-v2.json | 35 ++++ .../samples/attribute-escaped/input-v2.html | 1 + .../samples/attribute-escaped/output-v2.json | 35 ++++ .../attribute-multiple/_actual-v2.json | 49 +++++ .../samples/attribute-multiple/input-v2.html | 1 + .../samples/attribute-multiple/output-v2.json | 49 +++++ .../attribute-shorthand/_actual-v2.json | 40 ++++ .../samples/attribute-shorthand/input-v2.html | 1 + .../attribute-shorthand/output-v2.json | 40 ++++ .../attribute-static-boolean/_actual-v2.json | 28 +++ .../attribute-static-boolean/input-v2.html | 1 + .../attribute-static-boolean/output-v2.json | 28 +++ .../samples/attribute-static/_actual-v2.json | 35 ++++ .../samples/attribute-static/input-v2.html | 1 + .../samples/attribute-static/output-v2.json | 35 ++++ .../attribute-unique-error/input-v2.html | 1 + .../attribute-unquoted/_actual-v2.json | 35 ++++ .../samples/attribute-unquoted/input-v2.html | 1 + .../samples/attribute-unquoted/output-v2.json | 35 ++++ .../samples/await-then-catch/_actual-v2.json | 81 ++++++++ .../samples/await-then-catch/input-v2.html | 7 + .../samples/await-then-catch/output-v2.json | 161 ++++++++++++++++ .../samples/binding-shorthand/_actual-v2.json | 33 ++++ .../samples/binding-shorthand/input-v2.html | 1 + .../samples/binding-shorthand/output-v2.json | 33 ++++ test/parser/samples/binding/_actual-v2.json | 33 ++++ test/parser/samples/binding/input-v2.html | 1 + test/parser/samples/binding/output-v2.json | 33 ++++ test/parser/samples/comment/_actual-v2.json | 18 ++ test/parser/samples/comment/input-v2.html | 1 + test/parser/samples/comment/output-v2.json | 18 ++ .../samples/component-dynamic/_actual-v2.json | 68 +++++++ .../samples/component-dynamic/input-v2.html | 1 + .../samples/component-dynamic/output-v2.json | 43 +++++ .../_actual-v2.json | 27 +++ .../convert-entities-in-element/input-v2.html | 1 + .../output-v2.json | 27 +++ .../samples/convert-entities/_actual-v2.json | 18 ++ .../samples/convert-entities/input-v2.html | 1 + .../samples/convert-entities/output-v2.json | 18 ++ .../samples/css-ref-selector/_actual-v2.json | 96 +++++++++ .../samples/css-ref-selector/input-v2.html | 7 + .../samples/css-ref-selector/output-v2.json | 96 +++++++++ test/parser/samples/css/_actual-v2.json | 96 +++++++++ test/parser/samples/css/input-v2.html | 7 + test/parser/samples/css/output-v2.json | 96 +++++++++ .../samples/dynamic-import/_actual-v2.json | 182 ++++++++++++++++++ .../samples/dynamic-import/input-v2.html | 9 + .../samples/dynamic-import/output-v2.json | 182 ++++++++++++++++++ .../each-block-destructured/_actual-v2.json | 39 ++++ .../each-block-destructured/input-v2.html | 3 + .../each-block-destructured/output-v2.json | 67 +++++++ .../samples/each-block-else/_actual-v2.json | 60 ++++++ .../samples/each-block-else/input-v2.html | 5 + .../samples/each-block-else/output-v2.json | 68 +++++++ .../each-block-indexed/_actual-v2.json | 39 ++++ .../samples/each-block-indexed/input-v2.html | 3 + .../samples/each-block-indexed/output-v2.json | 64 ++++++ .../samples/each-block-keyed/_actual-v2.json | 39 ++++ .../samples/each-block-keyed/input-v2.html | 3 + .../samples/each-block-keyed/output-v2.json | 47 +++++ .../parser/samples/each-block/_actual-v2.json | 39 ++++ test/parser/samples/each-block/input-v2.html | 3 + test/parser/samples/each-block/output-v2.json | 46 +++++ .../element-with-mustache/_actual-v2.json | 44 +++++ .../element-with-mustache/input-v2.html | 1 + .../element-with-mustache/output-v2.json | 44 +++++ .../samples/element-with-text/_actual-v2.json | 27 +++ .../samples/element-with-text/input-v2.html | 1 + .../samples/element-with-text/output-v2.json | 27 +++ test/parser/samples/elements/_actual-v2.json | 28 +++ test/parser/samples/elements/input-v2.html | 1 + test/parser/samples/elements/output-v2.json | 28 +++ .../error-binding-disabled/input-v2.html | 1 + .../error-binding-mustaches/input-v2.html | 1 + .../error-binding-rvalue/input-v2.html | 1 + .../error-comment-unclosed/input-v2.html | 1 + test/parser/samples/error-css/input-v2.html | 3 + .../samples/error-event-handler/input-v2.html | 1 + .../error-illegal-expression/input-v2.html | 1 + .../error-multiple-styles/input-v2.html | 13 ++ .../samples/error-ref-value/input-v2.html | 1 + .../error-script-unclosed/input-v2.html | 3 + .../error-self-reference/input-v2.html | 1 + .../input-v2.html | 1 + .../input-v2.html | 1 + .../input-v2.html | 2 + .../input-v2.html | 1 + .../error-unmatched-closing-tag/input-v2.html | 1 + .../samples/error-void-closing/input-v2.html | 1 + .../error-window-children/input-v2.html | 1 + .../error-window-duplicate/input-v2.html | 2 + .../error-window-inside-block/input-v2.html | 3 + .../error-window-inside-element/input-v2.html | 3 + .../error-window-inside-element/input.html | 2 +- .../samples/event-handler/_actual-v2.json | 109 +++++++++++ .../samples/event-handler/input-v2.html | 5 + .../samples/event-handler/output-v2.json | 116 +++++++++++ .../samples/if-block-else/_actual-v2.json | 60 ++++++ .../samples/if-block-else/input-v2.html | 5 + .../samples/if-block-else/output-v2.json | 62 ++++++ .../samples/if-block-elseif/input-v2.html | 5 + test/parser/samples/if-block/_actual-v2.json | 18 ++ test/parser/samples/if-block/input-v2.html | 1 + test/parser/samples/if-block/output-v2.json | 31 +++ .../implicitly-closed-li/_actual-v2.json | 72 +++++++ .../implicitly-closed-li/input-v2.html | 5 + .../implicitly-closed-li/output-v2.json | 72 +++++++ test/parser/samples/nbsp/_actual-v2.json | 27 +++ test/parser/samples/nbsp/input-v2.html | 1 + test/parser/samples/nbsp/output-v2.json | 27 +++ .../samples/raw-mustaches/_actual-v2.json | 27 +++ .../samples/raw-mustaches/input-v2.html | 1 + .../samples/raw-mustaches/output-v2.json | 61 ++++++ test/parser/samples/refs/_actual-v2.json | 27 +++ test/parser/samples/refs/input-v2.html | 1 + test/parser/samples/refs/output-v2.json | 27 +++ .../script-comment-only/_actual-v2.json | 26 +++ .../samples/script-comment-only/input-v2.html | 5 + .../script-comment-only/output-v2.json | 26 +++ .../_actual-v2.json | 111 +++++++++++ .../input-v2.html | 13 ++ .../output-v2.json | 128 ++++++++++++ .../script-comment-trailing/_actual-v2.json | 111 +++++++++++ .../script-comment-trailing/input-v2.html | 11 ++ .../script-comment-trailing/output-v2.json | 128 ++++++++++++ test/parser/samples/script/_actual-v2.json | 111 +++++++++++ test/parser/samples/script/input-v2.html | 9 + test/parser/samples/script/output-v2.json | 128 ++++++++++++ .../self-closing-element/_actual-v2.json | 20 ++ .../self-closing-element/input-v2.html | 1 + .../self-closing-element/output-v2.json | 20 ++ .../samples/self-reference/_actual-v2.json | 47 +++++ .../samples/self-reference/input-v2.html | 3 + .../samples/self-reference/output-v2.json | 79 ++++++++ .../space-between-mustaches/_actual-v2.json | 27 +++ .../space-between-mustaches/input-v2.html | 1 + .../space-between-mustaches/output-v2.json | 78 ++++++++ test/parser/samples/spread/_actual-v2.json | 28 +++ test/parser/samples/spread/input-v2.html | 1 + test/parser/samples/spread/output-v2.json | 32 +++ .../samples/textarea-children/_actual-v2.json | 27 +++ .../samples/textarea-children/input-v2.html | 3 + .../samples/textarea-children/output-v2.json | 44 +++++ .../_actual-v2.json | 37 ++++ .../transition-intro-no-params/input-v2.html | 1 + .../transition-intro-no-params/output-v2.json | 37 ++++ .../samples/transition-intro/_actual-v2.json | 65 +++++++ .../samples/transition-intro/input-v2.html | 1 + .../samples/transition-intro/output-v2.json | 65 +++++++ .../unusual-identifier/_actual-v2.json | 39 ++++ .../samples/unusual-identifier/input-v2.html | 3 + .../samples/unusual-identifier/output-v2.json | 46 +++++ .../_actual-v2.json | 33 ++++ .../whitespace-leading-trailing/input-v2.html | 3 + .../output-v2.json | 33 ++++ .../samples/whitespace-normal/_actual-v2.json | 57 ++++++ .../samples/whitespace-normal/input-v2.html | 1 + .../samples/whitespace-normal/output-v2.json | 68 +++++++ test/parser/samples/yield/_actual-v2.json | 20 ++ test/parser/samples/yield/input-v2.html | 1 + test/parser/samples/yield/output-v2.json | 20 ++ 189 files changed, 5701 insertions(+), 7 deletions(-) create mode 100644 test/parser/samples/action-with-call/_actual-v2.json create mode 100644 test/parser/samples/action-with-call/input-v2.html create mode 100644 test/parser/samples/action-with-call/output-v2.json create mode 100644 test/parser/samples/action-with-identifier/_actual-v2.json create mode 100644 test/parser/samples/action-with-identifier/input-v2.html create mode 100644 test/parser/samples/action-with-identifier/output-v2.json create mode 100644 test/parser/samples/action-with-literal/_actual-v2.json create mode 100644 test/parser/samples/action-with-literal/input-v2.html create mode 100644 test/parser/samples/action-with-literal/output-v2.json create mode 100644 test/parser/samples/action/_actual-v2.json create mode 100644 test/parser/samples/action/input-v2.html create mode 100644 test/parser/samples/action/output-v2.json create mode 100644 test/parser/samples/attribute-dynamic-boolean/_actual-v2.json create mode 100644 test/parser/samples/attribute-dynamic-boolean/input-v2.html create mode 100644 test/parser/samples/attribute-dynamic-boolean/output-v2.json create mode 100644 test/parser/samples/attribute-dynamic-reserved/_actual-v2.json create mode 100644 test/parser/samples/attribute-dynamic-reserved/input-v2.html create mode 100644 test/parser/samples/attribute-dynamic-reserved/output-v2.json create mode 100644 test/parser/samples/attribute-dynamic/_actual-v2.json create mode 100644 test/parser/samples/attribute-dynamic/input-v2.html create mode 100644 test/parser/samples/attribute-dynamic/output-v2.json create mode 100644 test/parser/samples/attribute-escaped/_actual-v2.json create mode 100644 test/parser/samples/attribute-escaped/input-v2.html create mode 100644 test/parser/samples/attribute-escaped/output-v2.json create mode 100644 test/parser/samples/attribute-multiple/_actual-v2.json create mode 100644 test/parser/samples/attribute-multiple/input-v2.html create mode 100644 test/parser/samples/attribute-multiple/output-v2.json create mode 100644 test/parser/samples/attribute-shorthand/_actual-v2.json create mode 100644 test/parser/samples/attribute-shorthand/input-v2.html create mode 100644 test/parser/samples/attribute-shorthand/output-v2.json create mode 100644 test/parser/samples/attribute-static-boolean/_actual-v2.json create mode 100644 test/parser/samples/attribute-static-boolean/input-v2.html create mode 100644 test/parser/samples/attribute-static-boolean/output-v2.json create mode 100644 test/parser/samples/attribute-static/_actual-v2.json create mode 100644 test/parser/samples/attribute-static/input-v2.html create mode 100644 test/parser/samples/attribute-static/output-v2.json create mode 100644 test/parser/samples/attribute-unique-error/input-v2.html create mode 100644 test/parser/samples/attribute-unquoted/_actual-v2.json create mode 100644 test/parser/samples/attribute-unquoted/input-v2.html create mode 100644 test/parser/samples/attribute-unquoted/output-v2.json create mode 100644 test/parser/samples/await-then-catch/_actual-v2.json create mode 100644 test/parser/samples/await-then-catch/input-v2.html create mode 100644 test/parser/samples/await-then-catch/output-v2.json create mode 100644 test/parser/samples/binding-shorthand/_actual-v2.json create mode 100644 test/parser/samples/binding-shorthand/input-v2.html create mode 100644 test/parser/samples/binding-shorthand/output-v2.json create mode 100644 test/parser/samples/binding/_actual-v2.json create mode 100644 test/parser/samples/binding/input-v2.html create mode 100644 test/parser/samples/binding/output-v2.json create mode 100644 test/parser/samples/comment/_actual-v2.json create mode 100644 test/parser/samples/comment/input-v2.html create mode 100644 test/parser/samples/comment/output-v2.json create mode 100644 test/parser/samples/component-dynamic/_actual-v2.json create mode 100644 test/parser/samples/component-dynamic/input-v2.html create mode 100644 test/parser/samples/component-dynamic/output-v2.json create mode 100644 test/parser/samples/convert-entities-in-element/_actual-v2.json create mode 100644 test/parser/samples/convert-entities-in-element/input-v2.html create mode 100644 test/parser/samples/convert-entities-in-element/output-v2.json create mode 100644 test/parser/samples/convert-entities/_actual-v2.json create mode 100644 test/parser/samples/convert-entities/input-v2.html create mode 100644 test/parser/samples/convert-entities/output-v2.json create mode 100644 test/parser/samples/css-ref-selector/_actual-v2.json create mode 100644 test/parser/samples/css-ref-selector/input-v2.html create mode 100644 test/parser/samples/css-ref-selector/output-v2.json create mode 100644 test/parser/samples/css/_actual-v2.json create mode 100644 test/parser/samples/css/input-v2.html create mode 100644 test/parser/samples/css/output-v2.json create mode 100644 test/parser/samples/dynamic-import/_actual-v2.json create mode 100644 test/parser/samples/dynamic-import/input-v2.html create mode 100644 test/parser/samples/dynamic-import/output-v2.json create mode 100644 test/parser/samples/each-block-destructured/_actual-v2.json create mode 100644 test/parser/samples/each-block-destructured/input-v2.html create mode 100644 test/parser/samples/each-block-destructured/output-v2.json create mode 100644 test/parser/samples/each-block-else/_actual-v2.json create mode 100644 test/parser/samples/each-block-else/input-v2.html create mode 100644 test/parser/samples/each-block-else/output-v2.json create mode 100644 test/parser/samples/each-block-indexed/_actual-v2.json create mode 100644 test/parser/samples/each-block-indexed/input-v2.html create mode 100644 test/parser/samples/each-block-indexed/output-v2.json create mode 100644 test/parser/samples/each-block-keyed/_actual-v2.json create mode 100644 test/parser/samples/each-block-keyed/input-v2.html create mode 100644 test/parser/samples/each-block-keyed/output-v2.json create mode 100644 test/parser/samples/each-block/_actual-v2.json create mode 100644 test/parser/samples/each-block/input-v2.html create mode 100644 test/parser/samples/each-block/output-v2.json create mode 100644 test/parser/samples/element-with-mustache/_actual-v2.json create mode 100644 test/parser/samples/element-with-mustache/input-v2.html create mode 100644 test/parser/samples/element-with-mustache/output-v2.json create mode 100644 test/parser/samples/element-with-text/_actual-v2.json create mode 100644 test/parser/samples/element-with-text/input-v2.html create mode 100644 test/parser/samples/element-with-text/output-v2.json create mode 100644 test/parser/samples/elements/_actual-v2.json create mode 100644 test/parser/samples/elements/input-v2.html create mode 100644 test/parser/samples/elements/output-v2.json create mode 100644 test/parser/samples/error-binding-disabled/input-v2.html create mode 100644 test/parser/samples/error-binding-mustaches/input-v2.html create mode 100644 test/parser/samples/error-binding-rvalue/input-v2.html create mode 100644 test/parser/samples/error-comment-unclosed/input-v2.html create mode 100644 test/parser/samples/error-css/input-v2.html create mode 100644 test/parser/samples/error-event-handler/input-v2.html create mode 100644 test/parser/samples/error-illegal-expression/input-v2.html create mode 100644 test/parser/samples/error-multiple-styles/input-v2.html create mode 100644 test/parser/samples/error-ref-value/input-v2.html create mode 100644 test/parser/samples/error-script-unclosed/input-v2.html create mode 100644 test/parser/samples/error-self-reference/input-v2.html create mode 100644 test/parser/samples/error-unexpected-end-of-input-b/input-v2.html create mode 100644 test/parser/samples/error-unexpected-end-of-input-c/input-v2.html create mode 100644 test/parser/samples/error-unexpected-end-of-input-d/input-v2.html create mode 100644 test/parser/samples/error-unexpected-end-of-input/input-v2.html create mode 100644 test/parser/samples/error-unmatched-closing-tag/input-v2.html create mode 100644 test/parser/samples/error-void-closing/input-v2.html create mode 100644 test/parser/samples/error-window-children/input-v2.html create mode 100644 test/parser/samples/error-window-duplicate/input-v2.html create mode 100644 test/parser/samples/error-window-inside-block/input-v2.html create mode 100644 test/parser/samples/error-window-inside-element/input-v2.html create mode 100644 test/parser/samples/event-handler/_actual-v2.json create mode 100644 test/parser/samples/event-handler/input-v2.html create mode 100644 test/parser/samples/event-handler/output-v2.json create mode 100644 test/parser/samples/if-block-else/_actual-v2.json create mode 100644 test/parser/samples/if-block-else/input-v2.html create mode 100644 test/parser/samples/if-block-else/output-v2.json create mode 100644 test/parser/samples/if-block-elseif/input-v2.html create mode 100644 test/parser/samples/if-block/_actual-v2.json create mode 100644 test/parser/samples/if-block/input-v2.html create mode 100644 test/parser/samples/if-block/output-v2.json create mode 100644 test/parser/samples/implicitly-closed-li/_actual-v2.json create mode 100644 test/parser/samples/implicitly-closed-li/input-v2.html create mode 100644 test/parser/samples/implicitly-closed-li/output-v2.json create mode 100644 test/parser/samples/nbsp/_actual-v2.json create mode 100644 test/parser/samples/nbsp/input-v2.html create mode 100644 test/parser/samples/nbsp/output-v2.json create mode 100644 test/parser/samples/raw-mustaches/_actual-v2.json create mode 100644 test/parser/samples/raw-mustaches/input-v2.html create mode 100644 test/parser/samples/raw-mustaches/output-v2.json create mode 100644 test/parser/samples/refs/_actual-v2.json create mode 100644 test/parser/samples/refs/input-v2.html create mode 100644 test/parser/samples/refs/output-v2.json create mode 100644 test/parser/samples/script-comment-only/_actual-v2.json create mode 100644 test/parser/samples/script-comment-only/input-v2.html create mode 100644 test/parser/samples/script-comment-only/output-v2.json create mode 100644 test/parser/samples/script-comment-trailing-multiline/_actual-v2.json create mode 100644 test/parser/samples/script-comment-trailing-multiline/input-v2.html create mode 100644 test/parser/samples/script-comment-trailing-multiline/output-v2.json create mode 100644 test/parser/samples/script-comment-trailing/_actual-v2.json create mode 100644 test/parser/samples/script-comment-trailing/input-v2.html create mode 100644 test/parser/samples/script-comment-trailing/output-v2.json create mode 100644 test/parser/samples/script/_actual-v2.json create mode 100644 test/parser/samples/script/input-v2.html create mode 100644 test/parser/samples/script/output-v2.json create mode 100644 test/parser/samples/self-closing-element/_actual-v2.json create mode 100644 test/parser/samples/self-closing-element/input-v2.html create mode 100644 test/parser/samples/self-closing-element/output-v2.json create mode 100644 test/parser/samples/self-reference/_actual-v2.json create mode 100644 test/parser/samples/self-reference/input-v2.html create mode 100644 test/parser/samples/self-reference/output-v2.json create mode 100644 test/parser/samples/space-between-mustaches/_actual-v2.json create mode 100644 test/parser/samples/space-between-mustaches/input-v2.html create mode 100644 test/parser/samples/space-between-mustaches/output-v2.json create mode 100644 test/parser/samples/spread/_actual-v2.json create mode 100644 test/parser/samples/spread/input-v2.html create mode 100644 test/parser/samples/spread/output-v2.json create mode 100644 test/parser/samples/textarea-children/_actual-v2.json create mode 100644 test/parser/samples/textarea-children/input-v2.html create mode 100644 test/parser/samples/textarea-children/output-v2.json create mode 100644 test/parser/samples/transition-intro-no-params/_actual-v2.json create mode 100644 test/parser/samples/transition-intro-no-params/input-v2.html create mode 100644 test/parser/samples/transition-intro-no-params/output-v2.json create mode 100644 test/parser/samples/transition-intro/_actual-v2.json create mode 100644 test/parser/samples/transition-intro/input-v2.html create mode 100644 test/parser/samples/transition-intro/output-v2.json create mode 100644 test/parser/samples/unusual-identifier/_actual-v2.json create mode 100644 test/parser/samples/unusual-identifier/input-v2.html create mode 100644 test/parser/samples/unusual-identifier/output-v2.json create mode 100644 test/parser/samples/whitespace-leading-trailing/_actual-v2.json create mode 100644 test/parser/samples/whitespace-leading-trailing/input-v2.html create mode 100644 test/parser/samples/whitespace-leading-trailing/output-v2.json create mode 100644 test/parser/samples/whitespace-normal/_actual-v2.json create mode 100644 test/parser/samples/whitespace-normal/input-v2.html create mode 100644 test/parser/samples/whitespace-normal/output-v2.json create mode 100644 test/parser/samples/yield/_actual-v2.json create mode 100644 test/parser/samples/yield/input-v2.html create mode 100644 test/parser/samples/yield/output-v2.json diff --git a/src/interfaces.ts b/src/interfaces.ts index d44c6a030c5d..dc3fb614c159 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -66,6 +66,8 @@ export interface CompileOptions { onerror?: (error: Error) => void; onwarn?: (warning: Warning) => void; + + parser?: 'v2'; } export interface GenerateOptions { diff --git a/src/parse/index.ts b/src/parse/index.ts index 3e782214773b..b7656a426a67 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -13,11 +13,13 @@ import error from '../utils/error'; interface ParserOptions { filename?: string; bind?: boolean; + parser?: 'v2'; } type ParserState = (parser: Parser) => (ParserState | void); export class Parser { + readonly v2: boolean; readonly template: string; readonly filename?: string; @@ -32,6 +34,8 @@ export class Parser { allowBindings: boolean; constructor(template: string, options: ParserOptions) { + this.v2 = options.parser === 'v2'; + if (typeof template !== 'string') { throw new TypeError('Template must be a string'); } diff --git a/src/parse/state/fragment.ts b/src/parse/state/fragment.ts index c82b3e2f8a48..b2e6cb4c32c9 100644 --- a/src/parse/state/fragment.ts +++ b/src/parse/state/fragment.ts @@ -8,7 +8,7 @@ export default function fragment(parser: Parser) { return tag; } - if (parser.match('{{')) { + if (parser.match(parser.v2 ? '{' : '{{')) { return mustache; } diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 0a255b125602..8da2560fb2f5 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -32,7 +32,7 @@ function trimWhitespace(block: Node, trimBefore: boolean, trimAfter: boolean) { export default function mustache(parser: Parser) { const start = parser.index; - parser.index += 2; + parser.index += parser.v2 ? 1 : 2; parser.allowWhitespace(); @@ -329,7 +329,7 @@ export default function mustache(parser: Parser) { const expression = readExpression(parser); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); parser.current().children.push({ start, diff --git a/src/parse/state/text.ts b/src/parse/state/text.ts index bdd625569cb7..29da8f928a6b 100644 --- a/src/parse/state/text.ts +++ b/src/parse/state/text.ts @@ -9,7 +9,7 @@ export default function text(parser: Parser) { while ( parser.index < parser.template.length && !parser.match('<') && - !parser.match('{{') + !parser.match(parser.v2 ? '{' : '{{') ) { data += parser.template[parser.index++]; } diff --git a/test/parser/index.js b/test/parser/index.js index 7467e31b0c99..d0417c8bfa3e 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -2,7 +2,7 @@ import assert from 'assert'; import fs from 'fs'; import { svelte, tryToLoadJson } from '../helpers.js'; -describe('parse', () => { +describe.only('parse', () => { fs.readdirSync('test/parser/samples').forEach(dir => { if (dir[0] === '.') return; @@ -20,19 +20,37 @@ describe('parse', () => { .readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8') .replace(/\s+$/, ''); + const input_v2 = fs + .readFileSync(`test/parser/samples/${dir}/input-v2.html`, 'utf-8') + .replace(/\s+$/, ''); + const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {}; try { const actual = svelte.parse(input, options); + const expected = require(`./samples/${dir}/output.json`); + fs.writeFileSync( `test/parser/samples/${dir}/_actual.json`, JSON.stringify(actual, null, '\t') ); - const expected = require(`./samples/${dir}/output.json`); assert.deepEqual(actual.html, expected.html); assert.deepEqual(actual.css, expected.css); assert.deepEqual(actual.js, expected.js); + + // TODO remove v1 tests + const actual_v2 = svelte.parse(input_v2, Object.assign({ parser: 'v2' }, options)); + const expected_v2 = require(`./samples/${dir}/output-v2.json`); + + fs.writeFileSync( + `test/parser/samples/${dir}/_actual-v2.json`, + JSON.stringify(actual_v2, null, '\t') + ); + + assert.deepEqual(actual_v2.html, expected_v2.html); + assert.deepEqual(actual_v2.css, expected_v2.css); + assert.deepEqual(actual_v2.js, expected_v2.js); } catch (err) { if (err.name !== 'ParseError') throw err; diff --git a/test/parser/samples/action-with-call/_actual-v2.json b/test/parser/samples/action-with-call/_actual-v2.json new file mode 100644 index 000000000000..b7bc908e2482 --- /dev/null +++ b/test/parser/samples/action-with-call/_actual-v2.json @@ -0,0 +1,47 @@ +{ + "hash": "1eefngx", + "html": { + "start": 0, + "end": 38, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 38, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 37, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "CallExpression", + "start": 20, + "end": 36, + "callee": { + "type": "Identifier", + "start": 20, + "end": 21, + "name": "t" + }, + "arguments": [ + { + "type": "Literal", + "start": 22, + "end": 35, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + ] + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-call/input-v2.html b/test/parser/samples/action-with-call/input-v2.html new file mode 100644 index 000000000000..246bf02c59c3 --- /dev/null +++ b/test/parser/samples/action-with-call/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-call/output-v2.json b/test/parser/samples/action-with-call/output-v2.json new file mode 100644 index 000000000000..f5cc6824f3d9 --- /dev/null +++ b/test/parser/samples/action-with-call/output-v2.json @@ -0,0 +1,47 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 38, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 38, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 37, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "CallExpression", + "start": 20, + "end": 36, + "callee": { + "type": "Identifier", + "start": 20, + "end": 21, + "name": "t" + }, + "arguments": [ + { + "type": "Literal", + "start": 22, + "end": 35, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + ] + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/_actual-v2.json b/test/parser/samples/action-with-identifier/_actual-v2.json new file mode 100644 index 000000000000..6c6daa34b2b1 --- /dev/null +++ b/test/parser/samples/action-with-identifier/_actual-v2.json @@ -0,0 +1,33 @@ +{ + "hash": "1vce0rr", + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 28, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Identifier", + "start": 20, + "end": 27, + "name": "message" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/input-v2.html b/test/parser/samples/action-with-identifier/input-v2.html new file mode 100644 index 000000000000..14a65e83ed72 --- /dev/null +++ b/test/parser/samples/action-with-identifier/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-identifier/output-v2.json b/test/parser/samples/action-with-identifier/output-v2.json new file mode 100644 index 000000000000..6c39ed94bc16 --- /dev/null +++ b/test/parser/samples/action-with-identifier/output-v2.json @@ -0,0 +1,33 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 28, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Identifier", + "start": 20, + "end": 27, + "name": "message" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/_actual-v2.json b/test/parser/samples/action-with-literal/_actual-v2.json new file mode 100644 index 000000000000..472b5a306d3b --- /dev/null +++ b/test/parser/samples/action-with-literal/_actual-v2.json @@ -0,0 +1,34 @@ +{ + "hash": "1pm9eh0", + "html": { + "start": 0, + "end": 35, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 34, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Literal", + "start": 20, + "end": 33, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/input-v2.html b/test/parser/samples/action-with-literal/input-v2.html new file mode 100644 index 000000000000..60e16eacfc7c --- /dev/null +++ b/test/parser/samples/action-with-literal/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-literal/output-v2.json b/test/parser/samples/action-with-literal/output-v2.json new file mode 100644 index 000000000000..0da031888714 --- /dev/null +++ b/test/parser/samples/action-with-literal/output-v2.json @@ -0,0 +1,34 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 35, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 34, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Literal", + "start": 20, + "end": 33, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action/_actual-v2.json b/test/parser/samples/action/_actual-v2.json new file mode 100644 index 000000000000..0746bd601a0f --- /dev/null +++ b/test/parser/samples/action/_actual-v2.json @@ -0,0 +1,28 @@ +{ + "hash": "1e3ix5", + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 20, + "type": "Action", + "name": "autofocus", + "expression": null + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action/input-v2.html b/test/parser/samples/action/input-v2.html new file mode 100644 index 000000000000..64409c2a6507 --- /dev/null +++ b/test/parser/samples/action/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action/output-v2.json b/test/parser/samples/action/output-v2.json new file mode 100644 index 000000000000..597ae297a533 --- /dev/null +++ b/test/parser/samples/action/output-v2.json @@ -0,0 +1,28 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 20, + "type": "Action", + "name": "autofocus", + "expression": null + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json new file mode 100644 index 000000000000..c843275a4fba --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "7xolfv", + "html": { + "start": 0, + "end": 41, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 41, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 29, + "type": "Attribute", + "name": "readonly", + "value": [ + { + "start": 19, + "end": 29, + "type": "Text", + "data": "{readonly}" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/input-v2.html b/test/parser/samples/attribute-dynamic-boolean/input-v2.html new file mode 100644 index 000000000000..ba531f2f8116 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/attribute-dynamic-boolean/output-v2.json b/test/parser/samples/attribute-dynamic-boolean/output-v2.json new file mode 100644 index 000000000000..af1635a55d95 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/output-v2.json @@ -0,0 +1,40 @@ +{ + "hash": 3179574701, + "html": { + "start": 0, + "end": 45, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 45, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 33, + "type": "Attribute", + "name": "readonly", + "value": [ + { + "start": 20, + "end": 32, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 22, + "end": 30, + "name": "readonly" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json new file mode 100644 index 000000000000..76b70ef261aa --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "l0cddf", + "html": { + "start": 0, + "end": 25, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 25, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 18, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 11, + "end": 18, + "type": "Text", + "data": "{class}" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/input-v2.html b/test/parser/samples/attribute-dynamic-reserved/input-v2.html new file mode 100644 index 000000000000..d973a9dea043 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/output-v2.json b/test/parser/samples/attribute-dynamic-reserved/output-v2.json new file mode 100644 index 000000000000..aef0e5cb63ca --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/output-v2.json @@ -0,0 +1,40 @@ +{ + "hash": 2788845841, + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 22, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 12, + "end": 21, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 14, + "end": 19, + "name": "class" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/_actual-v2.json b/test/parser/samples/attribute-dynamic/_actual-v2.json new file mode 100644 index 000000000000..06f82de54aba --- /dev/null +++ b/test/parser/samples/attribute-dynamic/_actual-v2.json @@ -0,0 +1,42 @@ +{ + "hash": "ehtsx6", + "html": { + "start": 0, + "end": 42, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 42, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 28, + "type": "Attribute", + "name": "style", + "value": [ + { + "start": 12, + "end": 27, + "type": "Text", + "data": "color: {color};" + } + ] + } + ], + "children": [ + { + "start": 29, + "end": 36, + "type": "Text", + "data": "{color}" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/input-v2.html b/test/parser/samples/attribute-dynamic/input-v2.html new file mode 100644 index 000000000000..9171ae22a77e --- /dev/null +++ b/test/parser/samples/attribute-dynamic/input-v2.html @@ -0,0 +1 @@ +
{color}
diff --git a/test/parser/samples/attribute-dynamic/output-v2.json b/test/parser/samples/attribute-dynamic/output-v2.json new file mode 100644 index 000000000000..79ef81065fc7 --- /dev/null +++ b/test/parser/samples/attribute-dynamic/output-v2.json @@ -0,0 +1,64 @@ +{ + "hash": 804348386, + "html": { + "start": 0, + "end": 46, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 46, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 30, + "type": "Attribute", + "name": "style", + "value": [ + { + "start": 12, + "end": 19, + "type": "Text", + "data": "color: " + }, + { + "start": 19, + "end": 28, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 21, + "end": 26, + "name": "color" + } + }, + { + "start": 28, + "end": 29, + "type": "Text", + "data": ";" + } + ] + } + ], + "children": [ + { + "start": 31, + "end": 40, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 33, + "end": 38, + "name": "color" + } + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-escaped/_actual-v2.json b/test/parser/samples/attribute-escaped/_actual-v2.json new file mode 100644 index 000000000000..d048a3d94599 --- /dev/null +++ b/test/parser/samples/attribute-escaped/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "pv50w6", + "html": { + "start": 0, + "end": 41, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 41, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 34, + "type": "Attribute", + "name": "data-foo", + "value": [ + { + "start": 15, + "end": 33, + "type": "Text", + "data": "\"quoted\"" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-escaped/input-v2.html b/test/parser/samples/attribute-escaped/input-v2.html new file mode 100644 index 000000000000..82186dcee47b --- /dev/null +++ b/test/parser/samples/attribute-escaped/input-v2.html @@ -0,0 +1 @@ +
diff --git a/test/parser/samples/attribute-escaped/output-v2.json b/test/parser/samples/attribute-escaped/output-v2.json new file mode 100644 index 000000000000..974084bcdde3 --- /dev/null +++ b/test/parser/samples/attribute-escaped/output-v2.json @@ -0,0 +1,35 @@ +{ + "hash": 1563956934, + "html": { + "start": 0, + "end": 41, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 41, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 34, + "type": "Attribute", + "name": "data-foo", + "value": [ + { + "start": 15, + "end": 33, + "type": "Text", + "data": "\"quoted\"" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-multiple/_actual-v2.json b/test/parser/samples/attribute-multiple/_actual-v2.json new file mode 100644 index 000000000000..b185127d5657 --- /dev/null +++ b/test/parser/samples/attribute-multiple/_actual-v2.json @@ -0,0 +1,49 @@ +{ + "hash": "8dvm3u", + "html": { + "start": 0, + "end": 28, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 28, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 11, + "type": "Attribute", + "name": "id", + "value": [ + { + "start": 9, + "end": 10, + "type": "Text", + "data": "x" + } + ] + }, + { + "start": 12, + "end": 21, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 19, + "end": 20, + "type": "Text", + "data": "y" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-multiple/input-v2.html b/test/parser/samples/attribute-multiple/input-v2.html new file mode 100644 index 000000000000..6f61bd628983 --- /dev/null +++ b/test/parser/samples/attribute-multiple/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-multiple/output-v2.json b/test/parser/samples/attribute-multiple/output-v2.json new file mode 100644 index 000000000000..81af977b51a1 --- /dev/null +++ b/test/parser/samples/attribute-multiple/output-v2.json @@ -0,0 +1,49 @@ +{ + "hash": 507039402, + "html": { + "start": 0, + "end": 28, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 28, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 11, + "type": "Attribute", + "name": "id", + "value": [ + { + "start": 9, + "end": 10, + "type": "Text", + "data": "x" + } + ] + }, + { + "start": 12, + "end": 21, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 19, + "end": 20, + "type": "Text", + "data": "y" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-shorthand/_actual-v2.json b/test/parser/samples/attribute-shorthand/_actual-v2.json new file mode 100644 index 000000000000..01b3ae38b220 --- /dev/null +++ b/test/parser/samples/attribute-shorthand/_actual-v2.json @@ -0,0 +1,40 @@ +{ + "hash": "s7nwuc", + "html": { + "start": 0, + "end": 10, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 10, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 8, + "type": "Attribute", + "name": "id", + "value": [ + { + "type": "AttributeShorthand", + "start": 6, + "end": 8, + "expression": { + "type": "Identifier", + "start": 6, + "end": 8, + "name": "id" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-shorthand/input-v2.html b/test/parser/samples/attribute-shorthand/input-v2.html new file mode 100644 index 000000000000..e26deafb3a3d --- /dev/null +++ b/test/parser/samples/attribute-shorthand/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-shorthand/output-v2.json b/test/parser/samples/attribute-shorthand/output-v2.json new file mode 100644 index 000000000000..b6578c13eb51 --- /dev/null +++ b/test/parser/samples/attribute-shorthand/output-v2.json @@ -0,0 +1,40 @@ +{ + "hash": 1705925892, + "html": { + "start": 0, + "end": 10, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 10, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 8, + "type": "Attribute", + "name": "id", + "value": [ + { + "type": "AttributeShorthand", + "start": 6, + "end": 8, + "expression": { + "type": "Identifier", + "start": 6, + "end": 8, + "name": "id" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-static-boolean/_actual-v2.json b/test/parser/samples/attribute-static-boolean/_actual-v2.json new file mode 100644 index 000000000000..a70a135f2a6e --- /dev/null +++ b/test/parser/samples/attribute-static-boolean/_actual-v2.json @@ -0,0 +1,28 @@ +{ + "hash": "a1b7fo", + "html": { + "start": 0, + "end": 30, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 30, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 18, + "type": "Attribute", + "name": "readonly", + "value": true + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-static-boolean/input-v2.html b/test/parser/samples/attribute-static-boolean/input-v2.html new file mode 100644 index 000000000000..1536f3e1e882 --- /dev/null +++ b/test/parser/samples/attribute-static-boolean/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/attribute-static-boolean/output-v2.json b/test/parser/samples/attribute-static-boolean/output-v2.json new file mode 100644 index 000000000000..21429893fd7d --- /dev/null +++ b/test/parser/samples/attribute-static-boolean/output-v2.json @@ -0,0 +1,28 @@ +{ + "hash": 606864228, + "html": { + "start": 0, + "end": 30, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 30, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 18, + "type": "Attribute", + "name": "readonly", + "value": true + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-static/_actual-v2.json b/test/parser/samples/attribute-static/_actual-v2.json new file mode 100644 index 000000000000..28dc91df40f1 --- /dev/null +++ b/test/parser/samples/attribute-static/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "op11m5", + "html": { + "start": 0, + "end": 23, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 23, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 16, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 12, + "end": 15, + "type": "Text", + "data": "foo" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-static/input-v2.html b/test/parser/samples/attribute-static/input-v2.html new file mode 100644 index 000000000000..c6a8a8c95d59 --- /dev/null +++ b/test/parser/samples/attribute-static/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-static/output-v2.json b/test/parser/samples/attribute-static/output-v2.json new file mode 100644 index 000000000000..394f95f4580e --- /dev/null +++ b/test/parser/samples/attribute-static/output-v2.json @@ -0,0 +1,35 @@ +{ + "hash": 1493227373, + "html": { + "start": 0, + "end": 23, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 23, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 16, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 12, + "end": 15, + "type": "Text", + "data": "foo" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-unique-error/input-v2.html b/test/parser/samples/attribute-unique-error/input-v2.html new file mode 100644 index 000000000000..37fec733b3ce --- /dev/null +++ b/test/parser/samples/attribute-unique-error/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-unquoted/_actual-v2.json b/test/parser/samples/attribute-unquoted/_actual-v2.json new file mode 100644 index 000000000000..583e8814d6a1 --- /dev/null +++ b/test/parser/samples/attribute-unquoted/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "1lozhxt", + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 14, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 11, + "end": 14, + "type": "Text", + "data": "foo" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-unquoted/input-v2.html b/test/parser/samples/attribute-unquoted/input-v2.html new file mode 100644 index 000000000000..4bab0df72f3e --- /dev/null +++ b/test/parser/samples/attribute-unquoted/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-unquoted/output-v2.json b/test/parser/samples/attribute-unquoted/output-v2.json new file mode 100644 index 000000000000..474d925b2e47 --- /dev/null +++ b/test/parser/samples/attribute-unquoted/output-v2.json @@ -0,0 +1,35 @@ +{ + "hash": 3488539025, + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 14, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 11, + "end": 14, + "type": "Text", + "data": "foo" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/_actual-v2.json b/test/parser/samples/await-then-catch/_actual-v2.json new file mode 100644 index 000000000000..cfe0ab813487 --- /dev/null +++ b/test/parser/samples/await-then-catch/_actual-v2.json @@ -0,0 +1,81 @@ +{ + "hash": "1rt0tho", + "html": { + "start": 0, + "end": 149, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Text", + "data": "{#await thePromise}\n\t" + }, + { + "start": 21, + "end": 38, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 24, + "end": 34, + "type": "Text", + "data": "loading..." + } + ] + }, + { + "start": 38, + "end": 57, + "type": "Text", + "data": "\n{:then theValue}\n\t" + }, + { + "start": 57, + "end": 87, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 60, + "end": 83, + "type": "Text", + "data": "the value is {theValue}" + } + ] + }, + { + "start": 87, + "end": 107, + "type": "Text", + "data": "\n{:catch theError}\n\t" + }, + { + "start": 107, + "end": 140, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 110, + "end": 136, + "type": "Text", + "data": "oh no! {theError.message}}" + } + ] + }, + { + "start": 140, + "end": 149, + "type": "Text", + "data": "\n{/await}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/input-v2.html b/test/parser/samples/await-then-catch/input-v2.html new file mode 100644 index 000000000000..b4038bec8ccb --- /dev/null +++ b/test/parser/samples/await-then-catch/input-v2.html @@ -0,0 +1,7 @@ +{#await thePromise} +

loading...

+{:then theValue} +

the value is {theValue}

+{:catch theError} +

oh no! {theError.message}}

+{/await} \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/output-v2.json b/test/parser/samples/await-then-catch/output-v2.json new file mode 100644 index 000000000000..4f149e6a0cba --- /dev/null +++ b/test/parser/samples/await-then-catch/output-v2.json @@ -0,0 +1,161 @@ +{ + "hash": 1040536517, + "html": { + "start": 0, + "end": 158, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 158, + "type": "AwaitBlock", + "expression": { + "type": "Identifier", + "start": 9, + "end": 19, + "name": "thePromise" + }, + "value": "theValue", + "error": "theError", + "pending": { + "start": 21, + "end": 41, + "type": "PendingBlock", + "children": [ + { + "start": 21, + "end": 23, + "type": "Text", + "data": "\n\t" + }, + { + "start": 23, + "end": 40, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 26, + "end": 36, + "type": "Text", + "data": "loading..." + } + ] + }, + { + "start": 40, + "end": 41, + "type": "Text", + "data": "\n" + } + ] + }, + "then": { + "start": 41, + "end": 93, + "type": "ThenBlock", + "children": [ + { + "start": 58, + "end": 60, + "type": "Text", + "data": "\n\t" + }, + { + "start": 60, + "end": 92, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 63, + "end": 76, + "type": "Text", + "data": "the value is " + }, + { + "start": 76, + "end": 88, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 78, + "end": 86, + "name": "theValue" + } + } + ] + }, + { + "start": 92, + "end": 93, + "type": "Text", + "data": "\n" + } + ] + }, + "catch": { + "start": 93, + "end": 148, + "type": "CatchBlock", + "children": [ + { + "start": 111, + "end": 113, + "type": "Text", + "data": "\n\t" + }, + { + "start": 113, + "end": 147, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 116, + "end": 123, + "type": "Text", + "data": "oh no! " + }, + { + "start": 123, + "end": 143, + "type": "MustacheTag", + "expression": { + "type": "MemberExpression", + "start": 125, + "end": 141, + "object": { + "type": "Identifier", + "start": 125, + "end": 133, + "name": "theError" + }, + "property": { + "type": "Identifier", + "start": 134, + "end": 141, + "name": "message" + }, + "computed": false + } + } + ] + }, + { + "start": 147, + "end": 148, + "type": "Text", + "data": "\n" + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/_actual-v2.json b/test/parser/samples/binding-shorthand/_actual-v2.json new file mode 100644 index 000000000000..de159d6516cd --- /dev/null +++ b/test/parser/samples/binding-shorthand/_actual-v2.json @@ -0,0 +1,33 @@ +{ + "hash": "1f31b7d", + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Element", + "name": "Widget", + "attributes": [ + { + "start": 8, + "end": 16, + "type": "Binding", + "name": "foo", + "value": { + "type": "Identifier", + "start": 13, + "end": 16, + "name": "foo" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/input-v2.html b/test/parser/samples/binding-shorthand/input-v2.html new file mode 100644 index 000000000000..7f8116bdded9 --- /dev/null +++ b/test/parser/samples/binding-shorthand/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/output-v2.json b/test/parser/samples/binding-shorthand/output-v2.json new file mode 100644 index 000000000000..8a7b615cf420 --- /dev/null +++ b/test/parser/samples/binding-shorthand/output-v2.json @@ -0,0 +1,33 @@ +{ + "hash": 3088875001, + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Element", + "name": "Widget", + "attributes": [ + { + "start": 8, + "end": 16, + "type": "Binding", + "name": "foo", + "value": { + "type": "Identifier", + "start": 13, + "end": 16, + "name": "foo" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding/_actual-v2.json b/test/parser/samples/binding/_actual-v2.json new file mode 100644 index 000000000000..c124e9caf46d --- /dev/null +++ b/test/parser/samples/binding/_actual-v2.json @@ -0,0 +1,33 @@ +{ + "hash": "w1d13d", + "html": { + "start": 0, + "end": 25, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 25, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 24, + "type": "Binding", + "name": "value", + "value": { + "type": "Identifier", + "start": 19, + "end": 23, + "name": "name" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding/input-v2.html b/test/parser/samples/binding/input-v2.html new file mode 100644 index 000000000000..3af20a9ced1b --- /dev/null +++ b/test/parser/samples/binding/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/binding/output-v2.json b/test/parser/samples/binding/output-v2.json new file mode 100644 index 000000000000..74f2059f5929 --- /dev/null +++ b/test/parser/samples/binding/output-v2.json @@ -0,0 +1,33 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 25, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 25, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 24, + "type": "Binding", + "name": "value", + "value": { + "type": "Identifier", + "start": 19, + "end": 23, + "name": "name" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/comment/_actual-v2.json b/test/parser/samples/comment/_actual-v2.json new file mode 100644 index 000000000000..3dde7da39dcc --- /dev/null +++ b/test/parser/samples/comment/_actual-v2.json @@ -0,0 +1,18 @@ +{ + "hash": "1ihizni", + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Comment", + "data": " a comment " + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/comment/input-v2.html b/test/parser/samples/comment/input-v2.html new file mode 100644 index 000000000000..3b3ffe3222f9 --- /dev/null +++ b/test/parser/samples/comment/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/comment/output-v2.json b/test/parser/samples/comment/output-v2.json new file mode 100644 index 000000000000..e77c968b6b6b --- /dev/null +++ b/test/parser/samples/comment/output-v2.json @@ -0,0 +1,18 @@ +{ + "hash": 3294612990, + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Comment", + "data": " a comment " + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/_actual-v2.json b/test/parser/samples/component-dynamic/_actual-v2.json new file mode 100644 index 000000000000..9e6525a8cabd --- /dev/null +++ b/test/parser/samples/component-dynamic/_actual-v2.json @@ -0,0 +1,68 @@ +{ + "hash": "7yh2k2", + "html": { + "start": 0, + "end": 55, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 55, + "type": "Element", + "name": "svelte:component", + "attributes": [ + { + "start": 18, + "end": 23, + "type": "Attribute", + "name": "{foo", + "value": true + }, + { + "start": 23, + "end": 25, + "type": "Attribute", + "name": "?", + "value": true + }, + { + "start": 25, + "end": 29, + "type": "Attribute", + "name": "Foo", + "value": true + }, + { + "start": 29, + "end": 30, + "type": "Attribute", + "name": "", + "value": [ + { + "type": "AttributeShorthand", + "start": 30, + "end": 30, + "expression": { + "type": "Identifier", + "start": 30, + "end": 30, + "name": "" + } + } + ] + }, + { + "start": 31, + "end": 35, + "type": "Attribute", + "name": "Bar}", + "value": true + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/input-v2.html b/test/parser/samples/component-dynamic/input-v2.html new file mode 100644 index 000000000000..d692cce9b875 --- /dev/null +++ b/test/parser/samples/component-dynamic/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/output-v2.json b/test/parser/samples/component-dynamic/output-v2.json new file mode 100644 index 000000000000..614c28c0a9f7 --- /dev/null +++ b/test/parser/samples/component-dynamic/output-v2.json @@ -0,0 +1,43 @@ +{ + "hash": 410218696, + "html": { + "start": 0, + "end": 43, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 43, + "type": "Element", + "name": ":Component", + "attributes": [], + "children": [], + "expression": { + "type": "ConditionalExpression", + "start": 13, + "end": 28, + "test": { + "type": "Identifier", + "start": 13, + "end": 16, + "name": "foo" + }, + "consequent": { + "type": "Identifier", + "start": 19, + "end": 22, + "name": "Foo" + }, + "alternate": { + "type": "Identifier", + "start": 25, + "end": 28, + "name": "Bar" + } + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/_actual-v2.json b/test/parser/samples/convert-entities-in-element/_actual-v2.json new file mode 100644 index 000000000000..4946333f3f1d --- /dev/null +++ b/test/parser/samples/convert-entities-in-element/_actual-v2.json @@ -0,0 +1,27 @@ +{ + "hash": "134kmw9", + "html": { + "start": 0, + "end": 24, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 24, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 3, + "end": 20, + "type": "Text", + "data": "Hello & World" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/input-v2.html b/test/parser/samples/convert-entities-in-element/input-v2.html new file mode 100644 index 000000000000..f05dc391ad3e --- /dev/null +++ b/test/parser/samples/convert-entities-in-element/input-v2.html @@ -0,0 +1 @@ +

Hello & World

\ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/output-v2.json b/test/parser/samples/convert-entities-in-element/output-v2.json new file mode 100644 index 000000000000..cb3e50ec3b2c --- /dev/null +++ b/test/parser/samples/convert-entities-in-element/output-v2.json @@ -0,0 +1,27 @@ +{ + "hash": 2365862121, + "html": { + "start": 0, + "end": 24, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 24, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 3, + "end": 20, + "type": "Text", + "data": "Hello & World" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities/_actual-v2.json b/test/parser/samples/convert-entities/_actual-v2.json new file mode 100644 index 000000000000..2a2deedc9951 --- /dev/null +++ b/test/parser/samples/convert-entities/_actual-v2.json @@ -0,0 +1,18 @@ +{ + "hash": "2lbrq0", + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Text", + "data": "Hello & World" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities/input-v2.html b/test/parser/samples/convert-entities/input-v2.html new file mode 100644 index 000000000000..161463ec5858 --- /dev/null +++ b/test/parser/samples/convert-entities/input-v2.html @@ -0,0 +1 @@ +Hello & World \ No newline at end of file diff --git a/test/parser/samples/convert-entities/output-v2.json b/test/parser/samples/convert-entities/output-v2.json new file mode 100644 index 000000000000..479bae306482 --- /dev/null +++ b/test/parser/samples/convert-entities/output-v2.json @@ -0,0 +1,18 @@ +{ + "hash": 156753432, + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Text", + "data": "Hello & World" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/_actual-v2.json b/test/parser/samples/css-ref-selector/_actual-v2.json new file mode 100644 index 000000000000..5edf24cd19bd --- /dev/null +++ b/test/parser/samples/css-ref-selector/_actual-v2.json @@ -0,0 +1,96 @@ +{ + "hash": "i9aush", + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 12, + "type": "Ref", + "name": "foo" + } + ], + "children": [] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 60, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "RefSelector", + "start": 25, + "end": 32, + "name": "foo" + } + ], + "start": 25, + "end": 32 + } + ], + "start": 25, + "end": 32 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 44, + "end": 47 + } + ], + "start": 43, + "end": 47 + }, + "start": 37, + "end": 47 + } + ], + "start": 33, + "end": 51 + }, + "start": 25, + "end": 51 + } + ], + "content": { + "start": 23, + "end": 52, + "styles": "\n\tref:foo {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/input-v2.html b/test/parser/samples/css-ref-selector/input-v2.html new file mode 100644 index 000000000000..696075f93f0c --- /dev/null +++ b/test/parser/samples/css-ref-selector/input-v2.html @@ -0,0 +1,7 @@ +
+ + \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/output-v2.json b/test/parser/samples/css-ref-selector/output-v2.json new file mode 100644 index 000000000000..2ddafc4aae16 --- /dev/null +++ b/test/parser/samples/css-ref-selector/output-v2.json @@ -0,0 +1,96 @@ +{ + "hash": 1104014177, + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 12, + "type": "Ref", + "name": "foo" + } + ], + "children": [] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 60, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "RefSelector", + "start": 25, + "end": 32, + "name": "foo" + } + ], + "start": 25, + "end": 32 + } + ], + "start": 25, + "end": 32 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 44, + "end": 47 + } + ], + "start": 43, + "end": 47 + }, + "start": 37, + "end": 47 + } + ], + "start": 33, + "end": 51 + }, + "start": 25, + "end": 51 + } + ], + "content": { + "start": 23, + "end": 52, + "styles": "\n\tref:foo {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css/_actual-v2.json b/test/parser/samples/css/_actual-v2.json new file mode 100644 index 000000000000..316e6e72a598 --- /dev/null +++ b/test/parser/samples/css/_actual-v2.json @@ -0,0 +1,96 @@ +{ + "hash": "iz4x8b", + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [], + "children": [ + { + "start": 5, + "end": 8, + "type": "Text", + "data": "foo" + } + ] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 56, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "TypeSelector", + "name": "div", + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 40, + "end": 43 + } + ], + "start": 39, + "end": 43 + }, + "start": 33, + "end": 43 + } + ], + "start": 29, + "end": 47 + }, + "start": 25, + "end": 47 + } + ], + "content": { + "start": 23, + "end": 48, + "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css/input-v2.html b/test/parser/samples/css/input-v2.html new file mode 100644 index 000000000000..a573bcf778a3 --- /dev/null +++ b/test/parser/samples/css/input-v2.html @@ -0,0 +1,7 @@ +
foo
+ + \ No newline at end of file diff --git a/test/parser/samples/css/output-v2.json b/test/parser/samples/css/output-v2.json new file mode 100644 index 000000000000..4650ccea46bb --- /dev/null +++ b/test/parser/samples/css/output-v2.json @@ -0,0 +1,96 @@ +{ + "hash": 1147407419, + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [], + "children": [ + { + "start": 5, + "end": 8, + "type": "Text", + "data": "foo" + } + ] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 56, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "TypeSelector", + "name": "div", + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 40, + "end": 43 + } + ], + "start": 39, + "end": 43 + }, + "start": 33, + "end": 43 + } + ], + "start": 29, + "end": 47 + }, + "start": 25, + "end": 47 + } + ], + "content": { + "start": 23, + "end": 48, + "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/dynamic-import/_actual-v2.json b/test/parser/samples/dynamic-import/_actual-v2.json new file mode 100644 index 000000000000..5a1b7b0680bd --- /dev/null +++ b/test/parser/samples/dynamic-import/_actual-v2.json @@ -0,0 +1,182 @@ +{ + "hash": "uvuf1h", + "html": { + "start": null, + "end": null, + "type": "Fragment", + "children": [] + }, + "css": null, + "js": { + "start": 0, + "end": 131, + "attributes": [], + "content": { + "type": "Program", + "start": 8, + "end": 122, + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 10, + "end": 121, + "declaration": { + "type": "ObjectExpression", + "start": 25, + "end": 121, + "properties": [ + { + "type": "Property", + "start": 29, + "end": 118, + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 29, + "end": 37, + "name": "oncreate" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "start": 37, + "end": 118, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 40, + "end": 118, + "body": [ + { + "type": "ExpressionStatement", + "start": 45, + "end": 114, + "expression": { + "type": "CallExpression", + "start": 45, + "end": 113, + "callee": { + "type": "MemberExpression", + "start": 45, + "end": 68, + "object": { + "type": "CallExpression", + "start": 45, + "end": 63, + "callee": { + "type": "Import", + "start": 45, + "end": 51 + }, + "arguments": [ + { + "type": "Literal", + "start": 52, + "end": 62, + "value": "./foo.js", + "raw": "'./foo.js'" + } + ] + }, + "property": { + "type": "Identifier", + "start": 64, + "end": 68, + "name": "then" + }, + "computed": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 69, + "end": 112, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 69, + "end": 72, + "name": "foo" + } + ], + "body": { + "type": "BlockStatement", + "start": 76, + "end": 112, + "body": [ + { + "type": "ExpressionStatement", + "start": 82, + "end": 107, + "expression": { + "type": "CallExpression", + "start": 82, + "end": 106, + "callee": { + "type": "MemberExpression", + "start": 82, + "end": 93, + "object": { + "type": "Identifier", + "start": 82, + "end": 89, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 90, + "end": 93, + "name": "log" + }, + "computed": false + }, + "arguments": [ + { + "type": "MemberExpression", + "start": 94, + "end": 105, + "object": { + "type": "Identifier", + "start": 94, + "end": 97, + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 98, + "end": 105, + "name": "default" + }, + "computed": false + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } + } + ] + } + } + ], + "sourceType": "module" + } + } +} \ No newline at end of file diff --git a/test/parser/samples/dynamic-import/input-v2.html b/test/parser/samples/dynamic-import/input-v2.html new file mode 100644 index 000000000000..553ca6c38c5d --- /dev/null +++ b/test/parser/samples/dynamic-import/input-v2.html @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/test/parser/samples/dynamic-import/output-v2.json b/test/parser/samples/dynamic-import/output-v2.json new file mode 100644 index 000000000000..b27a780a58e4 --- /dev/null +++ b/test/parser/samples/dynamic-import/output-v2.json @@ -0,0 +1,182 @@ +{ + "hash": 1867472549, + "html": { + "start": null, + "end": null, + "type": "Fragment", + "children": [] + }, + "css": null, + "js": { + "start": 0, + "end": 131, + "attributes": [], + "content": { + "type": "Program", + "start": 8, + "end": 122, + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 10, + "end": 121, + "declaration": { + "type": "ObjectExpression", + "start": 25, + "end": 121, + "properties": [ + { + "type": "Property", + "start": 29, + "end": 118, + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 29, + "end": 37, + "name": "oncreate" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "start": 37, + "end": 118, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 40, + "end": 118, + "body": [ + { + "type": "ExpressionStatement", + "start": 45, + "end": 114, + "expression": { + "type": "CallExpression", + "start": 45, + "end": 113, + "callee": { + "type": "MemberExpression", + "start": 45, + "end": 68, + "object": { + "type": "CallExpression", + "start": 45, + "end": 63, + "callee": { + "type": "Import", + "start": 45, + "end": 51 + }, + "arguments": [ + { + "type": "Literal", + "start": 52, + "end": 62, + "value": "./foo.js", + "raw": "'./foo.js'" + } + ] + }, + "property": { + "type": "Identifier", + "start": 64, + "end": 68, + "name": "then" + }, + "computed": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 69, + "end": 112, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 69, + "end": 72, + "name": "foo" + } + ], + "body": { + "type": "BlockStatement", + "start": 76, + "end": 112, + "body": [ + { + "type": "ExpressionStatement", + "start": 82, + "end": 107, + "expression": { + "type": "CallExpression", + "start": 82, + "end": 106, + "callee": { + "type": "MemberExpression", + "start": 82, + "end": 93, + "object": { + "type": "Identifier", + "start": 82, + "end": 89, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 90, + "end": 93, + "name": "log" + }, + "computed": false + }, + "arguments": [ + { + "type": "MemberExpression", + "start": 94, + "end": 105, + "object": { + "type": "Identifier", + "start": 94, + "end": 97, + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 98, + "end": 105, + "name": "default" + }, + "computed": false + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } + } + ] + } + } + ], + "sourceType": "module" + } + } +} \ No newline at end of file diff --git a/test/parser/samples/each-block-destructured/_actual-v2.json b/test/parser/samples/each-block-destructured/_actual-v2.json new file mode 100644 index 000000000000..97b69a5730f3 --- /dev/null +++ b/test/parser/samples/each-block-destructured/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "gtdm5e", + "html": { + "start": 0, + "end": 62, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 33, + "type": "Text", + "data": "{#each animals as [key, value]}\n\t" + }, + { + "start": 33, + "end": 54, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 36, + "end": 50, + "type": "Text", + "data": "{key}: {value}" + } + ] + }, + { + "start": 54, + "end": 62, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-destructured/input-v2.html b/test/parser/samples/each-block-destructured/input-v2.html new file mode 100644 index 000000000000..4ddf33ef8585 --- /dev/null +++ b/test/parser/samples/each-block-destructured/input-v2.html @@ -0,0 +1,3 @@ +{#each animals as [key, value]} +

{key}: {value}

+{/each} diff --git a/test/parser/samples/each-block-destructured/output-v2.json b/test/parser/samples/each-block-destructured/output-v2.json new file mode 100644 index 000000000000..897fec88b82a --- /dev/null +++ b/test/parser/samples/each-block-destructured/output-v2.json @@ -0,0 +1,67 @@ +{ + "hash": 2621498076, + "html": { + "start": 0, + "end": 70, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 70, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 35, + "end": 60, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 38, + "end": 45, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 40, + "end": 43, + "name": "key" + } + }, + { + "start": 45, + "end": 47, + "type": "Text", + "data": ": " + }, + { + "start": 47, + "end": 56, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 49, + "end": 54, + "name": "value" + } + } + ] + } + ], + "destructuredContexts": [ + "key", + "value" + ], + "context": "key_value" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-else/_actual-v2.json b/test/parser/samples/each-block-else/_actual-v2.json new file mode 100644 index 000000000000..af7b618bf8e0 --- /dev/null +++ b/test/parser/samples/each-block-else/_actual-v2.json @@ -0,0 +1,60 @@ +{ + "hash": "ljl07n", + "html": { + "start": 0, + "end": 77, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 27, + "type": "Text", + "data": "{#each animals as animal}\n\t" + }, + { + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "Text", + "data": "{animal}" + } + ] + }, + { + "start": 42, + "end": 52, + "type": "Text", + "data": "\n{:else}\n\t" + }, + { + "start": 52, + "end": 69, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 55, + "end": 65, + "type": "Text", + "data": "no animals" + } + ] + }, + { + "start": 69, + "end": 77, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-else/input-v2.html b/test/parser/samples/each-block-else/input-v2.html new file mode 100644 index 000000000000..dc96d8b946be --- /dev/null +++ b/test/parser/samples/each-block-else/input-v2.html @@ -0,0 +1,5 @@ +{#each animals as animal} +

{animal}

+{:else} +

no animals

+{/each} diff --git a/test/parser/samples/each-block-else/output-v2.json b/test/parser/samples/each-block-else/output-v2.json new file mode 100644 index 000000000000..0dadad5f650f --- /dev/null +++ b/test/parser/samples/each-block-else/output-v2.json @@ -0,0 +1,68 @@ +{ + "hash": 3238289871, + "html": { + "start": 0, + "end": 84, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 84, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 29, + "end": 46, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 42, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 40, + "name": "animal" + } + } + ] + } + ], + "context": "animal", + "else": { + "start": 55, + "end": 75, + "type": "ElseBlock", + "children": [ + { + "start": 57, + "end": 74, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 60, + "end": 70, + "type": "Text", + "data": "no animals" + } + ] + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/_actual-v2.json b/test/parser/samples/each-block-indexed/_actual-v2.json new file mode 100644 index 000000000000..576bc5301403 --- /dev/null +++ b/test/parser/samples/each-block-indexed/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "1143n2g", + "html": { + "start": 0, + "end": 58, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 30, + "type": "Text", + "data": "{#each animals as animal, i}\n\t" + }, + { + "start": 30, + "end": 50, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 33, + "end": 46, + "type": "Text", + "data": "{i}: {animal}" + } + ] + }, + { + "start": 50, + "end": 58, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/input-v2.html b/test/parser/samples/each-block-indexed/input-v2.html new file mode 100644 index 000000000000..d5602ec82c06 --- /dev/null +++ b/test/parser/samples/each-block-indexed/input-v2.html @@ -0,0 +1,3 @@ +{#each animals as animal, i} +

{i}: {animal}

+{/each} diff --git a/test/parser/samples/each-block-indexed/output-v2.json b/test/parser/samples/each-block-indexed/output-v2.json new file mode 100644 index 000000000000..fc8954d6ad96 --- /dev/null +++ b/test/parser/samples/each-block-indexed/output-v2.json @@ -0,0 +1,64 @@ +{ + "hash": 2841674990, + "html": { + "start": 0, + "end": 66, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 66, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 32, + "end": 56, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 35, + "end": 40, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 37, + "end": 38, + "name": "i" + } + }, + { + "start": 40, + "end": 42, + "type": "Text", + "data": ": " + }, + { + "start": 42, + "end": 52, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 44, + "end": 50, + "name": "animal" + } + } + ] + } + ], + "context": "animal", + "index": "i" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/_actual-v2.json b/test/parser/samples/each-block-keyed/_actual-v2.json new file mode 100644 index 000000000000..c039c98ce95a --- /dev/null +++ b/test/parser/samples/each-block-keyed/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "3sm0ec", + "html": { + "start": 0, + "end": 56, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Text", + "data": "{#each todos as todo key todo.id}\n\t" + }, + { + "start": 35, + "end": 48, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 38, + "end": 44, + "type": "Text", + "data": "{todo}" + } + ] + }, + { + "start": 48, + "end": 56, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/input-v2.html b/test/parser/samples/each-block-keyed/input-v2.html new file mode 100644 index 000000000000..3cc00ce93e39 --- /dev/null +++ b/test/parser/samples/each-block-keyed/input-v2.html @@ -0,0 +1,3 @@ +{#each todos as todo key todo.id} +

{todo}

+{/each} diff --git a/test/parser/samples/each-block-keyed/output-v2.json b/test/parser/samples/each-block-keyed/output-v2.json new file mode 100644 index 000000000000..1a16afb82b31 --- /dev/null +++ b/test/parser/samples/each-block-keyed/output-v2.json @@ -0,0 +1,47 @@ +{ + "hash": 2025411181, + "html": { + "start": 0, + "end": 54, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 54, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 13, + "name": "todos" + }, + "children": [ + { + "start": 29, + "end": 44, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 40, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 38, + "name": "todo" + } + } + ] + } + ], + "context": "todo", + "key": "id" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block/_actual-v2.json b/test/parser/samples/each-block/_actual-v2.json new file mode 100644 index 000000000000..314ef918a50c --- /dev/null +++ b/test/parser/samples/each-block/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "mzeq0s", + "html": { + "start": 0, + "end": 50, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 27, + "type": "Text", + "data": "{#each animals as animal}\n\t" + }, + { + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "Text", + "data": "{animal}" + } + ] + }, + { + "start": 42, + "end": 50, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block/input-v2.html b/test/parser/samples/each-block/input-v2.html new file mode 100644 index 000000000000..83a5e88ddd2a --- /dev/null +++ b/test/parser/samples/each-block/input-v2.html @@ -0,0 +1,3 @@ +{#each animals as animal} +

{animal}

+{/each} diff --git a/test/parser/samples/each-block/output-v2.json b/test/parser/samples/each-block/output-v2.json new file mode 100644 index 000000000000..e549faca3953 --- /dev/null +++ b/test/parser/samples/each-block/output-v2.json @@ -0,0 +1,46 @@ +{ + "hash": 220340986, + "html": { + "start": 0, + "end": 56, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 56, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 29, + "end": 46, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 42, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 40, + "name": "animal" + } + } + ] + } + ], + "context": "animal" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/_actual-v2.json b/test/parser/samples/element-with-mustache/_actual-v2.json new file mode 100644 index 000000000000..a65459a200a8 --- /dev/null +++ b/test/parser/samples/element-with-mustache/_actual-v2.json @@ -0,0 +1,44 @@ +{ + "hash": "9fs56", + "html": { + "start": 0, + "end": 22, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 22, + "type": "Element", + "name": "h1", + "attributes": [], + "children": [ + { + "start": 4, + "end": 10, + "type": "Text", + "data": "hello " + }, + { + "start": 10, + "end": 16, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 11, + "end": 15, + "name": "name" + } + }, + { + "start": 16, + "end": 17, + "type": "Text", + "data": "!" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/input-v2.html b/test/parser/samples/element-with-mustache/input-v2.html new file mode 100644 index 000000000000..1e9232da02fd --- /dev/null +++ b/test/parser/samples/element-with-mustache/input-v2.html @@ -0,0 +1 @@ +

hello {name}!

diff --git a/test/parser/samples/element-with-mustache/output-v2.json b/test/parser/samples/element-with-mustache/output-v2.json new file mode 100644 index 000000000000..76e71dc3278f --- /dev/null +++ b/test/parser/samples/element-with-mustache/output-v2.json @@ -0,0 +1,44 @@ +{ + "hash": 1265376132, + "html": { + "start": 0, + "end": 22, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 22, + "type": "Element", + "name": "h1", + "attributes": [], + "children": [ + { + "start": 4, + "end": 10, + "type": "Text", + "data": "hello " + }, + { + "start": 10, + "end": 16, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 11, + "end": 15, + "name": "name" + } + }, + { + "start": 16, + "end": 17, + "type": "Text", + "data": "!" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-text/_actual-v2.json b/test/parser/samples/element-with-text/_actual-v2.json new file mode 100644 index 000000000000..ee940e82e7df --- /dev/null +++ b/test/parser/samples/element-with-text/_actual-v2.json @@ -0,0 +1,27 @@ +{ + "hash": "a3xqjm", + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Element", + "name": "span", + "attributes": [], + "children": [ + { + "start": 6, + "end": 10, + "type": "Text", + "data": "test" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-text/input-v2.html b/test/parser/samples/element-with-text/input-v2.html new file mode 100644 index 000000000000..fcf3199655df --- /dev/null +++ b/test/parser/samples/element-with-text/input-v2.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/parser/samples/element-with-text/output-v2.json b/test/parser/samples/element-with-text/output-v2.json new file mode 100644 index 000000000000..22cae35547ca --- /dev/null +++ b/test/parser/samples/element-with-text/output-v2.json @@ -0,0 +1,27 @@ +{ + "hash": 611274658, + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Element", + "name": "span", + "attributes": [], + "children": [ + { + "start": 6, + "end": 10, + "type": "Text", + "data": "test" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/elements/_actual-v2.json b/test/parser/samples/elements/_actual-v2.json new file mode 100644 index 000000000000..14de5ea00d40 --- /dev/null +++ b/test/parser/samples/elements/_actual-v2.json @@ -0,0 +1,28 @@ +{ + "hash": "dni3s5", + "html": { + "start": 0, + "end": 15, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 15, + "type": "Element", + "name": "!doctype", + "attributes": [ + { + "start": 10, + "end": 14, + "type": "Attribute", + "name": "html", + "value": true + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/elements/input-v2.html b/test/parser/samples/elements/input-v2.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/test/parser/samples/elements/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/elements/output-v2.json b/test/parser/samples/elements/output-v2.json new file mode 100644 index 000000000000..7b4e6bffe12e --- /dev/null +++ b/test/parser/samples/elements/output-v2.json @@ -0,0 +1,28 @@ +{ + "hash": 825536165, + "html": { + "start": 0, + "end": 15, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 15, + "type": "Element", + "name": "!doctype", + "attributes": [ + { + "start": 10, + "end": 14, + "type": "Attribute", + "name": "html", + "value": true + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/error-binding-disabled/input-v2.html b/test/parser/samples/error-binding-disabled/input-v2.html new file mode 100644 index 000000000000..3af20a9ced1b --- /dev/null +++ b/test/parser/samples/error-binding-disabled/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/error-binding-mustaches/input-v2.html b/test/parser/samples/error-binding-mustaches/input-v2.html new file mode 100644 index 000000000000..2629696c9ec8 --- /dev/null +++ b/test/parser/samples/error-binding-mustaches/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/error-binding-rvalue/input-v2.html b/test/parser/samples/error-binding-rvalue/input-v2.html new file mode 100644 index 000000000000..0b1f716c237e --- /dev/null +++ b/test/parser/samples/error-binding-rvalue/input-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/parser/samples/error-comment-unclosed/input-v2.html b/test/parser/samples/error-comment-unclosed/input-v2.html new file mode 100644 index 000000000000..fe6d748e1b04 --- /dev/null +++ b/test/parser/samples/error-comment-unclosed/input-v2.html @@ -0,0 +1 @@ +", + "loc": { + "line": 1, + "column": 24 + }, + "pos": 24 +} diff --git a/test/parser/samples/error-css/error-v2.json b/test/parser/samples/error-css/error-v2.json new file mode 100644 index 000000000000..177f6d977f90 --- /dev/null +++ b/test/parser/samples/error-css/error-v2.json @@ -0,0 +1,8 @@ +{ + "message": "LeftCurlyBracket is expected", + "loc": { + "line": 2, + "column": 16 + }, + "pos": 24 +} diff --git a/test/parser/samples/error-event-handler/error-v2.json b/test/parser/samples/error-event-handler/error-v2.json new file mode 100644 index 000000000000..f5e603b06af0 --- /dev/null +++ b/test/parser/samples/error-event-handler/error-v2.json @@ -0,0 +1,8 @@ +{ + "message": "Expected a method call", + "loc": { + "line": 1, + "column": 15 + }, + "pos": 15 +} \ No newline at end of file diff --git a/test/parser/samples/error-illegal-expression/error-v2.json b/test/parser/samples/error-illegal-expression/error-v2.json new file mode 100644 index 000000000000..b0b557202c35 --- /dev/null +++ b/test/parser/samples/error-illegal-expression/error-v2.json @@ -0,0 +1,8 @@ +{ + "message": "Assigning to rvalue", + "loc": { + "line": 1, + "column": 1 + }, + "pos": 1 +} diff --git a/test/parser/samples/error-multiple-styles/error-v2.json b/test/parser/samples/error-multiple-styles/error-v2.json new file mode 100644 index 000000000000..421c5558a77b --- /dev/null +++ b/test/parser/samples/error-multiple-styles/error-v2.json @@ -0,0 +1,8 @@ +{ + "message": "You can only have one top-level + + + + + + + + \ No newline at end of file diff --git a/test/js/samples/deconflict-builtins/_actual-bundle-v2.js b/test/js/samples/deconflict-builtins/_actual-bundle-v2.js new file mode 100644 index 000000000000..6680adfdb427 --- /dev/null +++ b/test/js/samples/deconflict-builtins/_actual-bundle-v2.js @@ -0,0 +1,317 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function destroyEach(iterations) { + for (var i = 0; i < iterations.length; i += 1) { + if (iterations[i]) iterations[i].d(); + } +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var each_anchor; + + var each_value = state.createElement; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + each_anchor = createComment(); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(each_anchor, target, anchor); + }, + + p: function update(changed, state) { + var each_value = state.createElement; + + if (changed.createElement) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(each_anchor.parentNode, each_anchor); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(each_anchor); + }, + + d: function destroy$$1() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each createElement as node} +function create_each_block(component, state) { + var node = state.node, each_value = state.each_value, node_index = state.node_index; + var span, text_value = node, text; + + return { + c: function create() { + span = createElement("span"); + text = createText(text_value); + }, + + m: function mount(target, anchor) { + insertNode(span, target, anchor); + appendNode(text, span); + }, + + p: function update(changed, state) { + node = state.node; + each_value = state.each_value; + node_index = state.node_index; + if ((changed.createElement) && text_value !== (text_value = node)) { + text.data = text_value; + } + }, + + u: function unmount() { + detachNode(span); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/deconflict-builtins/expected-bundle-v2.js b/test/js/samples/deconflict-builtins/expected-bundle-v2.js new file mode 100644 index 000000000000..6680adfdb427 --- /dev/null +++ b/test/js/samples/deconflict-builtins/expected-bundle-v2.js @@ -0,0 +1,317 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function destroyEach(iterations) { + for (var i = 0; i < iterations.length; i += 1) { + if (iterations[i]) iterations[i].d(); + } +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var each_anchor; + + var each_value = state.createElement; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + each_anchor = createComment(); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(each_anchor, target, anchor); + }, + + p: function update(changed, state) { + var each_value = state.createElement; + + if (changed.createElement) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(each_anchor.parentNode, each_anchor); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(each_anchor); + }, + + d: function destroy$$1() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each createElement as node} +function create_each_block(component, state) { + var node = state.node, each_value = state.each_value, node_index = state.node_index; + var span, text_value = node, text; + + return { + c: function create() { + span = createElement("span"); + text = createText(text_value); + }, + + m: function mount(target, anchor) { + insertNode(span, target, anchor); + appendNode(text, span); + }, + + p: function update(changed, state) { + node = state.node; + each_value = state.each_value; + node_index = state.node_index; + if ((changed.createElement) && text_value !== (text_value = node)) { + text.data = text_value; + } + }, + + u: function unmount() { + detachNode(span); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/deconflict-builtins/expected-v2.js b/test/js/samples/deconflict-builtins/expected-v2.js new file mode 100644 index 000000000000..f6861d255714 --- /dev/null +++ b/test/js/samples/deconflict-builtins/expected-v2.js @@ -0,0 +1,124 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createComment, createElement, createText, destroyEach, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var each_anchor; + + var each_value = state.createElement; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + each_anchor = createComment(); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(each_anchor, target, anchor); + }, + + p: function update(changed, state) { + var each_value = state.createElement; + + if (changed.createElement) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + node: each_value[i], + node_index: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(each_anchor.parentNode, each_anchor); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(each_anchor); + }, + + d: function destroy() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each createElement as node} +function create_each_block(component, state) { + var node = state.node, each_value = state.each_value, node_index = state.node_index; + var span, text_value = node, text; + + return { + c: function create() { + span = createElement("span"); + text = createText(text_value); + }, + + m: function mount(target, anchor) { + insertNode(span, target, anchor); + appendNode(text, span); + }, + + p: function update(changed, state) { + node = state.node; + each_value = state.each_value; + node_index = state.node_index; + if ((changed.createElement) && text_value !== (text_value = node)) { + text.data = text_value; + } + }, + + u: function unmount() { + detachNode(span); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/deconflict-builtins/input-v2.html b/test/js/samples/deconflict-builtins/input-v2.html new file mode 100644 index 000000000000..48a413b32353 --- /dev/null +++ b/test/js/samples/deconflict-builtins/input-v2.html @@ -0,0 +1,3 @@ +{#each createElement as node} + {node} +{/each} \ No newline at end of file diff --git a/test/js/samples/dev-warning-missing-data-computed/_actual-bundle-v2.js b/test/js/samples/dev-warning-missing-data-computed/_actual-bundle-v2.js new file mode 100644 index 000000000000..84a148c901d5 --- /dev/null +++ b/test/js/samples/dev-warning-missing-data-computed/_actual-bundle-v2.js @@ -0,0 +1,298 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function destroyDev(detach) { + destroy.call(this, detach); + this.destroy = function() { + console.warn('Component was already destroyed'); + }; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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 observeDev(key, callback, options) { + var c = (key = '' + key).search(/[.[]/); + if (c > -1) { + var message = + 'The first argument to component.observe(...) must be the name of a top-level property'; + if (c > 0) + message += ", i.e. '" + key.slice(0, c) + "' rather than '" + key + "'"; + + throw new Error(message); + } + + return observe.call(this, key, callback, options); +} + +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 onDev(eventName, handler) { + if (eventName === 'teardown') { + console.warn( + "Use component.on('destroy', ...) instead of component.on('teardown', ...) which has been deprecated and will be unsupported in Svelte 2" + ); + return this.on('destroy', handler); + } + + return on.call(this, eventName, handler); +} + +function set(newState) { + this._set(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function setDev(newState) { + if (typeof newState !== 'object') { + throw new Error( + this._debugName + '.set was called without an object of data key-values to update.' + ); + } + + this._checkReadOnly(newState); + set.call(this, newState); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var protoDev = { + destroy: destroyDev, + get: get, + fire: fire, + observe: observeDev, + on: onDev, + set: setDev, + teardown: destroyDev, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function bar(foo) { + return foo * 2; +} + +function create_main_fragment(component, state) { + var p, text_value = state.Math.max(0, state.foo), text, text_1, text_2; + + return { + c: function create() { + p = createElement("p"); + text = createText(text_value); + text_1 = createText("\n\t"); + text_2 = createText(state.bar); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + appendNode(text_2, p); + }, + + p: function update(changed, state) { + if ((changed.Math || changed.foo) && text_value !== (text_value = state.Math.max(0, state.foo))) { + text.data = text_value; + } + + if (changed.bar) { + text_2.data = state.bar; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + this._debugName = ''; + if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + init(this, options); + this._state = assign({ Math : Math }, options.data); + this._recompute({ foo: 1 }, this._state); + if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'"); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, protoDev); + +SvelteComponent.prototype._checkReadOnly = function _checkReadOnly(newState) { + if ('bar' in newState && !this._updatingReadonlyProperty) throw new Error(": Cannot set read-only property 'bar'"); +}; + +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.foo) { + if (this._differs(state.bar, (state.bar = bar(state.foo)))) changed.bar = true; + } +}; + +export default SvelteComponent; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected-bundle-v2.js b/test/js/samples/dev-warning-missing-data-computed/expected-bundle-v2.js new file mode 100644 index 000000000000..84a148c901d5 --- /dev/null +++ b/test/js/samples/dev-warning-missing-data-computed/expected-bundle-v2.js @@ -0,0 +1,298 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function destroyDev(detach) { + destroy.call(this, detach); + this.destroy = function() { + console.warn('Component was already destroyed'); + }; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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 observeDev(key, callback, options) { + var c = (key = '' + key).search(/[.[]/); + if (c > -1) { + var message = + 'The first argument to component.observe(...) must be the name of a top-level property'; + if (c > 0) + message += ", i.e. '" + key.slice(0, c) + "' rather than '" + key + "'"; + + throw new Error(message); + } + + return observe.call(this, key, callback, options); +} + +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 onDev(eventName, handler) { + if (eventName === 'teardown') { + console.warn( + "Use component.on('destroy', ...) instead of component.on('teardown', ...) which has been deprecated and will be unsupported in Svelte 2" + ); + return this.on('destroy', handler); + } + + return on.call(this, eventName, handler); +} + +function set(newState) { + this._set(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function setDev(newState) { + if (typeof newState !== 'object') { + throw new Error( + this._debugName + '.set was called without an object of data key-values to update.' + ); + } + + this._checkReadOnly(newState); + set.call(this, newState); +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var protoDev = { + destroy: destroyDev, + get: get, + fire: fire, + observe: observeDev, + on: onDev, + set: setDev, + teardown: destroyDev, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function bar(foo) { + return foo * 2; +} + +function create_main_fragment(component, state) { + var p, text_value = state.Math.max(0, state.foo), text, text_1, text_2; + + return { + c: function create() { + p = createElement("p"); + text = createText(text_value); + text_1 = createText("\n\t"); + text_2 = createText(state.bar); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + appendNode(text_2, p); + }, + + p: function update(changed, state) { + if ((changed.Math || changed.foo) && text_value !== (text_value = state.Math.max(0, state.foo))) { + text.data = text_value; + } + + if (changed.bar) { + text_2.data = state.bar; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + this._debugName = ''; + if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + init(this, options); + this._state = assign({ Math : Math }, options.data); + this._recompute({ foo: 1 }, this._state); + if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'"); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, protoDev); + +SvelteComponent.prototype._checkReadOnly = function _checkReadOnly(newState) { + if ('bar' in newState && !this._updatingReadonlyProperty) throw new Error(": Cannot set read-only property 'bar'"); +}; + +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.foo) { + if (this._differs(state.bar, (state.bar = bar(state.foo)))) changed.bar = true; + } +}; + +export default SvelteComponent; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected-v2.js b/test/js/samples/dev-warning-missing-data-computed/expected-v2.js new file mode 100644 index 000000000000..edf4331457b6 --- /dev/null +++ b/test/js/samples/dev-warning-missing-data-computed/expected-v2.js @@ -0,0 +1,72 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, protoDev } from "svelte/shared.js"; + +function bar(foo) { + return foo * 2; +} + +function create_main_fragment(component, state) { + var p, text_value = state.Math.max(0, state.foo), text, text_1, text_2; + + return { + c: function create() { + p = createElement("p"); + text = createText(text_value); + text_1 = createText("\n\t"); + text_2 = createText(state.bar); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + appendNode(text_2, p); + }, + + p: function update(changed, state) { + if ((changed.Math || changed.foo) && text_value !== (text_value = state.Math.max(0, state.foo))) { + text.data = text_value; + } + + if (changed.bar) { + text_2.data = state.bar; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + this._debugName = ''; + if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); + init(this, options); + this._state = assign({ Math : Math }, options.data); + this._recompute({ foo: 1 }, this._state); + if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'"); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, protoDev); + +SvelteComponent.prototype._checkReadOnly = function _checkReadOnly(newState) { + if ('bar' in newState && !this._updatingReadonlyProperty) throw new Error(": Cannot set read-only property 'bar'"); +}; + +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.foo) { + if (this._differs(state.bar, (state.bar = bar(state.foo)))) changed.bar = true; + } +} +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/dev-warning-missing-data-computed/input-v2.html b/test/js/samples/dev-warning-missing-data-computed/input-v2.html new file mode 100644 index 000000000000..3fbf45860e7a --- /dev/null +++ b/test/js/samples/dev-warning-missing-data-computed/input-v2.html @@ -0,0 +1,12 @@ +

+ {Math.max(0, foo)} + {bar} +

+ + \ No newline at end of file diff --git a/test/js/samples/do-use-dataset/_actual-bundle-v2.js b/test/js/samples/do-use-dataset/_actual-bundle-v2.js new file mode 100644 index 000000000000..883194110d60 --- /dev/null +++ b/test/js/samples/do-use-dataset/_actual-bundle-v2.js @@ -0,0 +1,234 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.dataset.foo = "bar"; + div_1.dataset.foo = state.bar; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + div_1.dataset.foo = state.bar; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/do-use-dataset/expected-bundle-v2.js b/test/js/samples/do-use-dataset/expected-bundle-v2.js new file mode 100644 index 000000000000..883194110d60 --- /dev/null +++ b/test/js/samples/do-use-dataset/expected-bundle-v2.js @@ -0,0 +1,234 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.dataset.foo = "bar"; + div_1.dataset.foo = state.bar; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + div_1.dataset.foo = state.bar; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/do-use-dataset/expected-v2.js b/test/js/samples/do-use-dataset/expected-v2.js new file mode 100644 index 000000000000..b88636a606d5 --- /dev/null +++ b/test/js/samples/do-use-dataset/expected-v2.js @@ -0,0 +1,55 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.dataset.foo = "bar"; + div_1.dataset.foo = state.bar; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + div_1.dataset.foo = state.bar; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/do-use-dataset/input-v2.html b/test/js/samples/do-use-dataset/input-v2.html new file mode 100644 index 000000000000..fcd821731e49 --- /dev/null +++ b/test/js/samples/do-use-dataset/input-v2.html @@ -0,0 +1,2 @@ +
+
diff --git a/test/js/samples/dont-use-dataset-in-legacy/_actual-bundle-v2.js b/test/js/samples/dont-use-dataset-in-legacy/_actual-bundle-v2.js new file mode 100644 index 000000000000..1e231ec05680 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-legacy/_actual-bundle-v2.js @@ -0,0 +1,238 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function setAttribute(node, attribute, value) { + node.setAttribute(attribute, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setAttribute(div, "data-foo", "bar"); + setAttribute(div_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(div_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle-v2.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle-v2.js new file mode 100644 index 000000000000..1e231ec05680 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle-v2.js @@ -0,0 +1,238 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function setAttribute(node, attribute, value) { + node.setAttribute(attribute, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setAttribute(div, "data-foo", "bar"); + setAttribute(div_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(div_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-v2.js b/test/js/samples/dont-use-dataset-in-legacy/expected-v2.js new file mode 100644 index 000000000000..699da1270b87 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-v2.js @@ -0,0 +1,55 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div, text, div_1; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setAttribute(div, "data-foo", "bar"); + setAttribute(div_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(div_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/dont-use-dataset-in-legacy/input-v2.html b/test/js/samples/dont-use-dataset-in-legacy/input-v2.html new file mode 100644 index 000000000000..fcd821731e49 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-legacy/input-v2.html @@ -0,0 +1,2 @@ +
+
diff --git a/test/js/samples/dont-use-dataset-in-svg/_actual-bundle-v2.js b/test/js/samples/dont-use-dataset-in-svg/_actual-bundle-v2.js new file mode 100644 index 000000000000..0b60ba22e2e4 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-svg/_actual-bundle-v2.js @@ -0,0 +1,236 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createSvgElement(name) { + return document.createElementNS('http://www.w3.org/2000/svg', name); +} + +function setAttribute(node, attribute, value) { + node.setAttribute(attribute, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var svg, g, g_1; + + return { + c: function create() { + svg = createSvgElement("svg"); + g = createSvgElement("g"); + g_1 = createSvgElement("g"); + this.h(); + }, + + h: function hydrate() { + setAttribute(g, "data-foo", "bar"); + setAttribute(g_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(svg, target, anchor); + appendNode(g, svg); + appendNode(g_1, svg); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(g_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(svg); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-bundle-v2.js b/test/js/samples/dont-use-dataset-in-svg/expected-bundle-v2.js new file mode 100644 index 000000000000..0b60ba22e2e4 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-svg/expected-bundle-v2.js @@ -0,0 +1,236 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createSvgElement(name) { + return document.createElementNS('http://www.w3.org/2000/svg', name); +} + +function setAttribute(node, attribute, value) { + node.setAttribute(attribute, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var svg, g, g_1; + + return { + c: function create() { + svg = createSvgElement("svg"); + g = createSvgElement("g"); + g_1 = createSvgElement("g"); + this.h(); + }, + + h: function hydrate() { + setAttribute(g, "data-foo", "bar"); + setAttribute(g_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(svg, target, anchor); + appendNode(g, svg); + appendNode(g_1, svg); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(g_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(svg); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-v2.js b/test/js/samples/dont-use-dataset-in-svg/expected-v2.js new file mode 100644 index 000000000000..42693672549b --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-svg/expected-v2.js @@ -0,0 +1,53 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createSvgElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var svg, g, g_1; + + return { + c: function create() { + svg = createSvgElement("svg"); + g = createSvgElement("g"); + g_1 = createSvgElement("g"); + this.h(); + }, + + h: function hydrate() { + setAttribute(g, "data-foo", "bar"); + setAttribute(g_1, "data-foo", state.bar); + }, + + m: function mount(target, anchor) { + insertNode(svg, target, anchor); + appendNode(g, svg); + appendNode(g_1, svg); + }, + + p: function update(changed, state) { + if (changed.bar) { + setAttribute(g_1, "data-foo", state.bar); + } + }, + + u: function unmount() { + detachNode(svg); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/dont-use-dataset-in-svg/input-v2.html b/test/js/samples/dont-use-dataset-in-svg/input-v2.html new file mode 100644 index 000000000000..3032322b8010 --- /dev/null +++ b/test/js/samples/dont-use-dataset-in-svg/input-v2.html @@ -0,0 +1,4 @@ + + + + diff --git a/test/js/samples/each-block-changed-check/_actual-bundle-v2.js b/test/js/samples/each-block-changed-check/_actual-bundle-v2.js new file mode 100644 index 000000000000..1ce468ca12c1 --- /dev/null +++ b/test/js/samples/each-block-changed-check/_actual-bundle-v2.js @@ -0,0 +1,364 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function detachAfter(before) { + while (before.nextSibling) { + before.parentNode.removeChild(before.nextSibling); + } +} + +function destroyEach(iterations) { + for (var i = 0; i < iterations.length; i += 1) { + if (iterations[i]) iterations[i].d(); + } +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var text, p, text_1; + + var each_value = state.comments; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + var each_value = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(text.parentNode, text); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + + if (changed.foo) { + text_1.data = state.foo; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(text); + detachNode(p); + }, + + d: function destroy$$1() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each comments as comment, i} +function create_each_block(component, state) { + var comment = state.comment, each_value = state.each_value, i = state.i; + var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; + + return { + c: function create() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.h(); + }, + + h: function hydrate() { + span.className = "meta"; + div.className = "comment"; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, + + p: function update(changed, state) { + comment = state.comment; + each_value = state.each_value; + i = state.i; + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { + text_2.data = text_2_value; + } + + if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) { + text_4.data = text_4_value; + } + + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { + detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, + + u: function unmount() { + detachAfter(raw_before); + + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/each-block-changed-check/expected-bundle-v2.js b/test/js/samples/each-block-changed-check/expected-bundle-v2.js new file mode 100644 index 000000000000..1ce468ca12c1 --- /dev/null +++ b/test/js/samples/each-block-changed-check/expected-bundle-v2.js @@ -0,0 +1,364 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function detachAfter(before) { + while (before.nextSibling) { + before.parentNode.removeChild(before.nextSibling); + } +} + +function destroyEach(iterations) { + for (var i = 0; i < iterations.length; i += 1) { + if (iterations[i]) iterations[i].d(); + } +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var text, p, text_1; + + var each_value = state.comments; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + var each_value = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(text.parentNode, text); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + + if (changed.foo) { + text_1.data = state.foo; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(text); + detachNode(p); + }, + + d: function destroy$$1() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each comments as comment, i} +function create_each_block(component, state) { + var comment = state.comment, each_value = state.each_value, i = state.i; + var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; + + return { + c: function create() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.h(); + }, + + h: function hydrate() { + span.className = "meta"; + div.className = "comment"; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, + + p: function update(changed, state) { + comment = state.comment; + each_value = state.each_value; + i = state.i; + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { + text_2.data = text_2_value; + } + + if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) { + text_4.data = text_4_value; + } + + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { + detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, + + u: function unmount() { + detachAfter(raw_before); + + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/each-block-changed-check/expected-v2.js b/test/js/samples/each-block-changed-check/expected-v2.js new file mode 100644 index 000000000000..e7e0ccca306f --- /dev/null +++ b/test/js/samples/each-block-changed-check/expected-v2.js @@ -0,0 +1,169 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var text, p, text_1; + + var each_value = state.comments; + + var each_blocks = []; + + for (var i = 0; i < each_value.length; i += 1) { + each_blocks[i] = create_each_block(component, assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + })); + } + + return { + c: function create() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, + + m: function mount(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].m(target, anchor); + } + + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + var each_value = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < each_value.length; i += 1) { + var each_context = assign(assign({}, state), { + each_value: each_value, + comment: each_value[i], + i: i + }); + + if (each_blocks[i]) { + each_blocks[i].p(changed, each_context); + } else { + each_blocks[i] = create_each_block(component, each_context); + each_blocks[i].c(); + each_blocks[i].m(text.parentNode, text); + } + } + + for (; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + each_blocks[i].d(); + } + each_blocks.length = each_value.length; + } + + if (changed.foo) { + text_1.data = state.foo; + } + }, + + u: function unmount() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].u(); + } + + detachNode(text); + detachNode(p); + }, + + d: function destroy() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {#each comments as comment, i} +function create_each_block(component, state) { + var comment = state.comment, each_value = state.each_value, i = state.i; + var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; + + return { + c: function create() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.h(); + }, + + h: function hydrate() { + span.className = "meta"; + div.className = "comment"; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, + + p: function update(changed, state) { + comment = state.comment; + each_value = state.each_value; + i = state.i; + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { + text_2.data = text_2_value; + } + + if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) { + text_4.data = text_4_value; + } + + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { + detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, + + u: function unmount() { + detachAfter(raw_before); + + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/each-block-changed-check/input-v2.html b/test/js/samples/each-block-changed-check/input-v2.html new file mode 100644 index 000000000000..b5b5703857c4 --- /dev/null +++ b/test/js/samples/each-block-changed-check/input-v2.html @@ -0,0 +1,13 @@ +{#each comments as comment, i} +
+ {i} + + + {comment.author} wrote {elapsed(comment.time, time)} ago: + + + {@html comment.html} +
+{/each} + +

{foo}

\ No newline at end of file diff --git a/test/js/samples/head-no-whitespace/_actual-bundle-v2.js b/test/js/samples/head-no-whitespace/_actual-bundle-v2.js new file mode 100644 index 000000000000..396cf8fb8c55 --- /dev/null +++ b/test/js/samples/head-no-whitespace/_actual-bundle-v2.js @@ -0,0 +1,225 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var meta, meta_1; + + return { + c: function create() { + meta = createElement("meta"); + meta_1 = createElement("meta"); + this.h(); + }, + + h: function hydrate() { + meta.name = "twitter:creator"; + meta.content = "@sveltejs"; + meta_1.name = "twitter:title"; + meta_1.content = "Svelte"; + }, + + m: function mount(target, anchor) { + appendNode(meta, document.head); + appendNode(meta_1, document.head); + }, + + p: noop, + + u: function unmount() { + detachNode(meta); + detachNode(meta_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/head-no-whitespace/expected-bundle-v2.js b/test/js/samples/head-no-whitespace/expected-bundle-v2.js new file mode 100644 index 000000000000..396cf8fb8c55 --- /dev/null +++ b/test/js/samples/head-no-whitespace/expected-bundle-v2.js @@ -0,0 +1,225 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var meta, meta_1; + + return { + c: function create() { + meta = createElement("meta"); + meta_1 = createElement("meta"); + this.h(); + }, + + h: function hydrate() { + meta.name = "twitter:creator"; + meta.content = "@sveltejs"; + meta_1.name = "twitter:title"; + meta_1.content = "Svelte"; + }, + + m: function mount(target, anchor) { + appendNode(meta, document.head); + appendNode(meta_1, document.head); + }, + + p: noop, + + u: function unmount() { + detachNode(meta); + detachNode(meta_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/head-no-whitespace/expected-v2.js b/test/js/samples/head-no-whitespace/expected-v2.js new file mode 100644 index 000000000000..9818f4211658 --- /dev/null +++ b/test/js/samples/head-no-whitespace/expected-v2.js @@ -0,0 +1,50 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createElement, detachNode, init, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var meta, meta_1; + + return { + c: function create() { + meta = createElement("meta"); + meta_1 = createElement("meta"); + this.h(); + }, + + h: function hydrate() { + meta.name = "twitter:creator"; + meta.content = "@sveltejs"; + meta_1.name = "twitter:title"; + meta_1.content = "Svelte"; + }, + + m: function mount(target, anchor) { + appendNode(meta, document.head); + appendNode(meta_1, document.head); + }, + + p: noop, + + u: function unmount() { + detachNode(meta); + detachNode(meta_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/head-no-whitespace/input-v2.html b/test/js/samples/head-no-whitespace/input-v2.html new file mode 100644 index 000000000000..000b643abeb6 --- /dev/null +++ b/test/js/samples/head-no-whitespace/input-v2.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/js/samples/if-block-no-update/_actual-bundle-v2.js b/test/js/samples/if-block-no-update/_actual-bundle-v2.js new file mode 100644 index 000000000000..7284a91fa7e8 --- /dev/null +++ b/test/js/samples/if-block-no-update/_actual-bundle-v2.js @@ -0,0 +1,283 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var if_block_anchor; + + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } + + var current_block_type = select_block_type(state); + var if_block = current_block_type(component, state); + + return { + c: function create() { + if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.u(); + if_block.d(); + if_block = current_block_type(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + }, + + u: function unmount() { + if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy$$1() { + if_block.d(); + } + }; +} + +// (1:0) {#if foo} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (2:12) {:else} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "not foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/if-block-no-update/expected-bundle-v2.js b/test/js/samples/if-block-no-update/expected-bundle-v2.js new file mode 100644 index 000000000000..59d3e9656b5e --- /dev/null +++ b/test/js/samples/if-block-no-update/expected-bundle-v2.js @@ -0,0 +1,283 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var if_block_anchor; + + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } + + var current_block_type = select_block_type(state); + var if_block = current_block_type(component, state); + + return { + c: function create() { + if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.u(); + if_block.d(); + if_block = current_block_type(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + }, + + u: function unmount() { + if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy$$1() { + if_block.d(); + } + }; +} + +// (1:0) {{#if foo}} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (3:0) {{else}} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "not foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/if-block-no-update/expected-v2.js b/test/js/samples/if-block-no-update/expected-v2.js new file mode 100644 index 000000000000..c06ff6ee679a --- /dev/null +++ b/test/js/samples/if-block-no-update/expected-v2.js @@ -0,0 +1,104 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var if_block_anchor; + + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } + + var current_block_type = select_block_type(state); + var if_block = current_block_type(component, state); + + return { + c: function create() { + if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.u(); + if_block.d(); + if_block = current_block_type(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + }, + + u: function unmount() { + if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy() { + if_block.d(); + } + }; +} + +// (1:0) {#if foo} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (3:0) {:else} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "not foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/if-block-no-update/input-v2.html b/test/js/samples/if-block-no-update/input-v2.html new file mode 100644 index 000000000000..57de21915969 --- /dev/null +++ b/test/js/samples/if-block-no-update/input-v2.html @@ -0,0 +1,5 @@ +{#if foo} +

foo!

+{:else} +

not foo!

+{/if} \ No newline at end of file diff --git a/test/js/samples/if-block-simple/_actual-bundle-v2.js b/test/js/samples/if-block-simple/_actual-bundle-v2.js new file mode 100644 index 000000000000..72dbdec8897c --- /dev/null +++ b/test/js/samples/if-block-simple/_actual-bundle-v2.js @@ -0,0 +1,259 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(component, state); + + return { + c: function create() { + if (if_block) if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if (if_block) if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + }, + + u: function unmount() { + if (if_block) if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy$$1() { + if (if_block) if_block.d(); + } + }; +} + +// (1:0) {#if foo} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/if-block-simple/expected-bundle-v2.js b/test/js/samples/if-block-simple/expected-bundle-v2.js new file mode 100644 index 000000000000..72dbdec8897c --- /dev/null +++ b/test/js/samples/if-block-simple/expected-bundle-v2.js @@ -0,0 +1,259 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(component, state); + + return { + c: function create() { + if (if_block) if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if (if_block) if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + }, + + u: function unmount() { + if (if_block) if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy$$1() { + if (if_block) if_block.d(); + } + }; +} + +// (1:0) {#if foo} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/if-block-simple/expected-v2.js b/test/js/samples/if-block-simple/expected-v2.js new file mode 100644 index 000000000000..b3447471d31e --- /dev/null +++ b/test/js/samples/if-block-simple/expected-v2.js @@ -0,0 +1,80 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(component, state); + + return { + c: function create() { + if (if_block) if_block.c(); + if_block_anchor = createComment(); + }, + + m: function mount(target, anchor) { + if (if_block) if_block.m(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + }, + + u: function unmount() { + if (if_block) if_block.u(); + detachNode(if_block_anchor); + }, + + d: function destroy() { + if (if_block) if_block.d(); + } + }; +} + +// (1:0) {#if foo} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "foo!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/if-block-simple/input-v2.html b/test/js/samples/if-block-simple/input-v2.html new file mode 100644 index 000000000000..e36517e10c2d --- /dev/null +++ b/test/js/samples/if-block-simple/input-v2.html @@ -0,0 +1,3 @@ +{#if foo} +

foo!

+{/if} \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-multiple/_actual-bundle-v2.js b/test/js/samples/inline-style-optimized-multiple/_actual-bundle-v2.js new file mode 100644 index 000000000000..eb528e4ebf0d --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/_actual-bundle-v2.js @@ -0,0 +1,232 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle-v2.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle-v2.js new file mode 100644 index 000000000000..eb528e4ebf0d --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle-v2.js @@ -0,0 +1,232 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-multiple/expected-v2.js b/test/js/samples/inline-style-optimized-multiple/expected-v2.js new file mode 100644 index 000000000000..7a94993b690c --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/expected-v2.js @@ -0,0 +1,53 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-multiple/input-v2.html b/test/js/samples/inline-style-optimized-multiple/input-v2.html new file mode 100644 index 000000000000..d9448e0ab06d --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-url/_actual-bundle-v2.js b/test/js/samples/inline-style-optimized-url/_actual-bundle-v2.js new file mode 100644 index 000000000000..a4d2dda6696e --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/_actual-bundle-v2.js @@ -0,0 +1,227 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle-v2.js b/test/js/samples/inline-style-optimized-url/expected-bundle-v2.js new file mode 100644 index 000000000000..a4d2dda6696e --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/expected-bundle-v2.js @@ -0,0 +1,227 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-url/expected-v2.js b/test/js/samples/inline-style-optimized-url/expected-v2.js new file mode 100644 index 000000000000..5a27ecfa4948 --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/expected-v2.js @@ -0,0 +1,48 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-url/input-v2.html b/test/js/samples/inline-style-optimized-url/input-v2.html new file mode 100644 index 000000000000..677da52c30f4 --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/_actual-bundle-v2.js b/test/js/samples/inline-style-optimized/_actual-bundle-v2.js new file mode 100644 index 000000000000..2b78d3932a8a --- /dev/null +++ b/test/js/samples/inline-style-optimized/_actual-bundle-v2.js @@ -0,0 +1,227 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized/expected-bundle-v2.js b/test/js/samples/inline-style-optimized/expected-bundle-v2.js new file mode 100644 index 000000000000..2b78d3932a8a --- /dev/null +++ b/test/js/samples/inline-style-optimized/expected-bundle-v2.js @@ -0,0 +1,227 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized/expected-v2.js b/test/js/samples/inline-style-optimized/expected-v2.js new file mode 100644 index 000000000000..86dabe8d21e1 --- /dev/null +++ b/test/js/samples/inline-style-optimized/expected-v2.js @@ -0,0 +1,48 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div; + + return { + c: function create() { + div = createElement("div"); + this.h(); + }, + + h: function hydrate() { + setStyle(div, "color", state.color); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + }, + + p: function update(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, + + u: function unmount() { + detachNode(div); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/input-v2.html b/test/js/samples/inline-style-optimized/input-v2.html new file mode 100644 index 000000000000..004fd595c94f --- /dev/null +++ b/test/js/samples/inline-style-optimized/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/_actual-bundle-v2.js b/test/js/samples/inline-style-unoptimized/_actual-bundle-v2.js new file mode 100644 index 000000000000..670a2c02f64a --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/_actual-bundle-v2.js @@ -0,0 +1,238 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1, div_1_style_value; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.style) { + div.style.cssText = state.style; + } + + if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) { + div_1.style.cssText = div_1_style_value; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle-v2.js b/test/js/samples/inline-style-unoptimized/expected-bundle-v2.js new file mode 100644 index 000000000000..670a2c02f64a --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/expected-bundle-v2.js @@ -0,0 +1,238 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, div_1, div_1_style_value; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.style) { + div.style.cssText = state.style; + } + + if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) { + div_1.style.cssText = div_1_style_value; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-unoptimized/expected-v2.js b/test/js/samples/inline-style-unoptimized/expected-v2.js new file mode 100644 index 000000000000..7d7e933c1226 --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/expected-v2.js @@ -0,0 +1,59 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div, text, div_1, div_1_style_value; + + return { + c: function create() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.h(); + }, + + h: function hydrate() { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + p: function update(changed, state) { + if (changed.style) { + div.style.cssText = state.style; + } + + if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) { + div_1.style.cssText = div_1_style_value; + } + }, + + u: function unmount() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/input-v2.html b/test/js/samples/inline-style-unoptimized/input-v2.html new file mode 100644 index 000000000000..eac76d5b6ede --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/input-v2.html @@ -0,0 +1,2 @@ +
+
\ No newline at end of file diff --git a/test/js/samples/title/input-v2.html b/test/js/samples/title/input-v2.html new file mode 100644 index 000000000000..0eb2a9519de6 --- /dev/null +++ b/test/js/samples/title/input-v2.html @@ -0,0 +1,3 @@ + + a {custom} title + \ No newline at end of file diff --git a/test/js/samples/use-elements-as-anchors/_actual-bundle-v2.js b/test/js/samples/use-elements-as-anchors/_actual-bundle-v2.js new file mode 100644 index 000000000000..7aefaab6c8c4 --- /dev/null +++ b/test/js/samples/use-elements-as-anchors/_actual-bundle-v2.js @@ -0,0 +1,449 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; + + var if_block = (state.a) && create_if_block(component, state); + + var if_block_1 = (state.b) && create_if_block_1(component, state); + + var if_block_2 = (state.c) && create_if_block_2(component, state); + + var if_block_3 = (state.d) && create_if_block_3(component, state); + + var if_block_4 = (state.e) && create_if_block_4(component, state); + + return { + c: function create() { + div = createElement("div"); + if (if_block) if_block.c(); + text = createText("\n\n\t"); + p = createElement("p"); + p.textContent = "this can be used as an anchor"; + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.c(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.c(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + p_1.textContent = "so can this"; + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.c(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.c(); + if_block_4_anchor = createComment(); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.m(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_2, div); + if (if_block_1) if_block_1.m(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.m(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_6, div); + if (if_block_3) if_block_3.m(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.m(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(div, text); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(component, state); + if_block_1.c(); + if_block_1.m(div, text_3); + } + } else if (if_block_1) { + if_block_1.u(); + if_block_1.d(); + if_block_1 = null; + } + + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(component, state); + if_block_2.c(); + if_block_2.m(div, text_4); + } + } else if (if_block_2) { + if_block_2.u(); + if_block_2.d(); + if_block_2 = null; + } + + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(component, state); + if_block_3.c(); + if_block_3.m(div, null); + } + } else if (if_block_3) { + if_block_3.u(); + if_block_3.d(); + if_block_3 = null; + } + + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(component, state); + if_block_4.c(); + if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor); + } + } else if (if_block_4) { + if_block_4.u(); + if_block_4.d(); + if_block_4 = null; + } + }, + + u: function unmount() { + detachNode(div); + if (if_block) if_block.u(); + if (if_block_1) if_block_1.u(); + if (if_block_2) if_block_2.u(); + if (if_block_3) if_block_3.u(); + detachNode(text_8); + if (if_block_4) if_block_4.u(); + detachNode(if_block_4_anchor); + }, + + d: function destroy$$1() { + if (if_block) if_block.d(); + if (if_block_1) if_block_1.d(); + if (if_block_2) if_block_2.d(); + if (if_block_3) if_block_3.d(); + if (if_block_4) if_block_4.d(); + } + }; +} + +// (2:1) {#if a} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "a"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (8:1) {#if b} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "b"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (12:1) {#if c} +function create_if_block_2(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "c"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (18:1) {#if d} +function create_if_block_3(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "d"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (25:0) {#if e} +function create_if_block_4(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "e"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle-v2.js b/test/js/samples/use-elements-as-anchors/expected-bundle-v2.js new file mode 100644 index 000000000000..7aefaab6c8c4 --- /dev/null +++ b/test/js/samples/use-elements-as-anchors/expected-bundle-v2.js @@ -0,0 +1,449 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function createComment() { + return document.createComment(''); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; + + var if_block = (state.a) && create_if_block(component, state); + + var if_block_1 = (state.b) && create_if_block_1(component, state); + + var if_block_2 = (state.c) && create_if_block_2(component, state); + + var if_block_3 = (state.d) && create_if_block_3(component, state); + + var if_block_4 = (state.e) && create_if_block_4(component, state); + + return { + c: function create() { + div = createElement("div"); + if (if_block) if_block.c(); + text = createText("\n\n\t"); + p = createElement("p"); + p.textContent = "this can be used as an anchor"; + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.c(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.c(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + p_1.textContent = "so can this"; + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.c(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.c(); + if_block_4_anchor = createComment(); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.m(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_2, div); + if (if_block_1) if_block_1.m(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.m(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_6, div); + if (if_block_3) if_block_3.m(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.m(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(div, text); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(component, state); + if_block_1.c(); + if_block_1.m(div, text_3); + } + } else if (if_block_1) { + if_block_1.u(); + if_block_1.d(); + if_block_1 = null; + } + + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(component, state); + if_block_2.c(); + if_block_2.m(div, text_4); + } + } else if (if_block_2) { + if_block_2.u(); + if_block_2.d(); + if_block_2 = null; + } + + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(component, state); + if_block_3.c(); + if_block_3.m(div, null); + } + } else if (if_block_3) { + if_block_3.u(); + if_block_3.d(); + if_block_3 = null; + } + + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(component, state); + if_block_4.c(); + if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor); + } + } else if (if_block_4) { + if_block_4.u(); + if_block_4.d(); + if_block_4 = null; + } + }, + + u: function unmount() { + detachNode(div); + if (if_block) if_block.u(); + if (if_block_1) if_block_1.u(); + if (if_block_2) if_block_2.u(); + if (if_block_3) if_block_3.u(); + detachNode(text_8); + if (if_block_4) if_block_4.u(); + detachNode(if_block_4_anchor); + }, + + d: function destroy$$1() { + if (if_block) if_block.d(); + if (if_block_1) if_block_1.d(); + if (if_block_2) if_block_2.d(); + if (if_block_3) if_block_3.d(); + if (if_block_4) if_block_4.d(); + } + }; +} + +// (2:1) {#if a} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "a"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (8:1) {#if b} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "b"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (12:1) {#if c} +function create_if_block_2(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "c"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (18:1) {#if d} +function create_if_block_3(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "d"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (25:0) {#if e} +function create_if_block_4(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "e"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected-v2.js b/test/js/samples/use-elements-as-anchors/expected-v2.js new file mode 100644 index 000000000000..d9cff08d3f98 --- /dev/null +++ b/test/js/samples/use-elements-as-anchors/expected-v2.js @@ -0,0 +1,262 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; + + var if_block = (state.a) && create_if_block(component, state); + + var if_block_1 = (state.b) && create_if_block_1(component, state); + + var if_block_2 = (state.c) && create_if_block_2(component, state); + + var if_block_3 = (state.d) && create_if_block_3(component, state); + + var if_block_4 = (state.e) && create_if_block_4(component, state); + + return { + c: function create() { + div = createElement("div"); + if (if_block) if_block.c(); + text = createText("\n\n\t"); + p = createElement("p"); + p.textContent = "this can be used as an anchor"; + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.c(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.c(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + p_1.textContent = "so can this"; + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.c(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.c(); + if_block_4_anchor = createComment(); + }, + + m: function mount(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.m(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_2, div); + if (if_block_1) if_block_1.m(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.m(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_6, div); + if (if_block_3) if_block_3.m(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.m(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + p: function update(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(component, state); + if_block.c(); + if_block.m(div, text); + } + } else if (if_block) { + if_block.u(); + if_block.d(); + if_block = null; + } + + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(component, state); + if_block_1.c(); + if_block_1.m(div, text_3); + } + } else if (if_block_1) { + if_block_1.u(); + if_block_1.d(); + if_block_1 = null; + } + + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(component, state); + if_block_2.c(); + if_block_2.m(div, text_4); + } + } else if (if_block_2) { + if_block_2.u(); + if_block_2.d(); + if_block_2 = null; + } + + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(component, state); + if_block_3.c(); + if_block_3.m(div, null); + } + } else if (if_block_3) { + if_block_3.u(); + if_block_3.d(); + if_block_3 = null; + } + + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(component, state); + if_block_4.c(); + if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor); + } + } else if (if_block_4) { + if_block_4.u(); + if_block_4.d(); + if_block_4 = null; + } + }, + + u: function unmount() { + detachNode(div); + if (if_block) if_block.u(); + if (if_block_1) if_block_1.u(); + if (if_block_2) if_block_2.u(); + if (if_block_3) if_block_3.u(); + detachNode(text_8); + if (if_block_4) if_block_4.u(); + detachNode(if_block_4_anchor); + }, + + d: function destroy() { + if (if_block) if_block.d(); + if (if_block_1) if_block_1.d(); + if (if_block_2) if_block_2.d(); + if (if_block_3) if_block_3.d(); + if (if_block_4) if_block_4.d(); + } + }; +} + +// (2:1) {#if a} +function create_if_block(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "a"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (8:1) {#if b} +function create_if_block_1(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "b"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (12:1) {#if c} +function create_if_block_2(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "c"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (18:1) {#if d} +function create_if_block_3(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "d"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +// (25:0) {#if e} +function create_if_block_4(component, state) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "e"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/use-elements-as-anchors/input-v2.html b/test/js/samples/use-elements-as-anchors/input-v2.html new file mode 100644 index 000000000000..9c18d40f582b --- /dev/null +++ b/test/js/samples/use-elements-as-anchors/input-v2.html @@ -0,0 +1,27 @@ +
+ {#if a} +

a

+ {/if} + +

this can be used as an anchor

+ + {#if b} +

b

+ {/if} + + {#if c} +

c

+ {/if} + +

so can this

+ + {#if d} +

d

+ {/if} + + +
+ +{#if e} +

e

+{/if} \ No newline at end of file diff --git a/test/js/samples/window-binding-scroll/_actual-bundle-v2.js b/test/js/samples/window-binding-scroll/_actual-bundle-v2.js new file mode 100644 index 000000000000..a98de2af6353 --- /dev/null +++ b/test/js/samples/window-binding-scroll/_actual-bundle-v2.js @@ -0,0 +1,251 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1; + + function onwindowscroll(event) { + if (window_updating) return; + window_updating = true; + + component.set({ + y: this.pageYOffset + }); + window_updating = false; + } + window.addEventListener("scroll", onwindowscroll); + + component.observe("y", function(y) { + window_updating = true; + clearTimeout(window_updating_timeout); + window.scrollTo(window.pageXOffset, y); + window_updating_timeout = setTimeout(clear_window_updating, 100); + }); + + return { + c: function create() { + p = createElement("p"); + text = createText("scrolled to "); + text_1 = createText(state.y); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + if (changed.y) { + text_1.data = state.y; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: function destroy$$1() { + window.removeEventListener("scroll", onwindowscroll); + } + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + this._state.y = window.pageYOffset; + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/window-binding-scroll/expected-bundle-v2.js b/test/js/samples/window-binding-scroll/expected-bundle-v2.js new file mode 100644 index 000000000000..a98de2af6353 --- /dev/null +++ b/test/js/samples/window-binding-scroll/expected-bundle-v2.js @@ -0,0 +1,251 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1; + + function onwindowscroll(event) { + if (window_updating) return; + window_updating = true; + + component.set({ + y: this.pageYOffset + }); + window_updating = false; + } + window.addEventListener("scroll", onwindowscroll); + + component.observe("y", function(y) { + window_updating = true; + clearTimeout(window_updating_timeout); + window.scrollTo(window.pageXOffset, y); + window_updating_timeout = setTimeout(clear_window_updating, 100); + }); + + return { + c: function create() { + p = createElement("p"); + text = createText("scrolled to "); + text_1 = createText(state.y); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + if (changed.y) { + text_1.data = state.y; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: function destroy$$1() { + window.removeEventListener("scroll", onwindowscroll); + } + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + this._state.y = window.pageYOffset; + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/window-binding-scroll/expected-v2.js b/test/js/samples/window-binding-scroll/expected-v2.js new file mode 100644 index 000000000000..59009aeb9b99 --- /dev/null +++ b/test/js/samples/window-binding-scroll/expected-v2.js @@ -0,0 +1,68 @@ +/* generated by Svelte vX.Y.Z */ +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1; + + function onwindowscroll(event) { + if (window_updating) return; + window_updating = true; + + component.set({ + y: this.pageYOffset + }); + window_updating = false; + } + window.addEventListener("scroll", onwindowscroll); + + component.observe("y", function(y) { + window_updating = true; + clearTimeout(window_updating_timeout); + window.scrollTo(window.pageXOffset, y); + window_updating_timeout = setTimeout(clear_window_updating, 100); + }); + + return { + c: function create() { + p = createElement("p"); + text = createText("scrolled to "); + text_1 = createText(state.y); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p: function update(changed, state) { + if (changed.y) { + text_1.data = state.y; + } + }, + + u: function unmount() { + detachNode(p); + }, + + d: function destroy() { + window.removeEventListener("scroll", onwindowscroll); + } + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + this._state.y = window.pageYOffset; + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/window-binding-scroll/input-v2.html b/test/js/samples/window-binding-scroll/input-v2.html new file mode 100644 index 000000000000..74ace567ab20 --- /dev/null +++ b/test/js/samples/window-binding-scroll/input-v2.html @@ -0,0 +1,3 @@ +<:Window bind:scrollY=y/> + +

scrolled to {y}

\ No newline at end of file From 7681939d3e741fb69115368f07c2e27f16b99a3b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 13 Apr 2018 11:53:20 -0400 Subject: [PATCH 10/15] fix head/window meta tags --- src/parse/state/tag.ts | 12 +- test/js/samples/title/_actual-bundle-v2.js | 202 ++++++++++++++++++++ test/js/samples/title/expected-bundle-v2.js | 202 ++++++++++++++++++++ test/js/samples/title/expected-v2.js | 39 ++++ 4 files changed, 449 insertions(+), 6 deletions(-) create mode 100644 test/js/samples/title/_actual-bundle-v2.js create mode 100644 test/js/samples/title/expected-bundle-v2.js create mode 100644 test/js/samples/title/expected-v2.js diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index ba4fce179f0d..fbbb62bddb51 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -10,11 +10,11 @@ import { Node } from '../../interfaces'; const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; -const metaTags = new Set([ - ':Window', - ':Head', - 'svelte:window', - 'svelte:head' +const metaTags = new Map([ + [':Window', 'Window'], + [':Head', 'Head'], + ['svelte:window', 'Window'], + ['svelte:head', 'Head'] ]); const specials = new Map([ @@ -105,7 +105,7 @@ export default function tag(parser: Parser) { } const type = metaTags.has(name) - ? name.slice(1) + ? metaTags.get(name) : 'Element'; // TODO in v2, capitalised name means 'Component' const element: Node = { diff --git a/test/js/samples/title/_actual-bundle-v2.js b/test/js/samples/title/_actual-bundle-v2.js new file mode 100644 index 000000000000..83c8815d6fbd --- /dev/null +++ b/test/js/samples/title/_actual-bundle-v2.js @@ -0,0 +1,202 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var title_value; + + document.title = title_value = "a " + state.custom + " title"; + + return { + c: noop, + + m: noop, + + p: function update(changed, state) { + if ((changed.custom) && title_value !== (title_value = "a " + state.custom + " title")) { + document.title = title_value; + } + }, + + u: noop, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/title/expected-bundle-v2.js b/test/js/samples/title/expected-bundle-v2.js new file mode 100644 index 000000000000..83c8815d6fbd --- /dev/null +++ b/test/js/samples/title/expected-bundle-v2.js @@ -0,0 +1,202 @@ +function noop() {} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + 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 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 get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (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(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign(assign({}, oldState), newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs +}; + +/* generated by Svelte vX.Y.Z */ + +function create_main_fragment(component, state) { + var title_value; + + document.title = title_value = "a " + state.custom + " title"; + + return { + c: noop, + + m: noop, + + p: function update(changed, state) { + if ((changed.custom) && title_value !== (title_value = "a " + state.custom + " title")) { + document.title = title_value; + } + }, + + u: noop, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/title/expected-v2.js b/test/js/samples/title/expected-v2.js new file mode 100644 index 000000000000..0e059bbb4c67 --- /dev/null +++ b/test/js/samples/title/expected-v2.js @@ -0,0 +1,39 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, init, noop, proto } from "svelte/shared.js"; + +function create_main_fragment(component, state) { + var title_value; + + document.title = title_value = "a " + state.custom + " title"; + + return { + c: noop, + + m: noop, + + p: function update(changed, state) { + if ((changed.custom) && title_value !== (title_value = "a " + state.custom + " title")) { + document.title = title_value; + } + }, + + u: noop, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = assign({}, options.data); + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file From 94a7ffb9a579767f971bc71aadbd3bc07666313a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 13 Apr 2018 12:01:16 -0400 Subject: [PATCH 11/15] fix debugging comments --- src/utils/createDebuggingComment.ts | 4 ++-- test/js/samples/if-block-no-update/_actual-bundle-v2.js | 2 +- test/js/samples/if-block-no-update/expected-bundle-v2.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/createDebuggingComment.ts b/src/utils/createDebuggingComment.ts index e967d7e5165b..1eadfd1c933e 100644 --- a/src/utils/createDebuggingComment.ts +++ b/src/utils/createDebuggingComment.ts @@ -6,8 +6,8 @@ export default function createDebuggingComment(node: Node, generator: DomGenerat let c = node.start; if (node.type === 'ElseBlock') { - while (source[c] !== '{') c -= 1; - c -= 1; + while (source[c - 1] !== '{') c -= 1; + while (source[c - 1] === '{') c -= 1; } let d = node.expression ? node.expression.end : c; diff --git a/test/js/samples/if-block-no-update/_actual-bundle-v2.js b/test/js/samples/if-block-no-update/_actual-bundle-v2.js index 7284a91fa7e8..29d151e15d64 100644 --- a/test/js/samples/if-block-no-update/_actual-bundle-v2.js +++ b/test/js/samples/if-block-no-update/_actual-bundle-v2.js @@ -244,7 +244,7 @@ function create_if_block(component, state) { }; } -// (2:12) {:else} +// (3:0) {:else} function create_if_block_1(component, state) { var p; diff --git a/test/js/samples/if-block-no-update/expected-bundle-v2.js b/test/js/samples/if-block-no-update/expected-bundle-v2.js index 59d3e9656b5e..29d151e15d64 100644 --- a/test/js/samples/if-block-no-update/expected-bundle-v2.js +++ b/test/js/samples/if-block-no-update/expected-bundle-v2.js @@ -222,7 +222,7 @@ function create_main_fragment(component, state) { }; } -// (1:0) {{#if foo}} +// (1:0) {#if foo} function create_if_block(component, state) { var p; @@ -244,7 +244,7 @@ function create_if_block(component, state) { }; } -// (3:0) {{else}} +// (3:0) {:else} function create_if_block_1(component, state) { var p; From e85eda82795e0754127a5e4260cecf5e311166f3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 13 Apr 2018 12:02:07 -0400 Subject: [PATCH 12/15] reenable all tests --- test/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js/index.js b/test/js/index.js index 43f7a4c47e4f..ef2a05a09e72 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -4,7 +4,7 @@ import * as path from "path"; import { rollup } from "rollup"; import { loadConfig, svelte } from "../helpers.js"; -describe.only("js", () => { +describe("js", () => { fs.readdirSync("test/js/samples").forEach(dir => { if (dir[0] === ".") return; From 9bba8d18d18c821d63626bb41bb177aa4ed9ab24 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 14 Apr 2018 14:01:28 -0400 Subject: [PATCH 13/15] implement dynamic components etc --- src/generators/Generator.ts | 2 +- src/generators/nodes/Component.ts | 2 +- .../visitors/Component.ts | 2 +- src/parse/state/tag.ts | 21 ++++++-- test/helpers.js | 10 +++- .../samples/component-dynamic/input-v2.html | 2 +- .../samples/component-dynamic/output-v2.json | 22 ++++---- test/runtime/index.js | 21 +++++--- .../samples/action-update/main-v2.html | 52 +++++++++++++++++++ .../main-v2.html | 13 +++++ .../main-v2.html | 1 + .../Green-v2.html | 1 + .../Red-v2.html | 1 + .../main-v2.html | 15 ++++++ .../dynamic-component-bindings/main-v2.html | 12 +++++ .../dynamic-component-events/main-v2.html | 12 +++++ .../Bar-v2.html | 1 + .../Foo-v2.html | 1 + .../main-v2.html | 14 +++++ .../dynamic-component-ref/main-v2.html | 11 ++++ .../dynamic-component-slot/main-v2.html | 45 ++++++++++++++++ .../Bar-v2.html | 1 + .../Foo-v2.html | 1 + .../main-v2.html | 12 +++++ .../samples/head-title-dynamic/main-v2.html | 4 ++ .../samples/head-title-static/main-v2.html | 4 ++ .../samples/self-reference-tree/main-v2.html | 11 ++++ .../samples/self-reference/main-v2.html | 4 ++ .../window-bind-scroll-update/main-v2.html | 3 ++ .../window-binding-resize/main-v2.html | 3 ++ .../samples/window-event-context/main-v2.html | 3 ++ .../samples/window-event-custom/main-v2.html | 25 +++++++++ 32 files changed, 305 insertions(+), 27 deletions(-) create mode 100644 test/runtime/samples/action-update/main-v2.html create mode 100644 test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html create mode 100644 test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html create mode 100644 test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html create mode 100644 test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-bindings/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-events/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-inside-element/Bar-v2.html create mode 100644 test/runtime/samples/dynamic-component-inside-element/Foo-v2.html create mode 100644 test/runtime/samples/dynamic-component-inside-element/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-ref/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-slot/main-v2.html create mode 100644 test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html create mode 100644 test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html create mode 100644 test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html create mode 100644 test/runtime/samples/head-title-dynamic/main-v2.html create mode 100644 test/runtime/samples/head-title-static/main-v2.html create mode 100644 test/runtime/samples/self-reference-tree/main-v2.html create mode 100644 test/runtime/samples/self-reference/main-v2.html create mode 100644 test/runtime/samples/window-bind-scroll-update/main-v2.html create mode 100644 test/runtime/samples/window-binding-resize/main-v2.html create mode 100644 test/runtime/samples/window-event-context/main-v2.html create mode 100644 test/runtime/samples/window-event-custom/main-v2.html diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index ce6c56fc7d80..6d49faf906d8 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -875,7 +875,7 @@ export default class Generator { this.skip(); } - if (node.type === 'Component' && node.name === ':Component') { + if (node.type === 'Component' && (node.name === ':Component' || node.name === 'svelte:component')) { node.metadata = contextualise(node.expression, contextDependencies, indexes, false); } diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index 239dc4bed197..25d7508ac223 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -292,7 +292,7 @@ export default class Component extends Node { `; } - if (this.name === ':Component') { + if (this.name === ':Component' || this.name === 'svelte:component') { const switch_value = block.getUniqueName('switch_value'); const switch_props = block.getUniqueName('switch_props'); diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index d0df39c9bef1..9c7d7ce930a1 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -87,7 +87,7 @@ export default function visitComponent( .concat(bindingProps) .join(', ')} }`; - const isDynamicComponent = node.name === ':Component'; + const isDynamicComponent = node.name === ':Component' || node.name === 'svelte:component'; if (isDynamicComponent) block.contextualise(node.expression); const expression = ( diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index fbbb62bddb51..dad44f81fe21 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -169,7 +169,7 @@ export default function tag(parser: Parser) { } } - if (name === (parser.v2 ? 'svelte:component' : ':Component')) { + if (name === ':Component') { parser.eat('{', true); element.expression = readExpression(parser); parser.allowWhitespace(); @@ -189,6 +189,21 @@ export default function tag(parser: Parser) { parser.allowWhitespace(); } + if (parser.v2 && name === 'svelte:component') { + // TODO post v2, treat this just as any other attribute + const index = element.attributes.findIndex(attr => attr.name === 'this'); + if (!~index) { + parser.error(` must have a 'this' attribute`, start); + } + + const definition = element.attributes.splice(index, 1)[0]; + if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') { + parser.error(`invalid component definition`, definition.start); + } + + element.expression = definition.value[0].expression; + } + // special cases – top-level \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html b/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html new file mode 100644 index 000000000000..eb6e7d8e8e61 --- /dev/null +++ b/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html b/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html new file mode 100644 index 000000000000..87b0403ee32e --- /dev/null +++ b/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html new file mode 100644 index 000000000000..b4faa1b66263 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html @@ -0,0 +1 @@ +

green {foo}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html new file mode 100644 index 000000000000..a3e3c792a03f --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html @@ -0,0 +1 @@ +

red {foo}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html new file mode 100644 index 000000000000..6d748ed21705 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings/main-v2.html b/test/runtime/samples/dynamic-component-bindings/main-v2.html new file mode 100644 index 000000000000..020855cb2272 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-events/main-v2.html b/test/runtime/samples/dynamic-component-events/main-v2.html new file mode 100644 index 000000000000..5fa66b2c6135 --- /dev/null +++ b/test/runtime/samples/dynamic-component-events/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html b/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html new file mode 100644 index 000000000000..79e01b851c34 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html @@ -0,0 +1 @@ +

{x}, therefore Bar

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html b/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html new file mode 100644 index 000000000000..cb35cfc082e4 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html @@ -0,0 +1 @@ +

{x}, therefore Foo

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/main-v2.html b/test/runtime/samples/dynamic-component-inside-element/main-v2.html new file mode 100644 index 000000000000..e889f2feb01f --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/main-v2.html @@ -0,0 +1,14 @@ +
+ +
+ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-ref/main-v2.html b/test/runtime/samples/dynamic-component-ref/main-v2.html new file mode 100644 index 000000000000..1d54b172995d --- /dev/null +++ b/test/runtime/samples/dynamic-component-ref/main-v2.html @@ -0,0 +1,11 @@ + + + diff --git a/test/runtime/samples/dynamic-component-slot/main-v2.html b/test/runtime/samples/dynamic-component-slot/main-v2.html new file mode 100644 index 000000000000..e8b5c487ad3d --- /dev/null +++ b/test/runtime/samples/dynamic-component-slot/main-v2.html @@ -0,0 +1,45 @@ + +

element

+ + {tag} + + {#if foo} +

foo

+ {:elseif bar} +

bar

+ {:else} +

neither foo nor bar

+ {/if} + + text + + {#each things as thing} + {thing} + {/each} + + + +
what goes up must come down
+
+ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html new file mode 100644 index 000000000000..36fa195dcd76 --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html @@ -0,0 +1 @@ +

Bar {x}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html new file mode 100644 index 000000000000..0a9cd0047a46 --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html @@ -0,0 +1 @@ +

Foo {x}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html new file mode 100644 index 000000000000..4bdf36f5299b --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/head-title-dynamic/main-v2.html b/test/runtime/samples/head-title-dynamic/main-v2.html new file mode 100644 index 000000000000..255f344c0098 --- /dev/null +++ b/test/runtime/samples/head-title-dynamic/main-v2.html @@ -0,0 +1,4 @@ + + a {adjective} title + + \ No newline at end of file diff --git a/test/runtime/samples/head-title-static/main-v2.html b/test/runtime/samples/head-title-static/main-v2.html new file mode 100644 index 000000000000..7f9da20911ab --- /dev/null +++ b/test/runtime/samples/head-title-static/main-v2.html @@ -0,0 +1,4 @@ + + changed + + \ No newline at end of file diff --git a/test/runtime/samples/self-reference-tree/main-v2.html b/test/runtime/samples/self-reference-tree/main-v2.html new file mode 100644 index 000000000000..6663cf95338f --- /dev/null +++ b/test/runtime/samples/self-reference-tree/main-v2.html @@ -0,0 +1,11 @@ +
+ {file.name} + + {#if file.type === 'folder'} +
    + {#each file.children as child} +
  • + {/each} +
+ {/if} +
\ No newline at end of file diff --git a/test/runtime/samples/self-reference/main-v2.html b/test/runtime/samples/self-reference/main-v2.html new file mode 100644 index 000000000000..e5581203c30c --- /dev/null +++ b/test/runtime/samples/self-reference/main-v2.html @@ -0,0 +1,4 @@ +{depth} +{#if depth > 0} + +{/if} \ No newline at end of file diff --git a/test/runtime/samples/window-bind-scroll-update/main-v2.html b/test/runtime/samples/window-bind-scroll-update/main-v2.html new file mode 100644 index 000000000000..107ebeef8fc6 --- /dev/null +++ b/test/runtime/samples/window-bind-scroll-update/main-v2.html @@ -0,0 +1,3 @@ + + +
\ No newline at end of file diff --git a/test/runtime/samples/window-binding-resize/main-v2.html b/test/runtime/samples/window-binding-resize/main-v2.html new file mode 100644 index 000000000000..54a1762eb83b --- /dev/null +++ b/test/runtime/samples/window-binding-resize/main-v2.html @@ -0,0 +1,3 @@ + + +
{width}x{height}
\ No newline at end of file diff --git a/test/runtime/samples/window-event-context/main-v2.html b/test/runtime/samples/window-event-context/main-v2.html new file mode 100644 index 000000000000..af60672a2ad7 --- /dev/null +++ b/test/runtime/samples/window-event-context/main-v2.html @@ -0,0 +1,3 @@ + + +{foo} \ No newline at end of file diff --git a/test/runtime/samples/window-event-custom/main-v2.html b/test/runtime/samples/window-event-custom/main-v2.html new file mode 100644 index 000000000000..515d5bc4caf0 --- /dev/null +++ b/test/runtime/samples/window-event-custom/main-v2.html @@ -0,0 +1,25 @@ + + +

escaped: {escaped}

+ + \ No newline at end of file From 7576d7dc931088947d59e5e6a6b230de4294863b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 14 Apr 2018 14:05:01 -0400 Subject: [PATCH 14/15] update keyed each block syntax --- src/parse/state/mustache.ts | 6 ++++-- .../samples/each-block-keyed/input-v2.html | 2 +- .../samples/each-block-keyed/output-v2.json | 18 +++++++++--------- .../samples/each-block-keyed/main-v2.html | 3 +++ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 test/runtime/samples/each-block-keyed/main-v2.html diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index de4d00037bad..41762c2575da 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -274,8 +274,8 @@ export default function mustache(parser: Parser) { parser.allowWhitespace(); } - if (parser.eat('key')) { - parser.requireWhitespace(); + if (parser.eat('(')) { + parser.allowWhitespace(); const expression = readExpression(parser); @@ -292,6 +292,8 @@ export default function mustache(parser: Parser) { block.key = expression.property.name; parser.allowWhitespace(); + parser.eat(')', true); + parser.allowWhitespace(); } else if (parser.eat('@')) { block.key = parser.readIdentifier(); if (!block.key) parser.error(`Expected name`); diff --git a/test/parser/samples/each-block-keyed/input-v2.html b/test/parser/samples/each-block-keyed/input-v2.html index 3cc00ce93e39..46348678d448 100644 --- a/test/parser/samples/each-block-keyed/input-v2.html +++ b/test/parser/samples/each-block-keyed/input-v2.html @@ -1,3 +1,3 @@ -{#each todos as todo key todo.id} +{#each todos as todo (todo.id)}

{todo}

{/each} diff --git a/test/parser/samples/each-block-keyed/output-v2.json b/test/parser/samples/each-block-keyed/output-v2.json index 514682b77024..461992347b74 100644 --- a/test/parser/samples/each-block-keyed/output-v2.json +++ b/test/parser/samples/each-block-keyed/output-v2.json @@ -1,13 +1,13 @@ { - "hash": "3sm0ec", + "hash": "1x6az5m", "html": { "start": 0, - "end": 56, + "end": 54, "type": "Fragment", "children": [ { "start": 0, - "end": 56, + "end": 54, "type": "EachBlock", "expression": { "type": "Identifier", @@ -17,20 +17,20 @@ }, "children": [ { - "start": 35, - "end": 48, + "start": 33, + "end": 46, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 38, - "end": 44, + "start": 36, + "end": 42, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 39, - "end": 43, + "start": 37, + "end": 41, "name": "todo" } } diff --git a/test/runtime/samples/each-block-keyed/main-v2.html b/test/runtime/samples/each-block-keyed/main-v2.html new file mode 100644 index 000000000000..3be42ebc77b4 --- /dev/null +++ b/test/runtime/samples/each-block-keyed/main-v2.html @@ -0,0 +1,3 @@ +{#each todos as todo, i (todo.id)} +

{i+1}: {todo.description}

+{/each} From 2b3fe0edc16d67d28caa18d60116269d32a8d960 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 14 Apr 2018 14:17:21 -0400 Subject: [PATCH 15/15] attribute shorthand test --- .../samples/attribute-dynamic-shorthand/main-v2.html | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/runtime/samples/attribute-dynamic-shorthand/main-v2.html diff --git a/test/runtime/samples/attribute-dynamic-shorthand/main-v2.html b/test/runtime/samples/attribute-dynamic-shorthand/main-v2.html new file mode 100644 index 000000000000..9bbc47727246 --- /dev/null +++ b/test/runtime/samples/attribute-dynamic-shorthand/main-v2.html @@ -0,0 +1,9 @@ +
+ +