From 81fd694dd7b4d8e264661fe7957f8b5ab6892658 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 19 Sep 2019 13:59:24 -0400 Subject: [PATCH] perf: avoid cloning in parser advanceBy --- .../__snapshots__/parse.spec.ts.snap | 7524 ----------------- packages/compiler-core/src/parse.ts | 10 +- packages/compiler-core/src/utils.ts | 22 +- 3 files changed, 16 insertions(+), 7540 deletions(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap index ebee2f72..29b2338f 100644 --- a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap @@ -1,7529 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`base parser Errors ABRUPT_CLOSING_OF_EMPTY_COMMENT 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "", - "loc": Object { - "end": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 3, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABRUPT_CLOSING_OF_EMPTY_COMMENT 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "", - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - "offset": 16, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 3, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABRUPT_CLOSING_OF_EMPTY_COMMENT 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "", - "loc": Object { - "end": Object { - "column": 18, - "line": 1, - "offset": 17, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 3, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - "offset": 28, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - "offset": 28, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [ - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - "offset": 22, - }, - "source": "attr=\\"c\\"", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "name": "attr", - "type": 5, - "value": Object { - "content": "c", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - "offset": 22, - }, - "source": "\\"c\\"", - "start": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - }, - "type": 2, - }, - }, - ], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 35, - "line": 1, - "offset": 34, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 35, - "line": 1, - "offset": 34, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [ - Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - "offset": 21, - }, - "source": "attr=\\"&#a;\\"", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "name": "attr", - "type": 5, - "value": Object { - "content": "&#a;", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - "offset": 21, - }, - "source": "\\"&#a;\\"", - "start": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - }, - "type": 2, - }, - }, - ], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - "offset": 33, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - "offset": 33, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [ - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - "offset": 23, - }, - "source": "attr=\\"ÿ\\"", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "name": "attr", - "type": 5, - "value": Object { - "content": "ÿ", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - "offset": 23, - }, - "source": "\\"ÿ\\"", - "start": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - }, - "type": 2, - }, - }, - ], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - "offset": 35, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - "offset": 35, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [ - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - "offset": 22, - }, - "source": "attr=\\"&#xg;\\"", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "name": "attr", - "type": 5, - "value": Object { - "content": "&#xg;", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - "offset": 22, - }, - "source": "\\"&#xg;\\"", - "start": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - }, - "type": 2, - }, - }, - ], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 35, - "line": 1, - "offset": 34, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 35, - "line": 1, - "offset": 34, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "c", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - "source": "c", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "&#a;", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - "offset": 14, - }, - "source": "&#a;", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - "offset": 25, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - "offset": 25, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "ÿ", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - "offset": 16, - }, - "source": "ÿ", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "&#xg;", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - "source": "&#xg;", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors CDATA_IN_HTML_CONTENT 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "[CDATA[cdata]]", - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 3, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - "offset": 38, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - "offset": 38, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors CDATA_IN_HTML_CONTENT 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "cdata", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - "offset": 29, - }, - "source": "cdata", - "start": Object { - "column": 25, - "line": 1, - "offset": 24, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - "offset": 38, - }, - "source": "cdata", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "ns": 1, - "tag": "svg", - "tagType": 0, - "type": 1, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 50, - "line": 1, - "offset": 49, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 50, - "line": 1, - "offset": 49, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors CHARACTER_REFERENCE_OUTSIDE_UNICODE_RANGE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "�", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - "offset": 20, - }, - "source": "�", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 32, - "line": 1, - "offset": 31, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 32, - "line": 1, - "offset": 31, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors CONTROL_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 18, - "line": 1, - "offset": 17, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - "offset": 28, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - "offset": 28, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors CONTROL_CHARACTER_REFERENCE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "content": "", - "isEmpty": false, - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - "offset": 16, - }, - "source": "", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "type": 2, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors DUPLICATE_ATTRIBUTE 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "attrs": Array [ - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - "offset": 20, - }, - "source": "id=\\"\\"", - "start": Object { - "column": 16, - "line": 1, - "offset": 15, - }, - }, - "name": "id", - "type": 5, - "value": Object { - "content": "", - "isEmpty": true, - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - "offset": 20, - }, - "source": "\\"\\"", - "start": Object { - "column": 19, - "line": 1, - "offset": 18, - }, - }, - "type": 2, - }, - }, - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "id=\\"\\"", - "start": Object { - "column": 22, - "line": 1, - "offset": 21, - }, - }, - "name": "id", - "type": 5, - "value": Object { - "content": "", - "isEmpty": true, - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - "offset": 26, - }, - "source": "\\"\\"", - "start": Object { - "column": 25, - "line": 1, - "offset": 24, - }, - }, - "type": 2, - }, - }, - ], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - "offset": 33, - }, - "source": "
", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "ns": 0, - "tag": "div", - "tagType": 0, - "type": 1, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 45, - "line": 1, - "offset": 44, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 45, - "line": 1, - "offset": 44, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors END_TAG_WITH_ATTRIBUTES 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "attrs": Array [], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - "offset": 27, - }, - "source": "
", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "ns": 0, - "tag": "div", - "tagType": 0, - "type": 1, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - "offset": 38, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - "offset": 38, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors END_TAG_WITH_TRAILING_SOLIDUS 1`] = ` -Object { - "children": Array [ - Object { - "attrs": Array [], - "children": Array [ - Object { - "attrs": Array [], - "children": Array [], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - "offset": 22, - }, - "source": "
", - "start": Object { - "column": 11, - "line": 1, - "offset": 10, - }, - }, - "ns": 0, - "tag": "div", - "tagType": 0, - "type": 1, - }, - ], - "directives": Array [], - "isSelfClosing": false, - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - "offset": 33, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "ns": 0, - "tag": "template", - "tagType": 3, - "type": 1, - }, - ], - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - "offset": 33, - }, - "source": "", - "start": Object { - "column": 1, - "line": 1, - "offset": 0, - }, - }, - "type": 0, -} -`; - -exports[`base parser Errors EOF_BEFORE_TAG_NAME