diff --git a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap index 37925af7..324a3fc3 100644 --- a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap @@ -45,6 +45,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -58,6 +59,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -107,6 +109,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -120,6 +123,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -169,6 +173,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 29, @@ -182,6 +187,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -249,6 +255,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 35, @@ -262,6 +269,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -329,6 +337,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 34, @@ -342,6 +351,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -409,6 +419,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 36, @@ -422,6 +433,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -489,6 +501,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 35, @@ -502,6 +515,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -552,6 +566,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -565,6 +580,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -615,6 +631,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 26, @@ -628,6 +645,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -678,6 +696,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -691,6 +710,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -741,6 +761,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -754,6 +775,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -803,6 +825,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 39, @@ -816,6 +839,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -890,6 +914,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 50, @@ -903,6 +928,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -953,6 +979,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 32, @@ -966,6 +993,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1016,6 +1044,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 29, @@ -1029,6 +1058,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1079,6 +1109,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -1092,6 +1123,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1218,6 +1250,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 45, @@ -1231,6 +1264,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1286,6 +1320,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 39, @@ -1299,6 +1334,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1354,6 +1390,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 34, @@ -1367,6 +1404,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1417,6 +1455,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 12, @@ -1430,6 +1469,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1480,6 +1520,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 13, @@ -1493,6 +1534,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1548,6 +1590,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -1561,6 +1604,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1635,6 +1679,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 30, @@ -1648,6 +1693,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1697,6 +1743,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 13, @@ -1710,6 +1757,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1759,6 +1807,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 14, @@ -1772,6 +1821,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1821,6 +1871,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 15, @@ -1834,6 +1885,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1883,6 +1935,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 22, @@ -1896,6 +1949,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -1945,6 +1999,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 16, @@ -1958,6 +2013,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2008,6 +2064,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 33, @@ -2021,6 +2078,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2071,6 +2129,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 29, @@ -2084,6 +2143,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2139,6 +2199,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 16, @@ -2152,6 +2213,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2207,6 +2269,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 15, @@ -2220,6 +2283,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2294,6 +2358,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 19, @@ -2307,6 +2372,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2381,6 +2447,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 20, @@ -2394,6 +2461,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2468,6 +2536,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 18, @@ -2481,6 +2550,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2572,6 +2642,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 23, @@ -2585,6 +2656,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2676,6 +2748,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 24, @@ -2689,6 +2762,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2780,6 +2854,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -2793,6 +2868,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2884,6 +2960,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 23, @@ -2897,6 +2974,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -2988,6 +3066,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 24, @@ -3001,6 +3080,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3092,6 +3172,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -3105,6 +3186,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3196,6 +3278,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 24, @@ -3209,6 +3292,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3300,6 +3384,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 22, @@ -3313,6 +3398,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3362,6 +3448,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 37, @@ -3375,6 +3462,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3400,6 +3488,7 @@ Object { "type": 3, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 16, @@ -3413,6 +3502,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3462,6 +3552,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -3475,6 +3566,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3524,6 +3616,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 26, @@ -3537,6 +3630,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3586,6 +3680,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 41, @@ -3599,6 +3694,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3648,6 +3744,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 26, @@ -3661,6 +3758,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3711,6 +3809,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -3724,6 +3823,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3774,6 +3874,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 31, @@ -3787,6 +3888,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3837,6 +3939,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -3850,6 +3953,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -3917,6 +4021,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -3930,6 +4035,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4021,6 +4127,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 39, @@ -4034,6 +4141,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4108,6 +4216,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 38, @@ -4121,6 +4230,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4195,6 +4305,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 37, @@ -4208,6 +4319,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4239,6 +4351,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -4252,6 +4365,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4302,6 +4416,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 26, @@ -4315,6 +4430,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4365,6 +4481,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -4378,6 +4495,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4428,6 +4546,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 26, @@ -4441,6 +4560,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4569,6 +4689,7 @@ class=\\"bar\\">", "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 30, @@ -4583,6 +4704,7 @@ class=\\"bar\\">", "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4709,6 +4831,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 53, @@ -4722,6 +4845,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4771,6 +4895,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 20, @@ -4784,6 +4909,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4833,6 +4959,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 32, @@ -4846,6 +4973,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4895,6 +5023,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 40, @@ -4908,6 +5037,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -4957,6 +5087,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 35, @@ -4970,6 +5101,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5020,6 +5152,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 31, @@ -5033,6 +5166,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5083,6 +5217,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 30, @@ -5096,6 +5231,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5146,6 +5282,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 29, @@ -5159,6 +5296,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5209,6 +5347,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 30, @@ -5222,6 +5361,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5313,6 +5453,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 41, @@ -5326,6 +5467,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5417,6 +5559,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 41, @@ -5430,6 +5573,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5521,6 +5665,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 41, @@ -5534,6 +5679,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5625,6 +5771,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 42, @@ -5638,6 +5785,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5729,6 +5877,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 42, @@ -5742,6 +5891,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5833,6 +5983,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 45, @@ -5846,6 +5997,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -5937,6 +6089,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 45, @@ -5950,6 +6103,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6041,6 +6195,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 42, @@ -6054,6 +6209,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6128,6 +6284,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 35, @@ -6141,6 +6298,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6232,6 +6390,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 42, @@ -6245,6 +6404,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6294,6 +6454,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 29, @@ -6307,6 +6468,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6399,6 +6561,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 37, @@ -6412,6 +6575,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6462,6 +6626,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 31, @@ -6475,6 +6640,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6525,6 +6691,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 30, @@ -6538,6 +6705,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6587,6 +6755,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 25, @@ -6600,6 +6769,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6631,6 +6801,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 34, @@ -6644,6 +6815,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6675,6 +6847,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -6688,6 +6861,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6738,6 +6912,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 34, @@ -6751,6 +6926,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6801,6 +6977,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 28, @@ -6814,6 +6991,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6869,6 +7047,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 16, @@ -6882,6 +7061,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6937,6 +7117,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 27, @@ -6950,6 +7131,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -6976,6 +7158,7 @@ Object { "type": 2, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 3, @@ -6989,6 +7172,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -7015,6 +7199,7 @@ Object { "type": 2, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 7, @@ -7028,6 +7213,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -7054,6 +7240,7 @@ Object { "type": 4, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 5, @@ -7067,6 +7254,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -7125,6 +7313,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 8, @@ -7141,6 +7330,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -7305,6 +7495,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 37, @@ -7319,6 +7510,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; @@ -7504,6 +7696,7 @@ Object { "type": 1, }, ], + "imports": Array [], "loc": Object { "end": Object { "column": 7, @@ -7520,6 +7713,7 @@ Object { "offset": 0, }, }, + "statements": Array [], "type": 0, } `; diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index 75d07527..897eaafa 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -65,6 +65,8 @@ export type ChildNode = export interface RootNode extends Node { type: NodeTypes.ROOT children: ChildNode[] + imports: string[] + statements: string[] } export interface ElementNode extends Node { diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index a495ddce..3b2d1f32 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -17,7 +17,7 @@ import { import { SourceMapGenerator, RawSourceMap } from 'source-map' import { advancePositionWithMutation, assert } from './utils' import { isString, isArray } from '@vue/shared' -import { RENDER_LIST_HELPER } from './transforms/vFor' +import { RENDER_LIST } from './runtimeConstants' type CodegenNode = ChildNode | JSChildNode @@ -43,8 +43,6 @@ export interface CodegenContext extends Required { column: number offset: number indentLevel: number - imports: Set - knownIdentifiers: Set map?: SourceMapGenerator push(code: string, node?: CodegenNode): void indent(): void @@ -70,8 +68,6 @@ function createCodegenContext( line: 1, offset: 0, indentLevel: 0, - imports: new Set(), - knownIdentifiers: new Set(), // lazy require source-map implementation, only in non-browser builds! map: __BROWSER__ @@ -123,16 +119,24 @@ export function generate( options: CodegenOptions = {} ): CodegenResult { const context = createCodegenContext(ast, options) - // TODO handle different output for module mode and IIFE mode const { mode, push, useWith, indent, deindent } = context + const imports = ast.imports.join(', ') if (mode === 'function') { - // TODO generate const declarations for helpers + // generate const declarations for helpers + if (imports) { + push(`const { ${imports} } = Vue\n\n`) + } push(`return `) } else { - // TODO generate import statements for helpers + // generate import statements for helpers + if (imports) { + push(`import { ${imports} } from 'vue'\n\n`) + } push(`export default `) } push(`function render() {`) + // generate asset resolution statements + ast.statements.forEach(s => push(s + `\n`)) if (useWith) { indent() push(`with (this) {`) @@ -317,7 +321,7 @@ function genIfBranch( function genFor(node: ForNode, context: CodegenContext) { const { push } = context const { source, keyAlias, valueAlias, objectIndexAlias, children } = node - push(`${RENDER_LIST_HELPER}(`, node) + push(`${RENDER_LIST}(`, node) genExpression(source, context) push(`, (`) if (valueAlias) { diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index e6f95be7..61df5cb9 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -82,6 +82,8 @@ export function parse(content: string, options: ParserOptions = {}): RootNode { return { type: NodeTypes.ROOT, children: parseChildren(context, TextModes.DATA, []), + imports: [], + statements: [], loc: getSelection(context, start) } } diff --git a/packages/compiler-core/src/runtimeConstants.ts b/packages/compiler-core/src/runtimeConstants.ts new file mode 100644 index 00000000..fa708c2d --- /dev/null +++ b/packages/compiler-core/src/runtimeConstants.ts @@ -0,0 +1,8 @@ +// Name mapping constants for runtime helpers that need to be imported in +// generated code. Make sure these are correctly exported in the runtime! +export const CREATE_ELEMENT = `h` +export const RESOLVE_COMPONENT = `resolveComponent` +export const RESOLVE_DIRECTIVE = `resolveDirective` +export const APPLY_DIRECTIVES = `applyDirectives` +export const RENDER_LIST = `renderList` +export const CAPITALIZE = `capitalize` diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 23eefd0d..3cf26ecd 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -43,6 +43,9 @@ export interface TransformOptions { } export interface TransformContext extends Required { + imports: Set + statements: string[] + identifiers: { [name: string]: true } parent: ParentNode ancestors: ParentNode[] childIndex: number @@ -52,16 +55,14 @@ export interface TransformContext extends Required { onNodeRemoved: () => void } -export function transform(root: RootNode, options: TransformOptions) { - const context = createTransformContext(root, options) - traverseChildren(root, context) -} - function createTransformContext( root: RootNode, options: TransformOptions ): TransformContext { const context: TransformContext = { + imports: new Set(), + statements: [], + identifiers: {}, nodeTransforms: options.nodeTransforms || [], directiveTransforms: options.directiveTransforms || {}, onError: options.onError || defaultOnError, @@ -103,11 +104,21 @@ function createTransformContext( return context } +export function transform(root: RootNode, options: TransformOptions) { + const context = createTransformContext(root, options) + traverseChildren(root, context) + root.imports = [...context.imports] + root.statements = context.statements +} + export function traverseChildren( parent: ParentNode, context: TransformContext ) { + // ancestors and identifiers need to be cached here since they may get + // replaced during a child's traversal const ancestors = context.ancestors.concat(parent) + const identifiers = context.identifiers let i = 0 const nodeRemoved = () => { i-- @@ -117,6 +128,7 @@ export function traverseChildren( context.ancestors = ancestors context.childIndex = i context.onNodeRemoved = nodeRemoved + context.identifiers = identifiers traverseNode((context.currentNode = parent.children[i]), context) } } diff --git a/packages/compiler-core/src/transforms/element.ts b/packages/compiler-core/src/transforms/element.ts index 42194252..3844f4e0 100644 --- a/packages/compiler-core/src/transforms/element.ts +++ b/packages/compiler-core/src/transforms/element.ts @@ -16,6 +16,14 @@ import { } from '../ast' import { isArray } from '@vue/shared' import { createCompilerError, ErrorCodes } from '../errors' +import { + CREATE_ELEMENT, + APPLY_DIRECTIVES, + RESOLVE_DIRECTIVE, + RESOLVE_COMPONENT +} from '../runtimeConstants' + +const toValidId = (str: string): string => str.replace(/[^\w]/g, '') // generate a JavaScript AST for this element's codegen export const prepareElementForCodegen: NodeTransform = (node, context) => { @@ -28,15 +36,20 @@ export const prepareElementForCodegen: NodeTransform = (node, context) => { const hasProps = node.props.length > 0 const hasChildren = node.children.length > 0 let runtimeDirectives: DirectiveNode[] | undefined + let componentIdentifier: string | undefined if (isComponent) { - // TODO inject import for `resolveComponent` - // TODO inject statement for resolving component + context.imports.add(RESOLVE_COMPONENT) + componentIdentifier = `_component_${toValidId(node.tag)}` + context.statements.push( + `const ${componentIdentifier} = ${RESOLVE_COMPONENT}(${JSON.stringify( + node.tag + )})` + ) } const args: CallExpression['arguments'] = [ - // TODO inject resolveComponent dep to root - isComponent ? node.tag : `"${node.tag}"` + isComponent ? componentIdentifier! : `"${node.tag}"` ] // props if (hasProps) { @@ -54,13 +67,13 @@ export const prepareElementForCodegen: NodeTransform = (node, context) => { } const { loc } = node - // TODO inject import for `h` - const vnode = createCallExpression(`h`, args, loc) + context.imports.add(CREATE_ELEMENT) + const vnode = createCallExpression(CREATE_ELEMENT, args, loc) if (runtimeDirectives && runtimeDirectives.length) { - // TODO inject import for `applyDirectives` + context.imports.add(APPLY_DIRECTIVES) node.codegenNode = createCallExpression( - `applyDirectives`, + APPLY_DIRECTIVES, [ vnode, createArrayExpression( @@ -174,9 +187,16 @@ function createDirectiveArgs( dir: DirectiveNode, context: TransformContext ): ArrayExpression { - // TODO inject import for `resolveDirective` - // TODO inject statement for resolving directive - const dirArgs: ArrayExpression['elements'] = [dir.name] + // inject import for `resolveDirective` + context.imports.add(RESOLVE_DIRECTIVE) + // inject statement for resolving directive + const dirIdentifier = `_directive_${toValidId(dir.name)}` + context.statements.push( + `const ${dirIdentifier} = _${RESOLVE_DIRECTIVE}(${JSON.stringify( + dir.name + )})` + ) + const dirArgs: ArrayExpression['elements'] = [dirIdentifier] const { loc } = dir if (dir.exp) dirArgs.push(dir.exp) if (dir.arg) dirArgs.push(dir.arg) diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 54dd3de0..8c293ea9 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -2,18 +2,17 @@ import { createStructuralDirectiveTransform } from '../transform' import { NodeTypes, ExpressionNode, createExpression } from '../ast' import { createCompilerError, ErrorCodes } from '../errors' import { getInnerRange } from '../utils' +import { RENDER_LIST } from '../runtimeConstants' const forAliasRE = /([\s\S]*?)(?:(?<=\))|\s+)(?:in|of)\s+([\s\S]*)/ const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/ const stripParensRE = /^\(|\)$/g -export const RENDER_LIST_HELPER = `renderList` - export const transformFor = createStructuralDirectiveTransform( 'for', (node, dir, context) => { if (dir.exp) { - // TODO inject helper import + context.imports.add(RENDER_LIST) const aliases = parseAliasExpressions(dir.exp.content) if (aliases) { diff --git a/packages/compiler-core/src/transforms/vOn.ts b/packages/compiler-core/src/transforms/vOn.ts index b7eae459..24e2eab8 100644 --- a/packages/compiler-core/src/transforms/vOn.ts +++ b/packages/compiler-core/src/transforms/vOn.ts @@ -1,6 +1,7 @@ import { DirectiveTransform } from '../transform' import { createObjectProperty, createExpression } from '../ast' import { capitalize } from '@vue/shared' +import { CAPITALIZE } from '../runtimeConstants' // v-on without arg is handled directly in ./element.ts due to it affecting // codegen for the entire props object. This transform here is only for v-on @@ -9,8 +10,7 @@ export const transformOn: DirectiveTransform = (dir, context) => { const arg = dir.arg! const eventName = arg.isStatic ? createExpression(`on${capitalize(arg.content)}`, true, arg.loc) - : // TODO inject capitalize helper - createExpression(`'on' + capitalize(${arg.content})`, false, arg.loc) + : createExpression(`'on' + ${CAPITALIZE}(${arg.content})`, false, arg.loc) // TODO .once modifier handling since it is platform agnostic // other modifiers are handled in compiler-dom return { diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 15c66f85..bb881f37 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -39,6 +39,7 @@ export { export { applyDirectives } from './directives' export { resolveComponent, resolveDirective } from './helpers/resolveAssets' export { renderList } from './helpers/renderList' +export { capitalize } from '@vue/shared' // Internal, for integration with runtime compiler export { registerRuntimeCompiler } from './component'