UNPKG

svelte-parse

Version:

An increidbly relaxed svelte-parser

1,807 lines (1,806 loc) 42.7 kB
{ "type": "root", "children": [ { "type": "svelteScript", "tagName": "script", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n\timport { quintOut } from 'svelte/easing';\n\timport { crossfade } from 'svelte/transition';\n\timport { flip } from 'svelte/animate';\n\n\tconst [send, receive] = crossfade({\n\t\tfallback(node, params) {\n\t\t\tconst style = getComputedStyle(node);\n\t\t\tconst transform = style.transform === 'none' ? '' : style.transform;\n\n\t\t\treturn {\n\t\t\t\tduration: 600,\n\t\t\t\teasing: quintOut,\n\t\t\t\tcss: t => `\n\t\t\t\t\ttransform: ${transform} scale(${t});\n\t\t\t\t\topacity: ${t}\n\t\t\t\t`\n\t\t\t};\n\t\t}\n\t});\n\n\tlet todos = [\n\t\t{ id: 1, done: false, description: 'write some docs' },\n\t\t{ id: 2, done: false, description: 'start writing JSConf talk' },\n\t\t{ id: 3, done: true, description: 'buy some milk' },\n\t\t{ id: 4, done: false, description: 'mow the lawn' },\n\t\t{ id: 5, done: false, description: 'feed the turtle' },\n\t\t{ id: 6, done: false, description: 'fix some bugs' },\n\t];\n\n\tlet uid = todos.length + 1;\n\n\tfunction add(input) {\n\t\tconst todo = {\n\t\t\tid: uid++,\n\t\t\tdone: false,\n\t\t\tdescription: input.value\n\t\t};\n\n\t\ttodos = [todo, ...todos];\n\t\tinput.value = '';\n\t}\n\n\tfunction remove(todo) {\n\t\ttodos = todos.filter(t => t !== todo);\n\t}\n", "position": { "start": { "line": 1, "column": 9, "offset": 8 }, "end": { "line": 47, "column": 1, "offset": 1096 } } } ], "position": { "start": { "line": 1, "column": 1, "offset": 0 }, "end": { "line": 47, "column": 10, "offset": 1105 } } }, { "type": "text", "value": "\n\n", "position": { "start": { "line": 47, "column": 10, "offset": 1105 }, "end": { "line": 49, "column": 1, "offset": 1107 } } }, { "type": "svelteStyle", "tagName": "style", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t.new-todo {\n\t\tfont-size: 1.4em;\n\t\twidth: 100%;\n\t\tmargin: 2em 0 1em 0;\n\t}\n\n\t.board {\n\t\tmax-width: 36em;\n\t\tmargin: 0 auto;\n\t}\n\n\t.left, .right {\n\t\tfloat: left;\n\t\twidth: 50%;\n\t\tpadding: 0 1em 0 0;\n\t\tbox-sizing: border-box;\n\t}\n\n\th2 {\n\t\tfont-size: 2em;\n\t\tfont-weight: 200;\n\t\tuser-select: none;\n\t}\n\n\tlabel {\n\t\ttop: 0;\n\t\tleft: 0;\n\t\tdisplay: block;\n\t\tfont-size: 1em;\n\t\tline-height: 1;\n\t\tpadding: 0.5em;\n\t\tmargin: 0 auto 0.5em auto;\n\t\tborder-radius: 2px;\n\t\tbackground-color: #eee;\n\t\tuser-select: none;\n\t}\n\n\tinput { margin: 0 }\n\n\t.right label {\n\t\tbackground-color: rgb(180,240,100);\n\t}\n\n\tbutton {\n\t\tfloat: right;\n\t\theight: 1em;\n\t\tbox-sizing: border-box;\n\t\tpadding: 0 0.5em;\n\t\tline-height: 1;\n\t\tbackground-color: transparent;\n\t\tborder: none;\n\t\tcolor: rgb(170,30,30);\n\t\topacity: 0;\n\t\ttransition: opacity 0.2s;\n\t}\n\n\tlabel:hover button {\n\t\topacity: 1;\n\t}\n", "position": { "start": { "line": 49, "column": 8, "offset": 1114 }, "end": { "line": 109, "column": 1, "offset": 1956 } } } ], "position": { "start": { "line": 49, "column": 1, "offset": 1107 }, "end": { "line": 109, "column": 9, "offset": 1964 } } }, { "type": "text", "value": "\n\n", "position": { "start": { "line": 109, "column": 9, "offset": 1964 }, "end": { "line": 111, "column": 1, "offset": 1966 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "board", "position": { "start": { "line": 111, "column": 13, "offset": 1978 }, "end": { "line": 111, "column": 19, "offset": 1984 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 111, "column": 6, "offset": 1971 }, "end": { "line": 111, "column": 19, "offset": 1984 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t", "position": { "start": { "line": 111, "column": 20, "offset": 1985 }, "end": { "line": 112, "column": 2, "offset": 1987 } } }, { "type": "svelteElement", "tagName": "input", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "new-todo", "position": { "start": { "line": 113, "column": 10, "offset": 2003 }, "end": { "line": 113, "column": 19, "offset": 2012 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 113, "column": 3, "offset": 1996 }, "end": { "line": 113, "column": 19, "offset": 2012 } } }, { "type": "svelteProperty", "name": "placeholder", "value": [ { "type": "text", "value": "what", "position": { "start": { "line": 114, "column": 16, "offset": 2028 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 114, "column": 20, "offset": 2032 }, "end": {} } }, { "type": "text", "value": "needs", "position": { "start": { "line": 114, "column": 21, "offset": 2033 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 114, "column": 26, "offset": 2038 }, "end": {} } }, { "type": "text", "value": "to", "position": { "start": { "line": 114, "column": 27, "offset": 2039 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 114, "column": 29, "offset": 2041 }, "end": {} } }, { "type": "text", "value": "be", "position": { "start": { "line": 114, "column": 30, "offset": 2042 }, "end": {} } }, { "type": "text", "value": " ", "position": { "start": { "line": 114, "column": 32, "offset": 2044 }, "end": {} } }, { "type": "text", "value": "done?", "position": { "start": { "line": 114, "column": 33, "offset": 2045 }, "end": { "line": 114, "column": 39, "offset": 2051 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 114, "column": 3, "offset": 2015 }, "end": { "line": 114, "column": 39, "offset": 2051 } } }, { "type": "svelteDirective", "name": "on", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 115, "column": 15, "offset": 2066 }, "end": { "line": 115, "column": 68, "offset": 2119 } }, "expression": { "type": "svelteExpression", "value": "event => event.key === 'Enter' && add(event.target)", "position": { "start": { "line": 115, "column": 16, "offset": 2067 }, "end": { "line": 115, "column": 67, "offset": 2118 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 115, "column": 3, "offset": 2054 }, "end": { "line": 115, "column": 69, "offset": 2120 } }, "specifier": "keydown" } ], "selfClosing": true, "children": [], "position": { "start": { "line": 112, "column": 2, "offset": 1987 }, "end": { "line": 116, "column": 3, "offset": 2123 } } }, { "type": "text", "value": "\n\n\t", "position": { "start": { "line": 116, "column": 3, "offset": 2123 }, "end": { "line": 118, "column": 2, "offset": 2126 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "left", "position": { "start": { "line": 118, "column": 14, "offset": 2138 }, "end": { "line": 118, "column": 19, "offset": 2143 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 118, "column": 7, "offset": 2131 }, "end": { "line": 118, "column": 19, "offset": 2143 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 118, "column": 20, "offset": 2144 }, "end": { "line": 119, "column": 3, "offset": 2147 } } }, { "type": "svelteElement", "tagName": "h2", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "todo", "position": { "start": { "line": 119, "column": 7, "offset": 2151 }, "end": { "line": 119, "column": 11, "offset": 2155 } } } ], "position": { "start": { "line": 119, "column": 3, "offset": 2147 }, "end": { "line": 119, "column": 16, "offset": 2160 } } }, { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 119, "column": 16, "offset": 2160 }, "end": { "line": 120, "column": 3, "offset": 2163 } } }, { "type": "svelteBranchingBlock", "name": "each", "branches": [ { "type": "svelteBranch", "name": "each", "expression": { "type": "svelteExpression", "value": "todos.filter(t => !t.done) as todo (todo.id)", "position": { "start": { "line": 120, "column": 10, "offset": 2170 }, "end": { "line": 120, "column": 54, "offset": 2214 } } }, "children": [ { "type": "text", "value": "\n\t\t\t", "position": { "start": { "line": 120, "column": 55, "offset": 2215 }, "end": { "line": 121, "column": 4, "offset": 2219 } } }, { "type": "svelteElement", "tagName": "label", "properties": [ { "type": "svelteDirective", "name": "in", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 122, "column": 17, "offset": 2242 }, "end": { "line": 122, "column": 33, "offset": 2258 } }, "expression": { "type": "svelteExpression", "value": "{key: todo.id}", "position": { "start": { "line": 122, "column": 18, "offset": 2243 }, "end": { "line": 122, "column": 32, "offset": 2257 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 122, "column": 5, "offset": 2230 }, "end": { "line": 122, "column": 34, "offset": 2259 } }, "specifier": "receive" }, { "type": "svelteDirective", "name": "out", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 123, "column": 15, "offset": 2274 }, "end": { "line": 123, "column": 31, "offset": 2290 } }, "expression": { "type": "svelteExpression", "value": "{key: todo.id}", "position": { "start": { "line": 123, "column": 16, "offset": 2275 }, "end": { "line": 123, "column": 30, "offset": 2289 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 123, "column": 5, "offset": 2264 }, "end": { "line": 123, "column": 32, "offset": 2291 } }, "specifier": "send" }, { "type": "svelteDirective", "name": "animate", "value": [], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 124, "column": 5, "offset": 2296 }, "end": { "line": 124, "column": 17, "offset": 2308 } }, "specifier": "flip" } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 125, "column": 5, "offset": 2313 }, "end": { "line": 126, "column": 5, "offset": 2318 } } }, { "type": "svelteElement", "tagName": "input", "properties": [ { "type": "svelteProperty", "name": "type", "value": [ { "type": "text", "value": "checkbox", "position": { "start": { "line": 126, "column": 17, "offset": 2330 }, "end": { "line": 126, "column": 25, "offset": 2338 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 126, "column": 12, "offset": 2325 }, "end": { "line": 126, "column": 25, "offset": 2338 } } }, { "type": "svelteDirective", "name": "bind", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 126, "column": 39, "offset": 2352 }, "end": { "line": 126, "column": 50, "offset": 2363 } }, "expression": { "type": "svelteExpression", "value": "todo.done", "position": { "start": { "line": 126, "column": 40, "offset": 2353 }, "end": { "line": 126, "column": 49, "offset": 2362 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 126, "column": 26, "offset": 2339 }, "end": { "line": 126, "column": 50, "offset": 2363 } }, "specifier": "checked" } ], "selfClosing": true, "children": [], "position": { "start": { "line": 126, "column": 5, "offset": 2318 }, "end": { "line": 126, "column": 51, "offset": 2364 } } }, { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 126, "column": 51, "offset": 2364 }, "end": { "line": 127, "column": 5, "offset": 2369 } } }, { "type": "svelteDynamicContent", "position": { "start": { "line": 127, "column": 5, "offset": 2369 }, "end": { "line": 127, "column": 23, "offset": 2387 } }, "expression": { "type": "svelteExpression", "value": "todo.description", "position": { "start": { "line": 127, "column": 6, "offset": 2370 }, "end": { "line": 127, "column": 22, "offset": 2386 } } } }, { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 127, "column": 23, "offset": 2387 }, "end": { "line": 128, "column": 5, "offset": 2392 } } }, { "type": "svelteElement", "tagName": "button", "properties": [ { "type": "svelteDirective", "name": "on", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 128, "column": 23, "offset": 2410 }, "end": { "line": 128, "column": 43, "offset": 2430 } }, "expression": { "type": "svelteExpression", "value": "() => remove(todo)", "position": { "start": { "line": 128, "column": 24, "offset": 2411 }, "end": { "line": 128, "column": 42, "offset": 2429 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 128, "column": 13, "offset": 2400 }, "end": { "line": 128, "column": 44, "offset": 2431 } }, "specifier": "click" } ], "selfClosing": false, "children": [ { "type": "text", "value": "x", "position": { "start": { "line": 128, "column": 45, "offset": 2432 }, "end": { "line": 128, "column": 46, "offset": 2433 } } } ], "position": { "start": { "line": 128, "column": 5, "offset": 2392 }, "end": { "line": 128, "column": 55, "offset": 2442 } } }, { "type": "text", "value": "\n\t\t\t", "position": { "start": { "line": 128, "column": 55, "offset": 2442 }, "end": { "line": 129, "column": 4, "offset": 2446 } } } ], "position": { "start": { "line": 121, "column": 4, "offset": 2219 }, "end": { "line": 129, "column": 12, "offset": 2454 } } }, { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 129, "column": 12, "offset": 2454 }, "end": { "line": 130, "column": 3, "offset": 2457 } } } ], "position": { "start": { "line": 120, "column": 3, "offset": 2163 }, "end": { "line": 130, "column": 3, "offset": 2457 } } } ], "position": { "start": { "line": 120, "column": 3, "offset": 2163 }, "end": { "line": 130, "column": 10, "offset": 2464 } } }, { "type": "text", "value": "\n\t", "position": { "start": { "line": 130, "column": 10, "offset": 2464 }, "end": { "line": 131, "column": 2, "offset": 2466 } } } ], "position": { "start": { "line": 118, "column": 2, "offset": 2126 }, "end": { "line": 131, "column": 8, "offset": 2472 } } }, { "type": "text", "value": "\n\n\t", "position": { "start": { "line": 131, "column": 8, "offset": 2472 }, "end": { "line": 133, "column": 2, "offset": 2475 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteProperty", "name": "class", "value": [ { "type": "text", "value": "right", "position": { "start": { "line": 133, "column": 14, "offset": 2487 }, "end": { "line": 133, "column": 20, "offset": 2493 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 133, "column": 7, "offset": 2480 }, "end": { "line": 133, "column": 20, "offset": 2493 } } } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 133, "column": 21, "offset": 2494 }, "end": { "line": 134, "column": 3, "offset": 2497 } } }, { "type": "svelteElement", "tagName": "h2", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "done", "position": { "start": { "line": 134, "column": 7, "offset": 2501 }, "end": { "line": 134, "column": 11, "offset": 2505 } } } ], "position": { "start": { "line": 134, "column": 3, "offset": 2497 }, "end": { "line": 134, "column": 16, "offset": 2510 } } }, { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 134, "column": 16, "offset": 2510 }, "end": { "line": 135, "column": 3, "offset": 2513 } } }, { "type": "svelteBranchingBlock", "name": "each", "branches": [ { "type": "svelteBranch", "name": "each", "expression": { "type": "svelteExpression", "value": "todos.filter(t => t.done) as todo (todo.id)", "position": { "start": { "line": 135, "column": 10, "offset": 2520 }, "end": { "line": 135, "column": 53, "offset": 2563 } } }, "children": [ { "type": "text", "value": "\n\t\t\t", "position": { "start": { "line": 135, "column": 54, "offset": 2564 }, "end": { "line": 136, "column": 4, "offset": 2568 } } }, { "type": "svelteElement", "tagName": "label", "properties": [ { "type": "svelteDirective", "name": "in", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 137, "column": 17, "offset": 2591 }, "end": { "line": 137, "column": 33, "offset": 2607 } }, "expression": { "type": "svelteExpression", "value": "{key: todo.id}", "position": { "start": { "line": 137, "column": 18, "offset": 2592 }, "end": { "line": 137, "column": 32, "offset": 2606 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 137, "column": 5, "offset": 2579 }, "end": { "line": 137, "column": 34, "offset": 2608 } }, "specifier": "receive" }, { "type": "svelteDirective", "name": "out", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 138, "column": 15, "offset": 2623 }, "end": { "line": 138, "column": 31, "offset": 2639 } }, "expression": { "type": "svelteExpression", "value": "{key: todo.id}", "position": { "start": { "line": 138, "column": 16, "offset": 2624 }, "end": { "line": 138, "column": 30, "offset": 2638 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 138, "column": 5, "offset": 2613 }, "end": { "line": 138, "column": 32, "offset": 2640 } }, "specifier": "send" }, { "type": "svelteDirective", "name": "animate", "value": [], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 139, "column": 5, "offset": 2645 }, "end": { "line": 139, "column": 17, "offset": 2657 } }, "specifier": "flip" } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 140, "column": 5, "offset": 2662 }, "end": { "line": 141, "column": 5, "offset": 2667 } } }, { "type": "svelteElement", "tagName": "input", "properties": [ { "type": "svelteProperty", "name": "type", "value": [ { "type": "text", "value": "checkbox", "position": { "start": { "line": 141, "column": 17, "offset": 2679 }, "end": { "line": 141, "column": 25, "offset": 2687 } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 141, "column": 12, "offset": 2674 }, "end": { "line": 141, "column": 25, "offset": 2687 } } }, { "type": "svelteDirective", "name": "bind", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 141, "column": 39, "offset": 2701 }, "end": { "line": 141, "column": 50, "offset": 2712 } }, "expression": { "type": "svelteExpression", "value": "todo.done", "position": { "start": { "line": 141, "column": 40, "offset": 2702 }, "end": { "line": 141, "column": 49, "offset": 2711 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 141, "column": 26, "offset": 2688 }, "end": { "line": 141, "column": 50, "offset": 2712 } }, "specifier": "checked" } ], "selfClosing": true, "children": [], "position": { "start": { "line": 141, "column": 5, "offset": 2667 }, "end": { "line": 141, "column": 51, "offset": 2713 } } }, { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 141, "column": 51, "offset": 2713 }, "end": { "line": 142, "column": 5, "offset": 2718 } } }, { "type": "svelteDynamicContent", "position": { "start": { "line": 142, "column": 5, "offset": 2718 }, "end": { "line": 142, "column": 23, "offset": 2736 } }, "expression": { "type": "svelteExpression", "value": "todo.description", "position": { "start": { "line": 142, "column": 6, "offset": 2719 }, "end": { "line": 142, "column": 22, "offset": 2735 } } } }, { "type": "text", "value": "\n\t\t\t\t", "position": { "start": { "line": 142, "column": 23, "offset": 2736 }, "end": { "line": 143, "column": 5, "offset": 2741 } } }, { "type": "svelteElement", "tagName": "button", "properties": [ { "type": "svelteDirective", "name": "on", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 143, "column": 23, "offset": 2759 }, "end": { "line": 143, "column": 43, "offset": 2779 } }, "expression": { "type": "svelteExpression", "value": "() => remove(todo)", "position": { "start": { "line": 143, "column": 24, "offset": 2760 }, "end": { "line": 143, "column": 42, "offset": 2778 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 143, "column": 13, "offset": 2749 }, "end": { "line": 143, "column": 44, "offset": 2780 } }, "specifier": "click" } ], "selfClosing": false, "children": [ { "type": "text", "value": "x", "position": { "start": { "line": 143, "column": 45, "offset": 2781 }, "end": { "line": 143, "column": 46, "offset": 2782 } } } ], "position": { "start": { "line": 143, "column": 5, "offset": 2741 }, "end": { "line": 143, "column": 55, "offset": 2791 } } }, { "type": "text", "value": "\n\t\t\t", "position": { "start": { "line": 143, "column": 55, "offset": 2791 }, "end": { "line": 144, "column": 4, "offset": 2795 } } } ], "position": { "start": { "line": 136, "column": 4, "offset": 2568 }, "end": { "line": 144, "column": 12, "offset": 2803 } } }, { "type": "text", "value": "\n\t\t", "position": { "start": { "line": 144, "column": 12, "offset": 2803 }, "end": { "line": 145, "column": 3, "offset": 2806 } } } ], "position": { "start": { "line": 135, "column": 3, "offset": 2513 }, "end": { "line": 145, "column": 3, "offset": 2806 } } } ], "position": { "start": { "line": 135, "column": 3, "offset": 2513 }, "end": { "line": 145, "column": 10, "offset": 2813 } } }, { "type": "text", "value": "\n\t", "position": { "start": { "line": 145, "column": 10, "offset": 2813 }, "end": { "line": 146, "column": 2, "offset": 2815 } } } ], "position": { "start": { "line": 133, "column": 2, "offset": 2475 }, "end": { "line": 146, "column": 8, "offset": 2821 } } }, { "type": "text", "value": "\n", "position": { "start": { "line": 146, "column": 8, "offset": 2821 }, "end": { "line": 147, "column": 1, "offset": 2822 } } } ], "position": { "start": { "line": 111, "column": 1, "offset": 1966 }, "end": { "line": 147, "column": 7, "offset": 2828 } } } ], "position": { "start": { "column": 1, "line": 1, "offset": 0 }, "end": { "line": 147, "column": 7, "offset": 2828 } } }