99 NodeTypes ,
1010 Position ,
1111 TextNode ,
12- AttributeNode ,
1312 InterpolationNode
1413} from '../src/ast'
1514
@@ -163,114 +162,6 @@ describe('compiler: parse', () => {
163162 }
164163 } )
165164 } )
166-
167- test ( 'HTML entities compatibility in text (https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state).' , ( ) => {
168- const spy = jest . fn ( )
169- const ast = baseParse ( '&ersand;' , {
170- namedCharacterReferences : { amp : '&' } ,
171- onError : spy
172- } )
173- const text = ast . children [ 0 ] as TextNode
174-
175- expect ( text ) . toStrictEqual ( {
176- type : NodeTypes . TEXT ,
177- content : '&ersand;' ,
178- loc : {
179- start : { offset : 0 , line : 1 , column : 1 } ,
180- end : { offset : 11 , line : 1 , column : 12 } ,
181- source : '&ersand;'
182- }
183- } )
184- expect ( spy . mock . calls ) . toMatchObject ( [
185- [
186- {
187- code : ErrorCodes . MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE ,
188- loc : {
189- start : { offset : 4 , line : 1 , column : 5 }
190- }
191- }
192- ]
193- ] )
194- } )
195-
196- test ( 'HTML entities compatibility in attribute (https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state).' , ( ) => {
197- const spy = jest . fn ( )
198- const ast = baseParse (
199- '<div a="&ersand;" b="&ersand;" c="&!"></div>' ,
200- {
201- namedCharacterReferences : { amp : '&' , 'amp;' : '&' } ,
202- onError : spy
203- }
204- )
205- const element = ast . children [ 0 ] as ElementNode
206- const text1 = ( element . props [ 0 ] as AttributeNode ) . value
207- const text2 = ( element . props [ 1 ] as AttributeNode ) . value
208- const text3 = ( element . props [ 2 ] as AttributeNode ) . value
209-
210- expect ( text1 ) . toStrictEqual ( {
211- type : NodeTypes . TEXT ,
212- content : '&ersand;' ,
213- loc : {
214- start : { offset : 7 , line : 1 , column : 8 } ,
215- end : { offset : 20 , line : 1 , column : 21 } ,
216- source : '"&ersand;"'
217- }
218- } )
219- expect ( text2 ) . toStrictEqual ( {
220- type : NodeTypes . TEXT ,
221- content : '&ersand;' ,
222- loc : {
223- start : { offset : 23 , line : 1 , column : 24 } ,
224- end : { offset : 37 , line : 1 , column : 38 } ,
225- source : '"&ersand;"'
226- }
227- } )
228- expect ( text3 ) . toStrictEqual ( {
229- type : NodeTypes . TEXT ,
230- content : '&!' ,
231- loc : {
232- start : { offset : 40 , line : 1 , column : 41 } ,
233- end : { offset : 47 , line : 1 , column : 48 } ,
234- source : '"&!"'
235- }
236- } )
237- expect ( spy . mock . calls ) . toMatchObject ( [
238- [
239- {
240- code : ErrorCodes . MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE ,
241- loc : {
242- start : { offset : 45 , line : 1 , column : 46 }
243- }
244- }
245- ]
246- ] )
247- } )
248-
249- test ( 'Some control character reference should be replaced.' , ( ) => {
250- const spy = jest . fn ( )
251- const ast = baseParse ( '†' , { onError : spy } )
252- const text = ast . children [ 0 ] as TextNode
253-
254- expect ( text ) . toStrictEqual ( {
255- type : NodeTypes . TEXT ,
256- content : '†' ,
257- loc : {
258- start : { offset : 0 , line : 1 , column : 1 } ,
259- end : { offset : 6 , line : 1 , column : 7 } ,
260- source : '†'
261- }
262- } )
263- expect ( spy . mock . calls ) . toMatchObject ( [
264- [
265- {
266- code : ErrorCodes . CONTROL_CHARACTER_REFERENCE ,
267- loc : {
268- start : { offset : 0 , line : 1 , column : 1 }
269- }
270- }
271- ]
272- ] )
273- } )
274165 } )
275166
276167 describe ( 'Interpolation' , ( ) => {
@@ -1652,12 +1543,10 @@ foo
16521543 expect ( baz . loc . end ) . toEqual ( { line : 2 , column : 28 , offset } )
16531544 } )
16541545
1655- describe ( 'namedCharacterReferences option' , ( ) => {
1546+ describe ( 'decodeEntities option' , ( ) => {
16561547 test ( 'use the given map' , ( ) => {
16571548 const ast : any = baseParse ( '&∪︀' , {
1658- namedCharacterReferences : {
1659- 'cups;' : '\u222A\uFE00' // UNION with serifs
1660- } ,
1549+ decodeEntities : text => text . replace ( '∪︀' , '\u222A\uFE00' ) ,
16611550 onError : ( ) => { } // Ignore errors
16621551 } )
16631552
@@ -1756,60 +1645,6 @@ foo
17561645 errors : [ ]
17571646 }
17581647 ] ,
1759- ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE : [
1760- {
1761- code : '<template>&#a;</template>' ,
1762- errors : [
1763- {
1764- type : ErrorCodes . ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE ,
1765- loc : { offset : 10 , line : 1 , column : 11 }
1766- }
1767- ]
1768- } ,
1769- {
1770- code : '<template>&#xg;</template>' ,
1771- errors : [
1772- {
1773- type : ErrorCodes . ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE ,
1774- loc : { offset : 10 , line : 1 , column : 11 }
1775- }
1776- ]
1777- } ,
1778- {
1779- code : '<template>c</template>' ,
1780- errors : [ ]
1781- } ,
1782- {
1783- code : '<template>ÿ</template>' ,
1784- errors : [ ]
1785- } ,
1786- {
1787- code : '<template attr="&#a;"></template>' ,
1788- errors : [
1789- {
1790- type : ErrorCodes . ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE ,
1791- loc : { offset : 16 , line : 1 , column : 17 }
1792- }
1793- ]
1794- } ,
1795- {
1796- code : '<template attr="&#xg;"></template>' ,
1797- errors : [
1798- {
1799- type : ErrorCodes . ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE ,
1800- loc : { offset : 16 , line : 1 , column : 17 }
1801- }
1802- ]
1803- } ,
1804- {
1805- code : '<template attr="c"></template>' ,
1806- errors : [ ]
1807- } ,
1808- {
1809- code : '<template attr="ÿ"></template>' ,
1810- errors : [ ]
1811- }
1812- ] ,
18131648 CDATA_IN_HTML_CONTENT : [
18141649 {
18151650 code : '<template><![CDATA[cdata]]></template>' ,
@@ -1825,37 +1660,6 @@ foo
18251660 errors : [ ]
18261661 }
18271662 ] ,
1828- CHARACTER_REFERENCE_OUTSIDE_UNICODE_RANGE : [
1829- {
1830- code : '<template>�</template>' ,
1831- errors : [
1832- {
1833- type : ErrorCodes . CHARACTER_REFERENCE_OUTSIDE_UNICODE_RANGE ,
1834- loc : { offset : 10 , line : 1 , column : 11 }
1835- }
1836- ]
1837- }
1838- ] ,
1839- CONTROL_CHARACTER_REFERENCE : [
1840- {
1841- code : '<template></template>' ,
1842- errors : [
1843- {
1844- type : ErrorCodes . CONTROL_CHARACTER_REFERENCE ,
1845- loc : { offset : 10 , line : 1 , column : 11 }
1846- }
1847- ]
1848- } ,
1849- {
1850- code : '<template></template>' ,
1851- errors : [
1852- {
1853- type : ErrorCodes . CONTROL_CHARACTER_REFERENCE ,
1854- loc : { offset : 10 , line : 1 , column : 11 }
1855- }
1856- ]
1857- }
1858- ] ,
18591663 DUPLICATE_ATTRIBUTE : [
18601664 {
18611665 code : '<template><div id="" id=""></div></template>' ,
@@ -2412,36 +2216,6 @@ foo
24122216 ]
24132217 }
24142218 ] ,
2415- MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE : [
2416- {
2417- code : '<template>&</template>' ,
2418- options : { namedCharacterReferences : { amp : '&' } } ,
2419- errors : [
2420- {
2421- type : ErrorCodes . MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE ,
2422- loc : { offset : 14 , line : 1 , column : 15 }
2423- }
2424- ]
2425- } ,
2426- {
2427- code : '<template>(</template>' ,
2428- errors : [
2429- {
2430- type : ErrorCodes . MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE ,
2431- loc : { offset : 14 , line : 1 , column : 15 }
2432- }
2433- ]
2434- } ,
2435- {
2436- code : '<template>@</template>' ,
2437- errors : [
2438- {
2439- type : ErrorCodes . MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE ,
2440- loc : { offset : 15 , line : 1 , column : 16 }
2441- }
2442- ]
2443- }
2444- ] ,
24452219 MISSING_WHITESPACE_BETWEEN_ATTRIBUTES : [
24462220 {
24472221 code : '<template><div id="foo"class="bar"></div></template>' ,
@@ -2500,48 +2274,6 @@ foo
25002274 ]
25012275 }
25022276 ] ,
2503- NONCHARACTER_CHARACTER_REFERENCE : [
2504- {
2505- code : '<template></template>' ,
2506- errors : [
2507- {
2508- type : ErrorCodes . NONCHARACTER_CHARACTER_REFERENCE ,
2509- loc : { offset : 10 , line : 1 , column : 11 }
2510- }
2511- ]
2512- } ,
2513- {
2514- code : '<template></template>' ,
2515- errors : [
2516- {
2517- type : ErrorCodes . NONCHARACTER_CHARACTER_REFERENCE ,
2518- loc : { offset : 10 , line : 1 , column : 11 }
2519- }
2520- ]
2521- }
2522- ] ,
2523- NULL_CHARACTER_REFERENCE : [
2524- {
2525- code : '<template>�</template>' ,
2526- errors : [
2527- {
2528- type : ErrorCodes . NULL_CHARACTER_REFERENCE ,
2529- loc : { offset : 10 , line : 1 , column : 11 }
2530- }
2531- ]
2532- }
2533- ] ,
2534- SURROGATE_CHARACTER_REFERENCE : [
2535- {
2536- code : '<template>�</template>' ,
2537- errors : [
2538- {
2539- type : ErrorCodes . SURROGATE_CHARACTER_REFERENCE ,
2540- loc : { offset : 10 , line : 1 , column : 11 }
2541- }
2542- ]
2543- }
2544- ] ,
25452277 UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME : [
25462278 {
25472279 code : "<template><div a\"bc=''></div></template>" ,
0 commit comments