diff --git a/src/interfaces.ts b/src/interfaces.ts index d44c6a030c..dc3fb614c1 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -66,6 +66,8 @@ export interface CompileOptions { onerror?: (error: Error) => void; onwarn?: (warning: Warning) => void; + + parser?: 'v2'; } export interface GenerateOptions { diff --git a/src/parse/index.ts b/src/parse/index.ts index 3e78221477..b7656a426a 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -13,11 +13,13 @@ import error from '../utils/error'; interface ParserOptions { filename?: string; bind?: boolean; + parser?: 'v2'; } type ParserState = (parser: Parser) => (ParserState | void); export class Parser { + readonly v2: boolean; readonly template: string; readonly filename?: string; @@ -32,6 +34,8 @@ export class Parser { allowBindings: boolean; constructor(template: string, options: ParserOptions) { + this.v2 = options.parser === 'v2'; + if (typeof template !== 'string') { throw new TypeError('Template must be a string'); } diff --git a/src/parse/state/fragment.ts b/src/parse/state/fragment.ts index c82b3e2f8a..b2e6cb4c32 100644 --- a/src/parse/state/fragment.ts +++ b/src/parse/state/fragment.ts @@ -8,7 +8,7 @@ export default function fragment(parser: Parser) { return tag; } - if (parser.match('{{')) { + if (parser.match(parser.v2 ? '{' : '{{')) { return mustache; } diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 0a255b1256..8da2560fb2 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -32,7 +32,7 @@ function trimWhitespace(block: Node, trimBefore: boolean, trimAfter: boolean) { export default function mustache(parser: Parser) { const start = parser.index; - parser.index += 2; + parser.index += parser.v2 ? 1 : 2; parser.allowWhitespace(); @@ -329,7 +329,7 @@ export default function mustache(parser: Parser) { const expression = readExpression(parser); parser.allowWhitespace(); - parser.eat('}}', true); + parser.eat(parser.v2 ? '}' : '}}', true); parser.current().children.push({ start, diff --git a/src/parse/state/text.ts b/src/parse/state/text.ts index bdd625569c..29da8f928a 100644 --- a/src/parse/state/text.ts +++ b/src/parse/state/text.ts @@ -9,7 +9,7 @@ export default function text(parser: Parser) { while ( parser.index < parser.template.length && !parser.match('<') && - !parser.match('{{') + !parser.match(parser.v2 ? '{' : '{{') ) { data += parser.template[parser.index++]; } diff --git a/test/parser/index.js b/test/parser/index.js index 7467e31b0c..d0417c8bfa 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -2,7 +2,7 @@ import assert from 'assert'; import fs from 'fs'; import { svelte, tryToLoadJson } from '../helpers.js'; -describe('parse', () => { +describe.only('parse', () => { fs.readdirSync('test/parser/samples').forEach(dir => { if (dir[0] === '.') return; @@ -20,19 +20,37 @@ describe('parse', () => { .readFileSync(`test/parser/samples/${dir}/input.html`, 'utf-8') .replace(/\s+$/, ''); + const input_v2 = fs + .readFileSync(`test/parser/samples/${dir}/input-v2.html`, 'utf-8') + .replace(/\s+$/, ''); + const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {}; try { const actual = svelte.parse(input, options); + const expected = require(`./samples/${dir}/output.json`); + fs.writeFileSync( `test/parser/samples/${dir}/_actual.json`, JSON.stringify(actual, null, '\t') ); - const expected = require(`./samples/${dir}/output.json`); assert.deepEqual(actual.html, expected.html); assert.deepEqual(actual.css, expected.css); assert.deepEqual(actual.js, expected.js); + + // TODO remove v1 tests + const actual_v2 = svelte.parse(input_v2, Object.assign({ parser: 'v2' }, options)); + const expected_v2 = require(`./samples/${dir}/output-v2.json`); + + fs.writeFileSync( + `test/parser/samples/${dir}/_actual-v2.json`, + JSON.stringify(actual_v2, null, '\t') + ); + + assert.deepEqual(actual_v2.html, expected_v2.html); + assert.deepEqual(actual_v2.css, expected_v2.css); + assert.deepEqual(actual_v2.js, expected_v2.js); } catch (err) { if (err.name !== 'ParseError') throw err; diff --git a/test/parser/samples/action-with-call/_actual-v2.json b/test/parser/samples/action-with-call/_actual-v2.json new file mode 100644 index 0000000000..b7bc908e24 --- /dev/null +++ b/test/parser/samples/action-with-call/_actual-v2.json @@ -0,0 +1,47 @@ +{ + "hash": "1eefngx", + "html": { + "start": 0, + "end": 38, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 38, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 37, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "CallExpression", + "start": 20, + "end": 36, + "callee": { + "type": "Identifier", + "start": 20, + "end": 21, + "name": "t" + }, + "arguments": [ + { + "type": "Literal", + "start": 22, + "end": 35, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + ] + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-call/input-v2.html b/test/parser/samples/action-with-call/input-v2.html new file mode 100644 index 0000000000..246bf02c59 --- /dev/null +++ b/test/parser/samples/action-with-call/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-call/output-v2.json b/test/parser/samples/action-with-call/output-v2.json new file mode 100644 index 0000000000..f5cc6824f3 --- /dev/null +++ b/test/parser/samples/action-with-call/output-v2.json @@ -0,0 +1,47 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 38, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 38, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 37, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "CallExpression", + "start": 20, + "end": 36, + "callee": { + "type": "Identifier", + "start": 20, + "end": 21, + "name": "t" + }, + "arguments": [ + { + "type": "Literal", + "start": 22, + "end": 35, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + ] + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/_actual-v2.json b/test/parser/samples/action-with-identifier/_actual-v2.json new file mode 100644 index 0000000000..6c6daa34b2 --- /dev/null +++ b/test/parser/samples/action-with-identifier/_actual-v2.json @@ -0,0 +1,33 @@ +{ + "hash": "1vce0rr", + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 28, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Identifier", + "start": 20, + "end": 27, + "name": "message" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/input-v2.html b/test/parser/samples/action-with-identifier/input-v2.html new file mode 100644 index 0000000000..14a65e83ed --- /dev/null +++ b/test/parser/samples/action-with-identifier/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-identifier/output-v2.json b/test/parser/samples/action-with-identifier/output-v2.json new file mode 100644 index 0000000000..6c39ed94bc --- /dev/null +++ b/test/parser/samples/action-with-identifier/output-v2.json @@ -0,0 +1,33 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 28, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Identifier", + "start": 20, + "end": 27, + "name": "message" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/_actual-v2.json b/test/parser/samples/action-with-literal/_actual-v2.json new file mode 100644 index 0000000000..472b5a306d --- /dev/null +++ b/test/parser/samples/action-with-literal/_actual-v2.json @@ -0,0 +1,34 @@ +{ + "hash": "1pm9eh0", + "html": { + "start": 0, + "end": 35, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 34, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Literal", + "start": 20, + "end": 33, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/input-v2.html b/test/parser/samples/action-with-literal/input-v2.html new file mode 100644 index 0000000000..60e16eacfc --- /dev/null +++ b/test/parser/samples/action-with-literal/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action-with-literal/output-v2.json b/test/parser/samples/action-with-literal/output-v2.json new file mode 100644 index 0000000000..0da0318887 --- /dev/null +++ b/test/parser/samples/action-with-literal/output-v2.json @@ -0,0 +1,34 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 35, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 34, + "type": "Action", + "name": "tooltip", + "expression": { + "type": "Literal", + "start": 20, + "end": 33, + "value": "tooltip msg", + "raw": "'tooltip msg'" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action/_actual-v2.json b/test/parser/samples/action/_actual-v2.json new file mode 100644 index 0000000000..0746bd601a --- /dev/null +++ b/test/parser/samples/action/_actual-v2.json @@ -0,0 +1,28 @@ +{ + "hash": "1e3ix5", + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 20, + "type": "Action", + "name": "autofocus", + "expression": null + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/action/input-v2.html b/test/parser/samples/action/input-v2.html new file mode 100644 index 0000000000..64409c2a65 --- /dev/null +++ b/test/parser/samples/action/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/action/output-v2.json b/test/parser/samples/action/output-v2.json new file mode 100644 index 0000000000..597ae297a5 --- /dev/null +++ b/test/parser/samples/action/output-v2.json @@ -0,0 +1,28 @@ +{ + "hash": 1937205193, + "html": { + "start": 0, + "end": 21, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 21, + "type": "Element", + "name": "input", + "attributes": [ + { + "start": 7, + "end": 20, + "type": "Action", + "name": "autofocus", + "expression": null + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json new file mode 100644 index 0000000000..c843275a4f --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "7xolfv", + "html": { + "start": 0, + "end": 41, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 41, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 29, + "type": "Attribute", + "name": "readonly", + "value": [ + { + "start": 19, + "end": 29, + "type": "Text", + "data": "{readonly}" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/input-v2.html b/test/parser/samples/attribute-dynamic-boolean/input-v2.html new file mode 100644 index 0000000000..ba531f2f81 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/input-v2.html @@ -0,0 +1 @@ + diff --git a/test/parser/samples/attribute-dynamic-boolean/output-v2.json b/test/parser/samples/attribute-dynamic-boolean/output-v2.json new file mode 100644 index 0000000000..af1635a55d --- /dev/null +++ b/test/parser/samples/attribute-dynamic-boolean/output-v2.json @@ -0,0 +1,40 @@ +{ + "hash": 3179574701, + "html": { + "start": 0, + "end": 45, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 45, + "type": "Element", + "name": "textarea", + "attributes": [ + { + "start": 10, + "end": 33, + "type": "Attribute", + "name": "readonly", + "value": [ + { + "start": 20, + "end": 32, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 22, + "end": 30, + "name": "readonly" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json new file mode 100644 index 0000000000..76b70ef261 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/_actual-v2.json @@ -0,0 +1,35 @@ +{ + "hash": "l0cddf", + "html": { + "start": 0, + "end": 25, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 25, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 18, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 11, + "end": 18, + "type": "Text", + "data": "{class}" + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/input-v2.html b/test/parser/samples/attribute-dynamic-reserved/input-v2.html new file mode 100644 index 0000000000..d973a9dea0 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/input-v2.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/output-v2.json b/test/parser/samples/attribute-dynamic-reserved/output-v2.json new file mode 100644 index 0000000000..aef0e5cb63 --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/output-v2.json @@ -0,0 +1,40 @@ +{ + "hash": 2788845841, + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 22, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 12, + "end": 21, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 14, + "end": 19, + "name": "class" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/_actual-v2.json b/test/parser/samples/attribute-dynamic/_actual-v2.json new file mode 100644 index 0000000000..06f82de54a --- /dev/null +++ b/test/parser/samples/attribute-dynamic/_actual-v2.json @@ -0,0 +1,42 @@ +{ + "hash": "ehtsx6", + "html": { + "start": 0, + "end": 42, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 42, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 28, + "type": "Attribute", + "name": "style", + "value": [ + { + "start": 12, + "end": 27, + "type": "Text", + "data": "color: {color};" + } + ] + } + ], + "children": [ + { + "start": 29, + "end": 36, + "type": "Text", + "data": "{color}" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/input-v2.html b/test/parser/samples/attribute-dynamic/input-v2.html new file mode 100644 index 0000000000..9171ae22a7 --- /dev/null +++ b/test/parser/samples/attribute-dynamic/input-v2.html @@ -0,0 +1 @@ +loading...
+{:then theValue} +the value is {theValue}
+{:catch theError} +oh no! {theError.message}}
+{/await} \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/output-v2.json b/test/parser/samples/await-then-catch/output-v2.json new file mode 100644 index 0000000000..4f149e6a0c --- /dev/null +++ b/test/parser/samples/await-then-catch/output-v2.json @@ -0,0 +1,161 @@ +{ + "hash": 1040536517, + "html": { + "start": 0, + "end": 158, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 158, + "type": "AwaitBlock", + "expression": { + "type": "Identifier", + "start": 9, + "end": 19, + "name": "thePromise" + }, + "value": "theValue", + "error": "theError", + "pending": { + "start": 21, + "end": 41, + "type": "PendingBlock", + "children": [ + { + "start": 21, + "end": 23, + "type": "Text", + "data": "\n\t" + }, + { + "start": 23, + "end": 40, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 26, + "end": 36, + "type": "Text", + "data": "loading..." + } + ] + }, + { + "start": 40, + "end": 41, + "type": "Text", + "data": "\n" + } + ] + }, + "then": { + "start": 41, + "end": 93, + "type": "ThenBlock", + "children": [ + { + "start": 58, + "end": 60, + "type": "Text", + "data": "\n\t" + }, + { + "start": 60, + "end": 92, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 63, + "end": 76, + "type": "Text", + "data": "the value is " + }, + { + "start": 76, + "end": 88, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 78, + "end": 86, + "name": "theValue" + } + } + ] + }, + { + "start": 92, + "end": 93, + "type": "Text", + "data": "\n" + } + ] + }, + "catch": { + "start": 93, + "end": 148, + "type": "CatchBlock", + "children": [ + { + "start": 111, + "end": 113, + "type": "Text", + "data": "\n\t" + }, + { + "start": 113, + "end": 147, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 116, + "end": 123, + "type": "Text", + "data": "oh no! " + }, + { + "start": 123, + "end": 143, + "type": "MustacheTag", + "expression": { + "type": "MemberExpression", + "start": 125, + "end": 141, + "object": { + "type": "Identifier", + "start": 125, + "end": 133, + "name": "theError" + }, + "property": { + "type": "Identifier", + "start": 134, + "end": 141, + "name": "message" + }, + "computed": false + } + } + ] + }, + { + "start": 147, + "end": 148, + "type": "Text", + "data": "\n" + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/_actual-v2.json b/test/parser/samples/binding-shorthand/_actual-v2.json new file mode 100644 index 0000000000..de159d6516 --- /dev/null +++ b/test/parser/samples/binding-shorthand/_actual-v2.json @@ -0,0 +1,33 @@ +{ + "hash": "1f31b7d", + "html": { + "start": 0, + "end": 18, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 18, + "type": "Element", + "name": "Widget", + "attributes": [ + { + "start": 8, + "end": 16, + "type": "Binding", + "name": "foo", + "value": { + "type": "Identifier", + "start": 13, + "end": 16, + "name": "foo" + } + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/input-v2.html b/test/parser/samples/binding-shorthand/input-v2.html new file mode 100644 index 0000000000..7f8116bdde --- /dev/null +++ b/test/parser/samples/binding-shorthand/input-v2.html @@ -0,0 +1 @@ +Hello & World
\ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/output-v2.json b/test/parser/samples/convert-entities-in-element/output-v2.json new file mode 100644 index 0000000000..cb3e50ec3b --- /dev/null +++ b/test/parser/samples/convert-entities-in-element/output-v2.json @@ -0,0 +1,27 @@ +{ + "hash": 2365862121, + "html": { + "start": 0, + "end": 24, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 24, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 3, + "end": 20, + "type": "Text", + "data": "Hello & World" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities/_actual-v2.json b/test/parser/samples/convert-entities/_actual-v2.json new file mode 100644 index 0000000000..2a2deedc99 --- /dev/null +++ b/test/parser/samples/convert-entities/_actual-v2.json @@ -0,0 +1,18 @@ +{ + "hash": "2lbrq0", + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Text", + "data": "Hello & World" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/convert-entities/input-v2.html b/test/parser/samples/convert-entities/input-v2.html new file mode 100644 index 0000000000..161463ec58 --- /dev/null +++ b/test/parser/samples/convert-entities/input-v2.html @@ -0,0 +1 @@ +Hello & World \ No newline at end of file diff --git a/test/parser/samples/convert-entities/output-v2.json b/test/parser/samples/convert-entities/output-v2.json new file mode 100644 index 0000000000..479bae3064 --- /dev/null +++ b/test/parser/samples/convert-entities/output-v2.json @@ -0,0 +1,18 @@ +{ + "hash": 156753432, + "html": { + "start": 0, + "end": 17, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 17, + "type": "Text", + "data": "Hello & World" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/_actual-v2.json b/test/parser/samples/css-ref-selector/_actual-v2.json new file mode 100644 index 0000000000..5edf24cd19 --- /dev/null +++ b/test/parser/samples/css-ref-selector/_actual-v2.json @@ -0,0 +1,96 @@ +{ + "hash": "i9aush", + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 12, + "type": "Ref", + "name": "foo" + } + ], + "children": [] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 60, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "RefSelector", + "start": 25, + "end": 32, + "name": "foo" + } + ], + "start": 25, + "end": 32 + } + ], + "start": 25, + "end": 32 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 44, + "end": 47 + } + ], + "start": 43, + "end": 47 + }, + "start": 37, + "end": 47 + } + ], + "start": 33, + "end": 51 + }, + "start": 25, + "end": 51 + } + ], + "content": { + "start": 23, + "end": 52, + "styles": "\n\tref:foo {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/input-v2.html b/test/parser/samples/css-ref-selector/input-v2.html new file mode 100644 index 0000000000..696075f93f --- /dev/null +++ b/test/parser/samples/css-ref-selector/input-v2.html @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/test/parser/samples/css-ref-selector/output-v2.json b/test/parser/samples/css-ref-selector/output-v2.json new file mode 100644 index 0000000000..2ddafc4aae --- /dev/null +++ b/test/parser/samples/css-ref-selector/output-v2.json @@ -0,0 +1,96 @@ +{ + "hash": 1104014177, + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 12, + "type": "Ref", + "name": "foo" + } + ], + "children": [] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 60, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "RefSelector", + "start": 25, + "end": 32, + "name": "foo" + } + ], + "start": 25, + "end": 32 + } + ], + "start": 25, + "end": 32 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 44, + "end": 47 + } + ], + "start": 43, + "end": 47 + }, + "start": 37, + "end": 47 + } + ], + "start": 33, + "end": 51 + }, + "start": 25, + "end": 51 + } + ], + "content": { + "start": 23, + "end": 52, + "styles": "\n\tref:foo {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css/_actual-v2.json b/test/parser/samples/css/_actual-v2.json new file mode 100644 index 0000000000..316e6e72a5 --- /dev/null +++ b/test/parser/samples/css/_actual-v2.json @@ -0,0 +1,96 @@ +{ + "hash": "iz4x8b", + "html": { + "start": 0, + "end": 14, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 14, + "type": "Element", + "name": "div", + "attributes": [], + "children": [ + { + "start": 5, + "end": 8, + "type": "Text", + "data": "foo" + } + ] + }, + { + "start": 14, + "end": 16, + "type": "Text", + "data": "\n\n" + } + ] + }, + "css": { + "start": 16, + "end": 56, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "TypeSelector", + "name": "div", + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", + "children": [ + { + "type": "Identifier", + "name": "red", + "start": 40, + "end": 43 + } + ], + "start": 39, + "end": 43 + }, + "start": 33, + "end": 43 + } + ], + "start": 29, + "end": 47 + }, + "start": 25, + "end": 47 + } + ], + "content": { + "start": 23, + "end": 48, + "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" + } + }, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/css/input-v2.html b/test/parser/samples/css/input-v2.html new file mode 100644 index 0000000000..a573bcf778 --- /dev/null +++ b/test/parser/samples/css/input-v2.html @@ -0,0 +1,7 @@ +{key}: {value}
+{/each} diff --git a/test/parser/samples/each-block-destructured/output-v2.json b/test/parser/samples/each-block-destructured/output-v2.json new file mode 100644 index 0000000000..897fec88b8 --- /dev/null +++ b/test/parser/samples/each-block-destructured/output-v2.json @@ -0,0 +1,67 @@ +{ + "hash": 2621498076, + "html": { + "start": 0, + "end": 70, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 70, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 35, + "end": 60, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 38, + "end": 45, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 40, + "end": 43, + "name": "key" + } + }, + { + "start": 45, + "end": 47, + "type": "Text", + "data": ": " + }, + { + "start": 47, + "end": 56, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 49, + "end": 54, + "name": "value" + } + } + ] + } + ], + "destructuredContexts": [ + "key", + "value" + ], + "context": "key_value" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-else/_actual-v2.json b/test/parser/samples/each-block-else/_actual-v2.json new file mode 100644 index 0000000000..af7b618bf8 --- /dev/null +++ b/test/parser/samples/each-block-else/_actual-v2.json @@ -0,0 +1,60 @@ +{ + "hash": "ljl07n", + "html": { + "start": 0, + "end": 77, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 27, + "type": "Text", + "data": "{#each animals as animal}\n\t" + }, + { + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "Text", + "data": "{animal}" + } + ] + }, + { + "start": 42, + "end": 52, + "type": "Text", + "data": "\n{:else}\n\t" + }, + { + "start": 52, + "end": 69, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 55, + "end": 65, + "type": "Text", + "data": "no animals" + } + ] + }, + { + "start": 69, + "end": 77, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-else/input-v2.html b/test/parser/samples/each-block-else/input-v2.html new file mode 100644 index 0000000000..dc96d8b946 --- /dev/null +++ b/test/parser/samples/each-block-else/input-v2.html @@ -0,0 +1,5 @@ +{#each animals as animal} +{animal}
+{:else} +no animals
+{/each} diff --git a/test/parser/samples/each-block-else/output-v2.json b/test/parser/samples/each-block-else/output-v2.json new file mode 100644 index 0000000000..0dadad5f65 --- /dev/null +++ b/test/parser/samples/each-block-else/output-v2.json @@ -0,0 +1,68 @@ +{ + "hash": 3238289871, + "html": { + "start": 0, + "end": 84, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 84, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 29, + "end": 46, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 42, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 40, + "name": "animal" + } + } + ] + } + ], + "context": "animal", + "else": { + "start": 55, + "end": 75, + "type": "ElseBlock", + "children": [ + { + "start": 57, + "end": 74, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 60, + "end": 70, + "type": "Text", + "data": "no animals" + } + ] + } + ] + } + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/_actual-v2.json b/test/parser/samples/each-block-indexed/_actual-v2.json new file mode 100644 index 0000000000..576bc53014 --- /dev/null +++ b/test/parser/samples/each-block-indexed/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "1143n2g", + "html": { + "start": 0, + "end": 58, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 30, + "type": "Text", + "data": "{#each animals as animal, i}\n\t" + }, + { + "start": 30, + "end": 50, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 33, + "end": 46, + "type": "Text", + "data": "{i}: {animal}" + } + ] + }, + { + "start": 50, + "end": 58, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/input-v2.html b/test/parser/samples/each-block-indexed/input-v2.html new file mode 100644 index 0000000000..d5602ec82c --- /dev/null +++ b/test/parser/samples/each-block-indexed/input-v2.html @@ -0,0 +1,3 @@ +{#each animals as animal, i} +{i}: {animal}
+{/each} diff --git a/test/parser/samples/each-block-indexed/output-v2.json b/test/parser/samples/each-block-indexed/output-v2.json new file mode 100644 index 0000000000..fc8954d6ad --- /dev/null +++ b/test/parser/samples/each-block-indexed/output-v2.json @@ -0,0 +1,64 @@ +{ + "hash": 2841674990, + "html": { + "start": 0, + "end": 66, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 66, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 32, + "end": 56, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 35, + "end": 40, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 37, + "end": 38, + "name": "i" + } + }, + { + "start": 40, + "end": 42, + "type": "Text", + "data": ": " + }, + { + "start": 42, + "end": 52, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 44, + "end": 50, + "name": "animal" + } + } + ] + } + ], + "context": "animal", + "index": "i" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/_actual-v2.json b/test/parser/samples/each-block-keyed/_actual-v2.json new file mode 100644 index 0000000000..c039c98ce9 --- /dev/null +++ b/test/parser/samples/each-block-keyed/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "3sm0ec", + "html": { + "start": 0, + "end": 56, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 35, + "type": "Text", + "data": "{#each todos as todo key todo.id}\n\t" + }, + { + "start": 35, + "end": 48, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 38, + "end": 44, + "type": "Text", + "data": "{todo}" + } + ] + }, + { + "start": 48, + "end": 56, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/input-v2.html b/test/parser/samples/each-block-keyed/input-v2.html new file mode 100644 index 0000000000..3cc00ce93e --- /dev/null +++ b/test/parser/samples/each-block-keyed/input-v2.html @@ -0,0 +1,3 @@ +{#each todos as todo key todo.id} +{todo}
+{/each} diff --git a/test/parser/samples/each-block-keyed/output-v2.json b/test/parser/samples/each-block-keyed/output-v2.json new file mode 100644 index 0000000000..1a16afb82b --- /dev/null +++ b/test/parser/samples/each-block-keyed/output-v2.json @@ -0,0 +1,47 @@ +{ + "hash": 2025411181, + "html": { + "start": 0, + "end": 54, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 54, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 13, + "name": "todos" + }, + "children": [ + { + "start": 29, + "end": 44, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 40, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 38, + "name": "todo" + } + } + ] + } + ], + "context": "todo", + "key": "id" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block/_actual-v2.json b/test/parser/samples/each-block/_actual-v2.json new file mode 100644 index 0000000000..314ef918a5 --- /dev/null +++ b/test/parser/samples/each-block/_actual-v2.json @@ -0,0 +1,39 @@ +{ + "hash": "mzeq0s", + "html": { + "start": 0, + "end": 50, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 27, + "type": "Text", + "data": "{#each animals as animal}\n\t" + }, + { + "start": 27, + "end": 42, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 30, + "end": 38, + "type": "Text", + "data": "{animal}" + } + ] + }, + { + "start": 42, + "end": 50, + "type": "Text", + "data": "\n{/each}" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/each-block/input-v2.html b/test/parser/samples/each-block/input-v2.html new file mode 100644 index 0000000000..83a5e88ddd --- /dev/null +++ b/test/parser/samples/each-block/input-v2.html @@ -0,0 +1,3 @@ +{#each animals as animal} +{animal}
+{/each} diff --git a/test/parser/samples/each-block/output-v2.json b/test/parser/samples/each-block/output-v2.json new file mode 100644 index 0000000000..e549faca39 --- /dev/null +++ b/test/parser/samples/each-block/output-v2.json @@ -0,0 +1,46 @@ +{ + "hash": 220340986, + "html": { + "start": 0, + "end": 56, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 56, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 29, + "end": 46, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 42, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 34, + "end": 40, + "name": "animal" + } + } + ] + } + ], + "context": "animal" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/_actual-v2.json b/test/parser/samples/element-with-mustache/_actual-v2.json new file mode 100644 index 0000000000..a65459a200 --- /dev/null +++ b/test/parser/samples/element-with-mustache/_actual-v2.json @@ -0,0 +1,44 @@ +{ + "hash": "9fs56", + "html": { + "start": 0, + "end": 22, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 22, + "type": "Element", + "name": "h1", + "attributes": [], + "children": [ + { + "start": 4, + "end": 10, + "type": "Text", + "data": "hello " + }, + { + "start": 10, + "end": 16, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 11, + "end": 15, + "name": "name" + } + }, + { + "start": 16, + "end": 17, + "type": "Text", + "data": "!" + } + ] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/input-v2.html b/test/parser/samples/element-with-mustache/input-v2.html new file mode 100644 index 0000000000..1e9232da02 --- /dev/null +++ b/test/parser/samples/element-with-mustache/input-v2.html @@ -0,0 +1 @@ +