diff --git a/src/parse/read/expression.ts b/src/parse/read/expression.ts index c8c3054274..606f8f92a7 100644 --- a/src/parse/read/expression.ts +++ b/src/parse/read/expression.ts @@ -6,7 +6,7 @@ const literals = new Map([['true', true], ['false', false], ['null', null]]); export default function readExpression(parser: Parser) { const start = parser.index; - const name = parser.readUntil(/\s*}}/); + const name = parser.readUntil(parser.v2 ? /\s*}/ : /\s*}}/); if (name && /^[a-z]+$/.test(name)) { const end = start + name.length; diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 8da2560fb2..a73237cf21 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -61,7 +61,7 @@ export default function mustache(parser: Parser) { parser.eat(expected, true); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); while (block.elseif) { block.end = parser.index; @@ -83,7 +83,7 @@ export default function mustache(parser: Parser) { block.end = parser.index; parser.stack.pop(); - } else if (parser.eat('elseif')) { + } else if (parser.eat(parser.v2 ? ':elseif' : 'elseif')) { const block = parser.current(); if (block.type !== 'IfBlock') parser.error( @@ -95,7 +95,7 @@ export default function mustache(parser: Parser) { const expression = readExpression(parser); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); block.else = { start: parser.index, @@ -114,7 +114,7 @@ export default function mustache(parser: Parser) { }; parser.stack.push(block.else.children[0]); - } else if (parser.eat('else')) { + } else if (parser.eat(parser.v2 ? ':else' : 'else')) { const block = parser.current(); if (block.type !== 'IfBlock' && block.type !== 'EachBlock') { parser.error( @@ -123,7 +123,7 @@ export default function mustache(parser: Parser) { } parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); block.else = { start: parser.index, @@ -133,7 +133,7 @@ export default function mustache(parser: Parser) { }; parser.stack.push(block.else); - } else if (parser.eat('then')) { + } else if (parser.eat(parser.v2 ? ':then' : 'then')) { // TODO DRY out this and the next section const pendingBlock = parser.current(); if (pendingBlock.type === 'PendingBlock') { @@ -145,7 +145,7 @@ export default function mustache(parser: Parser) { awaitBlock.value = parser.readIdentifier(); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); const thenBlock: Node = { start, @@ -157,7 +157,7 @@ export default function mustache(parser: Parser) { awaitBlock.then = thenBlock; parser.stack.push(thenBlock); } - } else if (parser.eat('catch')) { + } else if (parser.eat(parser.v2 ? ':catch' : 'catch')) { const thenBlock = parser.current(); if (thenBlock.type === 'ThenBlock') { thenBlock.end = start; @@ -168,7 +168,7 @@ export default function mustache(parser: Parser) { awaitBlock.error = parser.readIdentifier(); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); const catchBlock: Node = { start, @@ -288,7 +288,7 @@ export default function mustache(parser: Parser) { parser.allowWhitespace(); } - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); parser.current().children.push(block); parser.stack.push(block); @@ -302,22 +302,40 @@ export default function mustache(parser: Parser) { // {{yield}} // TODO deprecate parser.allowWhitespace(); - parser.eat('}}', true); - parser.current().children.push({ - start, - end: parser.index, - type: 'Element', - name: 'slot', - attributes: [], - children: [] - }); - } else if (parser.eat('{')) { + if (parser.v2) { + const expressionEnd = parser.index; + + parser.eat('}', true); + parser.current().children.push({ + start, + end: parser.index, + type: 'MustacheTag', + expression: { + start: expressionEnd - 5, + end: expressionEnd, + type: 'Identifier', + name: 'yield' + } + }); + } else { + parser.eat('}}', true); + + parser.current().children.push({ + start, + end: parser.index, + type: 'Element', + name: 'slot', + attributes: [], + children: [] + }); + } + } else if (parser.eat(parser.v2 ? '@html' : '{')) { // {{{raw}}} mustache 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/tag.ts b/src/parse/state/tag.ts index 4f7e7a117b..e1dbfcf6c6 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -170,7 +170,7 @@ export default function tag(parser: Parser) { } } - if (name === COMPONENT) { + if (name === (parser.v2 ? 'svelte:component' : ':Component')) { parser.eat('{', true); element.expression = readExpression(parser); parser.allowWhitespace(); @@ -249,6 +249,10 @@ export default function tag(parser: Parser) { function readTagName(parser: Parser) { const start = parser.index; + // TODO hoist these back to the top, post-v2 + const SELF = parser.v2 ? 'svelte:self' : ':Self'; + const COMPONENT = parser.v2 ? 'svelte:component' : ':Component'; + if (parser.eat(SELF)) { // check we're inside a block, otherwise this // will cause infinite recursion @@ -289,14 +293,14 @@ function readTagName(parser: Parser) { function readAttribute(parser: Parser, uniqueNames: Set) { const start = parser.index; - if (parser.eat('{{')) { + if (parser.eat(parser.v2 ? '{' : '{{')) { parser.allowWhitespace(); parser.eat('...', true, 'Expected spread operator (...)'); const expression = readExpression(parser); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); return { start, @@ -369,7 +373,7 @@ function readSequence(parser: Parser, done: () => boolean) { }); return chunks; - } else if (parser.eat('{{')) { + } else if (parser.eat(parser.v2 ? '{' : '{{')) { if (currentChunk.data) { currentChunk.end = index; chunks.push(currentChunk); @@ -377,9 +381,7 @@ function readSequence(parser: Parser, done: () => boolean) { const expression = readExpression(parser); parser.allowWhitespace(); - if (!parser.eat('}}')) { - parser.error(`Expected }}`); - } + parser.eat(parser.v2 ? '}' : '}}', true); chunks.push({ start: index, diff --git a/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json index c843275a4f..4d08df34a0 100644 --- a/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json +++ b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json @@ -20,8 +20,13 @@ { "start": 19, "end": 29, - "type": "Text", - "data": "{readonly}" + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 20, + "end": 28, + "name": "readonly" + } } ] } diff --git a/test/parser/samples/attribute-dynamic-boolean/output-v2.json b/test/parser/samples/attribute-dynamic-boolean/output-v2.json index af1635a55d..4d08df34a0 100644 --- a/test/parser/samples/attribute-dynamic-boolean/output-v2.json +++ b/test/parser/samples/attribute-dynamic-boolean/output-v2.json @@ -1,30 +1,30 @@ { - "hash": 3179574701, + "hash": "7xolfv", "html": { "start": 0, - "end": 45, + "end": 41, "type": "Fragment", "children": [ { "start": 0, - "end": 45, + "end": 41, "type": "Element", "name": "textarea", "attributes": [ { "start": 10, - "end": 33, + "end": 29, "type": "Attribute", "name": "readonly", "value": [ { - "start": 20, - "end": 32, + "start": 19, + "end": 29, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 22, - "end": 30, + "start": 20, + "end": 28, "name": "readonly" } } diff --git a/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json index 76b70ef261..4b6506b0cd 100644 --- a/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json +++ b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json @@ -20,8 +20,13 @@ { "start": 11, "end": 18, - "type": "Text", - "data": "{class}" + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 12, + "end": 17, + "name": "class" + } } ] } diff --git a/test/parser/samples/attribute-dynamic-reserved/output-v2.json b/test/parser/samples/attribute-dynamic-reserved/output-v2.json index aef0e5cb63..4b6506b0cd 100644 --- a/test/parser/samples/attribute-dynamic-reserved/output-v2.json +++ b/test/parser/samples/attribute-dynamic-reserved/output-v2.json @@ -1,30 +1,30 @@ { - "hash": 2788845841, + "hash": "l0cddf", "html": { "start": 0, - "end": 29, + "end": 25, "type": "Fragment", "children": [ { "start": 0, - "end": 29, + "end": 25, "type": "Element", "name": "div", "attributes": [ { "start": 5, - "end": 22, + "end": 18, "type": "Attribute", "name": "class", "value": [ { - "start": 12, - "end": 21, + "start": 11, + "end": 18, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 14, - "end": 19, + "start": 12, + "end": 17, "name": "class" } } diff --git a/test/parser/samples/attribute-dynamic/_actual-v2.json b/test/parser/samples/attribute-dynamic/_actual-v2.json index 06f82de54a..7ccb40d313 100644 --- a/test/parser/samples/attribute-dynamic/_actual-v2.json +++ b/test/parser/samples/attribute-dynamic/_actual-v2.json @@ -19,9 +19,26 @@ "value": [ { "start": 12, + "end": 19, + "type": "Text", + "data": "color: " + }, + { + "start": 19, + "end": 26, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 20, + "end": 25, + "name": "color" + } + }, + { + "start": 26, "end": 27, "type": "Text", - "data": "color: {color};" + "data": ";" } ] } @@ -30,8 +47,13 @@ { "start": 29, "end": 36, - "type": "Text", - "data": "{color}" + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 30, + "end": 35, + "name": "color" + } } ] } diff --git a/test/parser/samples/attribute-dynamic/output-v2.json b/test/parser/samples/attribute-dynamic/output-v2.json index 79ef81065f..7ccb40d313 100644 --- a/test/parser/samples/attribute-dynamic/output-v2.json +++ b/test/parser/samples/attribute-dynamic/output-v2.json @@ -1,19 +1,19 @@ { - "hash": 804348386, + "hash": "ehtsx6", "html": { "start": 0, - "end": 46, + "end": 42, "type": "Fragment", "children": [ { "start": 0, - "end": 46, + "end": 42, "type": "Element", "name": "div", "attributes": [ { "start": 5, - "end": 30, + "end": 28, "type": "Attribute", "name": "style", "value": [ @@ -25,18 +25,18 @@ }, { "start": 19, - "end": 28, + "end": 26, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 21, - "end": 26, + "start": 20, + "end": 25, "name": "color" } }, { - "start": 28, - "end": 29, + "start": 26, + "end": 27, "type": "Text", "data": ";" } @@ -45,13 +45,13 @@ ], "children": [ { - "start": 31, - "end": 40, + "start": 29, + "end": 36, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 33, - "end": 38, + "start": 30, + "end": 35, "name": "color" } } diff --git a/test/parser/samples/await-then-catch/_actual-v2.json b/test/parser/samples/await-then-catch/_actual-v2.json index cfe0ab8134..22ad4242e3 100644 --- a/test/parser/samples/await-then-catch/_actual-v2.json +++ b/test/parser/samples/await-then-catch/_actual-v2.json @@ -1,78 +1,158 @@ { - "hash": "1rt0tho", + "hash": "1b28gs9", "html": { "start": 0, - "end": 149, + "end": 148, "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}" + "end": 148, + "type": "AwaitBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 18, + "name": "thePromise" + }, + "value": "theValue", + "error": "theError", + "pending": { + "start": 19, + "end": 39, + "type": "PendingBlock", + "children": [ + { + "start": 19, + "end": 21, + "type": "Text", + "data": "\n\t" + }, + { + "start": 21, + "end": 38, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 24, + "end": 34, + "type": "Text", + "data": "loading..." + } + ] + }, + { + "start": 38, + "end": 39, + "type": "Text", + "data": "\n" + } + ] + }, + "then": { + "start": 39, + "end": 88, + "type": "ThenBlock", + "children": [ + { + "start": 55, + "end": 57, + "type": "Text", + "data": "\n\t" + }, + { + "start": 57, + "end": 87, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 60, + "end": 73, + "type": "Text", + "data": "the value is " + }, + { + "start": 73, + "end": 83, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 74, + "end": 82, + "name": "theValue" + } + } + ] + }, + { + "start": 87, + "end": 88, + "type": "Text", + "data": "\n" + } + ] + }, + "catch": { + "start": 88, + "end": 140, + "type": "CatchBlock", + "children": [ + { + "start": 105, + "end": 107, + "type": "Text", + "data": "\n\t" + }, + { + "start": 107, + "end": 139, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 110, + "end": 117, + "type": "Text", + "data": "oh no! " + }, + { + "start": 117, + "end": 135, + "type": "MustacheTag", + "expression": { + "type": "MemberExpression", + "start": 118, + "end": 134, + "object": { + "type": "Identifier", + "start": 118, + "end": 126, + "name": "theError" + }, + "property": { + "type": "Identifier", + "start": 127, + "end": 134, + "name": "message" + }, + "computed": false + } + } + ] + }, + { + "start": 139, + "end": 140, + "type": "Text", + "data": "\n" + } + ] + } } ] }, diff --git a/test/parser/samples/await-then-catch/input-v2.html b/test/parser/samples/await-then-catch/input-v2.html index b4038bec8c..79f5162ace 100644 --- a/test/parser/samples/await-then-catch/input-v2.html +++ b/test/parser/samples/await-then-catch/input-v2.html @@ -3,5 +3,5 @@ {:then theValue}

the value is {theValue}

{:catch theError} -

oh no! {theError.message}}

+

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 index 4f149e6a0c..22ad4242e3 100644 --- a/test/parser/samples/await-then-catch/output-v2.json +++ b/test/parser/samples/await-then-catch/output-v2.json @@ -1,143 +1,143 @@ { - "hash": 1040536517, + "hash": "1b28gs9", "html": { "start": 0, - "end": 158, + "end": 148, "type": "Fragment", "children": [ { "start": 0, - "end": 158, + "end": 148, "type": "AwaitBlock", "expression": { "type": "Identifier", - "start": 9, - "end": 19, + "start": 8, + "end": 18, "name": "thePromise" }, "value": "theValue", "error": "theError", "pending": { - "start": 21, - "end": 41, + "start": 19, + "end": 39, "type": "PendingBlock", "children": [ { - "start": 21, - "end": 23, + "start": 19, + "end": 21, "type": "Text", "data": "\n\t" }, { - "start": 23, - "end": 40, + "start": 21, + "end": 38, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 26, - "end": 36, + "start": 24, + "end": 34, "type": "Text", "data": "loading..." } ] }, { - "start": 40, - "end": 41, + "start": 38, + "end": 39, "type": "Text", "data": "\n" } ] }, "then": { - "start": 41, - "end": 93, + "start": 39, + "end": 88, "type": "ThenBlock", "children": [ { - "start": 58, - "end": 60, + "start": 55, + "end": 57, "type": "Text", "data": "\n\t" }, { - "start": 60, - "end": 92, + "start": 57, + "end": 87, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 63, - "end": 76, + "start": 60, + "end": 73, "type": "Text", "data": "the value is " }, { - "start": 76, - "end": 88, + "start": 73, + "end": 83, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 78, - "end": 86, + "start": 74, + "end": 82, "name": "theValue" } } ] }, { - "start": 92, - "end": 93, + "start": 87, + "end": 88, "type": "Text", "data": "\n" } ] }, "catch": { - "start": 93, - "end": 148, + "start": 88, + "end": 140, "type": "CatchBlock", "children": [ { - "start": 111, - "end": 113, + "start": 105, + "end": 107, "type": "Text", "data": "\n\t" }, { - "start": 113, - "end": 147, + "start": 107, + "end": 139, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 116, - "end": 123, + "start": 110, + "end": 117, "type": "Text", "data": "oh no! " }, { - "start": 123, - "end": 143, + "start": 117, + "end": 135, "type": "MustacheTag", "expression": { "type": "MemberExpression", - "start": 125, - "end": 141, + "start": 118, + "end": 134, "object": { "type": "Identifier", - "start": 125, - "end": 133, + "start": 118, + "end": 126, "name": "theError" }, "property": { "type": "Identifier", - "start": 134, - "end": 141, + "start": 127, + "end": 134, "name": "message" }, "computed": false @@ -146,8 +146,8 @@ ] }, { - "start": 147, - "end": 148, + "start": 139, + "end": 140, "type": "Text", "data": "\n" } diff --git a/test/parser/samples/component-dynamic/_actual-v2.json b/test/parser/samples/component-dynamic/_actual-v2.json index 9e6525a8ca..6080a11e9e 100644 --- a/test/parser/samples/component-dynamic/_actual-v2.json +++ b/test/parser/samples/component-dynamic/_actual-v2.json @@ -10,56 +10,31 @@ "end": 55, "type": "Element", "name": "svelte:component", - "attributes": [ - { - "start": 18, - "end": 23, - "type": "Attribute", - "name": "{foo", - "value": true + "attributes": [], + "children": [], + "expression": { + "type": "ConditionalExpression", + "start": 19, + "end": 34, + "test": { + "type": "Identifier", + "start": 19, + "end": 22, + "name": "foo" }, - { - "start": 23, - "end": 25, - "type": "Attribute", - "name": "?", - "value": true - }, - { + "consequent": { + "type": "Identifier", "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": "" - } - } - ] + "end": 28, + "name": "Foo" }, - { + "alternate": { + "type": "Identifier", "start": 31, - "end": 35, - "type": "Attribute", - "name": "Bar}", - "value": true + "end": 34, + "name": "Bar" } - ], - "children": [] + } } ] }, diff --git a/test/parser/samples/component-dynamic/output-v2.json b/test/parser/samples/component-dynamic/output-v2.json index 614c28c0a9..6080a11e9e 100644 --- a/test/parser/samples/component-dynamic/output-v2.json +++ b/test/parser/samples/component-dynamic/output-v2.json @@ -1,37 +1,37 @@ { - "hash": 410218696, + "hash": "7yh2k2", "html": { "start": 0, - "end": 43, + "end": 55, "type": "Fragment", "children": [ { "start": 0, - "end": 43, + "end": 55, "type": "Element", - "name": ":Component", + "name": "svelte:component", "attributes": [], "children": [], "expression": { "type": "ConditionalExpression", - "start": 13, - "end": 28, + "start": 19, + "end": 34, "test": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 19, + "end": 22, "name": "foo" }, "consequent": { "type": "Identifier", - "start": 19, - "end": 22, + "start": 25, + "end": 28, "name": "Foo" }, "alternate": { "type": "Identifier", - "start": 25, - "end": 28, + "start": 31, + "end": 34, "name": "Bar" } } diff --git a/test/parser/samples/each-block-destructured/_actual-v2.json b/test/parser/samples/each-block-destructured/_actual-v2.json index 97b69a5730..38d5ddc770 100644 --- a/test/parser/samples/each-block-destructured/_actual-v2.json +++ b/test/parser/samples/each-block-destructured/_actual-v2.json @@ -7,30 +7,58 @@ "children": [ { "start": 0, - "end": 33, - "type": "Text", - "data": "{#each animals as [key, value]}\n\t" - }, - { - "start": 33, - "end": 54, - "type": "Element", - "name": "p", - "attributes": [], + "end": 62, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 7, + "end": 14, + "name": "animals" + }, "children": [ { - "start": 36, - "end": 50, - "type": "Text", - "data": "{key}: {value}" + "start": 33, + "end": 54, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 36, + "end": 41, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 37, + "end": 40, + "name": "key" + } + }, + { + "start": 41, + "end": 43, + "type": "Text", + "data": ": " + }, + { + "start": 43, + "end": 50, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 44, + "end": 49, + "name": "value" + } + } + ] } - ] - }, - { - "start": 54, - "end": 62, - "type": "Text", - "data": "\n{/each}" + ], + "destructuredContexts": [ + "key", + "value" + ], + "context": "key_value" } ] }, diff --git a/test/parser/samples/each-block-destructured/output-v2.json b/test/parser/samples/each-block-destructured/output-v2.json index 897fec88b8..38d5ddc770 100644 --- a/test/parser/samples/each-block-destructured/output-v2.json +++ b/test/parser/samples/each-block-destructured/output-v2.json @@ -1,53 +1,53 @@ { - "hash": 2621498076, + "hash": "gtdm5e", "html": { "start": 0, - "end": 70, + "end": 62, "type": "Fragment", "children": [ { "start": 0, - "end": 70, + "end": 62, "type": "EachBlock", "expression": { "type": "Identifier", - "start": 8, - "end": 15, + "start": 7, + "end": 14, "name": "animals" }, "children": [ { - "start": 35, - "end": 60, + "start": 33, + "end": 54, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 38, - "end": 45, + "start": 36, + "end": 41, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 40, - "end": 43, + "start": 37, + "end": 40, "name": "key" } }, { - "start": 45, - "end": 47, + "start": 41, + "end": 43, "type": "Text", "data": ": " }, { - "start": 47, - "end": 56, + "start": 43, + "end": 50, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 49, - "end": 54, + "start": 44, + "end": 49, "name": "value" } } diff --git a/test/parser/samples/each-block-else/_actual-v2.json b/test/parser/samples/each-block-else/_actual-v2.json index af7b618bf8..9f8c5da79b 100644 --- a/test/parser/samples/each-block-else/_actual-v2.json +++ b/test/parser/samples/each-block-else/_actual-v2.json @@ -7,51 +7,59 @@ "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": [], + "end": 77, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 7, + "end": 14, + "name": "animals" + }, "children": [ { - "start": 55, - "end": 65, - "type": "Text", - "data": "no animals" + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 31, + "end": 37, + "name": "animal" + } + } + ] } - ] - }, - { - "start": 69, - "end": 77, - "type": "Text", - "data": "\n{/each}" + ], + "context": "animal", + "else": { + "start": 50, + "end": 70, + "type": "ElseBlock", + "children": [ + { + "start": 52, + "end": 69, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 55, + "end": 65, + "type": "Text", + "data": "no animals" + } + ] + } + ] + } } ] }, diff --git a/test/parser/samples/each-block-else/output-v2.json b/test/parser/samples/each-block-else/output-v2.json index 0dadad5f65..9f8c5da79b 100644 --- a/test/parser/samples/each-block-else/output-v2.json +++ b/test/parser/samples/each-block-else/output-v2.json @@ -1,36 +1,36 @@ { - "hash": 3238289871, + "hash": "ljl07n", "html": { "start": 0, - "end": 84, + "end": 77, "type": "Fragment", "children": [ { "start": 0, - "end": 84, + "end": 77, "type": "EachBlock", "expression": { "type": "Identifier", - "start": 8, - "end": 15, + "start": 7, + "end": 14, "name": "animals" }, "children": [ { - "start": 29, - "end": 46, + "start": 27, + "end": 42, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 32, - "end": 42, + "start": 30, + "end": 38, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 34, - "end": 40, + "start": 31, + "end": 37, "name": "animal" } } @@ -39,20 +39,20 @@ ], "context": "animal", "else": { - "start": 55, - "end": 75, + "start": 50, + "end": 70, "type": "ElseBlock", "children": [ { - "start": 57, - "end": 74, + "start": 52, + "end": 69, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 60, - "end": 70, + "start": 55, + "end": 65, "type": "Text", "data": "no animals" } diff --git a/test/parser/samples/each-block-indexed/_actual-v2.json b/test/parser/samples/each-block-indexed/_actual-v2.json index 576bc53014..9ffa02aaa8 100644 --- a/test/parser/samples/each-block-indexed/_actual-v2.json +++ b/test/parser/samples/each-block-indexed/_actual-v2.json @@ -7,30 +7,55 @@ "children": [ { "start": 0, - "end": 30, - "type": "Text", - "data": "{#each animals as animal, i}\n\t" - }, - { - "start": 30, - "end": 50, - "type": "Element", - "name": "p", - "attributes": [], + "end": 58, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 7, + "end": 14, + "name": "animals" + }, "children": [ { - "start": 33, - "end": 46, - "type": "Text", - "data": "{i}: {animal}" + "start": 30, + "end": 50, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 33, + "end": 36, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 35, + "name": "i" + } + }, + { + "start": 36, + "end": 38, + "type": "Text", + "data": ": " + }, + { + "start": 38, + "end": 46, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 39, + "end": 45, + "name": "animal" + } + } + ] } - ] - }, - { - "start": 50, - "end": 58, - "type": "Text", - "data": "\n{/each}" + ], + "context": "animal", + "index": "i" } ] }, diff --git a/test/parser/samples/each-block-indexed/output-v2.json b/test/parser/samples/each-block-indexed/output-v2.json index fc8954d6ad..9ffa02aaa8 100644 --- a/test/parser/samples/each-block-indexed/output-v2.json +++ b/test/parser/samples/each-block-indexed/output-v2.json @@ -1,53 +1,53 @@ { - "hash": 2841674990, + "hash": "1143n2g", "html": { "start": 0, - "end": 66, + "end": 58, "type": "Fragment", "children": [ { "start": 0, - "end": 66, + "end": 58, "type": "EachBlock", "expression": { "type": "Identifier", - "start": 8, - "end": 15, + "start": 7, + "end": 14, "name": "animals" }, "children": [ { - "start": 32, - "end": 56, + "start": 30, + "end": 50, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 35, - "end": 40, + "start": 33, + "end": 36, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 34, + "end": 35, "name": "i" } }, { - "start": 40, - "end": 42, + "start": 36, + "end": 38, "type": "Text", "data": ": " }, { - "start": 42, - "end": 52, + "start": 38, + "end": 46, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 44, - "end": 50, + "start": 39, + "end": 45, "name": "animal" } } diff --git a/test/parser/samples/each-block/_actual-v2.json b/test/parser/samples/each-block/_actual-v2.json index 314ef918a5..7df4a20eba 100644 --- a/test/parser/samples/each-block/_actual-v2.json +++ b/test/parser/samples/each-block/_actual-v2.json @@ -7,30 +7,37 @@ "children": [ { "start": 0, - "end": 27, - "type": "Text", - "data": "{#each animals as animal}\n\t" - }, - { - "start": 27, - "end": 42, - "type": "Element", - "name": "p", - "attributes": [], + "end": 50, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 7, + "end": 14, + "name": "animals" + }, "children": [ { - "start": 30, - "end": 38, - "type": "Text", - "data": "{animal}" + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 31, + "end": 37, + "name": "animal" + } + } + ] } - ] - }, - { - "start": 42, - "end": 50, - "type": "Text", - "data": "\n{/each}" + ], + "context": "animal" } ] }, diff --git a/test/parser/samples/each-block/output-v2.json b/test/parser/samples/each-block/output-v2.json index e549faca39..7df4a20eba 100644 --- a/test/parser/samples/each-block/output-v2.json +++ b/test/parser/samples/each-block/output-v2.json @@ -1,36 +1,36 @@ { - "hash": 220340986, + "hash": "mzeq0s", "html": { "start": 0, - "end": 56, + "end": 50, "type": "Fragment", "children": [ { "start": 0, - "end": 56, + "end": 50, "type": "EachBlock", "expression": { "type": "Identifier", - "start": 8, - "end": 15, + "start": 7, + "end": 14, "name": "animals" }, "children": [ { - "start": 29, - "end": 46, + "start": 27, + "end": 42, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 32, - "end": 42, + "start": 30, + "end": 38, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 34, - "end": 40, + "start": 31, + "end": 37, "name": "animal" } } diff --git a/test/parser/samples/event-handler/_actual-v2.json b/test/parser/samples/event-handler/_actual-v2.json index ce290b00e0..0d98c325c3 100644 --- a/test/parser/samples/event-handler/_actual-v2.json +++ b/test/parser/samples/event-handler/_actual-v2.json @@ -77,30 +77,37 @@ }, { "start": 61, - "end": 78, + "end": 63, "type": "Text", - "data": "\n\n{#if visible}\n\t" + "data": "\n\n" }, { - "start": 78, - "end": 91, - "type": "Element", - "name": "p", - "attributes": [], + "start": 63, + "end": 97, + "type": "IfBlock", + "expression": { + "type": "Identifier", + "start": 68, + "end": 75, + "name": "visible" + }, "children": [ { - "start": 81, - "end": 87, - "type": "Text", - "data": "hello!" + "start": 78, + "end": 91, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 81, + "end": 87, + "type": "Text", + "data": "hello!" + } + ] } ] - }, - { - "start": 91, - "end": 97, - "type": "Text", - "data": "\n{/if}" } ] }, diff --git a/test/parser/samples/event-handler/output-v2.json b/test/parser/samples/event-handler/output-v2.json index 2b5844bb1b..0d98c325c3 100644 --- a/test/parser/samples/event-handler/output-v2.json +++ b/test/parser/samples/event-handler/output-v2.json @@ -1,8 +1,8 @@ { - "hash": 4260626221, + "hash": "qi54it", "html": { "start": 0, - "end": 101, + "end": 97, "type": "Fragment", "children": [ { @@ -83,25 +83,25 @@ }, { "start": 63, - "end": 101, + "end": 97, "type": "IfBlock", "expression": { "type": "Identifier", - "start": 69, - "end": 76, + "start": 68, + "end": 75, "name": "visible" }, "children": [ { - "start": 80, - "end": 93, + "start": 78, + "end": 91, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 83, - "end": 89, + "start": 81, + "end": 87, "type": "Text", "data": "hello!" } diff --git a/test/parser/samples/if-block-else/_actual-v2.json b/test/parser/samples/if-block-else/_actual-v2.json index 2fffac3d3e..b922778f7e 100644 --- a/test/parser/samples/if-block-else/_actual-v2.json +++ b/test/parser/samples/if-block-else/_actual-v2.json @@ -7,51 +7,53 @@ "children": [ { "start": 0, - "end": 11, - "type": "Text", - "data": "{#if foo}\n\t" - }, - { - "start": 11, - "end": 21, - "type": "Element", - "name": "p", - "attributes": [], - "children": [ - { - "start": 14, - "end": 17, - "type": "Text", - "data": "foo" - } - ] - }, - { - "start": 21, - "end": 31, - "type": "Text", - "data": "\n{:else}\n\t" - }, - { - "start": 31, - "end": 45, - "type": "Element", - "name": "p", - "attributes": [], + "end": 51, + "type": "IfBlock", + "expression": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "foo" + }, "children": [ { - "start": 34, - "end": 41, - "type": "Text", - "data": "not foo" + "start": 11, + "end": 21, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 14, + "end": 17, + "type": "Text", + "data": "foo" + } + ] } - ] - }, - { - "start": 45, - "end": 51, - "type": "Text", - "data": "\n{/if}" + ], + "else": { + "start": 29, + "end": 46, + "type": "ElseBlock", + "children": [ + { + "start": 31, + "end": 45, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 34, + "end": 41, + "type": "Text", + "data": "not foo" + } + ] + } + ] + } } ] }, diff --git a/test/parser/samples/if-block-else/output-v2.json b/test/parser/samples/if-block-else/output-v2.json index af2c611220..b922778f7e 100644 --- a/test/parser/samples/if-block-else/output-v2.json +++ b/test/parser/samples/if-block-else/output-v2.json @@ -1,31 +1,31 @@ { - "hash": 3134964533, + "hash": "dbh411", "html": { "start": 0, - "end": 56, + "end": 51, "type": "Fragment", "children": [ { "start": 0, - "end": 56, + "end": 51, "type": "IfBlock", "expression": { "type": "Identifier", - "start": 6, - "end": 9, + "start": 5, + "end": 8, "name": "foo" }, "children": [ { - "start": 13, - "end": 23, + "start": 11, + "end": 21, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 16, - "end": 19, + "start": 14, + "end": 17, "type": "Text", "data": "foo" } @@ -33,20 +33,20 @@ } ], "else": { - "start": 32, - "end": 49, + "start": 29, + "end": 46, "type": "ElseBlock", "children": [ { - "start": 34, - "end": 48, + "start": 31, + "end": 45, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 37, - "end": 44, + "start": 34, + "end": 41, "type": "Text", "data": "not foo" } diff --git a/test/parser/samples/if-block-elseif/_actual-v2.json b/test/parser/samples/if-block-elseif/_actual-v2.json new file mode 100644 index 0000000000..758e3ee17a --- /dev/null +++ b/test/parser/samples/if-block-elseif/_actual-v2.json @@ -0,0 +1,102 @@ +{ + "hash": "tzpuwu", + "html": { + "start": 0, + "end": 88, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 88, + "type": "IfBlock", + "expression": { + "type": "BinaryExpression", + "start": 5, + "end": 11, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "x" + }, + "operator": ">", + "right": { + "type": "Literal", + "start": 9, + "end": 11, + "value": 10, + "raw": "10" + } + }, + "children": [ + { + "start": 14, + "end": 41, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 17, + "end": 37, + "type": "Text", + "data": "x is greater than 10" + } + ] + } + ], + "else": { + "start": 57, + "end": 83, + "type": "ElseBlock", + "children": [ + { + "start": 57, + "end": 88, + "type": "IfBlock", + "elseif": true, + "expression": { + "type": "BinaryExpression", + "start": 51, + "end": 56, + "left": { + "type": "Identifier", + "start": 51, + "end": 52, + "name": "x" + }, + "operator": "<", + "right": { + "type": "Literal", + "start": 55, + "end": 56, + "value": 5, + "raw": "5" + } + }, + "children": [ + { + "start": 59, + "end": 82, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 62, + "end": 78, + "type": "Text", + "data": "x is less than 5" + } + ] + } + ] + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/if-block-elseif/output-v2.json b/test/parser/samples/if-block-elseif/output-v2.json new file mode 100644 index 0000000000..758e3ee17a --- /dev/null +++ b/test/parser/samples/if-block-elseif/output-v2.json @@ -0,0 +1,102 @@ +{ + "hash": "tzpuwu", + "html": { + "start": 0, + "end": 88, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 88, + "type": "IfBlock", + "expression": { + "type": "BinaryExpression", + "start": 5, + "end": 11, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "x" + }, + "operator": ">", + "right": { + "type": "Literal", + "start": 9, + "end": 11, + "value": 10, + "raw": "10" + } + }, + "children": [ + { + "start": 14, + "end": 41, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 17, + "end": 37, + "type": "Text", + "data": "x is greater than 10" + } + ] + } + ], + "else": { + "start": 57, + "end": 83, + "type": "ElseBlock", + "children": [ + { + "start": 57, + "end": 88, + "type": "IfBlock", + "elseif": true, + "expression": { + "type": "BinaryExpression", + "start": 51, + "end": 56, + "left": { + "type": "Identifier", + "start": 51, + "end": 52, + "name": "x" + }, + "operator": "<", + "right": { + "type": "Literal", + "start": 55, + "end": 56, + "value": 5, + "raw": "5" + } + }, + "children": [ + { + "start": 59, + "end": 82, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 62, + "end": 78, + "type": "Text", + "data": "x is less than 5" + } + ] + } + ] + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/if-block/_actual-v2.json b/test/parser/samples/if-block/_actual-v2.json index 74de1716e8..25ac00f73d 100644 --- a/test/parser/samples/if-block/_actual-v2.json +++ b/test/parser/samples/if-block/_actual-v2.json @@ -8,8 +8,21 @@ { "start": 0, "end": 17, - "type": "Text", - "data": "{#if foo}bar{/if}" + "type": "IfBlock", + "expression": { + "type": "Identifier", + "start": 5, + "end": 8, + "name": "foo" + }, + "children": [ + { + "start": 9, + "end": 12, + "type": "Text", + "data": "bar" + } + ] } ] }, diff --git a/test/parser/samples/if-block/output-v2.json b/test/parser/samples/if-block/output-v2.json index d523d41596..25ac00f73d 100644 --- a/test/parser/samples/if-block/output-v2.json +++ b/test/parser/samples/if-block/output-v2.json @@ -1,24 +1,24 @@ { - "hash": 2374871934, + "hash": "w7ju0y", "html": { "start": 0, - "end": 21, + "end": 17, "type": "Fragment", "children": [ { "start": 0, - "end": 21, + "end": 17, "type": "IfBlock", "expression": { "type": "Identifier", - "start": 6, - "end": 9, + "start": 5, + "end": 8, "name": "foo" }, "children": [ { - "start": 11, - "end": 14, + "start": 9, + "end": 12, "type": "Text", "data": "bar" } diff --git a/test/parser/samples/raw-mustaches/_actual-v2.json b/test/parser/samples/raw-mustaches/_actual-v2.json index 1d3445d24e..983b401968 100644 --- a/test/parser/samples/raw-mustaches/_actual-v2.json +++ b/test/parser/samples/raw-mustaches/_actual-v2.json @@ -14,9 +14,43 @@ "children": [ { "start": 3, + "end": 4, + "type": "Text", + "data": " " + }, + { + "start": 4, + "end": 16, + "type": "RawMustacheTag", + "expression": { + "type": "Identifier", + "start": 11, + "end": 15, + "name": "raw1" + } + }, + { + "start": 16, + "end": 17, + "type": "Text", + "data": " " + }, + { + "start": 17, + "end": 29, + "type": "RawMustacheTag", + "expression": { + "type": "Identifier", + "start": 24, + "end": 28, + "name": "raw2" + } + }, + { + "start": 29, "end": 30, "type": "Text", - "data": " {@html raw1} {@html raw2} " + "data": " " } ] } diff --git a/test/parser/samples/raw-mustaches/output-v2.json b/test/parser/samples/raw-mustaches/output-v2.json index e4a1b91c6c..983b401968 100644 --- a/test/parser/samples/raw-mustaches/output-v2.json +++ b/test/parser/samples/raw-mustaches/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 183399343, + "hash": "9m9gjd", "html": { "start": 0, - "end": 30, + "end": 34, "type": "Fragment", "children": [ { "start": 0, - "end": 30, + "end": 34, "type": "Element", "name": "p", "attributes": [], @@ -20,35 +20,35 @@ }, { "start": 4, - "end": 14, + "end": 16, "type": "RawMustacheTag", "expression": { "type": "Identifier", - "start": 7, - "end": 11, + "start": 11, + "end": 15, "name": "raw1" } }, { - "start": 14, - "end": 15, + "start": 16, + "end": 17, "type": "Text", "data": " " }, { - "start": 15, - "end": 25, + "start": 17, + "end": 29, "type": "RawMustacheTag", "expression": { "type": "Identifier", - "start": 18, - "end": 22, + "start": 24, + "end": 28, "name": "raw2" } }, { - "start": 25, - "end": 26, + "start": 29, + "end": 30, "type": "Text", "data": " " } diff --git a/test/parser/samples/script-comment-trailing-multiline/_actual-v2.json b/test/parser/samples/script-comment-trailing-multiline/_actual-v2.json index 4d68bedef7..4517795aa7 100644 --- a/test/parser/samples/script-comment-trailing-multiline/_actual-v2.json +++ b/test/parser/samples/script-comment-trailing-multiline/_actual-v2.json @@ -14,9 +14,26 @@ "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": "Hello {name}!" + "data": "!" } ] }, diff --git a/test/parser/samples/script-comment-trailing-multiline/output-v2.json b/test/parser/samples/script-comment-trailing-multiline/output-v2.json index 4319919ee5..4517795aa7 100644 --- a/test/parser/samples/script-comment-trailing-multiline/output-v2.json +++ b/test/parser/samples/script-comment-trailing-multiline/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 1378757574, + "hash": "lvjec0", "html": { "start": 0, - "end": 24, + "end": 22, "type": "Fragment", "children": [ { "start": 0, - "end": 24, + "end": 22, "type": "Element", "name": "h1", "attributes": [], @@ -20,26 +20,26 @@ }, { "start": 10, - "end": 18, + "end": 16, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 12, - "end": 16, + "start": 11, + "end": 15, "name": "name" } }, { - "start": 18, - "end": 19, + "start": 16, + "end": 17, "type": "Text", "data": "!" } ] }, { - "start": 24, - "end": 26, + "start": 22, + "end": 24, "type": "Text", "data": "\n\n" } @@ -47,40 +47,40 @@ }, "css": null, "js": { - "start": 26, - "end": 143, + "start": 24, + "end": 141, "attributes": [], "content": { "type": "Program", - "start": 34, - "end": 134, + "start": 32, + "end": 132, "body": [ { "type": "ExportDefaultDeclaration", - "start": 36, - "end": 95, + "start": 34, + "end": 93, "declaration": { "type": "ObjectExpression", - "start": 51, - "end": 94, + "start": 49, + "end": 92, "properties": [ { "type": "Property", - "start": 55, - "end": 91, + "start": 53, + "end": 89, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 55, - "end": 59, + "start": 53, + "end": 57, "name": "data" }, "value": { "type": "ArrowFunctionExpression", - "start": 61, - "end": 91, + "start": 59, + "end": 89, "id": null, "generator": false, "expression": true, @@ -88,26 +88,26 @@ "params": [], "body": { "type": "ObjectExpression", - "start": 68, - "end": 90, + "start": 66, + "end": 88, "properties": [ { "type": "Property", - "start": 73, - "end": 86, + "start": 71, + "end": 84, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 73, - "end": 77, + "start": 71, + "end": 75, "name": "name" }, "value": { "type": "Literal", - "start": 79, - "end": 86, + "start": 77, + "end": 84, "value": "world", "raw": "'world'" }, diff --git a/test/parser/samples/script-comment-trailing/_actual-v2.json b/test/parser/samples/script-comment-trailing/_actual-v2.json index 6d0fe047ef..0ec47a4559 100644 --- a/test/parser/samples/script-comment-trailing/_actual-v2.json +++ b/test/parser/samples/script-comment-trailing/_actual-v2.json @@ -14,9 +14,26 @@ "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": "Hello {name}!" + "data": "!" } ] }, diff --git a/test/parser/samples/script-comment-trailing/output-v2.json b/test/parser/samples/script-comment-trailing/output-v2.json index 2977d6a7fa..0ec47a4559 100644 --- a/test/parser/samples/script-comment-trailing/output-v2.json +++ b/test/parser/samples/script-comment-trailing/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 619854804, + "hash": "19sno7e", "html": { "start": 0, - "end": 24, + "end": 22, "type": "Fragment", "children": [ { "start": 0, - "end": 24, + "end": 22, "type": "Element", "name": "h1", "attributes": [], @@ -20,26 +20,26 @@ }, { "start": 10, - "end": 18, + "end": 16, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 12, - "end": 16, + "start": 11, + "end": 15, "name": "name" } }, { - "start": 18, - "end": 19, + "start": 16, + "end": 17, "type": "Text", "data": "!" } ] }, { - "start": 24, - "end": 26, + "start": 22, + "end": 24, "type": "Text", "data": "\n\n" } @@ -47,40 +47,40 @@ }, "css": null, "js": { - "start": 26, - "end": 132, + "start": 24, + "end": 130, "attributes": [], "content": { "type": "Program", - "start": 34, - "end": 123, + "start": 32, + "end": 121, "body": [ { "type": "ExportDefaultDeclaration", - "start": 36, - "end": 95, + "start": 34, + "end": 93, "declaration": { "type": "ObjectExpression", - "start": 51, - "end": 94, + "start": 49, + "end": 92, "properties": [ { "type": "Property", - "start": 55, - "end": 91, + "start": 53, + "end": 89, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 55, - "end": 59, + "start": 53, + "end": 57, "name": "data" }, "value": { "type": "ArrowFunctionExpression", - "start": 61, - "end": 91, + "start": 59, + "end": 89, "id": null, "generator": false, "expression": true, @@ -88,26 +88,26 @@ "params": [], "body": { "type": "ObjectExpression", - "start": 68, - "end": 90, + "start": 66, + "end": 88, "properties": [ { "type": "Property", - "start": 73, - "end": 86, + "start": 71, + "end": 84, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 73, - "end": 77, + "start": 71, + "end": 75, "name": "name" }, "value": { "type": "Literal", - "start": 79, - "end": 86, + "start": 77, + "end": 84, "value": "world", "raw": "'world'" }, diff --git a/test/parser/samples/script/_actual-v2.json b/test/parser/samples/script/_actual-v2.json index ddc8d043c5..1a68ead9b6 100644 --- a/test/parser/samples/script/_actual-v2.json +++ b/test/parser/samples/script/_actual-v2.json @@ -14,9 +14,26 @@ "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": "Hello {name}!" + "data": "!" } ] }, diff --git a/test/parser/samples/script/output-v2.json b/test/parser/samples/script/output-v2.json index 5c8acef657..1a68ead9b6 100644 --- a/test/parser/samples/script/output-v2.json +++ b/test/parser/samples/script/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 388108696, + "hash": "6jy7zq", "html": { "start": 0, - "end": 24, + "end": 22, "type": "Fragment", "children": [ { "start": 0, - "end": 24, + "end": 22, "type": "Element", "name": "h1", "attributes": [], @@ -20,26 +20,26 @@ }, { "start": 10, - "end": 18, + "end": 16, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 12, - "end": 16, + "start": 11, + "end": 15, "name": "name" } }, { - "start": 18, - "end": 19, + "start": 16, + "end": 17, "type": "Text", "data": "!" } ] }, { - "start": 24, - "end": 26, + "start": 22, + "end": 24, "type": "Text", "data": "\n\n" } @@ -47,40 +47,40 @@ }, "css": null, "js": { - "start": 26, - "end": 105, + "start": 24, + "end": 103, "attributes": [], "content": { "type": "Program", - "start": 34, - "end": 96, + "start": 32, + "end": 94, "body": [ { "type": "ExportDefaultDeclaration", - "start": 36, - "end": 95, + "start": 34, + "end": 93, "declaration": { "type": "ObjectExpression", - "start": 51, - "end": 94, + "start": 49, + "end": 92, "properties": [ { "type": "Property", - "start": 55, - "end": 91, + "start": 53, + "end": 89, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 55, - "end": 59, + "start": 53, + "end": 57, "name": "data" }, "value": { "type": "ArrowFunctionExpression", - "start": 61, - "end": 91, + "start": 59, + "end": 89, "id": null, "generator": false, "expression": true, @@ -88,26 +88,26 @@ "params": [], "body": { "type": "ObjectExpression", - "start": 68, - "end": 90, + "start": 66, + "end": 88, "properties": [ { "type": "Property", - "start": 73, - "end": 86, + "start": 71, + "end": 84, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", - "start": 73, - "end": 77, + "start": 71, + "end": 75, "name": "name" }, "value": { "type": "Literal", - "start": 79, - "end": 86, + "start": 77, + "end": 84, "value": "world", "raw": "'world'" }, diff --git a/test/parser/samples/self-reference/_actual-v2.json b/test/parser/samples/self-reference/_actual-v2.json index db449c7cb1..ced5eabc41 100644 --- a/test/parser/samples/self-reference/_actual-v2.json +++ b/test/parser/samples/self-reference/_actual-v2.json @@ -7,38 +7,70 @@ "children": [ { "start": 0, - "end": 17, - "type": "Text", - "data": "{#if depth > 1}\n\t" - }, - { - "start": 17, - "end": 51, - "type": "Element", - "name": "svelte:self", - "attributes": [ + "end": 57, + "type": "IfBlock", + "expression": { + "type": "BinaryExpression", + "start": 5, + "end": 14, + "left": { + "type": "Identifier", + "start": 5, + "end": 10, + "name": "depth" + }, + "operator": ">", + "right": { + "type": "Literal", + "start": 13, + "end": 14, + "value": 1, + "raw": "1" + } + }, + "children": [ { - "start": 30, - "end": 49, - "type": "Attribute", - "name": "depth", - "value": [ + "start": 17, + "end": 51, + "type": "Element", + "name": "svelte:self", + "attributes": [ { - "start": 37, - "end": 48, - "type": "Text", - "data": "{depth - 1}" + "start": 30, + "end": 49, + "type": "Attribute", + "name": "depth", + "value": [ + { + "start": 37, + "end": 48, + "type": "MustacheTag", + "expression": { + "type": "BinaryExpression", + "start": 38, + "end": 47, + "left": { + "type": "Identifier", + "start": 38, + "end": 43, + "name": "depth" + }, + "operator": "-", + "right": { + "type": "Literal", + "start": 46, + "end": 47, + "value": 1, + "raw": "1" + } + } + } + ] } - ] + ], + "children": [] } - ], - "children": [] - }, - { - "start": 51, - "end": 57, - "type": "Text", - "data": "\n{/if}" + ] } ] }, diff --git a/test/parser/samples/self-reference/output-v2.json b/test/parser/samples/self-reference/output-v2.json index f9c788bd2f..ced5eabc41 100644 --- a/test/parser/samples/self-reference/output-v2.json +++ b/test/parser/samples/self-reference/output-v2.json @@ -1,5 +1,5 @@ { - "hash": 216762188, + "hash": "1wh7lqr", "html": { "start": 0, "end": 57, @@ -11,55 +11,55 @@ "type": "IfBlock", "expression": { "type": "BinaryExpression", - "start": 6, - "end": 15, + "start": 5, + "end": 14, "left": { "type": "Identifier", - "start": 6, - "end": 11, + "start": 5, + "end": 10, "name": "depth" }, "operator": ">", "right": { "type": "Literal", - "start": 14, - "end": 15, + "start": 13, + "end": 14, "value": 1, "raw": "1" } }, "children": [ { - "start": 19, - "end": 49, + "start": 17, + "end": 51, "type": "Element", - "name": ":Self", + "name": "svelte:self", "attributes": [ { - "start": 26, - "end": 47, + "start": 30, + "end": 49, "type": "Attribute", "name": "depth", "value": [ { - "start": 33, - "end": 46, + "start": 37, + "end": 48, "type": "MustacheTag", "expression": { "type": "BinaryExpression", - "start": 35, - "end": 44, + "start": 38, + "end": 47, "left": { "type": "Identifier", - "start": 35, - "end": 40, + "start": 38, + "end": 43, "name": "depth" }, "operator": "-", "right": { "type": "Literal", - "start": 43, - "end": 44, + "start": 46, + "end": 47, "value": 1, "raw": "1" } diff --git a/test/parser/samples/space-between-mustaches/_actual-v2.json b/test/parser/samples/space-between-mustaches/_actual-v2.json index 767a93da36..b6b5c1a4df 100644 --- a/test/parser/samples/space-between-mustaches/_actual-v2.json +++ b/test/parser/samples/space-between-mustaches/_actual-v2.json @@ -14,9 +14,60 @@ "children": [ { "start": 3, + "end": 4, + "type": "Text", + "data": " " + }, + { + "start": 4, + "end": 7, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 5, + "end": 6, + "name": "a" + } + }, + { + "start": 7, + "end": 8, + "type": "Text", + "data": " " + }, + { + "start": 8, + "end": 11, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 9, + "end": 10, + "name": "b" + } + }, + { + "start": 11, + "end": 14, + "type": "Text", + "data": " : " + }, + { + "start": 14, + "end": 17, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 15, + "end": 16, + "name": "c" + } + }, + { + "start": 17, "end": 20, "type": "Text", - "data": " {a} {b} : {c} : " + "data": " : " } ] } diff --git a/test/parser/samples/space-between-mustaches/output-v2.json b/test/parser/samples/space-between-mustaches/output-v2.json index 854608fb29..b6b5c1a4df 100644 --- a/test/parser/samples/space-between-mustaches/output-v2.json +++ b/test/parser/samples/space-between-mustaches/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 1185019088, + "hash": "1n7rpsi", "html": { "start": 0, - "end": 30, + "end": 24, "type": "Fragment", "children": [ { "start": 0, - "end": 30, + "end": 24, "type": "Element", "name": "p", "attributes": [], @@ -20,52 +20,52 @@ }, { "start": 4, - "end": 9, + "end": 7, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 6, - "end": 7, + "start": 5, + "end": 6, "name": "a" } }, { - "start": 9, - "end": 10, + "start": 7, + "end": 8, "type": "Text", "data": " " }, { - "start": 10, - "end": 15, + "start": 8, + "end": 11, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 12, - "end": 13, + "start": 9, + "end": 10, "name": "b" } }, { - "start": 15, - "end": 18, + "start": 11, + "end": 14, "type": "Text", "data": " : " }, { - "start": 18, - "end": 23, + "start": 14, + "end": 17, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 20, - "end": 21, + "start": 15, + "end": 16, "name": "c" } }, { - "start": 23, - "end": 26, + "start": 17, + "end": 20, "type": "Text", "data": " : " } diff --git a/test/parser/samples/spread/_actual-v2.json b/test/parser/samples/spread/_actual-v2.json index 48ef177cd7..e9c53e7446 100644 --- a/test/parser/samples/spread/_actual-v2.json +++ b/test/parser/samples/spread/_actual-v2.json @@ -14,9 +14,13 @@ { "start": 5, "end": 15, - "type": "Attribute", - "name": "{...props}", - "value": true + "type": "Spread", + "expression": { + "type": "Identifier", + "start": 9, + "end": 14, + "name": "props" + } } ], "children": [] diff --git a/test/parser/samples/spread/output-v2.json b/test/parser/samples/spread/output-v2.json index 09fa0b3027..e9c53e7446 100644 --- a/test/parser/samples/spread/output-v2.json +++ b/test/parser/samples/spread/output-v2.json @@ -1,24 +1,24 @@ { - "hash": "phg0l6", + "hash": "z82kse", "html": { "start": 0, - "end": 24, + "end": 22, "type": "Fragment", "children": [ { "start": 0, - "end": 24, + "end": 22, "type": "Element", "name": "div", "attributes": [ { "start": 5, - "end": 17, + "end": 15, "type": "Spread", "expression": { "type": "Identifier", - "start": 10, - "end": 15, + "start": 9, + "end": 14, "name": "props" } } diff --git a/test/parser/samples/textarea-children/_actual-v2.json b/test/parser/samples/textarea-children/_actual-v2.json index 12a5b99173..2e219bb750 100644 --- a/test/parser/samples/textarea-children/_actual-v2.json +++ b/test/parser/samples/textarea-children/_actual-v2.json @@ -14,9 +14,26 @@ "children": [ { "start": 10, + "end": 40, + "type": "Text", + "data": "\n\t

not actually an element. " + }, + { + "start": 40, + "end": 45, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 41, + "end": 44, + "name": "foo" + } + }, + { + "start": 45, "end": 50, "type": "Text", - "data": "\n\t

not actually an element. {foo}

\n" + "data": "

\n" } ] } diff --git a/test/parser/samples/textarea-children/output-v2.json b/test/parser/samples/textarea-children/output-v2.json index d4ea6f04bb..2e219bb750 100644 --- a/test/parser/samples/textarea-children/output-v2.json +++ b/test/parser/samples/textarea-children/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 2992234421, + "hash": "1uyqul7", "html": { "start": 0, - "end": 63, + "end": 61, "type": "Fragment", "children": [ { "start": 0, - "end": 63, + "end": 61, "type": "Element", "name": "textarea", "attributes": [], @@ -20,18 +20,18 @@ }, { "start": 40, - "end": 47, + "end": 45, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 42, - "end": 45, + "start": 41, + "end": 44, "name": "foo" } }, { - "start": 47, - "end": 52, + "start": 45, + "end": 50, "type": "Text", "data": "

\n" } diff --git a/test/parser/samples/unusual-identifier/_actual-v2.json b/test/parser/samples/unusual-identifier/_actual-v2.json index 1a6cb72eb4..e4a290c0a6 100644 --- a/test/parser/samples/unusual-identifier/_actual-v2.json +++ b/test/parser/samples/unusual-identifier/_actual-v2.json @@ -7,30 +7,37 @@ "children": [ { "start": 0, - "end": 22, - "type": "Text", - "data": "{#each things as 𐊧}\n\t" - }, - { - "start": 22, - "end": 33, - "type": "Element", - "name": "p", - "attributes": [], + "end": 41, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 7, + "end": 13, + "name": "things" + }, "children": [ { - "start": 25, - "end": 29, - "type": "Text", - "data": "{𐊧}" + "start": 22, + "end": 33, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 25, + "end": 29, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 26, + "end": 28, + "name": "𐊧" + } + } + ] } - ] - }, - { - "start": 33, - "end": 41, - "type": "Text", - "data": "\n{/each}" + ], + "context": "𐊧" } ] }, diff --git a/test/parser/samples/unusual-identifier/output-v2.json b/test/parser/samples/unusual-identifier/output-v2.json index 6434526df5..e4a290c0a6 100644 --- a/test/parser/samples/unusual-identifier/output-v2.json +++ b/test/parser/samples/unusual-identifier/output-v2.json @@ -1,36 +1,36 @@ { - "hash": 795130236, + "hash": "8weqxs", "html": { "start": 0, - "end": 47, + "end": 41, "type": "Fragment", "children": [ { "start": 0, - "end": 47, + "end": 41, "type": "EachBlock", "expression": { "type": "Identifier", - "start": 8, - "end": 14, + "start": 7, + "end": 13, "name": "things" }, "children": [ { - "start": 24, - "end": 37, + "start": 22, + "end": 33, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 27, - "end": 33, + "start": 25, + "end": 29, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 29, - "end": 31, + "start": 26, + "end": 28, "name": "𐊧" } } diff --git a/test/parser/samples/whitespace-normal/_actual-v2.json b/test/parser/samples/whitespace-normal/_actual-v2.json index d0a9c66d6a..e9d6a39b08 100644 --- a/test/parser/samples/whitespace-normal/_actual-v2.json +++ b/test/parser/samples/whitespace-normal/_actual-v2.json @@ -27,9 +27,20 @@ "children": [ { "start": 18, + "end": 24, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 19, + "end": 23, + "name": "name" + } + }, + { + "start": 24, "end": 26, "type": "Text", - "data": "{name}! " + "data": "! " } ] }, diff --git a/test/parser/samples/whitespace-normal/output-v2.json b/test/parser/samples/whitespace-normal/output-v2.json index 5b609c8e36..e9d6a39b08 100644 --- a/test/parser/samples/whitespace-normal/output-v2.json +++ b/test/parser/samples/whitespace-normal/output-v2.json @@ -1,13 +1,13 @@ { - "hash": 2961389466, + "hash": "1827l8g", "html": { "start": 0, - "end": 67, + "end": 65, "type": "Fragment", "children": [ { "start": 0, - "end": 67, + "end": 65, "type": "Element", "name": "h1", "attributes": [], @@ -20,40 +20,40 @@ }, { "start": 10, - "end": 37, + "end": 35, "type": "Element", "name": "strong", "attributes": [], "children": [ { "start": 18, - "end": 26, + "end": 24, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 20, - "end": 24, + "start": 19, + "end": 23, "name": "name" } }, { - "start": 26, - "end": 28, + "start": 24, + "end": 26, "type": "Text", "data": "! " } ] }, { - "start": 37, - "end": 62, + "start": 35, + "end": 60, "type": "Element", "name": "span", "attributes": [], "children": [ { - "start": 43, - "end": 55, + "start": 41, + "end": 53, "type": "Text", "data": "How are you?" } diff --git a/test/parser/samples/yield/_actual-v2.json b/test/parser/samples/yield/_actual-v2.json index cc8cf37176..da5ed52d0e 100644 --- a/test/parser/samples/yield/_actual-v2.json +++ b/test/parser/samples/yield/_actual-v2.json @@ -1,17 +1,20 @@ { - "hash": "1oiqcow", + "hash": "1na2f8c", "html": { "start": 0, - "end": 9, + "end": 7, "type": "Fragment", "children": [ { "start": 0, - "end": 9, - "type": "Element", - "name": "slot", - "attributes": [], - "children": [] + "end": 7, + "type": "MustacheTag", + "expression": { + "start": 1, + "end": 6, + "type": "Identifier", + "name": "yield" + } } ] }, diff --git a/test/parser/samples/yield/input-v2.html b/test/parser/samples/yield/input-v2.html index fb5c4b157d..f5e8aad053 100644 --- a/test/parser/samples/yield/input-v2.html +++ b/test/parser/samples/yield/input-v2.html @@ -1 +1 @@ -{{yield}} \ No newline at end of file +{yield} \ No newline at end of file diff --git a/test/parser/samples/yield/output-v2.json b/test/parser/samples/yield/output-v2.json index d3f3e602a6..da5ed52d0e 100644 --- a/test/parser/samples/yield/output-v2.json +++ b/test/parser/samples/yield/output-v2.json @@ -1,17 +1,20 @@ { - "hash": 3659433152, + "hash": "1na2f8c", "html": { "start": 0, - "end": 9, + "end": 7, "type": "Fragment", "children": [ { "start": 0, - "end": 9, - "type": "Element", - "name": "slot", - "attributes": [], - "children": [] + "end": 7, + "type": "MustacheTag", + "expression": { + "start": 1, + "end": 6, + "type": "Identifier", + "name": "yield" + } } ] },