Component
+raw
+{raw}+
preprocessed
+{preprocessed}+
script
+{script}+
web component script
+{wcScript}+
style
+{style}+
all
+{JSON.stringify(all, null, 2)}+
diff --git a/.changeset/fresh-papayas-change.md b/.changeset/fresh-papayas-change.md new file mode 100644 index 000000000..33271b0bf --- /dev/null +++ b/.changeset/fresh-papayas-change.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +ensure sources paths in sourcemaps are not absolute file paths diff --git a/.changeset/giant-tools-hunt.md b/.changeset/giant-tools-hunt.md new file mode 100644 index 000000000..dbad90906 --- /dev/null +++ b/.changeset/giant-tools-hunt.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': minor +--- + +support `&direct` and `&raw` query parameters for svelte requests diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md new file mode 100644 index 000000000..9e9906351 --- /dev/null +++ b/docs/advanced-usage.md @@ -0,0 +1,125 @@ +# Advanced usage + +> **HERE BE DRAGONS** +> +> The features described here are not meant to be used in regular libraries or end-user applications. +> They can be useful for frameworks, documentation sites or in special situations, but you are responsible for applying them correctly. +> +> **Proceed with caution!** + +## custom queries + +Vite supports using query parameters to request different outcomes for the same file. + +The following schemes are supported by vite-plugin-svelte: + +### raw + +```js +//get .svelte file content as a string +import content from 'File.svelte?raw'; +``` + +### experimental + +In addition to the plain .svelte source content, you can use special svelte queries. + +> These svelte subqueries are experimental, availability, syntax and output format may change + +#### raw&svelte + +```js +//get output of svelte.preprocess code as string +import preprocessed from 'File.svelte?raw&svelte&type=preprocessed'; +``` + +```js +//get output of svelte.compile js.code as string +import script from 'File.svelte?raw&svelte&type=script'; +``` + +```js +//get output of svelte.compile css.code as string +import style from 'File.svelte?raw&svelte&type=style'; +``` + +##### detail exports + +raw&svelte exports code string as default export, but also offers named exports if you need details + +```js +//get output of svelte.preprocess +import { code, map, dependencies } from 'File.svelte?raw&svelte&type=preprocessed'; +``` + +```js +//get output of svelte.compile js +import { code, map, dependencies } from 'File.svelte?raw&svelte&type=script'; +``` + +```js +//get output of svelte.compile css +import { code, map, dependencies } from 'File.svelte?raw&svelte&type=style'; +``` + +```js +//get everything in one go +import * as all from 'File.svelte?raw&svelte&type=all'; +import { + source, + preprocessed, + dependencies, + js, + css, + ast, + normalizedFilename, + ssr, + lang, + warnings, + stats +} from 'File.svelte?raw&svelte&type=all'; +``` + +#### direct&svelte + +```html + + + + +``` + +#### sourcemap + +add `&sourcemap` to `?(raw|direct)&svelte&type=(script|style|all)` queries to include sourcemaps (inline for direct) + +#### compilerOptions + +?raw and ?direct use default compilerOptions, even if you have different values in your svelte.config.js: + +```js +const compilerOptions = { + dev: false, + generate: 'dom', + css: false, + hydratable: false, + enableSourcemap: false // or {js: true} or {css:true} if sourcemap query is set +}; +``` + +to get output with different compilerOptions, append them as json like this: + +```js +//get ssr output of svelte.compile js as {code, map, dependencies} +import script from 'File.svelte?raw&svelte&type=script&compilerOptions={generate:"ssr"}'; +``` + +only a subset of compilerOptions is supported + +- generate +- dev +- css +- hydratable +- customElement +- immutable +- enableSourcemap diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/import-queries.spec.ts.snap b/packages/e2e-tests/import-queries/__tests__/__snapshots__/import-queries.spec.ts.snap new file mode 100644 index 000000000..6c016de89 --- /dev/null +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/import-queries.spec.ts.snap @@ -0,0 +1,1118 @@ +// Vitest Snapshot v1 + +exports[`direct > Dummy.svelte?direct&svelte&type=script&sourcemap&lang.js 1`] = ` +"/* src/Dummy.svelte generated by Svelte vXXX */ +import { + SvelteComponent as SvelteComponent$, + append as append$, + attr as attr$, + detach as detach$, + element as element$, + init as init$, + insert as insert$, + listen as listen$, + noop as noop$, + safe_not_equal as safe_not_equal$, + set_data as set_data$, + text as text$ +} from \\"/node_modules/.vite/deps/svelte_internal.js?v=XXX\\"; + +function create_fragment(ctx) { + let button$; + let t0$; + let t1$; + let t2$; + let mounted; + let dispose; + + return { + c() { + button$ = element$(\\"button\\"); + t0$ = text$(/*name*/ ctx[0]); + t1$ = text$(\\" clicks: \\"); + t2$ = text$(/*clicks*/ ctx[1]); + attr$(button$, \\"class\\", \\"svelte-d8vj6a\\"); + }, + m(target, anchor) { + insert$(target, button$, anchor); + append$(button$, t0$); + append$(button$, t1$); + append$(button$, t2$); + + if (!mounted) { + dispose = listen$(button$, \\"click\\", /*click_handler$*/ ctx[2]); + mounted = true; + } + }, + p(ctx, [dirty]) { + if (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]); + if (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]); + }, + i: noop$, + o: noop$, + d(detaching) { + if (detaching) detach$(button$); + mounted = false; + dispose(); + } + }; +} + +function instance$($$self, $$props, $$invalidate) { + let { name } = $$props; + let clicks = 0; + + const click_handler$ = () => { + $$invalidate(1, clicks++, clicks); + }; + + $$self.$$set = $$props => { + if ('name' in $$props) $$invalidate(0, name = $$props.name); + }; + + return [name, clicks, click_handler$]; +} + +class Dummy$ extends SvelteComponent$ { + constructor(options) { + super(); + init$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 }); + } +} + +export default Dummy$; + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O3dCQVFLLEdBQUk7ZUFBQyxXQUFTOzBCQUFDLEdBQU07Ozs7R0FIMUIsT0FJQTs7Ozs7Ozs7Ozs7bURBREssR0FBSTt1REFBVyxHQUFNOzs7Ozs7Ozs7Ozs7O09BUGQsSUFBQTtLQUNQLE1BQUEsR0FBUyxDQUFBOzs7a0JBS1osTUFBTTs7Ozs7Ozs7Ozs7Ozs7Ozs7IiwibmFtZXMiOltdLCJzb3VyY2VzIjpbIkR1bW15LnN2ZWx0ZSJdfQ== +" +`; + +exports[`direct > Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css 1`] = ` +"button.svelte-d8vj6a{color:#000099} + +/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRHVtbXkuc3ZlbHRlIiwibWFwcGluZ3MiOiJBQVdrQixNQUFBLGNBQUEsQ0FBQSxjQUtsQiIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJEdW1teS5zdmVsdGUiXX0= */ +" +`; + +exports[`raw > Dummy.svelte?raw 1`] = ` +" + + + + +" +`; + +exports[`raw > Dummy.svelte?raw&svelte&type=all&sourcemap 1`] = ` +"{ + \\"ast\\": { + \\"html\\": { + \\"start\\": 62, + \\"end\\": 138, + \\"type\\": \\"Fragment\\", + \\"children\\": [ + { + \\"start\\": 60, + \\"end\\": 62, + \\"type\\": \\"Text\\", + \\"raw\\": \\"\\\\n\\\\n\\", + \\"data\\": \\"\\\\n\\\\n\\" + }, + { + \\"start\\": 62, + \\"end\\": 138, + \\"type\\": \\"Element\\", + \\"name\\": \\"button\\", + \\"attributes\\": [ + { + \\"start\\": 71, + \\"end\\": 104, + \\"type\\": \\"EventHandler\\", + \\"name\\": \\"click\\", + \\"modifiers\\": [], + \\"expression\\": { + \\"type\\": \\"ArrowFunctionExpression\\", + \\"start\\": 81, + \\"end\\": 103, + \\"loc\\": { + \\"start\\": { + \\"line\\": 6, + \\"column\\": 11 + }, + \\"end\\": { + \\"line\\": 8, + \\"column\\": 2 + } + }, + \\"id\\": null, + \\"expression\\": false, + \\"generator\\": false, + \\"async\\": false, + \\"params\\": [], + \\"body\\": { + \\"type\\": \\"BlockStatement\\", + \\"start\\": 87, + \\"end\\": 103, + \\"loc\\": { + \\"start\\": { + \\"line\\": 6, + \\"column\\": 17 + }, + \\"end\\": { + \\"line\\": 8, + \\"column\\": 2 + } + }, + \\"body\\": [ + { + \\"type\\": \\"ExpressionStatement\\", + \\"start\\": 91, + \\"end\\": 100, + \\"loc\\": { + \\"start\\": { + \\"line\\": 7, + \\"column\\": 2 + }, + \\"end\\": { + \\"line\\": 7, + \\"column\\": 11 + } + }, + \\"expression\\": { + \\"type\\": \\"UpdateExpression\\", + \\"start\\": 91, + \\"end\\": 99, + \\"loc\\": { + \\"start\\": { + \\"line\\": 7, + \\"column\\": 2 + }, + \\"end\\": { + \\"line\\": 7, + \\"column\\": 10 + } + }, + \\"operator\\": \\"++\\", + \\"prefix\\": false, + \\"argument\\": { + \\"type\\": \\"Identifier\\", + \\"start\\": 91, + \\"end\\": 97, + \\"loc\\": { + \\"start\\": { + \\"line\\": 7, + \\"column\\": 2 + }, + \\"end\\": { + \\"line\\": 7, + \\"column\\": 8 + } + }, + \\"name\\": \\"clicks\\" + } + } + } + ] + } + } + } + ], + \\"children\\": [ + { + \\"start\\": 105, + \\"end\\": 111, + \\"type\\": \\"MustacheTag\\", + \\"expression\\": { + \\"type\\": \\"Identifier\\", + \\"start\\": 106, + \\"end\\": 110, + \\"loc\\": { + \\"start\\": { + \\"line\\": 8, + \\"column\\": 5 + }, + \\"end\\": { + \\"line\\": 8, + \\"column\\": 9 + } + }, + \\"name\\": \\"name\\" + } + }, + { + \\"start\\": 111, + \\"end\\": 120, + \\"type\\": \\"Text\\", + \\"raw\\": \\" clicks: \\", + \\"data\\": \\" clicks: \\" + }, + { + \\"start\\": 120, + \\"end\\": 128, + \\"type\\": \\"MustacheTag\\", + \\"expression\\": { + \\"type\\": \\"Identifier\\", + \\"start\\": 121, + \\"end\\": 127, + \\"loc\\": { + \\"start\\": { + \\"line\\": 8, + \\"column\\": 20 + }, + \\"end\\": { + \\"line\\": 8, + \\"column\\": 26 + } + }, + \\"name\\": \\"clicks\\" + } + } + ] + }, + { + \\"start\\": 138, + \\"end\\": 140, + \\"type\\": \\"Text\\", + \\"raw\\": \\"\\\\n\\\\n\\", + \\"data\\": \\"\\\\n\\\\n\\" + } + ] + }, + \\"css\\": { + \\"type\\": \\"Style\\", + \\"start\\": 140, + \\"end\\": 195, + \\"attributes\\": [ + { + \\"start\\": 147, + \\"end\\": 158, + \\"type\\": \\"Attribute\\", + \\"name\\": \\"lang\\", + \\"value\\": [ + { + \\"start\\": 153, + \\"end\\": 157, + \\"type\\": \\"Text\\", + \\"raw\\": \\"scss\\", + \\"data\\": \\"scss\\" + } + ] + } + ], + \\"children\\": [ + { + \\"type\\": \\"Rule\\", + \\"prelude\\": { + \\"type\\": \\"SelectorList\\", + \\"children\\": [ + { + \\"type\\": \\"Selector\\", + \\"children\\": [ + { + \\"type\\": \\"TypeSelector\\", + \\"name\\": \\"button\\", + \\"start\\": 159, + \\"end\\": 165 + } + ], + \\"start\\": 159, + \\"end\\": 165 + } + ], + \\"start\\": 159, + \\"end\\": 165 + }, + \\"block\\": { + \\"type\\": \\"Block\\", + \\"children\\": [ + { + \\"type\\": \\"Declaration\\", + \\"important\\": false, + \\"property\\": \\"color\\", + \\"value\\": { + \\"type\\": \\"Value\\", + \\"children\\": [ + { + \\"type\\": \\"Hash\\", + \\"value\\": \\"000099\\", + \\"start\\": 177, + \\"end\\": 184 + } + ], + \\"start\\": 177, + \\"end\\": 184 + }, + \\"start\\": 170, + \\"end\\": 184 + } + ], + \\"start\\": 166, + \\"end\\": 187 + }, + \\"start\\": 159, + \\"end\\": 187 + } + ], + \\"content\\": { + \\"start\\": 159, + \\"end\\": 187, + \\"styles\\": \\"button {\\\\n color: #000099;\\\\n}\\" + } + }, + \\"instance\\": { + \\"type\\": \\"Script\\", + \\"start\\": 0, + \\"end\\": 60, + \\"context\\": \\"default\\", + \\"content\\": { + \\"type\\": \\"Program\\", + \\"start\\": 18, + \\"end\\": 51, + \\"loc\\": { + \\"start\\": { + \\"line\\": 1, + \\"column\\": 0 + }, + \\"end\\": { + \\"line\\": 3, + \\"column\\": 0 + } + }, + \\"body\\": [ + { + \\"type\\": \\"ExportNamedDeclaration\\", + \\"start\\": 18, + \\"end\\": 34, + \\"loc\\": { + \\"start\\": { + \\"line\\": 1, + \\"column\\": 18 + }, + \\"end\\": { + \\"line\\": 1, + \\"column\\": 34 + } + }, + \\"declaration\\": { + \\"type\\": \\"VariableDeclaration\\", + \\"start\\": 25, + \\"end\\": 34, + \\"loc\\": { + \\"start\\": { + \\"line\\": 1, + \\"column\\": 25 + }, + \\"end\\": { + \\"line\\": 1, + \\"column\\": 34 + } + }, + \\"declarations\\": [ + { + \\"type\\": \\"VariableDeclarator\\", + \\"start\\": 29, + \\"end\\": 33, + \\"loc\\": { + \\"start\\": { + \\"line\\": 1, + \\"column\\": 29 + }, + \\"end\\": { + \\"line\\": 1, + \\"column\\": 33 + } + }, + \\"id\\": { + \\"type\\": \\"Identifier\\", + \\"start\\": 29, + \\"end\\": 33, + \\"loc\\": { + \\"start\\": { + \\"line\\": 1, + \\"column\\": 29 + }, + \\"end\\": { + \\"line\\": 1, + \\"column\\": 33 + } + }, + \\"name\\": \\"name\\" + }, + \\"init\\": null + } + ], + \\"kind\\": \\"let\\" + }, + \\"specifiers\\": [], + \\"source\\": null + }, + { + \\"type\\": \\"VariableDeclaration\\", + \\"start\\": 35, + \\"end\\": 50, + \\"loc\\": { + \\"start\\": { + \\"line\\": 2, + \\"column\\": 0 + }, + \\"end\\": { + \\"line\\": 2, + \\"column\\": 15 + } + }, + \\"declarations\\": [ + { + \\"type\\": \\"VariableDeclarator\\", + \\"start\\": 39, + \\"end\\": 49, + \\"loc\\": { + \\"start\\": { + \\"line\\": 2, + \\"column\\": 4 + }, + \\"end\\": { + \\"line\\": 2, + \\"column\\": 14 + } + }, + \\"id\\": { + \\"type\\": \\"Identifier\\", + \\"start\\": 39, + \\"end\\": 45, + \\"loc\\": { + \\"start\\": { + \\"line\\": 2, + \\"column\\": 4 + }, + \\"end\\": { + \\"line\\": 2, + \\"column\\": 10 + } + }, + \\"name\\": \\"clicks\\" + }, + \\"init\\": { + \\"type\\": \\"Literal\\", + \\"start\\": 48, + \\"end\\": 49, + \\"loc\\": { + \\"start\\": { + \\"line\\": 2, + \\"column\\": 13 + }, + \\"end\\": { + \\"line\\": 2, + \\"column\\": 14 + } + }, + \\"value\\": 0, + \\"raw\\": \\"0\\" + } + } + ], + \\"kind\\": \\"let\\" + } + ], + \\"sourceType\\": \\"module\\" + } + } + }, + \\"css\\": { + \\"code\\": \\"button.svelte-d8vj6a{color:#000099}\\", + \\"map\\": { + \\"version\\": 3, + \\"file\\": \\"Dummy.svelte\\", + \\"mappings\\": \\"AAWkB,MAAA,cAAA,CAAA,cAKlB\\", + \\"names\\": [], + \\"sources\\": [ + \\"Dummy.svelte\\" + ] + } + }, + \\"dependencies\\": [], + \\"js\\": { + \\"code\\": \\"/* src/Dummy.svelte generated by Svelte vXXX */\\\\nimport {\\\\n\\\\tSvelteComponent as SvelteComponent$,\\\\n\\\\tappend as append$,\\\\n\\\\tattr as attr$,\\\\n\\\\tdetach as detach$,\\\\n\\\\telement as element$,\\\\n\\\\tinit as init$,\\\\n\\\\tinsert as insert$,\\\\n\\\\tlisten as listen$,\\\\n\\\\tnoop as noop$,\\\\n\\\\tsafe_not_equal as safe_not_equal$,\\\\n\\\\tset_data as set_data$,\\\\n\\\\ttext as text$\\\\n} from \\\\\\"svelte/internal\\\\\\";\\\\n\\\\nfunction create_fragment(ctx) {\\\\n\\\\tlet button$;\\\\n\\\\tlet t0$;\\\\n\\\\tlet t1$;\\\\n\\\\tlet t2$;\\\\n\\\\tlet mounted;\\\\n\\\\tlet dispose;\\\\n\\\\n\\\\treturn {\\\\n\\\\t\\\\tc() {\\\\n\\\\t\\\\t\\\\tbutton$ = element$(\\\\\\"button\\\\\\");\\\\n\\\\t\\\\t\\\\tt0$ = text$(/*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tt1$ = text$(\\\\\\" clicks: \\\\\\");\\\\n\\\\t\\\\t\\\\tt2$ = text$(/*clicks*/ ctx[1]);\\\\n\\\\t\\\\t\\\\tattr$(button$, \\\\\\"class\\\\\\", \\\\\\"svelte-d8vj6a\\\\\\");\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tm(target, anchor) {\\\\n\\\\t\\\\t\\\\tinsert$(target, button$, anchor);\\\\n\\\\t\\\\t\\\\tappend$(button$, t0$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t1$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t2$);\\\\n\\\\n\\\\t\\\\t\\\\tif (!mounted) {\\\\n\\\\t\\\\t\\\\t\\\\tdispose = listen$(button$, \\\\\\"click\\\\\\", /*click_handler$*/ ctx[2]);\\\\n\\\\t\\\\t\\\\t\\\\tmounted = true;\\\\n\\\\t\\\\t\\\\t}\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tp(ctx, [dirty]) {\\\\n\\\\t\\\\t\\\\tif (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tif (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]);\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\ti: noop$,\\\\n\\\\t\\\\to: noop$,\\\\n\\\\t\\\\td(detaching) {\\\\n\\\\t\\\\t\\\\tif (detaching) detach$(button$);\\\\n\\\\t\\\\t\\\\tmounted = false;\\\\n\\\\t\\\\t\\\\tdispose();\\\\n\\\\t\\\\t}\\\\n\\\\t};\\\\n}\\\\n\\\\nfunction instance$($$self, $$props, $$invalidate) {\\\\n\\\\tlet { name } = $$props;\\\\n\\\\tlet clicks = 0;\\\\n\\\\n\\\\tconst click_handler$ = () => {\\\\n\\\\t\\\\t$$invalidate(1, clicks++, clicks);\\\\n\\\\t};\\\\n\\\\n\\\\t$$self.$$set = $$props => {\\\\n\\\\t\\\\tif ('name' in $$props) $$invalidate(0, name = $$props.name);\\\\n\\\\t};\\\\n\\\\n\\\\treturn [name, clicks, click_handler$];\\\\n}\\\\n\\\\nclass Dummy$ extends SvelteComponent$ {\\\\n\\\\tconstructor(options) {\\\\n\\\\t\\\\tsuper();\\\\n\\\\t\\\\tinit$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 });\\\\n\\\\t}\\\\n}\\\\n\\\\nexport default Dummy$;\\", + \\"map\\": { + \\"version\\": 3, + \\"mappings\\": \\";;;;;;;;;;;;;;;;;;;;;;;;;;;wBAQK,GAAI;eAAC,WAAS;0BAAC,GAAM;;;;GAH1B,OAIA;;;;;;;;;;;mDADK,GAAI;uDAAW,GAAM;;;;;;;;;;;;;OAPd,IAAA;KACP,MAAA,GAAS,CAAA;;;kBAKZ,MAAM;;;;;;;;;;;;;;;;;\\", + \\"names\\": [], + \\"sources\\": [ + \\"Dummy.svelte\\" + ] + }, + \\"dependencies\\": [] + }, + \\"lang\\": \\"ts\\", + \\"normalizedFilename\\": \\"/src/Dummy.svelte\\", + \\"preprocessed\\": { + \\"code\\": \\"\\\\n\\\\n\\\\n\\\\n\\\\n\\", + \\"dependencies\\": [], + \\"map\\": { + \\"version\\": 3, + \\"mappings\\": \\"AAAA,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CCCT,MAAA,CAAA,GAAA,CAAI,IAAA;AACX,GAAA,CAAI,MAAA,CAAA,CAAA,CAAS,CAAA;ADCd,CAAC,CAAC,MAAM;;AAER,CAAC;AACD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjB,EAAE,MAAM,CAAC,CAAC;AACV,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7B;;AAEA,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;;CAKlB,CAAC,CAAC,KAAK;\\", + \\"names\\": [], + \\"sources\\": [ + \\"Dummy.svelte\\", + \\"Dummy.svelte\\" + ] + } + }, + \\"source\\": \\"\\\\n\\\\n\\\\n\\\\n\\\\n\\", + \\"ssr\\": false, + \\"stats\\": { + \\"timings\\": { + \\"total\\":0.123456789, + \\"parse\\": { + \\"total\\":0.123456789 + }, + \\"create component\\": { + \\"total\\":0.123456789 + } + } + }, + \\"vars\\": [ + { + \\"name\\": \\"name\\", + \\"export_name\\": \\"name\\", + \\"injected\\": false, + \\"module\\": false, + \\"mutated\\": false, + \\"reassigned\\": false, + \\"referenced\\": true, + \\"writable\\": true, + \\"referenced_from_script\\": false + }, + { + \\"name\\": \\"clicks\\", + \\"export_name\\": null, + \\"injected\\": false, + \\"module\\": false, + \\"mutated\\": false, + \\"reassigned\\": true, + \\"referenced\\": true, + \\"writable\\": true, + \\"referenced_from_script\\": false + } + ], + \\"warnings\\": [] +}" +`; + +exports[`raw > Dummy.svelte?raw&svelte&type=preprocessed 1`] = ` +" + + + + +" +`; + +exports[`raw > Dummy.svelte?raw&svelte&type=script 1`] = ` +"/* src/Dummy.svelte generated by Svelte vXXX */ +import { + SvelteComponent as SvelteComponent$, + append as append$, + attr as attr$, + detach as detach$, + element as element$, + init as init$, + insert as insert$, + listen as listen$, + noop as noop$, + safe_not_equal as safe_not_equal$, + set_data as set_data$, + text as text$ +} from \\"svelte/internal\\"; + +function create_fragment(ctx) { + let button$; + let t0$; + let t1$; + let t2$; + let mounted; + let dispose; + + return { + c() { + button$ = element$(\\"button\\"); + t0$ = text$(/*name*/ ctx[0]); + t1$ = text$(\\" clicks: \\"); + t2$ = text$(/*clicks*/ ctx[1]); + attr$(button$, \\"class\\", \\"svelte-d8vj6a\\"); + }, + m(target, anchor) { + insert$(target, button$, anchor); + append$(button$, t0$); + append$(button$, t1$); + append$(button$, t2$); + + if (!mounted) { + dispose = listen$(button$, \\"click\\", /*click_handler$*/ ctx[2]); + mounted = true; + } + }, + p(ctx, [dirty]) { + if (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]); + if (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]); + }, + i: noop$, + o: noop$, + d(detaching) { + if (detaching) detach$(button$); + mounted = false; + dispose(); + } + }; +} + +function instance$($$self, $$props, $$invalidate) { + let { name } = $$props; + let clicks = 0; + + const click_handler$ = () => { + $$invalidate(1, clicks++, clicks); + }; + + $$self.$$set = $$props => { + if ('name' in $$props) $$invalidate(0, name = $$props.name); + }; + + return [name, clicks, click_handler$]; +} + +class Dummy$ extends SvelteComponent$ { + constructor(options) { + super(); + init$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 }); + } +} + +export default Dummy$;" +`; + +exports[`raw > Dummy.svelte?raw&svelte&type=script&compilerOptions={"customElement":true} 1`] = ` +"/* src/Dummy.svelte generated by Svelte vXXX */ +import { + SvelteElement as SvelteElement$, + append as append$, + attribute_to_object as attribute_to_object$, + detach as detach$, + element as element$, + flush as flush$, + init as init$, + insert as insert$, + listen as listen$, + noop as noop$, + safe_not_equal as safe_not_equal$, + set_data as set_data$, + text as text$ +} from \\"svelte/internal\\"; + +function create_fragment(ctx) { + let button$; + let t0$; + let t1$; + let t2$; + let mounted; + let dispose; + + return { + c() { + button$ = element$(\\"button\\"); + t0$ = text$(/*name*/ ctx[0]); + t1$ = text$(\\" clicks: \\"); + t2$ = text$(/*clicks*/ ctx[1]); + this.c = noop$; + }, + m(target, anchor) { + insert$(target, button$, anchor); + append$(button$, t0$); + append$(button$, t1$); + append$(button$, t2$); + + if (!mounted) { + dispose = listen$(button$, \\"click\\", /*click_handler$*/ ctx[2]); + mounted = true; + } + }, + p(ctx, [dirty]) { + if (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]); + if (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]); + }, + i: noop$, + o: noop$, + d(detaching) { + if (detaching) detach$(button$); + mounted = false; + dispose(); + } + }; +} + +function instance$($$self, $$props, $$invalidate) { + let { name } = $$props; + let clicks = 0; + + const click_handler$ = () => { + $$invalidate(1, clicks++, clicks); + }; + + $$self.$$set = $$props => { + if ('name' in $$props) $$invalidate(0, name = $$props.name); + }; + + return [name, clicks, click_handler$]; +} + +class Dummy$ extends SvelteElement$ { + constructor(options) { + super(); + this.shadowRoot.innerHTML = \`\`; + + init$( + this, + { + target: this.shadowRoot, + props: attribute_to_object$(this.attributes), + customElement: true + }, + instance$, + create_fragment, + safe_not_equal$, + { name: 0 }, + null + ); + + if (options) { + if (options.target) { + insert$(options.target, this, options.anchor); + } + + if (options.props) { + this.$set(options.props); + flush$(); + } + } + } + + static get observedAttributes() { + return [\\"name\\"]; + } + + get name() { + return this.$$.ctx[0]; + } + + set name(name) { + this.$$set({ name }); + flush$(); + } +} + +export default Dummy$;" +`; + +exports[`raw > Dummy.svelte?raw&svelte&type=style 1`] = `"button.svelte-d8vj6a{color:#000099}"`; + +exports[`raw > mixed exports > Dummy.svelte?raw&svelte&type=all 1`] = ` +"export const ast={\\"html\\":{\\"start\\":62,\\"end\\":138,\\"type\\":\\"Fragment\\",\\"children\\":[{\\"start\\":60,\\"end\\":62,\\"type\\":\\"Text\\",\\"raw\\":\\"\\\\n\\\\n\\",\\"data\\":\\"\\\\n\\\\n\\"},{\\"start\\":62,\\"end\\":138,\\"type\\":\\"Element\\",\\"name\\":\\"button\\",\\"attributes\\":[{\\"start\\":71,\\"end\\":104,\\"type\\":\\"EventHandler\\",\\"name\\":\\"click\\",\\"modifiers\\":[],\\"expression\\":{\\"type\\":\\"ArrowFunctionExpression\\",\\"start\\":81,\\"end\\":103,\\"loc\\":{\\"start\\":{\\"line\\":6,\\"column\\":11},\\"end\\":{\\"line\\":8,\\"column\\":2}},\\"id\\":null,\\"expression\\":false,\\"generator\\":false,\\"async\\":false,\\"params\\":[],\\"body\\":{\\"type\\":\\"BlockStatement\\",\\"start\\":87,\\"end\\":103,\\"loc\\":{\\"start\\":{\\"line\\":6,\\"column\\":17},\\"end\\":{\\"line\\":8,\\"column\\":2}},\\"body\\":[{\\"type\\":\\"ExpressionStatement\\",\\"start\\":91,\\"end\\":100,\\"loc\\":{\\"start\\":{\\"line\\":7,\\"column\\":2},\\"end\\":{\\"line\\":7,\\"column\\":11}},\\"expression\\":{\\"type\\":\\"UpdateExpression\\",\\"start\\":91,\\"end\\":99,\\"loc\\":{\\"start\\":{\\"line\\":7,\\"column\\":2},\\"end\\":{\\"line\\":7,\\"column\\":10}},\\"operator\\":\\"++\\",\\"prefix\\":false,\\"argument\\":{\\"type\\":\\"Identifier\\",\\"start\\":91,\\"end\\":97,\\"loc\\":{\\"start\\":{\\"line\\":7,\\"column\\":2},\\"end\\":{\\"line\\":7,\\"column\\":8}},\\"name\\":\\"clicks\\"}}}]}}}],\\"children\\":[{\\"start\\":105,\\"end\\":111,\\"type\\":\\"MustacheTag\\",\\"expression\\":{\\"type\\":\\"Identifier\\",\\"start\\":106,\\"end\\":110,\\"loc\\":{\\"start\\":{\\"line\\":8,\\"column\\":5},\\"end\\":{\\"line\\":8,\\"column\\":9}},\\"name\\":\\"name\\"}},{\\"start\\":111,\\"end\\":120,\\"type\\":\\"Text\\",\\"raw\\":\\" clicks: \\",\\"data\\":\\" clicks: \\"},{\\"start\\":120,\\"end\\":128,\\"type\\":\\"MustacheTag\\",\\"expression\\":{\\"type\\":\\"Identifier\\",\\"start\\":121,\\"end\\":127,\\"loc\\":{\\"start\\":{\\"line\\":8,\\"column\\":20},\\"end\\":{\\"line\\":8,\\"column\\":26}},\\"name\\":\\"clicks\\"}}]},{\\"start\\":138,\\"end\\":140,\\"type\\":\\"Text\\",\\"raw\\":\\"\\\\n\\\\n\\",\\"data\\":\\"\\\\n\\\\n\\"}]},\\"css\\":{\\"type\\":\\"Style\\",\\"start\\":140,\\"end\\":195,\\"attributes\\":[{\\"start\\":147,\\"end\\":158,\\"type\\":\\"Attribute\\",\\"name\\":\\"lang\\",\\"value\\":[{\\"start\\":153,\\"end\\":157,\\"type\\":\\"Text\\",\\"raw\\":\\"scss\\",\\"data\\":\\"scss\\"}]}],\\"children\\":[{\\"type\\":\\"Rule\\",\\"prelude\\":{\\"type\\":\\"SelectorList\\",\\"children\\":[{\\"type\\":\\"Selector\\",\\"children\\":[{\\"type\\":\\"TypeSelector\\",\\"name\\":\\"button\\",\\"start\\":159,\\"end\\":165}],\\"start\\":159,\\"end\\":165}],\\"start\\":159,\\"end\\":165},\\"block\\":{\\"type\\":\\"Block\\",\\"children\\":[{\\"type\\":\\"Declaration\\",\\"important\\":false,\\"property\\":\\"color\\",\\"value\\":{\\"type\\":\\"Value\\",\\"children\\":[{\\"type\\":\\"Hash\\",\\"value\\":\\"000099\\",\\"start\\":177,\\"end\\":184}],\\"start\\":177,\\"end\\":184},\\"start\\":170,\\"end\\":184}],\\"start\\":166,\\"end\\":187},\\"start\\":159,\\"end\\":187}],\\"content\\":{\\"start\\":159,\\"end\\":187,\\"styles\\":\\"button {\\\\n color: #000099;\\\\n}\\"}},\\"instance\\":{\\"type\\":\\"Script\\",\\"start\\":0,\\"end\\":60,\\"context\\":\\"default\\",\\"content\\":{\\"type\\":\\"Program\\",\\"start\\":18,\\"end\\":51,\\"loc\\":{\\"start\\":{\\"line\\":1,\\"column\\":0},\\"end\\":{\\"line\\":3,\\"column\\":0}},\\"body\\":[{\\"type\\":\\"ExportNamedDeclaration\\",\\"start\\":18,\\"end\\":34,\\"loc\\":{\\"start\\":{\\"line\\":1,\\"column\\":18},\\"end\\":{\\"line\\":1,\\"column\\":34}},\\"declaration\\":{\\"type\\":\\"VariableDeclaration\\",\\"start\\":25,\\"end\\":34,\\"loc\\":{\\"start\\":{\\"line\\":1,\\"column\\":25},\\"end\\":{\\"line\\":1,\\"column\\":34}},\\"declarations\\":[{\\"type\\":\\"VariableDeclarator\\",\\"start\\":29,\\"end\\":33,\\"loc\\":{\\"start\\":{\\"line\\":1,\\"column\\":29},\\"end\\":{\\"line\\":1,\\"column\\":33}},\\"id\\":{\\"type\\":\\"Identifier\\",\\"start\\":29,\\"end\\":33,\\"loc\\":{\\"start\\":{\\"line\\":1,\\"column\\":29},\\"end\\":{\\"line\\":1,\\"column\\":33}},\\"name\\":\\"name\\"},\\"init\\":null}],\\"kind\\":\\"let\\"},\\"specifiers\\":[],\\"source\\":null},{\\"type\\":\\"VariableDeclaration\\",\\"start\\":35,\\"end\\":50,\\"loc\\":{\\"start\\":{\\"line\\":2,\\"column\\":0},\\"end\\":{\\"line\\":2,\\"column\\":15}},\\"declarations\\":[{\\"type\\":\\"VariableDeclarator\\",\\"start\\":39,\\"end\\":49,\\"loc\\":{\\"start\\":{\\"line\\":2,\\"column\\":4},\\"end\\":{\\"line\\":2,\\"column\\":14}},\\"id\\":{\\"type\\":\\"Identifier\\",\\"start\\":39,\\"end\\":45,\\"loc\\":{\\"start\\":{\\"line\\":2,\\"column\\":4},\\"end\\":{\\"line\\":2,\\"column\\":10}},\\"name\\":\\"clicks\\"},\\"init\\":{\\"type\\":\\"Literal\\",\\"start\\":48,\\"end\\":49,\\"loc\\":{\\"start\\":{\\"line\\":2,\\"column\\":13},\\"end\\":{\\"line\\":2,\\"column\\":14}},\\"value\\":0,\\"raw\\":\\"0\\"}}],\\"kind\\":\\"let\\"}],\\"sourceType\\":\\"module\\"}}} +export const css={\\"code\\":\\"button.svelte-d8vj6a{color:#000099}\\",\\"map\\":null} +export const dependencies=[] +export const js={\\"code\\":\\"/* src/Dummy.svelte generated by Svelte vXXX */\\\\nimport {\\\\n\\\\tSvelteComponent as SvelteComponent$,\\\\n\\\\tappend as append$,\\\\n\\\\tattr as attr$,\\\\n\\\\tdetach as detach$,\\\\n\\\\telement as element$,\\\\n\\\\tinit as init$,\\\\n\\\\tinsert as insert$,\\\\n\\\\tlisten as listen$,\\\\n\\\\tnoop as noop$,\\\\n\\\\tsafe_not_equal as safe_not_equal$,\\\\n\\\\tset_data as set_data$,\\\\n\\\\ttext as text$\\\\n} from \\\\\\"svelte/internal\\\\\\";\\\\n\\\\nfunction create_fragment(ctx) {\\\\n\\\\tlet button$;\\\\n\\\\tlet t0$;\\\\n\\\\tlet t1$;\\\\n\\\\tlet t2$;\\\\n\\\\tlet mounted;\\\\n\\\\tlet dispose;\\\\n\\\\n\\\\treturn {\\\\n\\\\t\\\\tc() {\\\\n\\\\t\\\\t\\\\tbutton$ = element$(\\\\\\"button\\\\\\");\\\\n\\\\t\\\\t\\\\tt0$ = text$(/*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tt1$ = text$(\\\\\\" clicks: \\\\\\");\\\\n\\\\t\\\\t\\\\tt2$ = text$(/*clicks*/ ctx[1]);\\\\n\\\\t\\\\t\\\\tattr$(button$, \\\\\\"class\\\\\\", \\\\\\"svelte-d8vj6a\\\\\\");\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tm(target, anchor) {\\\\n\\\\t\\\\t\\\\tinsert$(target, button$, anchor);\\\\n\\\\t\\\\t\\\\tappend$(button$, t0$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t1$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t2$);\\\\n\\\\n\\\\t\\\\t\\\\tif (!mounted) {\\\\n\\\\t\\\\t\\\\t\\\\tdispose = listen$(button$, \\\\\\"click\\\\\\", /*click_handler$*/ ctx[2]);\\\\n\\\\t\\\\t\\\\t\\\\tmounted = true;\\\\n\\\\t\\\\t\\\\t}\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tp(ctx, [dirty]) {\\\\n\\\\t\\\\t\\\\tif (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tif (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]);\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\ti: noop$,\\\\n\\\\t\\\\to: noop$,\\\\n\\\\t\\\\td(detaching) {\\\\n\\\\t\\\\t\\\\tif (detaching) detach$(button$);\\\\n\\\\t\\\\t\\\\tmounted = false;\\\\n\\\\t\\\\t\\\\tdispose();\\\\n\\\\t\\\\t}\\\\n\\\\t};\\\\n}\\\\n\\\\nfunction instance$($$self, $$props, $$invalidate) {\\\\n\\\\tlet { name } = $$props;\\\\n\\\\tlet clicks = 0;\\\\n\\\\n\\\\tconst click_handler$ = () => {\\\\n\\\\t\\\\t$$invalidate(1, clicks++, clicks);\\\\n\\\\t};\\\\n\\\\n\\\\t$$self.$$set = $$props => {\\\\n\\\\t\\\\tif ('name' in $$props) $$invalidate(0, name = $$props.name);\\\\n\\\\t};\\\\n\\\\n\\\\treturn [name, clicks, click_handler$];\\\\n}\\\\n\\\\nclass Dummy$ extends SvelteComponent$ {\\\\n\\\\tconstructor(options) {\\\\n\\\\t\\\\tsuper();\\\\n\\\\t\\\\tinit$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 });\\\\n\\\\t}\\\\n}\\\\n\\\\nexport default Dummy$;\\",\\"map\\":null,\\"dependencies\\":[]} +export const lang=\\"ts\\" +export const normalizedFilename=\\"/src/Dummy.svelte\\" +export const preprocessed={\\"code\\":\\"\\\\n\\\\n\\\\n\\\\n\\\\n\\",\\"dependencies\\":[],\\"map\\":{\\"version\\":3,\\"mappings\\":\\"AAAA,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CCCT,MAAA,CAAA,GAAA,CAAI,IAAA;AACX,GAAA,CAAI,MAAA,CAAA,CAAA,CAAS,CAAA;ADCd,CAAC,CAAC,MAAM;;AAER,CAAC;AACD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjB,EAAE,MAAM,CAAC,CAAC;AACV,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7B;;AAEA,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;;CAKlB,CAAC,CAAC,KAAK;\\",\\"names\\":[],\\"sources\\":[\\"Dummy.svelte\\",\\"Dummy.svelte\\"]}} +export const source=\\"\\\\n\\\\n\\\\n\\\\n\\\\n\\" +export const ssr=false +export const stats={\\"timings\\":{\\"total\\":0.123456789,\\"parse\\":{\\"total\\":0.123456789},\\"create component\\":{\\"total\\":0.123456789}}} +export const vars=[{\\"name\\":\\"name\\",\\"export_name\\":\\"name\\",\\"injected\\":false,\\"module\\":false,\\"mutated\\":false,\\"reassigned\\":false,\\"referenced\\":true,\\"writable\\":true,\\"referenced_from_script\\":false},{\\"name\\":\\"clicks\\",\\"export_name\\":null,\\"injected\\":false,\\"module\\":false,\\"mutated\\":false,\\"reassigned\\":true,\\"referenced\\":true,\\"writable\\":true,\\"referenced_from_script\\":false}] +export const warnings=[] +" +`; + +exports[`raw > mixed exports > Dummy.svelte?raw&svelte&type=preprocessed 1`] = ` +"export const code=\\"\\\\n\\\\n\\\\n\\\\n\\\\n\\" +export const dependencies=[] +export const map={\\"version\\":3,\\"mappings\\":\\"AAAA,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CCCT,MAAA,CAAA,GAAA,CAAI,IAAA;AACX,GAAA,CAAI,MAAA,CAAA,CAAA,CAAS,CAAA;ADCd,CAAC,CAAC,MAAM;;AAER,CAAC;AACD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjB,EAAE,MAAM,CAAC,CAAC;AACV,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7B;;AAEA,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;;CAKlB,CAAC,CAAC,KAAK;\\",\\"names\\":[],\\"sources\\":[\\"Dummy.svelte\\",\\"Dummy.svelte\\"]} +export default code +" +`; + +exports[`raw > mixed exports > Dummy.svelte?raw&svelte&type=script 1`] = ` +"export const code=\\"/* src/Dummy.svelte generated by Svelte vXXX */\\\\nimport {\\\\n\\\\tSvelteComponent as SvelteComponent$,\\\\n\\\\tappend as append$,\\\\n\\\\tattr as attr$,\\\\n\\\\tdetach as detach$,\\\\n\\\\telement as element$,\\\\n\\\\tinit as init$,\\\\n\\\\tinsert as insert$,\\\\n\\\\tlisten as listen$,\\\\n\\\\tnoop as noop$,\\\\n\\\\tsafe_not_equal as safe_not_equal$,\\\\n\\\\tset_data as set_data$,\\\\n\\\\ttext as text$\\\\n} from \\\\\\"svelte/internal\\\\\\";\\\\n\\\\nfunction create_fragment(ctx) {\\\\n\\\\tlet button$;\\\\n\\\\tlet t0$;\\\\n\\\\tlet t1$;\\\\n\\\\tlet t2$;\\\\n\\\\tlet mounted;\\\\n\\\\tlet dispose;\\\\n\\\\n\\\\treturn {\\\\n\\\\t\\\\tc() {\\\\n\\\\t\\\\t\\\\tbutton$ = element$(\\\\\\"button\\\\\\");\\\\n\\\\t\\\\t\\\\tt0$ = text$(/*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tt1$ = text$(\\\\\\" clicks: \\\\\\");\\\\n\\\\t\\\\t\\\\tt2$ = text$(/*clicks*/ ctx[1]);\\\\n\\\\t\\\\t\\\\tattr$(button$, \\\\\\"class\\\\\\", \\\\\\"svelte-d8vj6a\\\\\\");\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tm(target, anchor) {\\\\n\\\\t\\\\t\\\\tinsert$(target, button$, anchor);\\\\n\\\\t\\\\t\\\\tappend$(button$, t0$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t1$);\\\\n\\\\t\\\\t\\\\tappend$(button$, t2$);\\\\n\\\\n\\\\t\\\\t\\\\tif (!mounted) {\\\\n\\\\t\\\\t\\\\t\\\\tdispose = listen$(button$, \\\\\\"click\\\\\\", /*click_handler$*/ ctx[2]);\\\\n\\\\t\\\\t\\\\t\\\\tmounted = true;\\\\n\\\\t\\\\t\\\\t}\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\tp(ctx, [dirty]) {\\\\n\\\\t\\\\t\\\\tif (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]);\\\\n\\\\t\\\\t\\\\tif (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]);\\\\n\\\\t\\\\t},\\\\n\\\\t\\\\ti: noop$,\\\\n\\\\t\\\\to: noop$,\\\\n\\\\t\\\\td(detaching) {\\\\n\\\\t\\\\t\\\\tif (detaching) detach$(button$);\\\\n\\\\t\\\\t\\\\tmounted = false;\\\\n\\\\t\\\\t\\\\tdispose();\\\\n\\\\t\\\\t}\\\\n\\\\t};\\\\n}\\\\n\\\\nfunction instance$($$self, $$props, $$invalidate) {\\\\n\\\\tlet { name } = $$props;\\\\n\\\\tlet clicks = 0;\\\\n\\\\n\\\\tconst click_handler$ = () => {\\\\n\\\\t\\\\t$$invalidate(1, clicks++, clicks);\\\\n\\\\t};\\\\n\\\\n\\\\t$$self.$$set = $$props => {\\\\n\\\\t\\\\tif ('name' in $$props) $$invalidate(0, name = $$props.name);\\\\n\\\\t};\\\\n\\\\n\\\\treturn [name, clicks, click_handler$];\\\\n}\\\\n\\\\nclass Dummy$ extends SvelteComponent$ {\\\\n\\\\tconstructor(options) {\\\\n\\\\t\\\\tsuper();\\\\n\\\\t\\\\tinit$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 });\\\\n\\\\t}\\\\n}\\\\n\\\\nexport default Dummy$;\\" +export const dependencies=[] +export const map=null +export default code +" +`; + +exports[`raw > mixed exports > Dummy.svelte?raw&svelte&type=style 1`] = ` +"export const code=\\"button.svelte-d8vj6a{color:#000099}\\" +export const map=null +export default code +" +`; + +exports[`ssrLoadModule > ?raw 1`] = ` +" + + + + +" +`; + +exports[`ssrLoadModule > ?raw&svelte&type=preprocessed 1`] = ` +" + + + + +" +`; + +exports[`ssrLoadModule > ?raw&svelte&type=script 1`] = ` +"/* src/Dummy.svelte generated by Svelte vXXX */ +import { + SvelteComponent as SvelteComponent$, + append as append$, + attr as attr$, + detach as detach$, + element as element$, + init as init$, + insert as insert$, + listen as listen$, + noop as noop$, + safe_not_equal as safe_not_equal$, + set_data as set_data$, + text as text$ +} from \\"svelte/internal\\"; + +function create_fragment(ctx) { + let button$; + let t0$; + let t1$; + let t2$; + let mounted; + let dispose; + + return { + c() { + button$ = element$(\\"button\\"); + t0$ = text$(/*name*/ ctx[0]); + t1$ = text$(\\" clicks: \\"); + t2$ = text$(/*clicks*/ ctx[1]); + attr$(button$, \\"class\\", \\"svelte-d8vj6a\\"); + }, + m(target, anchor) { + insert$(target, button$, anchor); + append$(button$, t0$); + append$(button$, t1$); + append$(button$, t2$); + + if (!mounted) { + dispose = listen$(button$, \\"click\\", /*click_handler$*/ ctx[2]); + mounted = true; + } + }, + p(ctx, [dirty]) { + if (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]); + if (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]); + }, + i: noop$, + o: noop$, + d(detaching) { + if (detaching) detach$(button$); + mounted = false; + dispose(); + } + }; +} + +function instance$($$self, $$props, $$invalidate) { + let { name } = $$props; + let clicks = 0; + + const click_handler$ = () => { + $$invalidate(1, clicks++, clicks); + }; + + $$self.$$set = $$props => { + if ('name' in $$props) $$invalidate(0, name = $$props.name); + }; + + return [name, clicks, click_handler$]; +} + +class Dummy$ extends SvelteComponent$ { + constructor(options) { + super(); + init$(this, options, instance$, create_fragment, safe_not_equal$, { name: 0 }); + } +} + +export default Dummy$;" +`; + +exports[`ssrLoadModule > ?raw&svelte&type=script&compilerOptions={"customElement":true} 1`] = ` +"/* src/Dummy.svelte generated by Svelte vXXX */ +import { + SvelteElement as SvelteElement$, + append as append$, + attribute_to_object as attribute_to_object$, + detach as detach$, + element as element$, + flush as flush$, + init as init$, + insert as insert$, + listen as listen$, + noop as noop$, + safe_not_equal as safe_not_equal$, + set_data as set_data$, + text as text$ +} from \\"svelte/internal\\"; + +function create_fragment(ctx) { + let button$; + let t0$; + let t1$; + let t2$; + let mounted; + let dispose; + + return { + c() { + button$ = element$(\\"button\\"); + t0$ = text$(/*name*/ ctx[0]); + t1$ = text$(\\" clicks: \\"); + t2$ = text$(/*clicks*/ ctx[1]); + this.c = noop$; + }, + m(target, anchor) { + insert$(target, button$, anchor); + append$(button$, t0$); + append$(button$, t1$); + append$(button$, t2$); + + if (!mounted) { + dispose = listen$(button$, \\"click\\", /*click_handler$*/ ctx[2]); + mounted = true; + } + }, + p(ctx, [dirty]) { + if (dirty & /*name*/ 1) set_data$(t0$, /*name*/ ctx[0]); + if (dirty & /*clicks*/ 2) set_data$(t2$, /*clicks*/ ctx[1]); + }, + i: noop$, + o: noop$, + d(detaching) { + if (detaching) detach$(button$); + mounted = false; + dispose(); + } + }; +} + +function instance$($$self, $$props, $$invalidate) { + let { name } = $$props; + let clicks = 0; + + const click_handler$ = () => { + $$invalidate(1, clicks++, clicks); + }; + + $$self.$$set = $$props => { + if ('name' in $$props) $$invalidate(0, name = $$props.name); + }; + + return [name, clicks, click_handler$]; +} + +class Dummy$ extends SvelteElement$ { + constructor(options) { + super(); + this.shadowRoot.innerHTML = \`\`; + + init$( + this, + { + target: this.shadowRoot, + props: attribute_to_object$(this.attributes), + customElement: true + }, + instance$, + create_fragment, + safe_not_equal$, + { name: 0 }, + null + ); + + if (options) { + if (options.target) { + insert$(options.target, this, options.anchor); + } + + if (options.props) { + this.$set(options.props); + flush$(); + } + } + } + + static get observedAttributes() { + return [\\"name\\"]; + } + + get name() { + return this.$$.ctx[0]; + } + + set name(name) { + this.$$set({ name }); + flush$(); + } +} + +export default Dummy$;" +`; + +exports[`ssrLoadModule > ?raw&svelte&type=style 1`] = `"button.svelte-d8vj6a{color:#000099}"`; diff --git a/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts new file mode 100644 index 000000000..27f7c8638 --- /dev/null +++ b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts @@ -0,0 +1,164 @@ +import { browserLogs, fetchFromPage, getText, isBuild, testDir } from '~utils'; +import { createServer, ViteDevServer } from 'vite'; + +function normalizeSnapshot(result: string) { + // during dev, the import is rewritten but can vary on the v= hash. replace with stable short import + return result + .replace(/\.js\?v=[0-9a-f]{8}/g, '.js?v=XXX') // vite import analysis import rewrite version query + .replace(/generated by Svelte v\d\.\d+\.\d+/g, 'generated by Svelte vXXX') // compiler version comment + .replace(/"total": *\d+\.\d+/g, '"total":0.123456789'); // svelte compile stats +} + +describe('raw', () => { + test('does not have failed requests', async () => { + browserLogs.forEach((msg) => { + expect(msg).not.toMatch('404'); + }); + }); + + test('Dummy.svelte', async () => { + expect(await getText('#component button')).toBe('dummy clicks: 0'); + }); + + test('Dummy.svelte?raw', async () => { + const result = await getText('#raw'); + expect(result).toMatchSnapshot(); + }); + + test('Dummy.svelte?raw&svelte&type=preprocessed', async () => { + const result = await getText('#preprocessed'); + expect(result).toMatchSnapshot(); + }); + + test(`Dummy.svelte?raw&svelte&type=script`, async () => { + const result = await getText('#script'); + expect(normalizeSnapshot(result)).toMatchSnapshot(); + }); + + test('Dummy.svelte?raw&svelte&type=script&compilerOptions={"customElement":true}', async () => { + const result = await getText('#wcScript'); + expect(normalizeSnapshot(result)).toMatchSnapshot(); + }); + + test('Dummy.svelte?raw&svelte&type=style', async () => { + const result = await getText('#style'); + expect(result).toMatchSnapshot(); + }); + + test('Dummy.svelte?raw&svelte&type=all&sourcemap', async () => { + const result = await getText('#all'); + expect(normalizeSnapshot(result)).toMatchSnapshot(); + }); + + describe.runIf(!isBuild)('mixed exports', () => { + test('Dummy.svelte?raw&svelte&type=preprocessed', async () => { + const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=preprocessed').then( + (res) => res.text() + ); + expect(normalizeSnapshot(module)).toMatchSnapshot(); + }); + test('Dummy.svelte?raw&svelte&type=style', async () => { + const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=style').then((res) => + res.text() + ); + expect(normalizeSnapshot(module)).toMatchSnapshot(); + }); + test('Dummy.svelte?raw&svelte&type=script', async () => { + const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=script').then((res) => + res.text() + ); + expect(normalizeSnapshot(module)).toMatchSnapshot(); + }); + test('Dummy.svelte?raw&svelte&type=all', async () => { + const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=all').then((res) => + res.text() + ); + expect(normalizeSnapshot(module)).toMatchSnapshot(); + }); + }); +}); + +// vitest prints a warning about obsolete snapshots during build tests, ignore it, they are used in dev tests. +// always regenerate snapshots with `pnpm test:serve import-queries -u` and check the diffs if they are correct +describe.runIf(isBuild)('snapshots not obsolete warning', async () => { + afterAll(() => { + console.log( + 'Ignore the obsolete snapshot warnings for ssrLoadModule snapshots from vitest during test:build, they are used in test:serve' + ); + }); + test('suite not empty', () => { + expect(true).toBe(true); + }); +}); + +describe.runIf(!isBuild)('direct', () => { + test('Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css', async () => { + const response = await fetchFromPage( + 'src/Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css', + { + headers: { Accept: 'text/css' } + } + ); + expect(response.ok).toBe(true); + expect(response.headers.get('Content-Type')).toBe('text/css'); + const css = await response.text(); + expect(css).toMatchSnapshot(); + }); + test('Dummy.svelte?direct&svelte&type=script&sourcemap&lang.js', async () => { + const response = await fetchFromPage( + 'src/Dummy.svelte?direct&svelte&type=script&sourcemap&lang.js', + { + headers: { Accept: 'application/javascript' } + } + ); + expect(response.ok).toBe(true); + expect(response.headers.get('Content-Type')).toBe('application/javascript'); + const js = await response.text(); + expect(normalizeSnapshot(js)).toMatchSnapshot(); + }); +}); + +describe.runIf(!isBuild)('ssrLoadModule', () => { + let vite: ViteDevServer; + let ssrLoadDummy; + beforeAll(async () => { + vite = await createServer({ + root: testDir + '/', + appType: 'custom', + server: { middlewareMode: true, hmr: false } + }); + // needed to init plugins + await vite.pluginContainer.buildStart({}); + ssrLoadDummy = async (query) => + vite + .ssrLoadModule('./src/Dummy.svelte' + query, { fixStacktrace: true }) + .then((m) => m.default?.code ?? m.default); + }); + afterAll(async () => { + await vite.close(); + vite = null; + ssrLoadDummy = null; + }); + test('?raw', async () => { + const result = await ssrLoadDummy('?raw'); + expect(result).toMatchSnapshot(); + }); + test('?raw&svelte&type=preprocessed', async () => { + const result = await ssrLoadDummy('?raw&svelte&type=preprocessed'); + expect(result).toMatchSnapshot(); + }); + test('?raw&svelte&type=script', async () => { + const result = await ssrLoadDummy('?raw&svelte&type=script'); + expect(normalizeSnapshot(result)).toMatchSnapshot(); + }); + test('?raw&svelte&type=script&compilerOptions={"customElement":true}', async () => { + const result = await ssrLoadDummy( + '?raw&svelte&type=script&compilerOptions={"customElement":true}' + ); + expect(normalizeSnapshot(result)).toMatchSnapshot(); + }); + test('?raw&svelte&type=style', async () => { + const result = await ssrLoadDummy('?raw&svelte&type=style'); + expect(result).toMatchSnapshot(); + }); +}); diff --git a/packages/e2e-tests/import-queries/index.html b/packages/e2e-tests/import-queries/index.html new file mode 100644 index 000000000..c4b05496b --- /dev/null +++ b/packages/e2e-tests/import-queries/index.html @@ -0,0 +1,13 @@ + + +
+ + + +{raw}+
{preprocessed}+
{script}+
{wcScript}+
{style}+
{JSON.stringify(all, null, 2)}+