@vue-vine/eslint-parser 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2129 -2078
- package/dist/index.mjs +2130 -2079
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
@@ -24,20 +24,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
24
24
|
mod
|
25
25
|
));
|
26
26
|
|
27
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/
|
28
|
-
var
|
29
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/
|
27
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/head.js
|
28
|
+
var require_head = __commonJS({
|
29
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/head.js"(exports, module) {
|
30
30
|
"use strict";
|
31
|
-
function
|
32
|
-
|
33
|
-
while (fromRight ? index-- : ++index < length) {
|
34
|
-
if (predicate(array[index], index, array)) {
|
35
|
-
return index;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
return -1;
|
31
|
+
function head(array) {
|
32
|
+
return array && array.length ? array[0] : void 0;
|
39
33
|
}
|
40
|
-
module.exports =
|
34
|
+
module.exports = head;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/first.js
|
39
|
+
var require_first = __commonJS({
|
40
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/first.js"(exports, module) {
|
41
|
+
"use strict";
|
42
|
+
module.exports = require_head();
|
43
|
+
}
|
44
|
+
});
|
45
|
+
|
46
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/last.js
|
47
|
+
var require_last = __commonJS({
|
48
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/last.js"(exports, module) {
|
49
|
+
"use strict";
|
50
|
+
function last4(array) {
|
51
|
+
var length = array == null ? 0 : array.length;
|
52
|
+
return length ? array[length - 1] : void 0;
|
53
|
+
}
|
54
|
+
module.exports = last4;
|
41
55
|
}
|
42
56
|
});
|
43
57
|
|
@@ -2123,6 +2137,79 @@ var require_baseIteratee = __commonJS({
|
|
2123
2137
|
}
|
2124
2138
|
});
|
2125
2139
|
|
2140
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndexBy.js
|
2141
|
+
var require_baseSortedIndexBy = __commonJS({
|
2142
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndexBy.js"(exports, module) {
|
2143
|
+
"use strict";
|
2144
|
+
var isSymbol = require_isSymbol();
|
2145
|
+
var MAX_ARRAY_LENGTH = 4294967295;
|
2146
|
+
var MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
|
2147
|
+
var nativeFloor = Math.floor;
|
2148
|
+
var nativeMin = Math.min;
|
2149
|
+
function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
2150
|
+
var low = 0, high = array == null ? 0 : array.length;
|
2151
|
+
if (high === 0) {
|
2152
|
+
return 0;
|
2153
|
+
}
|
2154
|
+
value = iteratee(value);
|
2155
|
+
var valIsNaN = value !== value, valIsNull = value === null, valIsSymbol = isSymbol(value), valIsUndefined = value === void 0;
|
2156
|
+
while (low < high) {
|
2157
|
+
var mid = nativeFloor((low + high) / 2), computed = iteratee(array[mid]), othIsDefined = computed !== void 0, othIsNull = computed === null, othIsReflexive = computed === computed, othIsSymbol = isSymbol(computed);
|
2158
|
+
if (valIsNaN) {
|
2159
|
+
var setLow = retHighest || othIsReflexive;
|
2160
|
+
} else if (valIsUndefined) {
|
2161
|
+
setLow = othIsReflexive && (retHighest || othIsDefined);
|
2162
|
+
} else if (valIsNull) {
|
2163
|
+
setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
2164
|
+
} else if (valIsSymbol) {
|
2165
|
+
setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
2166
|
+
} else if (othIsNull || othIsSymbol) {
|
2167
|
+
setLow = false;
|
2168
|
+
} else {
|
2169
|
+
setLow = retHighest ? computed <= value : computed < value;
|
2170
|
+
}
|
2171
|
+
if (setLow) {
|
2172
|
+
low = mid + 1;
|
2173
|
+
} else {
|
2174
|
+
high = mid;
|
2175
|
+
}
|
2176
|
+
}
|
2177
|
+
return nativeMin(high, MAX_ARRAY_INDEX);
|
2178
|
+
}
|
2179
|
+
module.exports = baseSortedIndexBy;
|
2180
|
+
}
|
2181
|
+
});
|
2182
|
+
|
2183
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/sortedIndexBy.js
|
2184
|
+
var require_sortedIndexBy = __commonJS({
|
2185
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/sortedIndexBy.js"(exports, module) {
|
2186
|
+
"use strict";
|
2187
|
+
var baseIteratee = require_baseIteratee();
|
2188
|
+
var baseSortedIndexBy = require_baseSortedIndexBy();
|
2189
|
+
function sortedIndexBy2(array, value, iteratee) {
|
2190
|
+
return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2));
|
2191
|
+
}
|
2192
|
+
module.exports = sortedIndexBy2;
|
2193
|
+
}
|
2194
|
+
});
|
2195
|
+
|
2196
|
+
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFindIndex.js
|
2197
|
+
var require_baseFindIndex = __commonJS({
|
2198
|
+
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFindIndex.js"(exports, module) {
|
2199
|
+
"use strict";
|
2200
|
+
function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
2201
|
+
var length = array.length, index = fromIndex + (fromRight ? 1 : -1);
|
2202
|
+
while (fromRight ? index-- : ++index < length) {
|
2203
|
+
if (predicate(array[index], index, array)) {
|
2204
|
+
return index;
|
2205
|
+
}
|
2206
|
+
}
|
2207
|
+
return -1;
|
2208
|
+
}
|
2209
|
+
module.exports = baseFindIndex;
|
2210
|
+
}
|
2211
|
+
});
|
2212
|
+
|
2126
2213
|
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_trimmedEndIndex.js
|
2127
2214
|
var require_trimmedEndIndex = __commonJS({
|
2128
2215
|
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_trimmedEndIndex.js"(exports, module) {
|
@@ -2245,61 +2332,6 @@ var require_findLastIndex = __commonJS({
|
|
2245
2332
|
}
|
2246
2333
|
});
|
2247
2334
|
|
2248
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/last.js
|
2249
|
-
var require_last = __commonJS({
|
2250
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/last.js"(exports, module) {
|
2251
|
-
"use strict";
|
2252
|
-
function last4(array) {
|
2253
|
-
var length = array == null ? 0 : array.length;
|
2254
|
-
return length ? array[length - 1] : void 0;
|
2255
|
-
}
|
2256
|
-
module.exports = last4;
|
2257
|
-
}
|
2258
|
-
});
|
2259
|
-
|
2260
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndexBy.js
|
2261
|
-
var require_baseSortedIndexBy = __commonJS({
|
2262
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndexBy.js"(exports, module) {
|
2263
|
-
"use strict";
|
2264
|
-
var isSymbol = require_isSymbol();
|
2265
|
-
var MAX_ARRAY_LENGTH = 4294967295;
|
2266
|
-
var MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
|
2267
|
-
var nativeFloor = Math.floor;
|
2268
|
-
var nativeMin = Math.min;
|
2269
|
-
function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
2270
|
-
var low = 0, high = array == null ? 0 : array.length;
|
2271
|
-
if (high === 0) {
|
2272
|
-
return 0;
|
2273
|
-
}
|
2274
|
-
value = iteratee(value);
|
2275
|
-
var valIsNaN = value !== value, valIsNull = value === null, valIsSymbol = isSymbol(value), valIsUndefined = value === void 0;
|
2276
|
-
while (low < high) {
|
2277
|
-
var mid = nativeFloor((low + high) / 2), computed = iteratee(array[mid]), othIsDefined = computed !== void 0, othIsNull = computed === null, othIsReflexive = computed === computed, othIsSymbol = isSymbol(computed);
|
2278
|
-
if (valIsNaN) {
|
2279
|
-
var setLow = retHighest || othIsReflexive;
|
2280
|
-
} else if (valIsUndefined) {
|
2281
|
-
setLow = othIsReflexive && (retHighest || othIsDefined);
|
2282
|
-
} else if (valIsNull) {
|
2283
|
-
setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
2284
|
-
} else if (valIsSymbol) {
|
2285
|
-
setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
2286
|
-
} else if (othIsNull || othIsSymbol) {
|
2287
|
-
setLow = false;
|
2288
|
-
} else {
|
2289
|
-
setLow = retHighest ? computed <= value : computed < value;
|
2290
|
-
}
|
2291
|
-
if (setLow) {
|
2292
|
-
low = mid + 1;
|
2293
|
-
} else {
|
2294
|
-
high = mid;
|
2295
|
-
}
|
2296
|
-
}
|
2297
|
-
return nativeMin(high, MAX_ARRAY_INDEX);
|
2298
|
-
}
|
2299
|
-
module.exports = baseSortedIndexBy;
|
2300
|
-
}
|
2301
|
-
});
|
2302
|
-
|
2303
2335
|
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndex.js
|
2304
2336
|
var require_baseSortedIndex = __commonJS({
|
2305
2337
|
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSortedIndex.js"(exports, module) {
|
@@ -2340,38 +2372,6 @@ var require_sortedLastIndex = __commonJS({
|
|
2340
2372
|
}
|
2341
2373
|
});
|
2342
2374
|
|
2343
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/head.js
|
2344
|
-
var require_head = __commonJS({
|
2345
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/head.js"(exports, module) {
|
2346
|
-
"use strict";
|
2347
|
-
function head(array) {
|
2348
|
-
return array && array.length ? array[0] : void 0;
|
2349
|
-
}
|
2350
|
-
module.exports = head;
|
2351
|
-
}
|
2352
|
-
});
|
2353
|
-
|
2354
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/first.js
|
2355
|
-
var require_first = __commonJS({
|
2356
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/first.js"(exports, module) {
|
2357
|
-
"use strict";
|
2358
|
-
module.exports = require_head();
|
2359
|
-
}
|
2360
|
-
});
|
2361
|
-
|
2362
|
-
// ../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/sortedIndexBy.js
|
2363
|
-
var require_sortedIndexBy = __commonJS({
|
2364
|
-
"../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/sortedIndexBy.js"(exports, module) {
|
2365
|
-
"use strict";
|
2366
|
-
var baseIteratee = require_baseIteratee();
|
2367
|
-
var baseSortedIndexBy = require_baseSortedIndexBy();
|
2368
|
-
function sortedIndexBy2(array, value, iteratee) {
|
2369
|
-
return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2));
|
2370
|
-
}
|
2371
|
-
module.exports = sortedIndexBy2;
|
2372
|
-
}
|
2373
|
-
});
|
2374
|
-
|
2375
2375
|
// src/parse.ts
|
2376
2376
|
import { parseForESLint as tsParseForESLint } from "@typescript-eslint/parser";
|
2377
2377
|
|
@@ -3019,2158 +3019,2209 @@ function createVirtualVineFnPropsReference({
|
|
3019
3019
|
return virtualReference;
|
3020
3020
|
}
|
3021
3021
|
|
3022
|
-
// src/
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
|
3029
|
-
|
3030
|
-
"transition-group",
|
3031
|
-
"TransitionGroup",
|
3032
|
-
"keep-alive",
|
3033
|
-
"KeepAlive",
|
3034
|
-
"teleport",
|
3035
|
-
"Teleport",
|
3036
|
-
"suspense",
|
3037
|
-
"Suspense"
|
3038
|
-
]);
|
3039
|
-
var BUILTIN_DIRECTIVES = /* @__PURE__ */ new Set([
|
3040
|
-
"bind",
|
3041
|
-
"on",
|
3042
|
-
"text",
|
3043
|
-
"html",
|
3044
|
-
"show",
|
3045
|
-
"if",
|
3046
|
-
"else",
|
3047
|
-
"else-if",
|
3048
|
-
"for",
|
3049
|
-
"model",
|
3050
|
-
"slot",
|
3051
|
-
"pre",
|
3052
|
-
"cloak",
|
3053
|
-
"once",
|
3054
|
-
"memo",
|
3055
|
-
"is"
|
3056
|
-
]);
|
3057
|
-
var HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
3058
|
-
var SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
3059
|
-
var NATIVE_TAGS = /* @__PURE__ */ new Set([...HTML_TAGS.split(","), ...SVG_TAGS.split(",")]);
|
3060
|
-
function isUnique(reference, index, references) {
|
3061
|
-
return index === 0 || reference.identifier !== references[index - 1].identifier;
|
3062
|
-
}
|
3063
|
-
function camelize(str) {
|
3064
|
-
return str.replace(/-(\w)/gu, (_, c) => c ? c.toUpperCase() : "");
|
3065
|
-
}
|
3066
|
-
function capitalize(str) {
|
3067
|
-
return str[0].toUpperCase() + str.slice(1);
|
3068
|
-
}
|
3069
|
-
function hasDefinition(variable) {
|
3070
|
-
return variable.defs.length >= 1;
|
3022
|
+
// src/common/debug.ts
|
3023
|
+
import debugFactory from "debug";
|
3024
|
+
var debug = debugFactory("vue-vine-eslint-parser");
|
3025
|
+
|
3026
|
+
// src/common/error-utils.ts
|
3027
|
+
function insertError(templateMeta, error) {
|
3028
|
+
const index = templateMeta.errors.findIndex((e) => e.index === error.index);
|
3029
|
+
templateMeta.errors.splice(index, 0, error);
|
3071
3030
|
}
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
|
3077
|
-
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3031
|
+
|
3032
|
+
// src/common/token-utils.ts
|
3033
|
+
function createSimpleToken(type, start, end, value, linesAndColumns) {
|
3034
|
+
return {
|
3035
|
+
type,
|
3036
|
+
range: [start, end],
|
3037
|
+
loc: {
|
3038
|
+
start: linesAndColumns.getLocFromIndex(start),
|
3039
|
+
end: linesAndColumns.getLocFromIndex(end)
|
3040
|
+
},
|
3041
|
+
value
|
3082
3042
|
};
|
3083
|
-
Object.defineProperty(ret, "variable", { enumerable: false });
|
3084
|
-
return ret;
|
3085
3043
|
}
|
3086
|
-
function
|
3087
|
-
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3091
|
-
|
3092
|
-
Object.defineProperty(ret, "references", { enumerable: false });
|
3093
|
-
return ret;
|
3044
|
+
function insertComments(templateMeta, newComments) {
|
3045
|
+
if (newComments.length === 0) {
|
3046
|
+
return;
|
3047
|
+
}
|
3048
|
+
const index = templateMeta.comments.findIndex((comment) => comment.range[0] === newComments[0].range[0]);
|
3049
|
+
templateMeta.comments.splice(index, 0, ...newComments);
|
3094
3050
|
}
|
3095
|
-
function
|
3096
|
-
const
|
3097
|
-
|
3051
|
+
function replaceTokens(templateMeta, node, newTokens) {
|
3052
|
+
const index = templateMeta.tokens.findIndex((token) => token.range[0] === node.range[0]);
|
3053
|
+
const count = templateMeta.tokens.findIndex((token) => token.range[1] === node.range[1]) - index + 1;
|
3054
|
+
templateMeta.tokens.splice(index, count, ...newTokens);
|
3098
3055
|
}
|
3099
|
-
|
3100
|
-
|
3101
|
-
|
3102
|
-
|
3103
|
-
|
3104
|
-
|
3105
|
-
|
3106
|
-
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3056
|
+
|
3057
|
+
// src/script/index.ts
|
3058
|
+
var import_first = __toESM(require_first());
|
3059
|
+
var import_last = __toESM(require_last());
|
3060
|
+
var import_sortedIndexBy = __toESM(require_sortedIndexBy());
|
3061
|
+
|
3062
|
+
// src/common/fix-locations.ts
|
3063
|
+
function fixLocations(result, locationCalculator) {
|
3064
|
+
fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
|
3065
|
+
for (const token of result.ast.tokens || []) {
|
3066
|
+
fixLocation(token, locationCalculator);
|
3067
|
+
}
|
3068
|
+
for (const comment of result.ast.comments || []) {
|
3069
|
+
fixLocation(comment, locationCalculator);
|
3070
|
+
}
|
3071
|
+
}
|
3072
|
+
function fixNodeLocations(rootNode, visitorKeys, locationCalculator) {
|
3073
|
+
const traversed = /* @__PURE__ */ new Map();
|
3074
|
+
traverseNodes(rootNode, {
|
3075
|
+
visitorKeys,
|
3076
|
+
enterNode(node, parent) {
|
3077
|
+
if (!traversed.has(node)) {
|
3078
|
+
traversed.set(node, node);
|
3079
|
+
node.parent = parent;
|
3080
|
+
if (traversed.has(node.range)) {
|
3081
|
+
if (!traversed.has(node.loc)) {
|
3082
|
+
node.loc.start = locationCalculator.getLocFromIndex(
|
3083
|
+
node.range[0]
|
3084
|
+
);
|
3085
|
+
node.loc.end = locationCalculator.getLocFromIndex(
|
3086
|
+
node.range[1]
|
3087
|
+
);
|
3088
|
+
traversed.set(node.loc, node);
|
3089
|
+
} else if (node.start != null || node.end != null) {
|
3090
|
+
const traversedNode = traversed.get(node.range);
|
3091
|
+
if (traversedNode.type === node.type) {
|
3092
|
+
node.start = traversedNode.start;
|
3093
|
+
node.end = traversedNode.end;
|
3094
|
+
}
|
3095
|
+
}
|
3096
|
+
} else {
|
3097
|
+
fixLocation(node, locationCalculator);
|
3098
|
+
traversed.set(node.range, node);
|
3099
|
+
traversed.set(node.loc, node);
|
3100
|
+
}
|
3101
|
+
}
|
3102
|
+
},
|
3103
|
+
leaveNode() {
|
3104
|
+
}
|
3110
3105
|
});
|
3111
|
-
return result;
|
3112
3106
|
}
|
3113
|
-
function
|
3114
|
-
const
|
3115
|
-
|
3107
|
+
function fixLocation(node, locationCalculator) {
|
3108
|
+
const range = node.range;
|
3109
|
+
const loc = node.loc;
|
3110
|
+
const d0 = locationCalculator.getFixOffset(range[0], "start");
|
3111
|
+
const d1 = locationCalculator.getFixOffset(range[1], "end");
|
3112
|
+
if (d0 !== 0) {
|
3113
|
+
range[0] += d0;
|
3114
|
+
if (node.start != null) {
|
3115
|
+
node.start += d0;
|
3116
|
+
}
|
3117
|
+
loc.start = locationCalculator.getLocFromIndex(range[0]);
|
3118
|
+
}
|
3119
|
+
if (d1 !== 0) {
|
3120
|
+
range[1] += d1;
|
3121
|
+
if (node.end != null) {
|
3122
|
+
node.end += d0;
|
3123
|
+
}
|
3124
|
+
loc.end = locationCalculator.getLocFromIndex(range[1]);
|
3125
|
+
}
|
3126
|
+
return node;
|
3116
3127
|
}
|
3117
|
-
function
|
3118
|
-
const
|
3119
|
-
|
3128
|
+
function fixErrorLocation(error, locationCalculator) {
|
3129
|
+
const diff = locationCalculator.getFixOffset(error.index, "start");
|
3130
|
+
error.index += diff;
|
3131
|
+
const loc = locationCalculator.getLocFromIndex(error.index);
|
3132
|
+
error.lineNumber = loc.line;
|
3133
|
+
error.column = loc.column;
|
3120
3134
|
}
|
3121
|
-
|
3122
|
-
|
3135
|
+
|
3136
|
+
// src/common/parser-object.ts
|
3137
|
+
function isParserObject(value) {
|
3138
|
+
return isEnhancedParserObject(value) || isBasicParserObject(value);
|
3139
|
+
}
|
3140
|
+
function isEnhancedParserObject(value) {
|
3141
|
+
return Boolean(value && typeof value.parseForESLint === "function");
|
3142
|
+
}
|
3143
|
+
function isBasicParserObject(value) {
|
3144
|
+
return Boolean(value && typeof value.parse === "function");
|
3145
|
+
}
|
3146
|
+
|
3147
|
+
// src/script/index.ts
|
3148
|
+
var ALIAS_ITERATOR = /^([\s\S]*?(?:\s|\)))(\bin\b|\bof\b)([\s\S]*)$/u;
|
3149
|
+
var PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u;
|
3150
|
+
var DUMMY_PARENT = {};
|
3151
|
+
var IS_FUNCTION_EXPRESSION = /^\s*(?:[\w$]+|\([^)]*\))\s*=>|^function\s*\(/u;
|
3152
|
+
var IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*'\]|\["[^"]*"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u;
|
3153
|
+
function processVForAliasAndIterator(code) {
|
3154
|
+
const match = ALIAS_ITERATOR.exec(code);
|
3155
|
+
if (match != null) {
|
3156
|
+
const aliases = match[1];
|
3157
|
+
const parenMatch = PARENS.exec(aliases);
|
3158
|
+
return {
|
3159
|
+
aliases,
|
3160
|
+
hasParens: Boolean(parenMatch),
|
3161
|
+
aliasesWithBrackets: parenMatch ? `${parenMatch[1].slice(0, -1)}[${parenMatch[2]}]${parenMatch[3].slice(1)}` : `[${aliases.slice(0, -1)}]`,
|
3162
|
+
delimiter: match[2] || "",
|
3163
|
+
iterator: match[3]
|
3164
|
+
};
|
3165
|
+
}
|
3123
3166
|
return {
|
3124
|
-
|
3125
|
-
|
3167
|
+
aliases: "",
|
3168
|
+
hasParens: false,
|
3169
|
+
aliasesWithBrackets: "",
|
3170
|
+
delimiter: "",
|
3171
|
+
iterator: code
|
3126
3172
|
};
|
3127
3173
|
}
|
3128
|
-
function
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
}
|
3134
|
-
for (const variable of globalScope.variables) {
|
3135
|
-
scriptVariables.set(variable.name, variable);
|
3136
|
-
}
|
3137
|
-
const moduleScope = globalScope.childScopes.find(
|
3138
|
-
(scope) => scope.type === "module"
|
3174
|
+
function getCommaTokenBeforeNode(tokens, node) {
|
3175
|
+
let tokenIndex = (0, import_sortedIndexBy.default)(
|
3176
|
+
tokens,
|
3177
|
+
{ range: node.range },
|
3178
|
+
(t) => t.range[0]
|
3139
3179
|
);
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
let foundVCFScope;
|
3145
|
-
if (templateRoot.parent) {
|
3146
|
-
do {
|
3147
|
-
foundVCF = foundVCF.parent;
|
3148
|
-
} while (foundVCF && foundVCF.type !== "FunctionDeclaration" && foundVCF.type !== "FunctionExpression" && foundVCF.type !== "ArrowFunctionExpression");
|
3149
|
-
if (foundVCF) {
|
3150
|
-
Object.assign(
|
3151
|
-
foundVCF,
|
3152
|
-
{ __isVine__: true }
|
3153
|
-
);
|
3154
|
-
const tryGetVCFScope = tsFileScopeManager.nodeToScope.get(foundVCF);
|
3155
|
-
if (tryGetVCFScope?.[0]) {
|
3156
|
-
foundVCFScope = tryGetVCFScope[0];
|
3157
|
-
for (const variable of foundVCFScope.variables) {
|
3158
|
-
scriptVariables.set(variable.name, variable);
|
3159
|
-
}
|
3160
|
-
const compFnPropsIdentifier = foundVCF.params?.[0]?.type === "Identifier" && foundVCF.params[0]?.name === "props" ? foundVCF.params[0] : null;
|
3161
|
-
const propsVar = scriptVariables.get("props");
|
3162
|
-
if (compFnPropsIdentifier && propsVar) {
|
3163
|
-
;
|
3164
|
-
propsVar.eslintUsed = true;
|
3165
|
-
propsVar.references.push(
|
3166
|
-
createVirtualVineFnPropsReference({
|
3167
|
-
foundVCFScope,
|
3168
|
-
compFnPropsIdentifier
|
3169
|
-
})
|
3170
|
-
);
|
3171
|
-
}
|
3172
|
-
}
|
3180
|
+
while (tokenIndex >= 0) {
|
3181
|
+
const token = tokens[tokenIndex];
|
3182
|
+
if (token.type === "Punctuator" && token.value === ",") {
|
3183
|
+
return token;
|
3173
3184
|
}
|
3185
|
+
tokenIndex -= 1;
|
3174
3186
|
}
|
3175
|
-
return
|
3187
|
+
return null;
|
3176
3188
|
}
|
3177
|
-
function
|
3178
|
-
const
|
3179
|
-
const
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
name = nameOrRef.id.name;
|
3205
|
-
isValueReference = nameOrRef.isValueReference;
|
3206
|
-
isTypeReference = nameOrRef.isTypeReference;
|
3207
|
-
}
|
3208
|
-
const variable = scriptVariables.get(name);
|
3209
|
-
if (!variable || variable.identifiers.length === 0) {
|
3210
|
-
return;
|
3211
|
-
}
|
3212
|
-
if (markedVariables.has(name)) {
|
3213
|
-
return;
|
3189
|
+
function throwEmptyError(locationCalculator, expected) {
|
3190
|
+
const loc = locationCalculator.getLocation(0);
|
3191
|
+
const err = new ParseError(
|
3192
|
+
`Expected to be ${expected}, but got empty.`,
|
3193
|
+
void 0,
|
3194
|
+
0,
|
3195
|
+
loc.line,
|
3196
|
+
loc.column
|
3197
|
+
);
|
3198
|
+
fixErrorLocation(err, locationCalculator);
|
3199
|
+
throw err;
|
3200
|
+
}
|
3201
|
+
function throwUnexpectedTokenError(name, token) {
|
3202
|
+
const err = new ParseError(
|
3203
|
+
`Unexpected token '${name}'.`,
|
3204
|
+
void 0,
|
3205
|
+
token.range[0],
|
3206
|
+
token.loc.start.line,
|
3207
|
+
token.loc.start.column
|
3208
|
+
);
|
3209
|
+
throw err;
|
3210
|
+
}
|
3211
|
+
function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
|
3212
|
+
if (ParseError.isParseError(err)) {
|
3213
|
+
const endOffset = locationCalculator.getOffsetWithGap(code.length);
|
3214
|
+
if (err.index >= endOffset) {
|
3215
|
+
err.message = "Unexpected end of expression.";
|
3214
3216
|
}
|
3215
|
-
|
3216
|
-
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3223
|
-
isValueReference ? 1 /* Value */ : isTypeReference ? 2 /* Type */ : void 0
|
3217
|
+
}
|
3218
|
+
throw err;
|
3219
|
+
}
|
3220
|
+
function parseScriptFragment(code, locationCalculator, parserOptions) {
|
3221
|
+
try {
|
3222
|
+
const result = parseScript(
|
3223
|
+
code,
|
3224
|
+
parserOptions
|
3224
3225
|
);
|
3225
|
-
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
reference.resolved = variable;
|
3233
|
-
if (reference.isTypeReference) {
|
3234
|
-
;
|
3235
|
-
variable.eslintUsed = true;
|
3226
|
+
fixLocations(result, locationCalculator);
|
3227
|
+
return result;
|
3228
|
+
} catch (err) {
|
3229
|
+
const perr = ParseError.normalize(err);
|
3230
|
+
if (perr) {
|
3231
|
+
fixErrorLocation(perr, locationCalculator);
|
3232
|
+
throw perr;
|
3236
3233
|
}
|
3234
|
+
throw err;
|
3237
3235
|
}
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3236
|
+
}
|
3237
|
+
var validDivisionCharRE = /[\w).+\-$\]]/u;
|
3238
|
+
function splitFilters(exp) {
|
3239
|
+
const result = [];
|
3240
|
+
let inSingle = false;
|
3241
|
+
let inDouble = false;
|
3242
|
+
let inTemplateString = false;
|
3243
|
+
let inRegex = false;
|
3244
|
+
let curly = 0;
|
3245
|
+
let square = 0;
|
3246
|
+
let paren = 0;
|
3247
|
+
let lastFilterIndex = 0;
|
3248
|
+
let c = 0;
|
3249
|
+
let prev = 0;
|
3250
|
+
for (let i = 0; i < exp.length; i++) {
|
3251
|
+
prev = c;
|
3252
|
+
c = exp.charCodeAt(i);
|
3253
|
+
if (inSingle) {
|
3254
|
+
if (c === 39 && prev !== 92) {
|
3255
|
+
inSingle = false;
|
3256
|
+
}
|
3257
|
+
} else if (inDouble) {
|
3258
|
+
if (c === 34 && prev !== 92) {
|
3259
|
+
inDouble = false;
|
3260
|
+
}
|
3261
|
+
} else if (inTemplateString) {
|
3262
|
+
if (c === 96 && prev !== 92) {
|
3263
|
+
inTemplateString = false;
|
3264
|
+
}
|
3265
|
+
} else if (inRegex) {
|
3266
|
+
if (c === 47 && prev !== 92) {
|
3267
|
+
inRegex = false;
|
3268
|
+
}
|
3269
|
+
} else if (c === 124 && exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
3270
|
+
result.push(exp.slice(lastFilterIndex, i));
|
3271
|
+
lastFilterIndex = i + 1;
|
3272
|
+
} else {
|
3273
|
+
switch (c) {
|
3274
|
+
case 34:
|
3275
|
+
inDouble = true;
|
3276
|
+
break;
|
3277
|
+
case 39:
|
3278
|
+
inSingle = true;
|
3279
|
+
break;
|
3280
|
+
case 96:
|
3281
|
+
inTemplateString = true;
|
3282
|
+
break;
|
3283
|
+
case 40:
|
3284
|
+
paren++;
|
3285
|
+
break;
|
3286
|
+
case 41:
|
3287
|
+
paren--;
|
3288
|
+
break;
|
3289
|
+
case 91:
|
3290
|
+
square++;
|
3291
|
+
break;
|
3292
|
+
case 93:
|
3293
|
+
square--;
|
3294
|
+
break;
|
3295
|
+
case 123:
|
3296
|
+
curly++;
|
3297
|
+
break;
|
3298
|
+
case 125:
|
3299
|
+
curly--;
|
3300
|
+
break;
|
3301
|
+
}
|
3302
|
+
if (c === 47) {
|
3303
|
+
let j = i - 1;
|
3304
|
+
let p;
|
3305
|
+
for (; j >= 0; j--) {
|
3306
|
+
p = exp.charAt(j);
|
3307
|
+
if (p !== " ") {
|
3308
|
+
break;
|
3309
|
+
}
|
3310
|
+
}
|
3311
|
+
if (!p || !validDivisionCharRE.test(p)) {
|
3312
|
+
inRegex = true;
|
3313
|
+
}
|
3314
|
+
}
|
3243
3315
|
}
|
3244
3316
|
}
|
3245
|
-
|
3246
|
-
|
3247
|
-
|
3317
|
+
result.push(exp.slice(lastFilterIndex));
|
3318
|
+
return result;
|
3319
|
+
}
|
3320
|
+
function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
|
3321
|
+
debug('[script] parse expression: "0(%s)"', code);
|
3322
|
+
try {
|
3323
|
+
const result = parseScriptFragment(
|
3324
|
+
`0(${code})`,
|
3325
|
+
locationCalculator.getSubCalculatorShift(-2),
|
3326
|
+
parserOptions
|
3327
|
+
);
|
3328
|
+
const { ast } = result;
|
3329
|
+
const tokens = ast.tokens || [];
|
3330
|
+
const comments = ast.comments || [];
|
3331
|
+
const references = analyzeExternalReferences(result, parserOptions);
|
3332
|
+
const statement = ast.body[0];
|
3333
|
+
const callExpression = statement.expression;
|
3334
|
+
const expression = callExpression.arguments[0];
|
3335
|
+
if (!allowEmpty && !expression) {
|
3336
|
+
return throwEmptyError(locationCalculator, "an expression");
|
3248
3337
|
}
|
3249
|
-
if (
|
3250
|
-
|
3251
|
-
if (dotIndex > 0) {
|
3252
|
-
markSetupReferenceVariableAsUsed(
|
3253
|
-
node.rawName.slice(0, dotIndex)
|
3254
|
-
);
|
3255
|
-
}
|
3338
|
+
if (expression && expression.type === "SpreadElement") {
|
3339
|
+
return throwUnexpectedTokenError("...", expression);
|
3256
3340
|
}
|
3257
|
-
|
3258
|
-
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`);
|
3264
|
-
} else if (node.key.name === "ref" && node.value) {
|
3265
|
-
markVariableAsUsed(node.value.value);
|
3341
|
+
if (callExpression.arguments[1]) {
|
3342
|
+
const node = callExpression.arguments[1];
|
3343
|
+
return throwUnexpectedTokenError(
|
3344
|
+
",",
|
3345
|
+
getCommaTokenBeforeNode(tokens, node) || node
|
3346
|
+
);
|
3266
3347
|
}
|
3348
|
+
tokens.shift();
|
3349
|
+
tokens.shift();
|
3350
|
+
tokens.pop();
|
3351
|
+
return { expression, tokens, comments, references, variables: [] };
|
3352
|
+
} catch (err) {
|
3353
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3267
3354
|
}
|
3268
|
-
traverseNodes(templateRoot, {
|
3269
|
-
enterNode(node) {
|
3270
|
-
if (node.type === "VExpressionContainer") {
|
3271
|
-
processVExpressionContainer(node);
|
3272
|
-
} else if (node.type === "VElement") {
|
3273
|
-
processVElement(node);
|
3274
|
-
} else if (node.type === "VAttribute") {
|
3275
|
-
processVAttribute(node);
|
3276
|
-
}
|
3277
|
-
},
|
3278
|
-
leaveNode() {
|
3279
|
-
}
|
3280
|
-
});
|
3281
3355
|
}
|
3282
|
-
|
3283
|
-
|
3284
|
-
|
3285
|
-
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
// src/common/location-calculator.ts
|
3293
|
-
var import_sortedLastIndex2 = __toESM(require_sortedLastIndex());
|
3294
|
-
|
3295
|
-
// src/common/lines-and-columns.ts
|
3296
|
-
var import_sortedLastIndex = __toESM(require_sortedLastIndex());
|
3297
|
-
var LinesAndColumns = class {
|
3298
|
-
ltOffsets;
|
3299
|
-
/**
|
3300
|
-
* Initialize.
|
3301
|
-
* @param ltOffsets The list of the offset of line terminators.
|
3302
|
-
*/
|
3303
|
-
constructor(ltOffsets) {
|
3304
|
-
this.ltOffsets = ltOffsets;
|
3305
|
-
}
|
3306
|
-
/**
|
3307
|
-
* Calculate the location of the given index.
|
3308
|
-
* @param index The index to calculate their location.
|
3309
|
-
* @returns The location of the index.
|
3310
|
-
*/
|
3311
|
-
getLocFromIndex(index) {
|
3312
|
-
const line = (0, import_sortedLastIndex.default)(this.ltOffsets, index) + 1;
|
3313
|
-
const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]);
|
3314
|
-
return { line, column };
|
3315
|
-
}
|
3316
|
-
createOffsetLocationCalculator(offset) {
|
3317
|
-
return {
|
3318
|
-
getFixOffset() {
|
3319
|
-
return offset;
|
3320
|
-
},
|
3321
|
-
getLocFromIndex: this.getLocFromIndex.bind(this)
|
3356
|
+
function parseFilter(code, locationCalculator, parserOptions) {
|
3357
|
+
debug('[script] parse filter: "%s"', code);
|
3358
|
+
try {
|
3359
|
+
const expression = {
|
3360
|
+
type: "VFilter",
|
3361
|
+
parent: null,
|
3362
|
+
range: [0, 0],
|
3363
|
+
loc: {},
|
3364
|
+
callee: null,
|
3365
|
+
arguments: []
|
3322
3366
|
};
|
3367
|
+
const tokens = [];
|
3368
|
+
const comments = [];
|
3369
|
+
const references = [];
|
3370
|
+
const paren = code.indexOf("(");
|
3371
|
+
const calleeCode = paren === -1 ? code : code.slice(0, paren);
|
3372
|
+
const argsCode = paren === -1 ? null : code.slice(paren);
|
3373
|
+
if (calleeCode.trim()) {
|
3374
|
+
const spaces = /^\s*/u.exec(calleeCode)[0];
|
3375
|
+
const subCalculator = locationCalculator.getSubCalculatorShift(
|
3376
|
+
spaces.length
|
3377
|
+
);
|
3378
|
+
const { ast } = parseScriptFragment(
|
3379
|
+
`"${calleeCode.trim()}"`,
|
3380
|
+
subCalculator,
|
3381
|
+
parserOptions
|
3382
|
+
);
|
3383
|
+
const statement = ast.body[0];
|
3384
|
+
const callee = statement.expression;
|
3385
|
+
if (callee.type !== "Literal") {
|
3386
|
+
const { loc, range } = ast.tokens[0];
|
3387
|
+
return throwUnexpectedTokenError('"', {
|
3388
|
+
range: [range[1] - 1, range[1]],
|
3389
|
+
loc: {
|
3390
|
+
start: {
|
3391
|
+
line: loc.end.line,
|
3392
|
+
column: loc.end.column - 1
|
3393
|
+
},
|
3394
|
+
end: loc.end
|
3395
|
+
}
|
3396
|
+
});
|
3397
|
+
}
|
3398
|
+
expression.callee = {
|
3399
|
+
type: "Identifier",
|
3400
|
+
parent: expression,
|
3401
|
+
range: [
|
3402
|
+
callee.range[0],
|
3403
|
+
subCalculator.getOffsetWithGap(calleeCode.trim().length)
|
3404
|
+
],
|
3405
|
+
loc: {
|
3406
|
+
start: callee.loc.start,
|
3407
|
+
end: subCalculator.getLocation(calleeCode.trim().length)
|
3408
|
+
},
|
3409
|
+
name: String(callee.value)
|
3410
|
+
};
|
3411
|
+
tokens.push({
|
3412
|
+
type: "Identifier",
|
3413
|
+
value: calleeCode.trim(),
|
3414
|
+
range: expression.callee.range,
|
3415
|
+
loc: expression.callee.loc
|
3416
|
+
});
|
3417
|
+
} else {
|
3418
|
+
return throwEmptyError(locationCalculator, "a filter name");
|
3419
|
+
}
|
3420
|
+
if (argsCode != null) {
|
3421
|
+
const result = parseScriptFragment(
|
3422
|
+
`0${argsCode}`,
|
3423
|
+
locationCalculator.getSubCalculatorAfter(paren).getSubCalculatorShift(-1),
|
3424
|
+
parserOptions
|
3425
|
+
);
|
3426
|
+
const { ast } = result;
|
3427
|
+
const statement = ast.body[0];
|
3428
|
+
const callExpression = statement.expression;
|
3429
|
+
ast.tokens.shift();
|
3430
|
+
if (callExpression.type !== "CallExpression" || callExpression.callee.type !== "Literal") {
|
3431
|
+
let nestCount = 1;
|
3432
|
+
for (const token2 of ast.tokens.slice(1)) {
|
3433
|
+
if (nestCount === 0) {
|
3434
|
+
return throwUnexpectedTokenError(token2.value, token2);
|
3435
|
+
}
|
3436
|
+
if (token2.type === "Punctuator" && token2.value === "(") {
|
3437
|
+
nestCount += 1;
|
3438
|
+
}
|
3439
|
+
if (token2.type === "Punctuator" && token2.value === ")") {
|
3440
|
+
nestCount -= 1;
|
3441
|
+
}
|
3442
|
+
}
|
3443
|
+
const token = (0, import_last.default)(ast.tokens);
|
3444
|
+
return throwUnexpectedTokenError(token.value, token);
|
3445
|
+
}
|
3446
|
+
for (const argument of callExpression.arguments) {
|
3447
|
+
argument.parent = expression;
|
3448
|
+
expression.arguments.push(argument);
|
3449
|
+
}
|
3450
|
+
tokens.push(...ast.tokens);
|
3451
|
+
comments.push(...ast.comments);
|
3452
|
+
references.push(...analyzeExternalReferences(result, parserOptions));
|
3453
|
+
}
|
3454
|
+
const firstToken = tokens[0];
|
3455
|
+
const lastToken = (0, import_last.default)(tokens);
|
3456
|
+
expression.range = [firstToken.range[0], lastToken.range[1]];
|
3457
|
+
expression.loc = { start: firstToken.loc.start, end: lastToken.loc.end };
|
3458
|
+
return { expression, tokens, comments, references, variables: [] };
|
3459
|
+
} catch (err) {
|
3460
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3323
3461
|
}
|
3324
|
-
}
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
baseOffset;
|
3330
|
-
baseIndexOfGap;
|
3331
|
-
shiftOffset;
|
3332
|
-
/**
|
3333
|
-
* Initialize this calculator.
|
3334
|
-
* @param gapOffsets The list of the offset of removed characters in tokenization phase.
|
3335
|
-
* @param ltOffsets The list of the offset of line terminators.
|
3336
|
-
* @param baseOffset The base offset to calculate locations.
|
3337
|
-
* @param shiftOffset The shift offset to calculate locations.
|
3338
|
-
*/
|
3339
|
-
constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) {
|
3340
|
-
super(ltOffsets);
|
3341
|
-
this.gapOffsets = gapOffsets;
|
3342
|
-
this.ltOffsets = ltOffsets;
|
3343
|
-
this.baseOffset = baseOffset || 0;
|
3344
|
-
this.baseIndexOfGap = this.baseOffset === 0 ? 0 : (0, import_sortedLastIndex2.default)(gapOffsets, this.baseOffset);
|
3345
|
-
this.shiftOffset = shiftOffset;
|
3346
|
-
}
|
3347
|
-
/**
|
3348
|
-
* Get sub calculator which have the given base offset.
|
3349
|
-
* @param offset The base offset of new sub calculator.
|
3350
|
-
* @returns Sub calculator.
|
3351
|
-
*/
|
3352
|
-
getSubCalculatorAfter(offset) {
|
3353
|
-
return new _LocationCalculatorForHtml(
|
3354
|
-
this.gapOffsets,
|
3355
|
-
this.ltOffsets,
|
3356
|
-
this.baseOffset + offset,
|
3357
|
-
this.shiftOffset
|
3462
|
+
}
|
3463
|
+
function loadParser(parser) {
|
3464
|
+
if (parser !== "espree") {
|
3465
|
+
const __require = createRequire(
|
3466
|
+
typeof __filename ? __filename : fileURLToPath(import.meta.url)
|
3358
3467
|
);
|
3468
|
+
return __require(parser);
|
3359
3469
|
}
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
return
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3470
|
+
return getEspreeFromUser();
|
3471
|
+
}
|
3472
|
+
function parseScript(code, parserOptions) {
|
3473
|
+
const parser = typeof parserOptions.parser === "string" ? loadParser(parserOptions.parser) : isParserObject(parserOptions.parser) ? parserOptions.parser : getEspreeFromEcmaVersion(parserOptions.ecmaVersion);
|
3474
|
+
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code, parserOptions) : parser.parse(code, parserOptions);
|
3475
|
+
if (result.ast != null) {
|
3476
|
+
return result;
|
3477
|
+
}
|
3478
|
+
return { ast: result };
|
3479
|
+
}
|
3480
|
+
function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
|
3481
|
+
debug('[script] parse expression: "%s"', code);
|
3482
|
+
const [mainCode, ...filterCodes] = allowFilters ? splitFilters(code) : [code];
|
3483
|
+
if (filterCodes.length === 0) {
|
3484
|
+
return parseExpressionBody(
|
3485
|
+
code,
|
3486
|
+
locationCalculator,
|
3487
|
+
parserOptions,
|
3488
|
+
allowEmpty
|
3371
3489
|
);
|
3372
3490
|
}
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
|
3377
|
-
|
3378
|
-
|
3379
|
-
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3491
|
+
const retB = parseExpressionBody(
|
3492
|
+
mainCode,
|
3493
|
+
locationCalculator,
|
3494
|
+
parserOptions
|
3495
|
+
);
|
3496
|
+
if (!retB.expression) {
|
3497
|
+
return retB;
|
3498
|
+
}
|
3499
|
+
const ret = retB;
|
3500
|
+
ret.expression = {
|
3501
|
+
type: "VFilterSequenceExpression",
|
3502
|
+
parent: null,
|
3503
|
+
expression: retB.expression,
|
3504
|
+
filters: [],
|
3505
|
+
range: retB.expression.range.slice(0),
|
3506
|
+
loc: Object.assign({}, retB.expression.loc)
|
3507
|
+
};
|
3508
|
+
ret.expression.expression.parent = ret.expression;
|
3509
|
+
let prevLoc = mainCode.length;
|
3510
|
+
for (const filterCode of filterCodes) {
|
3511
|
+
ret.tokens.push(
|
3512
|
+
fixLocation(
|
3513
|
+
{
|
3514
|
+
type: "Punctuator",
|
3515
|
+
value: "|",
|
3516
|
+
range: [prevLoc, prevLoc + 1],
|
3517
|
+
loc: {}
|
3518
|
+
},
|
3519
|
+
locationCalculator
|
3520
|
+
)
|
3521
|
+
);
|
3522
|
+
const retF = parseFilter(
|
3523
|
+
filterCode,
|
3524
|
+
locationCalculator.getSubCalculatorShift(prevLoc + 1),
|
3525
|
+
parserOptions
|
3526
|
+
);
|
3527
|
+
if (retF) {
|
3528
|
+
if (retF.expression) {
|
3529
|
+
ret.expression.filters.push(retF.expression);
|
3530
|
+
retF.expression.parent = ret.expression;
|
3531
|
+
}
|
3532
|
+
ret.tokens.push(...retF.tokens);
|
3533
|
+
ret.comments.push(...retF.comments);
|
3534
|
+
ret.references.push(...retF.references);
|
3384
3535
|
}
|
3385
|
-
|
3536
|
+
prevLoc += 1 + filterCode.length;
|
3386
3537
|
}
|
3387
|
-
|
3388
|
-
|
3389
|
-
|
3390
|
-
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3538
|
+
const lastToken = (0, import_last.default)(ret.tokens);
|
3539
|
+
ret.expression.range[1] = lastToken.range[1];
|
3540
|
+
ret.expression.loc.end = lastToken.loc.end;
|
3541
|
+
return ret;
|
3542
|
+
}
|
3543
|
+
function parseVForExpression(code, locationCalculator, parserOptions) {
|
3544
|
+
if (code.trim() === "") {
|
3545
|
+
throwEmptyError(locationCalculator, "'<alias> in <expression>'");
|
3394
3546
|
}
|
3395
|
-
|
3396
|
-
|
3397
|
-
* @param index The index to calculate their location.
|
3398
|
-
* @returns The offset of the index.
|
3399
|
-
*/
|
3400
|
-
getOffsetWithGap(index) {
|
3401
|
-
return index + this.getFixOffset(index);
|
3402
|
-
}
|
3403
|
-
/**
|
3404
|
-
* Gets the fix location offset of the given offset with using the base offset of this calculator.
|
3405
|
-
* @param offset The offset to modify.
|
3406
|
-
*/
|
3407
|
-
getFixOffset(offset) {
|
3408
|
-
const shiftOffset = this.shiftOffset;
|
3409
|
-
const gap = this._getGap(offset + shiftOffset);
|
3410
|
-
return this.baseOffset + gap + shiftOffset;
|
3411
|
-
}
|
3412
|
-
};
|
3413
|
-
|
3414
|
-
// src/template/intermediate-tokenizer.ts
|
3415
|
-
var import_last = __toESM(require_last());
|
3416
|
-
import assert from "node:assert";
|
3417
|
-
var DUMMY_PARENT = Object.freeze({});
|
3418
|
-
function concat(text, token) {
|
3419
|
-
return text + token.value;
|
3420
|
-
}
|
3421
|
-
var IntermediateTokenizer = class {
|
3422
|
-
tokenizer;
|
3423
|
-
baseParserOptions;
|
3424
|
-
currentToken;
|
3425
|
-
attribute;
|
3426
|
-
attributeNames;
|
3427
|
-
expressionStartToken;
|
3428
|
-
expressionTokens;
|
3429
|
-
tokens;
|
3430
|
-
comments;
|
3431
|
-
/**
|
3432
|
-
* The source code text.
|
3433
|
-
*/
|
3434
|
-
get text() {
|
3435
|
-
return this.tokenizer.text;
|
3436
|
-
}
|
3437
|
-
/**
|
3438
|
-
* The parse errors.
|
3439
|
-
*/
|
3440
|
-
get errors() {
|
3441
|
-
return this.tokenizer.errors;
|
3442
|
-
}
|
3443
|
-
/**
|
3444
|
-
* The current state.
|
3445
|
-
*/
|
3446
|
-
get state() {
|
3447
|
-
return this.tokenizer.state;
|
3448
|
-
}
|
3449
|
-
set state(value) {
|
3450
|
-
this.tokenizer.state = value;
|
3451
|
-
}
|
3452
|
-
/**
|
3453
|
-
* The current namespace.
|
3454
|
-
*/
|
3455
|
-
get namespace() {
|
3456
|
-
return this.tokenizer.namespace;
|
3457
|
-
}
|
3458
|
-
set namespace(value) {
|
3459
|
-
this.tokenizer.namespace = value;
|
3460
|
-
}
|
3461
|
-
/**
|
3462
|
-
* The current flag of expression enabled.
|
3463
|
-
*/
|
3464
|
-
get expressionEnabled() {
|
3465
|
-
return this.tokenizer.expressionEnabled;
|
3466
|
-
}
|
3467
|
-
set expressionEnabled(value) {
|
3468
|
-
this.tokenizer.expressionEnabled = value;
|
3469
|
-
}
|
3470
|
-
/**
|
3471
|
-
* Initialize this intermediate tokenizer.
|
3472
|
-
* @param tokenizer The tokenizer.
|
3473
|
-
*/
|
3474
|
-
constructor(tokenizer, parserOptions) {
|
3475
|
-
this.tokenizer = tokenizer;
|
3476
|
-
this.baseParserOptions = parserOptions;
|
3477
|
-
this.currentToken = null;
|
3478
|
-
this.attribute = null;
|
3479
|
-
this.attributeNames = /* @__PURE__ */ new Set();
|
3480
|
-
this.expressionStartToken = null;
|
3481
|
-
this.expressionTokens = [];
|
3482
|
-
this.tokens = [];
|
3483
|
-
this.comments = [];
|
3484
|
-
}
|
3485
|
-
/**
|
3486
|
-
* Get the next intermediate token.
|
3487
|
-
* @returns The intermediate token or null.
|
3488
|
-
*/
|
3489
|
-
nextToken() {
|
3490
|
-
let token = null;
|
3491
|
-
let result = null;
|
3492
|
-
while (result == null) {
|
3493
|
-
token = this.tokenizer.nextToken();
|
3494
|
-
if (token == null) {
|
3495
|
-
break;
|
3496
|
-
}
|
3497
|
-
result = this[token.type](token);
|
3498
|
-
}
|
3499
|
-
if (result == null && token == null && this.currentToken != null) {
|
3500
|
-
result = this.commit();
|
3501
|
-
}
|
3502
|
-
return result;
|
3503
|
-
}
|
3504
|
-
/**
|
3505
|
-
* Commit the current token.
|
3506
|
-
*/
|
3507
|
-
commit() {
|
3508
|
-
assert(this.currentToken != null || this.expressionStartToken != null);
|
3509
|
-
let token = this.currentToken;
|
3510
|
-
this.currentToken = null;
|
3511
|
-
this.attribute = null;
|
3512
|
-
if (this.expressionStartToken != null) {
|
3513
|
-
const start = this.expressionStartToken;
|
3514
|
-
const end = (0, import_last.default)(this.expressionTokens) || start;
|
3515
|
-
const value = this.expressionTokens.reduce(concat, start.value);
|
3516
|
-
this.expressionStartToken = null;
|
3517
|
-
this.expressionTokens = [];
|
3518
|
-
if (token == null) {
|
3519
|
-
token = {
|
3520
|
-
type: "Text",
|
3521
|
-
range: [start.range[0], end.range[1]],
|
3522
|
-
loc: { start: start.loc.start, end: end.loc.end },
|
3523
|
-
value
|
3524
|
-
};
|
3525
|
-
} else if (token.type === "Text") {
|
3526
|
-
token.range[1] = end.range[1];
|
3527
|
-
token.loc.end = end.loc.end;
|
3528
|
-
token.value += value;
|
3529
|
-
} else {
|
3530
|
-
throw new Error("unreachable");
|
3531
|
-
}
|
3532
|
-
}
|
3533
|
-
return token;
|
3534
|
-
}
|
3535
|
-
/**
|
3536
|
-
* Report an invalid character error.
|
3537
|
-
* @param token The invalid token.
|
3538
|
-
* @param code The error code.
|
3539
|
-
*/
|
3540
|
-
reportParseError(token, code) {
|
3541
|
-
const error = ParseError.fromCode(
|
3547
|
+
if (isEcmaVersion5(parserOptions)) {
|
3548
|
+
return parseVForExpressionForEcmaVersion5(
|
3542
3549
|
code,
|
3543
|
-
|
3544
|
-
|
3545
|
-
token.loc.start.column
|
3550
|
+
locationCalculator,
|
3551
|
+
parserOptions
|
3546
3552
|
);
|
3547
|
-
this.errors.push(error);
|
3548
|
-
debug("[html] syntax error:", error.message);
|
3549
3553
|
}
|
3550
|
-
|
3551
|
-
|
3552
|
-
|
3553
|
-
*/
|
3554
|
-
processComment(token) {
|
3555
|
-
this.comments.push(token);
|
3556
|
-
if (this.currentToken != null && this.currentToken.type === "Text") {
|
3557
|
-
return this.commit();
|
3558
|
-
}
|
3559
|
-
return null;
|
3554
|
+
const processed = processVForAliasAndIterator(code);
|
3555
|
+
if (!processed.aliases.trim()) {
|
3556
|
+
return throwEmptyError(locationCalculator, "an alias");
|
3560
3557
|
}
|
3561
|
-
|
3562
|
-
|
3563
|
-
|
3564
|
-
|
3565
|
-
|
3566
|
-
|
3567
|
-
|
3568
|
-
|
3569
|
-
|
3570
|
-
|
3571
|
-
|
3572
|
-
|
3558
|
+
try {
|
3559
|
+
debug(
|
3560
|
+
'[script] parse v-for expression: "for(%s%s%s);"',
|
3561
|
+
processed.aliasesWithBrackets,
|
3562
|
+
processed.delimiter,
|
3563
|
+
processed.iterator
|
3564
|
+
);
|
3565
|
+
const result = parseScriptFragment(
|
3566
|
+
`for(let ${processed.aliasesWithBrackets}${processed.delimiter}${processed.iterator});`,
|
3567
|
+
locationCalculator.getSubCalculatorShift(
|
3568
|
+
processed.hasParens ? -8 : -9
|
3569
|
+
),
|
3570
|
+
parserOptions
|
3571
|
+
);
|
3572
|
+
const { ast } = result;
|
3573
|
+
const tokens = ast.tokens || [];
|
3574
|
+
const comments = ast.comments || [];
|
3575
|
+
const scope = analyzeVariablesAndExternalReferences(
|
3576
|
+
result,
|
3577
|
+
"v-for",
|
3578
|
+
parserOptions
|
3579
|
+
);
|
3580
|
+
const references = scope.references;
|
3581
|
+
const variables = scope.variables;
|
3582
|
+
const statement = ast.body[0];
|
3583
|
+
const varDecl = statement.left;
|
3584
|
+
const id = varDecl.declarations[0].id;
|
3585
|
+
const left = id.elements;
|
3586
|
+
const right = statement.right;
|
3587
|
+
if (!processed.hasParens && !left.length) {
|
3588
|
+
return throwEmptyError(locationCalculator, "an alias");
|
3589
|
+
}
|
3590
|
+
tokens.shift();
|
3591
|
+
tokens.shift();
|
3592
|
+
tokens.shift();
|
3593
|
+
tokens.pop();
|
3594
|
+
tokens.pop();
|
3595
|
+
const closeOffset = statement.left.range[1] - 1;
|
3596
|
+
const closeIndex = tokens.findIndex((t) => t.range[0] === closeOffset);
|
3597
|
+
if (processed.hasParens) {
|
3598
|
+
const open = tokens[0];
|
3599
|
+
if (open != null) {
|
3600
|
+
open.value = "(";
|
3573
3601
|
}
|
3574
|
-
|
3575
|
-
|
3576
|
-
|
3577
|
-
this.currentToken.value += token.value;
|
3578
|
-
this.currentToken.range[1] = token.range[1];
|
3579
|
-
this.currentToken.loc.end = token.loc.end;
|
3580
|
-
return null;
|
3602
|
+
const close = tokens[closeIndex];
|
3603
|
+
if (close != null) {
|
3604
|
+
close.value = ")";
|
3581
3605
|
}
|
3582
|
-
|
3606
|
+
} else {
|
3607
|
+
tokens.splice(closeIndex, 1);
|
3608
|
+
tokens.shift();
|
3583
3609
|
}
|
3584
|
-
|
3585
|
-
|
3586
|
-
|
3587
|
-
|
3588
|
-
|
3589
|
-
|
3610
|
+
const firstToken = tokens[0] || statement.left;
|
3611
|
+
const lastToken = tokens[tokens.length - 1] || statement.right;
|
3612
|
+
const expression = {
|
3613
|
+
type: "VForExpression",
|
3614
|
+
range: [firstToken.range[0], lastToken.range[1]],
|
3615
|
+
loc: { start: firstToken.loc.start, end: lastToken.loc.end },
|
3616
|
+
parent: DUMMY_PARENT,
|
3617
|
+
left,
|
3618
|
+
right
|
3590
3619
|
};
|
3591
|
-
|
3620
|
+
for (const l of left) {
|
3621
|
+
if (l != null) {
|
3622
|
+
l.parent = expression;
|
3623
|
+
}
|
3624
|
+
}
|
3625
|
+
right.parent = expression;
|
3626
|
+
return { expression, tokens, comments, references, variables };
|
3627
|
+
} catch (err) {
|
3628
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3592
3629
|
}
|
3593
|
-
|
3594
|
-
|
3595
|
-
|
3596
|
-
|
3597
|
-
|
3598
|
-
|
3599
|
-
|
3600
|
-
|
3601
|
-
|
3602
|
-
if (this.currentToken == null || this.currentToken.type !== "StartTag") {
|
3603
|
-
throw new Error("unreachable");
|
3604
|
-
}
|
3605
|
-
this.currentToken.range[1] = token.range[1];
|
3606
|
-
this.currentToken.loc.end = token.loc.end;
|
3607
|
-
}
|
3608
|
-
return null;
|
3609
|
-
}
|
3610
|
-
/**
|
3611
|
-
* Process a HTMLBogusComment token.
|
3612
|
-
* @param token The token to process.
|
3613
|
-
*/
|
3614
|
-
HTMLBogusComment(token) {
|
3615
|
-
return this.processComment(token);
|
3616
|
-
}
|
3617
|
-
/**
|
3618
|
-
* Process a HTMLCDataText token.
|
3619
|
-
* @param token The token to process.
|
3620
|
-
*/
|
3621
|
-
HTMLCDataText(token) {
|
3622
|
-
return this.processText(token);
|
3623
|
-
}
|
3624
|
-
/**
|
3625
|
-
* Process a HTMLComment token.
|
3626
|
-
* @param token The token to process.
|
3627
|
-
*/
|
3628
|
-
HTMLComment(token) {
|
3629
|
-
return this.processComment(token);
|
3630
|
-
}
|
3631
|
-
/**
|
3632
|
-
* Process a HTMLEndTagOpen token.
|
3633
|
-
* @param token The token to process.
|
3634
|
-
*/
|
3635
|
-
HTMLEndTagOpen(token) {
|
3636
|
-
this.tokens.push(token);
|
3637
|
-
let result = null;
|
3638
|
-
if (this.currentToken != null || this.expressionStartToken != null) {
|
3639
|
-
result = this.commit();
|
3640
|
-
}
|
3641
|
-
this.currentToken = {
|
3642
|
-
type: "EndTag",
|
3643
|
-
range: [token.range[0], token.range[1]],
|
3644
|
-
loc: { start: token.loc.start, end: token.loc.end },
|
3645
|
-
name: token.value
|
3646
|
-
};
|
3647
|
-
return result;
|
3630
|
+
}
|
3631
|
+
function isEcmaVersion5(parserOptions) {
|
3632
|
+
const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
|
3633
|
+
return ecmaVersion != null && ecmaVersion <= 5;
|
3634
|
+
}
|
3635
|
+
function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
|
3636
|
+
const processed = processVForAliasAndIterator(code);
|
3637
|
+
if (!processed.aliases.trim()) {
|
3638
|
+
return throwEmptyError(locationCalculator, "an alias");
|
3648
3639
|
}
|
3649
|
-
|
3650
|
-
|
3651
|
-
|
3652
|
-
|
3653
|
-
|
3654
|
-
|
3655
|
-
|
3656
|
-
|
3657
|
-
|
3658
|
-
|
3659
|
-
|
3660
|
-
|
3640
|
+
try {
|
3641
|
+
const tokens = [];
|
3642
|
+
const comments = [];
|
3643
|
+
const parsedAliases = parseVForAliasesForEcmaVersion5(
|
3644
|
+
processed.aliasesWithBrackets,
|
3645
|
+
locationCalculator.getSubCalculatorShift(
|
3646
|
+
processed.hasParens ? 0 : -1
|
3647
|
+
),
|
3648
|
+
parserOptions
|
3649
|
+
);
|
3650
|
+
if (processed.hasParens) {
|
3651
|
+
const open = parsedAliases.tokens[0];
|
3652
|
+
if (open != null) {
|
3653
|
+
open.value = "(";
|
3654
|
+
}
|
3655
|
+
const close = (0, import_last.default)(parsedAliases.tokens);
|
3656
|
+
if (close != null) {
|
3657
|
+
close.value = ")";
|
3658
|
+
}
|
3659
|
+
} else {
|
3660
|
+
parsedAliases.tokens.shift();
|
3661
|
+
parsedAliases.tokens.pop();
|
3661
3662
|
}
|
3662
|
-
|
3663
|
-
|
3663
|
+
tokens.push(...parsedAliases.tokens);
|
3664
|
+
comments.push(...parsedAliases.comments);
|
3665
|
+
const { left, variables } = parsedAliases;
|
3666
|
+
if (!processed.hasParens && !left.length) {
|
3667
|
+
return throwEmptyError(locationCalculator, "an alias");
|
3664
3668
|
}
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3668
|
-
|
3669
|
-
|
3669
|
+
const delimiterStart = processed.aliases.length;
|
3670
|
+
const delimiterEnd = delimiterStart + processed.delimiter.length;
|
3671
|
+
tokens.push(
|
3672
|
+
fixLocation(
|
3673
|
+
{
|
3674
|
+
type: processed.delimiter === "in" ? "Keyword" : "Identifier",
|
3675
|
+
value: processed.delimiter,
|
3676
|
+
start: delimiterStart,
|
3677
|
+
end: delimiterEnd,
|
3678
|
+
loc: {},
|
3679
|
+
range: [delimiterStart, delimiterEnd]
|
3680
|
+
},
|
3681
|
+
locationCalculator
|
3682
|
+
)
|
3683
|
+
);
|
3684
|
+
const parsedIterator = parseVForIteratorForEcmaVersion5(
|
3685
|
+
processed.iterator,
|
3686
|
+
locationCalculator.getSubCalculatorShift(delimiterEnd),
|
3687
|
+
parserOptions
|
3688
|
+
);
|
3689
|
+
tokens.push(...parsedIterator.tokens);
|
3690
|
+
comments.push(...parsedIterator.comments);
|
3691
|
+
const { right, references } = parsedIterator;
|
3692
|
+
const firstToken = tokens[0];
|
3693
|
+
const lastToken = (0, import_last.default)(tokens) || firstToken;
|
3694
|
+
const expression = {
|
3695
|
+
type: "VForExpression",
|
3696
|
+
range: [firstToken.range[0], lastToken.range[1]],
|
3697
|
+
loc: { start: firstToken.loc.start, end: lastToken.loc.end },
|
3670
3698
|
parent: DUMMY_PARENT,
|
3671
|
-
|
3672
|
-
|
3673
|
-
type: "VIdentifier",
|
3674
|
-
range: [token.range[0], token.range[1]],
|
3675
|
-
loc: { start: token.loc.start, end: token.loc.end },
|
3676
|
-
parent: DUMMY_PARENT,
|
3677
|
-
name: token.value,
|
3678
|
-
rawName: this.text.slice(token.range[0], token.range[1])
|
3679
|
-
},
|
3680
|
-
value: null
|
3699
|
+
left,
|
3700
|
+
right
|
3681
3701
|
};
|
3682
|
-
|
3683
|
-
|
3684
|
-
|
3685
|
-
|
3686
|
-
|
3702
|
+
for (const l of left) {
|
3703
|
+
if (l != null) {
|
3704
|
+
l.parent = expression;
|
3705
|
+
}
|
3706
|
+
}
|
3707
|
+
right.parent = expression;
|
3708
|
+
return { expression, tokens, comments, references, variables };
|
3709
|
+
} catch (err) {
|
3710
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3687
3711
|
}
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
|
3693
|
-
|
3694
|
-
|
3695
|
-
|
3696
|
-
|
3697
|
-
|
3698
|
-
|
3699
|
-
|
3700
|
-
|
3701
|
-
|
3702
|
-
|
3703
|
-
|
3704
|
-
|
3705
|
-
|
3712
|
+
}
|
3713
|
+
function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
|
3714
|
+
const result = parseScriptFragment(
|
3715
|
+
`0(${code})`,
|
3716
|
+
locationCalculator.getSubCalculatorShift(-2),
|
3717
|
+
parserOptions
|
3718
|
+
);
|
3719
|
+
const { ast } = result;
|
3720
|
+
const tokens = ast.tokens || [];
|
3721
|
+
const comments = ast.comments || [];
|
3722
|
+
const variables = analyzeExternalReferences(result, parserOptions).map(
|
3723
|
+
transformVariable2
|
3724
|
+
);
|
3725
|
+
const statement = ast.body[0];
|
3726
|
+
const callExpression = statement.expression;
|
3727
|
+
const expression = callExpression.arguments[0];
|
3728
|
+
const left = expression.elements.filter(
|
3729
|
+
(e) => {
|
3730
|
+
if (e == null || e.type === "Identifier") {
|
3731
|
+
return true;
|
3706
3732
|
}
|
3707
|
-
|
3708
|
-
|
3733
|
+
const errorToken = tokens.find(
|
3734
|
+
(t) => e.range[0] <= t.range[0] && t.range[1] <= e.range[1]
|
3735
|
+
);
|
3736
|
+
return throwUnexpectedTokenError(errorToken.value, errorToken);
|
3709
3737
|
}
|
3710
|
-
|
3738
|
+
);
|
3739
|
+
tokens.shift();
|
3740
|
+
tokens.shift();
|
3741
|
+
tokens.pop();
|
3742
|
+
return { left, tokens, comments, variables };
|
3743
|
+
function transformVariable2(reference) {
|
3744
|
+
const ret = {
|
3745
|
+
id: reference.id,
|
3746
|
+
kind: "v-for",
|
3747
|
+
references: []
|
3748
|
+
};
|
3749
|
+
Object.defineProperty(ret, "references", { enumerable: false });
|
3750
|
+
return ret;
|
3711
3751
|
}
|
3712
|
-
|
3713
|
-
|
3714
|
-
|
3715
|
-
|
3716
|
-
|
3717
|
-
|
3752
|
+
}
|
3753
|
+
function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
|
3754
|
+
const result = parseScriptFragment(
|
3755
|
+
`0(${code})`,
|
3756
|
+
locationCalculator.getSubCalculatorShift(-2),
|
3757
|
+
parserOptions
|
3758
|
+
);
|
3759
|
+
const { ast } = result;
|
3760
|
+
const tokens = ast.tokens || [];
|
3761
|
+
const comments = ast.comments || [];
|
3762
|
+
const references = analyzeExternalReferences(result, parserOptions);
|
3763
|
+
const statement = ast.body[0];
|
3764
|
+
const callExpression = statement.expression;
|
3765
|
+
const expression = callExpression.arguments[0];
|
3766
|
+
if (!expression) {
|
3767
|
+
return throwEmptyError(locationCalculator, "an expression");
|
3718
3768
|
}
|
3719
|
-
|
3720
|
-
|
3721
|
-
* @param token The token to process.
|
3722
|
-
*/
|
3723
|
-
HTMLRawText(token) {
|
3724
|
-
return this.processText(token);
|
3769
|
+
if (expression && expression.type === "SpreadElement") {
|
3770
|
+
return throwUnexpectedTokenError("...", expression);
|
3725
3771
|
}
|
3726
|
-
|
3727
|
-
|
3728
|
-
|
3729
|
-
|
3730
|
-
|
3731
|
-
|
3732
|
-
|
3733
|
-
|
3734
|
-
|
3735
|
-
|
3736
|
-
|
3737
|
-
|
3738
|
-
|
3739
|
-
}
|
3740
|
-
this.currentToken.range[1] = token.range[1];
|
3741
|
-
this.currentToken.loc.end = token.loc.end;
|
3742
|
-
return this.commit();
|
3772
|
+
const right = expression;
|
3773
|
+
tokens.shift();
|
3774
|
+
tokens.shift();
|
3775
|
+
tokens.pop();
|
3776
|
+
return { right, tokens, comments, references };
|
3777
|
+
}
|
3778
|
+
function parseVOnExpression(code, locationCalculator, parserOptions) {
|
3779
|
+
if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
|
3780
|
+
return parseExpressionBody(
|
3781
|
+
code,
|
3782
|
+
locationCalculator,
|
3783
|
+
parserOptions
|
3784
|
+
);
|
3743
3785
|
}
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3747
|
-
|
3748
|
-
|
3749
|
-
|
3750
|
-
|
3751
|
-
|
3752
|
-
|
3753
|
-
|
3754
|
-
this.currentToken.loc.end = token.loc.end;
|
3755
|
-
return this.commit();
|
3786
|
+
return parseVOnExpressionBody(
|
3787
|
+
code,
|
3788
|
+
locationCalculator,
|
3789
|
+
parserOptions
|
3790
|
+
);
|
3791
|
+
}
|
3792
|
+
function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
|
3793
|
+
debug('[script] parse v-on expression: "void function($event){%s}"', code);
|
3794
|
+
if (code.trim() === "") {
|
3795
|
+
throwEmptyError(locationCalculator, "statements");
|
3756
3796
|
}
|
3757
|
-
|
3758
|
-
|
3759
|
-
|
3760
|
-
|
3761
|
-
|
3762
|
-
|
3763
|
-
|
3764
|
-
|
3765
|
-
|
3766
|
-
|
3767
|
-
|
3768
|
-
|
3769
|
-
|
3770
|
-
|
3771
|
-
|
3772
|
-
|
3773
|
-
|
3774
|
-
|
3797
|
+
try {
|
3798
|
+
const result = parseScriptFragment(
|
3799
|
+
`void function($event){${code}}`,
|
3800
|
+
locationCalculator.getSubCalculatorShift(-22),
|
3801
|
+
parserOptions
|
3802
|
+
);
|
3803
|
+
const { ast } = result;
|
3804
|
+
const references = analyzeExternalReferences(result, parserOptions);
|
3805
|
+
const outermostStatement = ast.body[0];
|
3806
|
+
const functionDecl = outermostStatement.expression.argument;
|
3807
|
+
const block = functionDecl.body;
|
3808
|
+
const body = block.body;
|
3809
|
+
const firstStatement = (0, import_first.default)(body);
|
3810
|
+
const lastStatement = (0, import_last.default)(body);
|
3811
|
+
const expression = {
|
3812
|
+
type: "VOnExpression",
|
3813
|
+
range: [
|
3814
|
+
firstStatement != null ? firstStatement.range[0] : block.range[0] + 1,
|
3815
|
+
lastStatement != null ? lastStatement.range[1] : block.range[1] - 1
|
3816
|
+
],
|
3817
|
+
loc: {
|
3818
|
+
start: firstStatement != null ? firstStatement.loc.start : locationCalculator.getLocation(1),
|
3819
|
+
end: lastStatement != null ? lastStatement.loc.end : locationCalculator.getLocation(code.length + 1)
|
3820
|
+
},
|
3821
|
+
parent: DUMMY_PARENT,
|
3822
|
+
body
|
3775
3823
|
};
|
3776
|
-
|
3777
|
-
|
3778
|
-
|
3779
|
-
|
3780
|
-
/**
|
3781
|
-
* Process a HTMLText token.
|
3782
|
-
* @param token The token to process.
|
3783
|
-
*/
|
3784
|
-
HTMLText(token) {
|
3785
|
-
return this.processText(token);
|
3786
|
-
}
|
3787
|
-
/**
|
3788
|
-
* Process a HTMLWhitespace token.
|
3789
|
-
* @param token The token to process.
|
3790
|
-
*/
|
3791
|
-
HTMLWhitespace(token) {
|
3792
|
-
return this.processText(token);
|
3793
|
-
}
|
3794
|
-
/**
|
3795
|
-
* Process a VExpressionStart token.
|
3796
|
-
* @param token The token to process.
|
3797
|
-
*/
|
3798
|
-
VExpressionStart(token) {
|
3799
|
-
if (this.expressionStartToken != null) {
|
3800
|
-
return this.processText(token);
|
3824
|
+
const tokens = ast.tokens || [];
|
3825
|
+
const comments = ast.comments || [];
|
3826
|
+
for (const b of body) {
|
3827
|
+
b.parent = expression;
|
3801
3828
|
}
|
3802
|
-
|
3803
|
-
|
3804
|
-
|
3805
|
-
|
3806
|
-
return
|
3829
|
+
tokens.splice(0, 6);
|
3830
|
+
tokens.pop();
|
3831
|
+
return { expression, tokens, comments, references, variables: [] };
|
3832
|
+
} catch (err) {
|
3833
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3807
3834
|
}
|
3808
|
-
|
3809
|
-
|
3810
|
-
|
3811
|
-
|
3812
|
-
|
3813
|
-
|
3814
|
-
|
3815
|
-
|
3816
|
-
|
3817
|
-
|
3818
|
-
|
3819
|
-
|
3820
|
-
|
3821
|
-
|
3822
|
-
|
3823
|
-
|
3835
|
+
}
|
3836
|
+
function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
|
3837
|
+
debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
|
3838
|
+
if (code.trim() === "") {
|
3839
|
+
throwEmptyError(
|
3840
|
+
locationCalculator,
|
3841
|
+
"an identifier or an array/object pattern"
|
3842
|
+
);
|
3843
|
+
}
|
3844
|
+
try {
|
3845
|
+
const result = parseScriptFragment(
|
3846
|
+
`void function(${code}) {}`,
|
3847
|
+
locationCalculator.getSubCalculatorShift(-14),
|
3848
|
+
parserOptions
|
3849
|
+
);
|
3850
|
+
const { ast } = result;
|
3851
|
+
const statement = ast.body[0];
|
3852
|
+
const rawExpression = statement.expression;
|
3853
|
+
const functionDecl = rawExpression.argument;
|
3854
|
+
const params = functionDecl.params;
|
3855
|
+
if (params.length === 0) {
|
3856
|
+
return {
|
3857
|
+
expression: null,
|
3858
|
+
tokens: [],
|
3859
|
+
comments: [],
|
3860
|
+
references: [],
|
3861
|
+
variables: []
|
3862
|
+
};
|
3824
3863
|
}
|
3825
|
-
|
3826
|
-
|
3827
|
-
|
3828
|
-
|
3864
|
+
const tokens = ast.tokens || [];
|
3865
|
+
const comments = ast.comments || [];
|
3866
|
+
const scope = analyzeVariablesAndExternalReferences(
|
3867
|
+
result,
|
3868
|
+
"scope",
|
3869
|
+
parserOptions
|
3870
|
+
);
|
3871
|
+
const references = scope.references;
|
3872
|
+
const variables = scope.variables;
|
3873
|
+
const firstParam = (0, import_first.default)(params);
|
3874
|
+
const lastParam = (0, import_last.default)(params);
|
3875
|
+
const expression = {
|
3876
|
+
type: "VSlotScopeExpression",
|
3877
|
+
range: [firstParam.range[0], lastParam.range[1]],
|
3878
|
+
loc: { start: firstParam.loc.start, end: lastParam.loc.end },
|
3879
|
+
parent: DUMMY_PARENT,
|
3880
|
+
params: functionDecl.params
|
3881
|
+
};
|
3882
|
+
for (const param of params) {
|
3883
|
+
param.parent = expression;
|
3829
3884
|
}
|
3830
|
-
|
3831
|
-
|
3832
|
-
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
3837
|
-
|
3838
|
-
|
3839
|
-
|
3840
|
-
|
3841
|
-
|
3885
|
+
tokens.shift();
|
3886
|
+
tokens.shift();
|
3887
|
+
tokens.shift();
|
3888
|
+
tokens.pop();
|
3889
|
+
tokens.pop();
|
3890
|
+
tokens.pop();
|
3891
|
+
return { expression, tokens, comments, references, variables };
|
3892
|
+
} catch (err) {
|
3893
|
+
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
3894
|
+
}
|
3895
|
+
}
|
3896
|
+
|
3897
|
+
// src/template/utils/index.ts
|
3898
|
+
var shorthandSign = /^[.:@#]/u;
|
3899
|
+
var shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" };
|
3900
|
+
var invalidDynamicArgumentNextChar = /^[\s=/>]$/u;
|
3901
|
+
function camelize(str) {
|
3902
|
+
return str.replace(/-(\w)/gu, (_, c) => c ? c.toUpperCase() : "");
|
3903
|
+
}
|
3904
|
+
function isPropModifier(node) {
|
3905
|
+
return node.name === "prop";
|
3906
|
+
}
|
3907
|
+
function isNotEmptyModifier(node) {
|
3908
|
+
return node.name !== "";
|
3909
|
+
}
|
3910
|
+
function getStandardDirectiveKind(element, directiveKey) {
|
3911
|
+
const directiveName = directiveKey.name.name;
|
3912
|
+
if (directiveName === "for") {
|
3913
|
+
return "for";
|
3914
|
+
} else if (directiveName === "on") {
|
3915
|
+
return "on";
|
3916
|
+
} else if (directiveName === "slot" || directiveName === "slot-scope" || directiveName === "scope" && element.rawName === "template") {
|
3917
|
+
return "slot";
|
3918
|
+
} else if (directiveName === "bind") {
|
3919
|
+
return "bind";
|
3920
|
+
}
|
3921
|
+
return null;
|
3922
|
+
}
|
3923
|
+
function parseAttributeValue(code, parserOptions, globalLocationCalculator, node, element, directiveKey) {
|
3924
|
+
const firstChar = code[node.range[0]];
|
3925
|
+
const quoted = firstChar === '"' || firstChar === "'";
|
3926
|
+
const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(
|
3927
|
+
node.range[0] + (quoted ? 1 : 0)
|
3928
|
+
);
|
3929
|
+
const directiveKind = getStandardDirectiveKind(
|
3930
|
+
element,
|
3931
|
+
directiveKey
|
3932
|
+
);
|
3933
|
+
let result;
|
3934
|
+
if (quoted && node.value === "") {
|
3935
|
+
result = {
|
3936
|
+
expression: null,
|
3937
|
+
tokens: [],
|
3938
|
+
comments: [],
|
3939
|
+
variables: [],
|
3940
|
+
references: []
|
3842
3941
|
};
|
3843
|
-
|
3942
|
+
} else if (directiveKind === "for") {
|
3943
|
+
result = parseVForExpression(
|
3944
|
+
node.value,
|
3945
|
+
locationCalculator,
|
3946
|
+
parserOptions
|
3947
|
+
);
|
3948
|
+
} else if (directiveKind === "on" && directiveKey.argument != null) {
|
3949
|
+
result = parseVOnExpression(
|
3950
|
+
node.value,
|
3951
|
+
locationCalculator,
|
3952
|
+
parserOptions
|
3953
|
+
);
|
3954
|
+
} else if (directiveKind === "slot") {
|
3955
|
+
result = parseSlotScopeExpression(
|
3956
|
+
node.value,
|
3957
|
+
locationCalculator,
|
3958
|
+
parserOptions
|
3959
|
+
);
|
3960
|
+
} else if (directiveKind === "bind") {
|
3961
|
+
result = parseExpression(
|
3962
|
+
node.value,
|
3963
|
+
locationCalculator,
|
3964
|
+
parserOptions,
|
3965
|
+
{ allowFilters: true }
|
3966
|
+
);
|
3967
|
+
} else {
|
3968
|
+
result = parseExpression(
|
3969
|
+
node.value,
|
3970
|
+
locationCalculator,
|
3971
|
+
parserOptions
|
3972
|
+
);
|
3973
|
+
}
|
3974
|
+
if (quoted) {
|
3975
|
+
result.tokens.unshift(
|
3976
|
+
createSimpleToken(
|
3977
|
+
"Punctuator",
|
3978
|
+
node.range[0],
|
3979
|
+
node.range[0] + 1,
|
3980
|
+
firstChar,
|
3981
|
+
globalLocationCalculator
|
3982
|
+
)
|
3983
|
+
);
|
3984
|
+
result.tokens.push(
|
3985
|
+
createSimpleToken(
|
3986
|
+
"Punctuator",
|
3987
|
+
node.range[1] - 1,
|
3988
|
+
node.range[1],
|
3989
|
+
firstChar,
|
3990
|
+
globalLocationCalculator
|
3991
|
+
)
|
3992
|
+
);
|
3844
3993
|
}
|
3845
|
-
|
3846
|
-
|
3847
|
-
// src/common/error-utils.ts
|
3848
|
-
function insertError(templateMeta, error) {
|
3849
|
-
const index = templateMeta.errors.findIndex((e) => e.index === error.index);
|
3850
|
-
templateMeta.errors.splice(index, 0, error);
|
3994
|
+
return result;
|
3851
3995
|
}
|
3852
|
-
|
3853
|
-
|
3854
|
-
|
3855
|
-
|
3856
|
-
|
3857
|
-
range: [start, end],
|
3996
|
+
function parseDirectiveKeyStatically(node, templateMeta) {
|
3997
|
+
const {
|
3998
|
+
name: text,
|
3999
|
+
rawName: rawText,
|
4000
|
+
range: [offset],
|
3858
4001
|
loc: {
|
3859
|
-
start:
|
3860
|
-
|
3861
|
-
|
3862
|
-
|
4002
|
+
start: { column, line }
|
4003
|
+
}
|
4004
|
+
} = node;
|
4005
|
+
const directiveKey = {
|
4006
|
+
type: "VDirectiveKey",
|
4007
|
+
range: node.range,
|
4008
|
+
loc: node.loc,
|
4009
|
+
parent: node.parent,
|
4010
|
+
name: null,
|
4011
|
+
argument: null,
|
4012
|
+
modifiers: []
|
3863
4013
|
};
|
3864
|
-
|
3865
|
-
function
|
3866
|
-
|
3867
|
-
|
4014
|
+
let i = 0;
|
4015
|
+
function createIdentifier(start, end, name) {
|
4016
|
+
const id = {
|
4017
|
+
type: "VIdentifier",
|
4018
|
+
parent: directiveKey,
|
4019
|
+
range: [offset + start, offset + end],
|
4020
|
+
loc: {
|
4021
|
+
start: { column: column + start, line },
|
4022
|
+
end: { column: column + end, line }
|
4023
|
+
},
|
4024
|
+
name: name || text.slice(start, end),
|
4025
|
+
rawName: rawText.slice(start, end)
|
4026
|
+
};
|
4027
|
+
return id;
|
3868
4028
|
}
|
3869
|
-
|
3870
|
-
|
3871
|
-
|
3872
|
-
|
3873
|
-
|
3874
|
-
|
3875
|
-
|
3876
|
-
|
3877
|
-
|
3878
|
-
|
3879
|
-
var import_first = __toESM(require_first());
|
3880
|
-
var import_last2 = __toESM(require_last());
|
3881
|
-
var import_sortedIndexBy = __toESM(require_sortedIndexBy());
|
3882
|
-
|
3883
|
-
// src/common/fix-locations.ts
|
3884
|
-
function fixLocations(result, locationCalculator) {
|
3885
|
-
fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
|
3886
|
-
for (const token of result.ast.tokens || []) {
|
3887
|
-
fixLocation(token, locationCalculator);
|
4029
|
+
if (shorthandSign.test(text)) {
|
4030
|
+
const sign = text[0];
|
4031
|
+
directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
|
4032
|
+
i = 1;
|
4033
|
+
} else {
|
4034
|
+
const colon = text.indexOf(":");
|
4035
|
+
if (colon !== -1) {
|
4036
|
+
directiveKey.name = createIdentifier(0, colon);
|
4037
|
+
i = colon + 1;
|
4038
|
+
}
|
3888
4039
|
}
|
3889
|
-
|
3890
|
-
|
4040
|
+
if (directiveKey.name != null && text[i] === "[") {
|
4041
|
+
const len = text.slice(i).lastIndexOf("]");
|
4042
|
+
if (len !== -1) {
|
4043
|
+
directiveKey.argument = createIdentifier(i, i + len + 1);
|
4044
|
+
i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
|
4045
|
+
}
|
3891
4046
|
}
|
3892
|
-
|
3893
|
-
|
3894
|
-
|
3895
|
-
|
3896
|
-
|
3897
|
-
|
3898
|
-
|
3899
|
-
|
3900
|
-
|
3901
|
-
|
3902
|
-
|
3903
|
-
|
3904
|
-
|
3905
|
-
);
|
3906
|
-
node.loc.end = locationCalculator.getLocFromIndex(
|
3907
|
-
node.range[1]
|
3908
|
-
);
|
3909
|
-
traversed.set(node.loc, node);
|
3910
|
-
} else if (node.start != null || node.end != null) {
|
3911
|
-
const traversedNode = traversed.get(node.range);
|
3912
|
-
if (traversedNode.type === node.type) {
|
3913
|
-
node.start = traversedNode.start;
|
3914
|
-
node.end = traversedNode.end;
|
3915
|
-
}
|
3916
|
-
}
|
3917
|
-
} else {
|
3918
|
-
fixLocation(node, locationCalculator);
|
3919
|
-
traversed.set(node.range, node);
|
3920
|
-
traversed.set(node.loc, node);
|
3921
|
-
}
|
3922
|
-
}
|
3923
|
-
},
|
3924
|
-
leaveNode() {
|
4047
|
+
const modifiers = text.slice(i).split(".").map((modifierName) => {
|
4048
|
+
const modifier = createIdentifier(i, i + modifierName.length);
|
4049
|
+
if (modifierName === "" && i < text.length) {
|
4050
|
+
insertError(
|
4051
|
+
templateMeta,
|
4052
|
+
new ParseError(
|
4053
|
+
`Unexpected token '${text[i]}'`,
|
4054
|
+
void 0,
|
4055
|
+
offset + i,
|
4056
|
+
line,
|
4057
|
+
column + i
|
4058
|
+
)
|
4059
|
+
);
|
3925
4060
|
}
|
4061
|
+
i += modifierName.length + 1;
|
4062
|
+
return modifier;
|
3926
4063
|
});
|
3927
|
-
|
3928
|
-
|
3929
|
-
|
3930
|
-
|
3931
|
-
const d0 = locationCalculator.getFixOffset(range[0], "start");
|
3932
|
-
const d1 = locationCalculator.getFixOffset(range[1], "end");
|
3933
|
-
if (d0 !== 0) {
|
3934
|
-
range[0] += d0;
|
3935
|
-
if (node.start != null) {
|
3936
|
-
node.start += d0;
|
3937
|
-
}
|
3938
|
-
loc.start = locationCalculator.getLocFromIndex(range[0]);
|
4064
|
+
if (directiveKey.name == null) {
|
4065
|
+
directiveKey.name = modifiers.shift();
|
4066
|
+
} else if (directiveKey.argument == null && modifiers[0].name !== "") {
|
4067
|
+
directiveKey.argument = modifiers.shift() || null;
|
3939
4068
|
}
|
3940
|
-
|
3941
|
-
|
3942
|
-
|
3943
|
-
|
3944
|
-
|
3945
|
-
|
4069
|
+
directiveKey.modifiers = modifiers.filter(isNotEmptyModifier);
|
4070
|
+
if (directiveKey.name.name === "v-") {
|
4071
|
+
insertError(
|
4072
|
+
templateMeta,
|
4073
|
+
new ParseError(
|
4074
|
+
`Unexpected token '${text[directiveKey.name.range[1] - offset]}'`,
|
4075
|
+
void 0,
|
4076
|
+
directiveKey.name.range[1],
|
4077
|
+
directiveKey.name.loc.end.line,
|
4078
|
+
directiveKey.name.loc.end.column
|
4079
|
+
)
|
4080
|
+
);
|
3946
4081
|
}
|
3947
|
-
|
3948
|
-
|
3949
|
-
|
3950
|
-
|
3951
|
-
error.index += diff;
|
3952
|
-
const loc = locationCalculator.getLocFromIndex(error.index);
|
3953
|
-
error.lineNumber = loc.line;
|
3954
|
-
error.column = loc.column;
|
3955
|
-
}
|
3956
|
-
|
3957
|
-
// src/common/parser-object.ts
|
3958
|
-
function isParserObject(value) {
|
3959
|
-
return isEnhancedParserObject(value) || isBasicParserObject(value);
|
3960
|
-
}
|
3961
|
-
function isEnhancedParserObject(value) {
|
3962
|
-
return Boolean(value && typeof value.parseForESLint === "function");
|
3963
|
-
}
|
3964
|
-
function isBasicParserObject(value) {
|
3965
|
-
return Boolean(value && typeof value.parse === "function");
|
3966
|
-
}
|
3967
|
-
|
3968
|
-
// src/script/index.ts
|
3969
|
-
var ALIAS_ITERATOR = /^([\s\S]*?(?:\s|\)))(\bin\b|\bof\b)([\s\S]*)$/u;
|
3970
|
-
var PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u;
|
3971
|
-
var DUMMY_PARENT2 = {};
|
3972
|
-
var IS_FUNCTION_EXPRESSION = /^\s*(?:[\w$]+|\([^)]*\))\s*=>|^function\s*\(/u;
|
3973
|
-
var IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*'\]|\["[^"]*"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u;
|
3974
|
-
function processVForAliasAndIterator(code) {
|
3975
|
-
const match = ALIAS_ITERATOR.exec(code);
|
3976
|
-
if (match != null) {
|
3977
|
-
const aliases = match[1];
|
3978
|
-
const parenMatch = PARENS.exec(aliases);
|
3979
|
-
return {
|
3980
|
-
aliases,
|
3981
|
-
hasParens: Boolean(parenMatch),
|
3982
|
-
aliasesWithBrackets: parenMatch ? `${parenMatch[1].slice(0, -1)}[${parenMatch[2]}]${parenMatch[3].slice(1)}` : `[${aliases.slice(0, -1)}]`,
|
3983
|
-
delimiter: match[2] || "",
|
3984
|
-
iterator: match[3]
|
3985
|
-
};
|
4082
|
+
if (directiveKey.name.rawName === "." && !directiveKey.modifiers.some(isPropModifier)) {
|
4083
|
+
const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
|
4084
|
+
const propModifier = createIdentifier(pos, pos, "prop");
|
4085
|
+
directiveKey.modifiers.unshift(propModifier);
|
3986
4086
|
}
|
3987
|
-
return
|
3988
|
-
aliases: "",
|
3989
|
-
hasParens: false,
|
3990
|
-
aliasesWithBrackets: "",
|
3991
|
-
delimiter: "",
|
3992
|
-
iterator: code
|
3993
|
-
};
|
4087
|
+
return directiveKey;
|
3994
4088
|
}
|
3995
|
-
function
|
3996
|
-
|
3997
|
-
|
3998
|
-
|
3999
|
-
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4003
|
-
|
4004
|
-
|
4089
|
+
function parseDirectiveKeyTokens(node) {
|
4090
|
+
const { name, argument, modifiers } = node;
|
4091
|
+
const shorthand = name.range[1] - name.range[0] === 1;
|
4092
|
+
const tokens = [];
|
4093
|
+
if (shorthand) {
|
4094
|
+
tokens.push({
|
4095
|
+
type: "Punctuator",
|
4096
|
+
range: name.range,
|
4097
|
+
loc: name.loc,
|
4098
|
+
value: name.rawName
|
4099
|
+
});
|
4100
|
+
} else {
|
4101
|
+
tokens.push({
|
4102
|
+
type: "HTMLIdentifier",
|
4103
|
+
range: name.range,
|
4104
|
+
loc: name.loc,
|
4105
|
+
value: name.rawName
|
4106
|
+
});
|
4107
|
+
if (argument) {
|
4108
|
+
tokens.push({
|
4109
|
+
type: "Punctuator",
|
4110
|
+
range: [name.range[1], argument.range[0]],
|
4111
|
+
loc: { start: name.loc.end, end: argument.loc.start },
|
4112
|
+
value: ":"
|
4113
|
+
});
|
4005
4114
|
}
|
4006
|
-
tokenIndex -= 1;
|
4007
4115
|
}
|
4008
|
-
|
4009
|
-
|
4010
|
-
|
4011
|
-
|
4012
|
-
|
4013
|
-
|
4014
|
-
|
4015
|
-
|
4016
|
-
|
4017
|
-
|
4018
|
-
|
4019
|
-
|
4020
|
-
throw err;
|
4021
|
-
}
|
4022
|
-
function throwUnexpectedTokenError(name, token) {
|
4023
|
-
const err = new ParseError(
|
4024
|
-
`Unexpected token '${name}'.`,
|
4025
|
-
void 0,
|
4026
|
-
token.range[0],
|
4027
|
-
token.loc.start.line,
|
4028
|
-
token.loc.start.column
|
4029
|
-
);
|
4030
|
-
throw err;
|
4031
|
-
}
|
4032
|
-
function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
|
4033
|
-
if (ParseError.isParseError(err)) {
|
4034
|
-
const endOffset = locationCalculator.getOffsetWithGap(code.length);
|
4035
|
-
if (err.index >= endOffset) {
|
4036
|
-
err.message = "Unexpected end of expression.";
|
4116
|
+
if (argument) {
|
4117
|
+
tokens.push({
|
4118
|
+
type: "HTMLIdentifier",
|
4119
|
+
range: argument.range,
|
4120
|
+
loc: argument.loc,
|
4121
|
+
value: argument.rawName
|
4122
|
+
});
|
4123
|
+
}
|
4124
|
+
let lastNode = argument || name;
|
4125
|
+
for (const modifier of modifiers) {
|
4126
|
+
if (modifier.rawName === "") {
|
4127
|
+
continue;
|
4037
4128
|
}
|
4129
|
+
tokens.push(
|
4130
|
+
{
|
4131
|
+
type: "Punctuator",
|
4132
|
+
range: [lastNode.range[1], modifier.range[0]],
|
4133
|
+
loc: { start: lastNode.loc.end, end: modifier.loc.start },
|
4134
|
+
value: "."
|
4135
|
+
},
|
4136
|
+
{
|
4137
|
+
type: "HTMLIdentifier",
|
4138
|
+
range: modifier.range,
|
4139
|
+
loc: modifier.loc,
|
4140
|
+
value: modifier.rawName
|
4141
|
+
}
|
4142
|
+
);
|
4143
|
+
lastNode = modifier;
|
4038
4144
|
}
|
4039
|
-
|
4145
|
+
return tokens;
|
4040
4146
|
}
|
4041
|
-
function
|
4147
|
+
function convertDynamicArgument(node, templateMeta, parserOptions, locationCalculator) {
|
4148
|
+
const { argument } = node;
|
4149
|
+
if (!(argument != null && argument.type === "VIdentifier" && argument.name.startsWith("[") && argument.name.endsWith("]"))) {
|
4150
|
+
return;
|
4151
|
+
}
|
4152
|
+
const { rawName, range, loc } = argument;
|
4042
4153
|
try {
|
4043
|
-
const
|
4044
|
-
|
4154
|
+
const { comments, expression, references, tokens } = parseExpression(
|
4155
|
+
rawName.slice(1, -1),
|
4156
|
+
locationCalculator.getSubCalculatorAfter(range[0] + 1),
|
4045
4157
|
parserOptions
|
4046
4158
|
);
|
4047
|
-
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4159
|
+
node.argument = {
|
4160
|
+
type: "VExpressionContainer",
|
4161
|
+
range,
|
4162
|
+
loc,
|
4163
|
+
parent: node,
|
4164
|
+
expression,
|
4165
|
+
references
|
4166
|
+
};
|
4167
|
+
if (expression != null) {
|
4168
|
+
expression.parent = node.argument;
|
4169
|
+
}
|
4170
|
+
tokens.unshift(
|
4171
|
+
createSimpleToken(
|
4172
|
+
"Punctuator",
|
4173
|
+
range[0],
|
4174
|
+
range[0] + 1,
|
4175
|
+
"[",
|
4176
|
+
locationCalculator
|
4177
|
+
)
|
4178
|
+
);
|
4179
|
+
tokens.push(
|
4180
|
+
createSimpleToken(
|
4181
|
+
"Punctuator",
|
4182
|
+
range[1] - 1,
|
4183
|
+
range[1],
|
4184
|
+
"]",
|
4185
|
+
locationCalculator
|
4186
|
+
)
|
4187
|
+
);
|
4188
|
+
replaceTokens(templateMeta, node.argument, tokens);
|
4189
|
+
insertComments(templateMeta, comments);
|
4190
|
+
} catch (error) {
|
4191
|
+
debug("[template] Parse error: %s", error);
|
4192
|
+
if (ParseError.isParseError(error)) {
|
4193
|
+
node.argument = {
|
4194
|
+
type: "VExpressionContainer",
|
4195
|
+
range,
|
4196
|
+
loc,
|
4197
|
+
parent: node,
|
4198
|
+
expression: null,
|
4199
|
+
references: []
|
4200
|
+
};
|
4201
|
+
insertError(templateMeta, error);
|
4202
|
+
} else {
|
4203
|
+
throw error;
|
4054
4204
|
}
|
4055
|
-
throw err;
|
4056
4205
|
}
|
4057
4206
|
}
|
4058
|
-
|
4059
|
-
|
4060
|
-
const
|
4061
|
-
|
4062
|
-
|
4063
|
-
|
4064
|
-
|
4065
|
-
|
4066
|
-
|
4067
|
-
|
4068
|
-
|
4069
|
-
|
4070
|
-
|
4071
|
-
|
4072
|
-
|
4073
|
-
|
4074
|
-
|
4075
|
-
|
4076
|
-
|
4077
|
-
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4081
|
-
|
4082
|
-
|
4083
|
-
|
4084
|
-
|
4085
|
-
|
4086
|
-
|
4087
|
-
|
4088
|
-
|
4089
|
-
|
4090
|
-
|
4091
|
-
|
4092
|
-
|
4093
|
-
|
4094
|
-
|
4095
|
-
|
4096
|
-
|
4097
|
-
|
4098
|
-
|
4099
|
-
|
4100
|
-
|
4101
|
-
|
4102
|
-
|
4103
|
-
|
4104
|
-
|
4105
|
-
|
4106
|
-
|
4107
|
-
|
4108
|
-
|
4109
|
-
|
4110
|
-
|
4111
|
-
|
4112
|
-
|
4113
|
-
|
4114
|
-
|
4115
|
-
break;
|
4116
|
-
case 123:
|
4117
|
-
curly++;
|
4118
|
-
break;
|
4119
|
-
case 125:
|
4120
|
-
curly--;
|
4121
|
-
break;
|
4122
|
-
}
|
4123
|
-
if (c === 47) {
|
4124
|
-
let j = i - 1;
|
4125
|
-
let p;
|
4126
|
-
for (; j >= 0; j--) {
|
4127
|
-
p = exp.charAt(j);
|
4128
|
-
if (p !== " ") {
|
4129
|
-
break;
|
4130
|
-
}
|
4131
|
-
}
|
4132
|
-
if (!p || !validDivisionCharRE.test(p)) {
|
4133
|
-
inRegex = true;
|
4134
|
-
}
|
4135
|
-
}
|
4207
|
+
function createDirectiveKey(node, templateMeta, parserOptions, locationCalculator) {
|
4208
|
+
const directiveKey = parseDirectiveKeyStatically(node, templateMeta);
|
4209
|
+
const tokens = parseDirectiveKeyTokens(directiveKey);
|
4210
|
+
replaceTokens(templateMeta, directiveKey, tokens);
|
4211
|
+
if (directiveKey.name.name.startsWith("v-")) {
|
4212
|
+
directiveKey.name.name = directiveKey.name.name.slice(2);
|
4213
|
+
}
|
4214
|
+
if (directiveKey.name.rawName.startsWith("v-")) {
|
4215
|
+
directiveKey.name.rawName = directiveKey.name.rawName.slice(2);
|
4216
|
+
}
|
4217
|
+
convertDynamicArgument(
|
4218
|
+
directiveKey,
|
4219
|
+
templateMeta,
|
4220
|
+
parserOptions,
|
4221
|
+
locationCalculator
|
4222
|
+
);
|
4223
|
+
return directiveKey;
|
4224
|
+
}
|
4225
|
+
function convertToDirective(node, code, templateMeta, locationCalculator, vineFixLocationContext, parserOptions) {
|
4226
|
+
debug(
|
4227
|
+
'[template] convert to directive: %s="%s" %j',
|
4228
|
+
node.key.name,
|
4229
|
+
node.value && node.value.value,
|
4230
|
+
node.range
|
4231
|
+
);
|
4232
|
+
const directive = node;
|
4233
|
+
directive.directive = true;
|
4234
|
+
directive.key = createDirectiveKey(
|
4235
|
+
node.key,
|
4236
|
+
templateMeta,
|
4237
|
+
parserOptions,
|
4238
|
+
locationCalculator
|
4239
|
+
);
|
4240
|
+
const { argument } = directive.key;
|
4241
|
+
if (argument && argument.type === "VIdentifier" && argument.name.startsWith("[")) {
|
4242
|
+
const nextChar = code[argument.range[1]];
|
4243
|
+
if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) {
|
4244
|
+
const char = nextChar == null ? "EOF" : JSON.stringify(nextChar).slice(1, -1);
|
4245
|
+
insertError(
|
4246
|
+
templateMeta,
|
4247
|
+
new ParseError(
|
4248
|
+
`Dynamic argument cannot contain the '${char}' character.`,
|
4249
|
+
void 0,
|
4250
|
+
argument.range[1],
|
4251
|
+
argument.loc.end.line,
|
4252
|
+
argument.loc.end.column
|
4253
|
+
)
|
4254
|
+
);
|
4255
|
+
}
|
4256
|
+
}
|
4257
|
+
if (node.value == null) {
|
4258
|
+
if (directive.key.name.name === "bind") {
|
4259
|
+
convertForVBindSameNameShorthandValue(
|
4260
|
+
directive,
|
4261
|
+
parserOptions,
|
4262
|
+
locationCalculator
|
4263
|
+
);
|
4136
4264
|
}
|
4265
|
+
return;
|
4137
4266
|
}
|
4138
|
-
result.push(exp.slice(lastFilterIndex));
|
4139
|
-
return result;
|
4140
|
-
}
|
4141
|
-
function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
|
4142
|
-
debug('[script] parse expression: "0(%s)"', code);
|
4143
4267
|
try {
|
4144
|
-
const
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4268
|
+
const ret = parseAttributeValue(
|
4269
|
+
code,
|
4270
|
+
parserOptions,
|
4271
|
+
locationCalculator,
|
4272
|
+
node.value,
|
4273
|
+
node.parent.parent,
|
4274
|
+
directive.key
|
4148
4275
|
);
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
if (expression && expression.type === "SpreadElement") {
|
4160
|
-
return throwUnexpectedTokenError("...", expression);
|
4276
|
+
directive.value = {
|
4277
|
+
type: "VExpressionContainer",
|
4278
|
+
range: node.value.range,
|
4279
|
+
loc: node.value.loc,
|
4280
|
+
parent: directive,
|
4281
|
+
expression: ret.expression,
|
4282
|
+
references: ret.references
|
4283
|
+
};
|
4284
|
+
if (ret.expression != null) {
|
4285
|
+
ret.expression.parent = directive.value;
|
4161
4286
|
}
|
4162
|
-
|
4163
|
-
|
4164
|
-
return throwUnexpectedTokenError(
|
4165
|
-
",",
|
4166
|
-
getCommaTokenBeforeNode(tokens, node) || node
|
4167
|
-
);
|
4287
|
+
for (const variable of ret.variables) {
|
4288
|
+
node.parent.parent.variables.push(variable);
|
4168
4289
|
}
|
4169
|
-
tokens
|
4170
|
-
|
4171
|
-
tokens.pop();
|
4172
|
-
return { expression, tokens, comments, references, variables: [] };
|
4290
|
+
replaceTokens(templateMeta, node.value, ret.tokens);
|
4291
|
+
insertComments(templateMeta, ret.comments);
|
4173
4292
|
} catch (err) {
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
|
4183
|
-
range: [0, 0],
|
4184
|
-
loc: {},
|
4185
|
-
callee: null,
|
4186
|
-
arguments: []
|
4187
|
-
};
|
4188
|
-
const tokens = [];
|
4189
|
-
const comments = [];
|
4190
|
-
const references = [];
|
4191
|
-
const paren = code.indexOf("(");
|
4192
|
-
const calleeCode = paren === -1 ? code : code.slice(0, paren);
|
4193
|
-
const argsCode = paren === -1 ? null : code.slice(paren);
|
4194
|
-
if (calleeCode.trim()) {
|
4195
|
-
const spaces = /^\s*/u.exec(calleeCode)[0];
|
4196
|
-
const subCalculator = locationCalculator.getSubCalculatorShift(
|
4197
|
-
spaces.length
|
4198
|
-
);
|
4199
|
-
const { ast } = parseScriptFragment(
|
4200
|
-
`"${calleeCode.trim()}"`,
|
4201
|
-
subCalculator,
|
4202
|
-
parserOptions
|
4203
|
-
);
|
4204
|
-
const statement = ast.body[0];
|
4205
|
-
const callee = statement.expression;
|
4206
|
-
if (callee.type !== "Literal") {
|
4207
|
-
const { loc, range } = ast.tokens[0];
|
4208
|
-
return throwUnexpectedTokenError('"', {
|
4209
|
-
range: [range[1] - 1, range[1]],
|
4210
|
-
loc: {
|
4211
|
-
start: {
|
4212
|
-
line: loc.end.line,
|
4213
|
-
column: loc.end.column - 1
|
4214
|
-
},
|
4215
|
-
end: loc.end
|
4216
|
-
}
|
4217
|
-
});
|
4218
|
-
}
|
4219
|
-
expression.callee = {
|
4220
|
-
type: "Identifier",
|
4221
|
-
parent: expression,
|
4222
|
-
range: [
|
4223
|
-
callee.range[0],
|
4224
|
-
subCalculator.getOffsetWithGap(calleeCode.trim().length)
|
4225
|
-
],
|
4226
|
-
loc: {
|
4227
|
-
start: callee.loc.start,
|
4228
|
-
end: subCalculator.getLocation(calleeCode.trim().length)
|
4229
|
-
},
|
4230
|
-
name: String(callee.value)
|
4293
|
+
debug("[template] Parse error: %s", err);
|
4294
|
+
if (ParseError.isParseError(err)) {
|
4295
|
+
directive.value = {
|
4296
|
+
type: "VExpressionContainer",
|
4297
|
+
range: node.value.range,
|
4298
|
+
loc: node.value.loc,
|
4299
|
+
parent: directive,
|
4300
|
+
expression: null,
|
4301
|
+
references: []
|
4231
4302
|
};
|
4232
|
-
|
4233
|
-
type: "Identifier",
|
4234
|
-
value: calleeCode.trim(),
|
4235
|
-
range: expression.callee.range,
|
4236
|
-
loc: expression.callee.loc
|
4237
|
-
});
|
4303
|
+
insertError(templateMeta, err);
|
4238
4304
|
} else {
|
4239
|
-
|
4240
|
-
}
|
4241
|
-
if (argsCode != null) {
|
4242
|
-
const result = parseScriptFragment(
|
4243
|
-
`0${argsCode}`,
|
4244
|
-
locationCalculator.getSubCalculatorAfter(paren).getSubCalculatorShift(-1),
|
4245
|
-
parserOptions
|
4246
|
-
);
|
4247
|
-
const { ast } = result;
|
4248
|
-
const statement = ast.body[0];
|
4249
|
-
const callExpression = statement.expression;
|
4250
|
-
ast.tokens.shift();
|
4251
|
-
if (callExpression.type !== "CallExpression" || callExpression.callee.type !== "Literal") {
|
4252
|
-
let nestCount = 1;
|
4253
|
-
for (const token2 of ast.tokens.slice(1)) {
|
4254
|
-
if (nestCount === 0) {
|
4255
|
-
return throwUnexpectedTokenError(token2.value, token2);
|
4256
|
-
}
|
4257
|
-
if (token2.type === "Punctuator" && token2.value === "(") {
|
4258
|
-
nestCount += 1;
|
4259
|
-
}
|
4260
|
-
if (token2.type === "Punctuator" && token2.value === ")") {
|
4261
|
-
nestCount -= 1;
|
4262
|
-
}
|
4263
|
-
}
|
4264
|
-
const token = (0, import_last2.default)(ast.tokens);
|
4265
|
-
return throwUnexpectedTokenError(token.value, token);
|
4266
|
-
}
|
4267
|
-
for (const argument of callExpression.arguments) {
|
4268
|
-
argument.parent = expression;
|
4269
|
-
expression.arguments.push(argument);
|
4270
|
-
}
|
4271
|
-
tokens.push(...ast.tokens);
|
4272
|
-
comments.push(...ast.comments);
|
4273
|
-
references.push(...analyzeExternalReferences(result, parserOptions));
|
4305
|
+
throw err;
|
4274
4306
|
}
|
4275
|
-
const firstToken = tokens[0];
|
4276
|
-
const lastToken = (0, import_last2.default)(tokens);
|
4277
|
-
expression.range = [firstToken.range[0], lastToken.range[1]];
|
4278
|
-
expression.loc = { start: firstToken.loc.start, end: lastToken.loc.end };
|
4279
|
-
return { expression, tokens, comments, references, variables: [] };
|
4280
|
-
} catch (err) {
|
4281
|
-
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
4282
|
-
}
|
4283
|
-
}
|
4284
|
-
function loadParser(parser) {
|
4285
|
-
if (parser !== "espree") {
|
4286
|
-
const __require = createRequire(
|
4287
|
-
typeof __filename ? __filename : fileURLToPath(import.meta.url)
|
4288
|
-
);
|
4289
|
-
return __require(parser);
|
4290
|
-
}
|
4291
|
-
return getEspreeFromUser();
|
4292
|
-
}
|
4293
|
-
function parseScript(code, parserOptions) {
|
4294
|
-
const parser = typeof parserOptions.parser === "string" ? loadParser(parserOptions.parser) : isParserObject(parserOptions.parser) ? parserOptions.parser : getEspreeFromEcmaVersion(parserOptions.ecmaVersion);
|
4295
|
-
const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code, parserOptions) : parser.parse(code, parserOptions);
|
4296
|
-
if (result.ast != null) {
|
4297
|
-
return result;
|
4298
4307
|
}
|
4299
|
-
return { ast: result };
|
4300
4308
|
}
|
4301
|
-
function
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4309
|
+
function processMustache(parserOptions, globalLocationCalculator, vineFixLocationContext, templateMeta, node, mustache) {
|
4310
|
+
const range = [
|
4311
|
+
mustache.startToken.range[1],
|
4312
|
+
mustache.endToken.range[0]
|
4313
|
+
];
|
4314
|
+
debug("[template] convert mustache {{%s}} %j", mustache.value, range);
|
4315
|
+
try {
|
4316
|
+
const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
|
4317
|
+
const ret = parseExpression(
|
4318
|
+
mustache.value,
|
4307
4319
|
locationCalculator,
|
4308
4320
|
parserOptions,
|
4309
|
-
allowEmpty
|
4310
|
-
);
|
4311
|
-
}
|
4312
|
-
const retB = parseExpressionBody(
|
4313
|
-
mainCode,
|
4314
|
-
locationCalculator,
|
4315
|
-
parserOptions
|
4316
|
-
);
|
4317
|
-
if (!retB.expression) {
|
4318
|
-
return retB;
|
4319
|
-
}
|
4320
|
-
const ret = retB;
|
4321
|
-
ret.expression = {
|
4322
|
-
type: "VFilterSequenceExpression",
|
4323
|
-
parent: null,
|
4324
|
-
expression: retB.expression,
|
4325
|
-
filters: [],
|
4326
|
-
range: retB.expression.range.slice(0),
|
4327
|
-
loc: Object.assign({}, retB.expression.loc)
|
4328
|
-
};
|
4329
|
-
ret.expression.expression.parent = ret.expression;
|
4330
|
-
let prevLoc = mainCode.length;
|
4331
|
-
for (const filterCode of filterCodes) {
|
4332
|
-
ret.tokens.push(
|
4333
|
-
fixLocation(
|
4334
|
-
{
|
4335
|
-
type: "Punctuator",
|
4336
|
-
value: "|",
|
4337
|
-
range: [prevLoc, prevLoc + 1],
|
4338
|
-
loc: {}
|
4339
|
-
},
|
4340
|
-
locationCalculator
|
4341
|
-
)
|
4342
|
-
);
|
4343
|
-
const retF = parseFilter(
|
4344
|
-
filterCode,
|
4345
|
-
locationCalculator.getSubCalculatorShift(prevLoc + 1),
|
4346
|
-
parserOptions
|
4321
|
+
{ allowEmpty: true, allowFilters: true }
|
4347
4322
|
);
|
4348
|
-
|
4349
|
-
|
4350
|
-
|
4351
|
-
|
4323
|
+
node.expression = ret.expression || null;
|
4324
|
+
node.references = ret.references;
|
4325
|
+
if (ret.expression != null) {
|
4326
|
+
ret.expression.parent = node;
|
4327
|
+
}
|
4328
|
+
replaceTokens(templateMeta, { range }, ret.tokens);
|
4329
|
+
insertComments(templateMeta, ret.comments);
|
4330
|
+
} catch (err) {
|
4331
|
+
debug("[template] Parse error: %s", err);
|
4332
|
+
if (ParseError.isParseError(err)) {
|
4333
|
+
insertError(templateMeta, err);
|
4334
|
+
} else {
|
4335
|
+
throw err;
|
4336
|
+
}
|
4337
|
+
}
|
4338
|
+
}
|
4339
|
+
function resolveReference(referene, element) {
|
4340
|
+
let node = element;
|
4341
|
+
while (node != null && node.type === "VElement") {
|
4342
|
+
for (const variable of node.variables) {
|
4343
|
+
if (variable.id.name === referene.id.name) {
|
4344
|
+
referene.variable = variable;
|
4345
|
+
variable.references.push(referene);
|
4346
|
+
return;
|
4352
4347
|
}
|
4353
|
-
ret.tokens.push(...retF.tokens);
|
4354
|
-
ret.comments.push(...retF.comments);
|
4355
|
-
ret.references.push(...retF.references);
|
4356
4348
|
}
|
4357
|
-
|
4349
|
+
node = node.parent;
|
4358
4350
|
}
|
4359
|
-
const lastToken = (0, import_last2.default)(ret.tokens);
|
4360
|
-
ret.expression.range[1] = lastToken.range[1];
|
4361
|
-
ret.expression.loc.end = lastToken.loc.end;
|
4362
|
-
return ret;
|
4363
4351
|
}
|
4364
|
-
function
|
4365
|
-
|
4366
|
-
|
4352
|
+
function resolveReferences(container) {
|
4353
|
+
let element = container.parent;
|
4354
|
+
while (element != null && element.type !== "VElement") {
|
4355
|
+
element = element.parent;
|
4367
4356
|
}
|
4368
|
-
if (
|
4369
|
-
|
4370
|
-
|
4371
|
-
|
4372
|
-
parserOptions
|
4373
|
-
);
|
4357
|
+
if (element != null) {
|
4358
|
+
for (const reference of container.references) {
|
4359
|
+
resolveReference(reference, element);
|
4360
|
+
}
|
4374
4361
|
}
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4362
|
+
}
|
4363
|
+
function convertForVBindSameNameShorthandValue(directive, parserOptions, locationCalculator) {
|
4364
|
+
if (directive.key.name.name !== "bind" || directive.key.argument == null || directive.key.argument.type !== "VIdentifier") {
|
4365
|
+
return;
|
4378
4366
|
}
|
4367
|
+
const vId = directive.key.argument;
|
4368
|
+
const camelName = camelize(vId.name);
|
4369
|
+
let result = null;
|
4379
4370
|
try {
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
processed.delimiter,
|
4384
|
-
processed.iterator
|
4385
|
-
);
|
4386
|
-
const result = parseScriptFragment(
|
4387
|
-
`for(let ${processed.aliasesWithBrackets}${processed.delimiter}${processed.iterator});`,
|
4388
|
-
locationCalculator.getSubCalculatorShift(
|
4389
|
-
processed.hasParens ? -8 : -9
|
4390
|
-
),
|
4391
|
-
parserOptions
|
4392
|
-
);
|
4393
|
-
const { ast } = result;
|
4394
|
-
const tokens = ast.tokens || [];
|
4395
|
-
const comments = ast.comments || [];
|
4396
|
-
const scope = analyzeVariablesAndExternalReferences(
|
4397
|
-
result,
|
4398
|
-
"v-for",
|
4371
|
+
result = parseScriptFragment(
|
4372
|
+
camelName,
|
4373
|
+
locationCalculator.getSubCalculatorAfter(vId.range[0]),
|
4399
4374
|
parserOptions
|
4400
4375
|
);
|
4401
|
-
|
4402
|
-
|
4403
|
-
|
4404
|
-
|
4405
|
-
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4376
|
+
} catch (err) {
|
4377
|
+
debug("[template] Parse error: %s", err);
|
4378
|
+
}
|
4379
|
+
if (result == null || result.ast.body.length !== 1 || result.ast.body[0].type !== "ExpressionStatement" || result.ast.body[0].expression.type !== "Identifier") {
|
4380
|
+
return;
|
4381
|
+
}
|
4382
|
+
const id = result.ast.body[0].expression;
|
4383
|
+
id.range[1] = vId.range[1];
|
4384
|
+
id.loc.end = { ...vId.loc.end };
|
4385
|
+
if (id.end != null) {
|
4386
|
+
id.end = vId.end;
|
4387
|
+
}
|
4388
|
+
directive.value = {
|
4389
|
+
type: "VExpressionContainer",
|
4390
|
+
range: [...vId.range],
|
4391
|
+
loc: {
|
4392
|
+
start: { ...vId.loc.start },
|
4393
|
+
end: { ...vId.loc.end }
|
4394
|
+
},
|
4395
|
+
parent: directive,
|
4396
|
+
expression: id,
|
4397
|
+
references: [
|
4398
|
+
{
|
4399
|
+
id,
|
4400
|
+
mode: "r",
|
4401
|
+
variable: null
|
4426
4402
|
}
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4439
|
-
|
4440
|
-
|
4441
|
-
|
4442
|
-
|
4443
|
-
|
4403
|
+
]
|
4404
|
+
};
|
4405
|
+
id.parent = directive.value;
|
4406
|
+
}
|
4407
|
+
|
4408
|
+
// src/script/scope-analyzer.ts
|
4409
|
+
var BUILTIN_COMPONENTS = /* @__PURE__ */ new Set([
|
4410
|
+
"template",
|
4411
|
+
"slot",
|
4412
|
+
"component",
|
4413
|
+
"Component",
|
4414
|
+
"transition",
|
4415
|
+
"Transition",
|
4416
|
+
"transition-group",
|
4417
|
+
"TransitionGroup",
|
4418
|
+
"keep-alive",
|
4419
|
+
"KeepAlive",
|
4420
|
+
"teleport",
|
4421
|
+
"Teleport",
|
4422
|
+
"suspense",
|
4423
|
+
"Suspense"
|
4424
|
+
]);
|
4425
|
+
var BUILTIN_DIRECTIVES = /* @__PURE__ */ new Set([
|
4426
|
+
"bind",
|
4427
|
+
"on",
|
4428
|
+
"text",
|
4429
|
+
"html",
|
4430
|
+
"show",
|
4431
|
+
"if",
|
4432
|
+
"else",
|
4433
|
+
"else-if",
|
4434
|
+
"for",
|
4435
|
+
"model",
|
4436
|
+
"slot",
|
4437
|
+
"pre",
|
4438
|
+
"cloak",
|
4439
|
+
"once",
|
4440
|
+
"memo",
|
4441
|
+
"is"
|
4442
|
+
]);
|
4443
|
+
var HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
4444
|
+
var SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
4445
|
+
var NATIVE_TAGS = /* @__PURE__ */ new Set([...HTML_TAGS.split(","), ...SVG_TAGS.split(",")]);
|
4446
|
+
function isUnique(reference, index, references) {
|
4447
|
+
return index === 0 || reference.identifier !== references[index - 1].identifier;
|
4448
|
+
}
|
4449
|
+
function capitalize(str) {
|
4450
|
+
return str[0].toUpperCase() + str.slice(1);
|
4451
|
+
}
|
4452
|
+
function hasDefinition(variable) {
|
4453
|
+
return variable.defs.length >= 1;
|
4454
|
+
}
|
4455
|
+
function transformReference(reference) {
|
4456
|
+
const ret = {
|
4457
|
+
id: reference.identifier,
|
4458
|
+
mode: reference.isReadOnly() ? "r" : reference.isWriteOnly() ? "w" : (
|
4459
|
+
/* otherwise */
|
4460
|
+
"rw"
|
4461
|
+
),
|
4462
|
+
variable: null,
|
4463
|
+
isValueReference: reference.isValueReference,
|
4464
|
+
isTypeReference: reference.isTypeReference
|
4465
|
+
};
|
4466
|
+
Object.defineProperty(ret, "variable", { enumerable: false });
|
4467
|
+
return ret;
|
4468
|
+
}
|
4469
|
+
function transformVariable(variable, kind) {
|
4470
|
+
const ret = {
|
4471
|
+
id: variable.defs[0].name,
|
4472
|
+
kind,
|
4473
|
+
references: []
|
4474
|
+
};
|
4475
|
+
Object.defineProperty(ret, "references", { enumerable: false });
|
4476
|
+
return ret;
|
4477
|
+
}
|
4478
|
+
function getForScope(scope) {
|
4479
|
+
const child = scope.childScopes[0];
|
4480
|
+
return child.block === scope.block ? child.childScopes[0] : child;
|
4481
|
+
}
|
4482
|
+
function analyzeScope(ast, parserOptions) {
|
4483
|
+
const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
|
4484
|
+
const ecmaFeatures = parserOptions.ecmaFeatures || {};
|
4485
|
+
const sourceType = parserOptions.sourceType || "script";
|
4486
|
+
const result = getEslintScope().analyze(ast, {
|
4487
|
+
ignoreEval: true,
|
4488
|
+
nodejsScope: false,
|
4489
|
+
impliedStrict: ecmaFeatures.impliedStrict,
|
4490
|
+
ecmaVersion,
|
4491
|
+
sourceType,
|
4492
|
+
fallback: getFallbackKeys
|
4493
|
+
});
|
4494
|
+
return result;
|
4495
|
+
}
|
4496
|
+
function analyze(parserResult, parserOptions) {
|
4497
|
+
const scopeManager = parserResult.scopeManager || analyzeScope(parserResult.ast, parserOptions);
|
4498
|
+
return scopeManager.globalScope;
|
4499
|
+
}
|
4500
|
+
function analyzeExternalReferences(parserResult, parserOptions) {
|
4501
|
+
const scope = analyze(parserResult, parserOptions);
|
4502
|
+
return scope.through.filter(isUnique).map(transformReference);
|
4503
|
+
}
|
4504
|
+
function analyzeVariablesAndExternalReferences(parserResult, kind, parserOptions) {
|
4505
|
+
const scope = analyze(parserResult, parserOptions);
|
4506
|
+
return {
|
4507
|
+
variables: getForScope(scope).variables.filter(hasDefinition).map((v) => transformVariable(v, kind)),
|
4508
|
+
references: scope.through.filter(isUnique).map(transformReference)
|
4509
|
+
};
|
4510
|
+
}
|
4511
|
+
function collectVariablesForVCF(tsFileScopeManager, templateRoot) {
|
4512
|
+
const scriptVariables = /* @__PURE__ */ new Map();
|
4513
|
+
const globalScope = tsFileScopeManager.globalScope;
|
4514
|
+
if (!globalScope) {
|
4515
|
+
return scriptVariables;
|
4516
|
+
}
|
4517
|
+
for (const variable of globalScope.variables) {
|
4518
|
+
scriptVariables.set(variable.name, variable);
|
4519
|
+
}
|
4520
|
+
const moduleScope = globalScope.childScopes.find(
|
4521
|
+
(scope) => scope.type === "module"
|
4522
|
+
);
|
4523
|
+
for (const variable of moduleScope && moduleScope.variables || []) {
|
4524
|
+
scriptVariables.set(variable.name, variable);
|
4525
|
+
}
|
4526
|
+
let foundVCF = templateRoot.parent;
|
4527
|
+
let foundVCFScope;
|
4528
|
+
if (templateRoot.parent) {
|
4529
|
+
do {
|
4530
|
+
foundVCF = foundVCF.parent;
|
4531
|
+
} while (foundVCF && foundVCF.type !== "FunctionDeclaration" && foundVCF.type !== "FunctionExpression" && foundVCF.type !== "ArrowFunctionExpression");
|
4532
|
+
if (foundVCF) {
|
4533
|
+
Object.assign(
|
4534
|
+
foundVCF,
|
4535
|
+
{ __isVine__: true }
|
4536
|
+
);
|
4537
|
+
const tryGetVCFScope = tsFileScopeManager.nodeToScope.get(foundVCF);
|
4538
|
+
if (tryGetVCFScope?.[0]) {
|
4539
|
+
foundVCFScope = tryGetVCFScope[0];
|
4540
|
+
for (const variable of foundVCFScope.variables) {
|
4541
|
+
scriptVariables.set(variable.name, variable);
|
4542
|
+
}
|
4543
|
+
const compFnPropsIdentifier = foundVCF.params?.[0]?.type === "Identifier" && foundVCF.params[0]?.name === "props" ? foundVCF.params[0] : null;
|
4544
|
+
const propsVar = scriptVariables.get("props");
|
4545
|
+
if (compFnPropsIdentifier && propsVar) {
|
4546
|
+
;
|
4547
|
+
propsVar.eslintUsed = true;
|
4548
|
+
propsVar.references.push(
|
4549
|
+
createVirtualVineFnPropsReference({
|
4550
|
+
foundVCFScope,
|
4551
|
+
compFnPropsIdentifier
|
4552
|
+
})
|
4553
|
+
);
|
4554
|
+
}
|
4444
4555
|
}
|
4445
4556
|
}
|
4446
|
-
right.parent = expression;
|
4447
|
-
return { expression, tokens, comments, references, variables };
|
4448
|
-
} catch (err) {
|
4449
|
-
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
4450
4557
|
}
|
4558
|
+
return scriptVariables;
|
4451
4559
|
}
|
4452
|
-
function
|
4453
|
-
const
|
4454
|
-
|
4455
|
-
|
4456
|
-
|
4457
|
-
|
4458
|
-
|
4459
|
-
return throwEmptyError(locationCalculator, "an alias");
|
4460
|
-
}
|
4461
|
-
try {
|
4462
|
-
const tokens = [];
|
4463
|
-
const comments = [];
|
4464
|
-
const parsedAliases = parseVForAliasesForEcmaVersion5(
|
4465
|
-
processed.aliasesWithBrackets,
|
4466
|
-
locationCalculator.getSubCalculatorShift(
|
4467
|
-
processed.hasParens ? 0 : -1
|
4468
|
-
),
|
4469
|
-
parserOptions
|
4470
|
-
);
|
4471
|
-
if (processed.hasParens) {
|
4472
|
-
const open = parsedAliases.tokens[0];
|
4473
|
-
if (open != null) {
|
4474
|
-
open.value = "(";
|
4475
|
-
}
|
4476
|
-
const close = (0, import_last2.default)(parsedAliases.tokens);
|
4477
|
-
if (close != null) {
|
4478
|
-
close.value = ")";
|
4479
|
-
}
|
4480
|
-
} else {
|
4481
|
-
parsedAliases.tokens.shift();
|
4482
|
-
parsedAliases.tokens.pop();
|
4560
|
+
function analyzeUsedInTemplateVariables(scopeManager, templateRoot) {
|
4561
|
+
const scriptVariables = collectVariablesForVCF(scopeManager, templateRoot);
|
4562
|
+
const markedVariables = /* @__PURE__ */ new Set();
|
4563
|
+
function markSetupReferenceVariableAsUsed(name) {
|
4564
|
+
if (scriptVariables.has(name)) {
|
4565
|
+
markVariableAsUsed(name);
|
4566
|
+
return true;
|
4483
4567
|
}
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
return throwEmptyError(locationCalculator, "an alias");
|
4568
|
+
const camelName = camelize(name);
|
4569
|
+
if (scriptVariables.has(camelName)) {
|
4570
|
+
markVariableAsUsed(camelName);
|
4571
|
+
return true;
|
4489
4572
|
}
|
4490
|
-
const
|
4491
|
-
|
4492
|
-
|
4493
|
-
|
4494
|
-
{
|
4495
|
-
type: processed.delimiter === "in" ? "Keyword" : "Identifier",
|
4496
|
-
value: processed.delimiter,
|
4497
|
-
start: delimiterStart,
|
4498
|
-
end: delimiterEnd,
|
4499
|
-
loc: {},
|
4500
|
-
range: [delimiterStart, delimiterEnd]
|
4501
|
-
},
|
4502
|
-
locationCalculator
|
4503
|
-
)
|
4504
|
-
);
|
4505
|
-
const parsedIterator = parseVForIteratorForEcmaVersion5(
|
4506
|
-
processed.iterator,
|
4507
|
-
locationCalculator.getSubCalculatorShift(delimiterEnd),
|
4508
|
-
parserOptions
|
4509
|
-
);
|
4510
|
-
tokens.push(...parsedIterator.tokens);
|
4511
|
-
comments.push(...parsedIterator.comments);
|
4512
|
-
const { right, references } = parsedIterator;
|
4513
|
-
const firstToken = tokens[0];
|
4514
|
-
const lastToken = (0, import_last2.default)(tokens) || firstToken;
|
4515
|
-
const expression = {
|
4516
|
-
type: "VForExpression",
|
4517
|
-
range: [firstToken.range[0], lastToken.range[1]],
|
4518
|
-
loc: { start: firstToken.loc.start, end: lastToken.loc.end },
|
4519
|
-
parent: DUMMY_PARENT2,
|
4520
|
-
left,
|
4521
|
-
right
|
4522
|
-
};
|
4523
|
-
for (const l of left) {
|
4524
|
-
if (l != null) {
|
4525
|
-
l.parent = expression;
|
4526
|
-
}
|
4573
|
+
const pascalName = capitalize(camelName);
|
4574
|
+
if (scriptVariables.has(pascalName)) {
|
4575
|
+
markVariableAsUsed(pascalName);
|
4576
|
+
return true;
|
4527
4577
|
}
|
4528
|
-
|
4529
|
-
return { expression, tokens, comments, references, variables };
|
4530
|
-
} catch (err) {
|
4531
|
-
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
4578
|
+
return false;
|
4532
4579
|
}
|
4533
|
-
|
4534
|
-
|
4535
|
-
|
4536
|
-
|
4537
|
-
|
4538
|
-
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
const variables = analyzeExternalReferences(result, parserOptions).map(
|
4544
|
-
transformVariable2
|
4545
|
-
);
|
4546
|
-
const statement = ast.body[0];
|
4547
|
-
const callExpression = statement.expression;
|
4548
|
-
const expression = callExpression.arguments[0];
|
4549
|
-
const left = expression.elements.filter(
|
4550
|
-
(e) => {
|
4551
|
-
if (e == null || e.type === "Identifier") {
|
4552
|
-
return true;
|
4553
|
-
}
|
4554
|
-
const errorToken = tokens.find(
|
4555
|
-
(t) => e.range[0] <= t.range[0] && t.range[1] <= e.range[1]
|
4556
|
-
);
|
4557
|
-
return throwUnexpectedTokenError(errorToken.value, errorToken);
|
4580
|
+
function markVariableAsUsed(nameOrRef) {
|
4581
|
+
let name;
|
4582
|
+
let isValueReference;
|
4583
|
+
let isTypeReference;
|
4584
|
+
if (typeof nameOrRef === "string") {
|
4585
|
+
name = nameOrRef;
|
4586
|
+
} else {
|
4587
|
+
name = nameOrRef.id.name;
|
4588
|
+
isValueReference = nameOrRef.isValueReference;
|
4589
|
+
isTypeReference = nameOrRef.isTypeReference;
|
4558
4590
|
}
|
4559
|
-
|
4560
|
-
|
4561
|
-
|
4562
|
-
|
4563
|
-
|
4564
|
-
|
4565
|
-
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
|
4571
|
-
|
4572
|
-
|
4573
|
-
|
4574
|
-
|
4575
|
-
|
4576
|
-
|
4577
|
-
|
4578
|
-
|
4579
|
-
|
4580
|
-
|
4581
|
-
|
4582
|
-
|
4583
|
-
|
4584
|
-
|
4585
|
-
|
4586
|
-
|
4587
|
-
if (!expression) {
|
4588
|
-
return throwEmptyError(locationCalculator, "an expression");
|
4589
|
-
}
|
4590
|
-
if (expression && expression.type === "SpreadElement") {
|
4591
|
-
return throwUnexpectedTokenError("...", expression);
|
4592
|
-
}
|
4593
|
-
const right = expression;
|
4594
|
-
tokens.shift();
|
4595
|
-
tokens.shift();
|
4596
|
-
tokens.pop();
|
4597
|
-
return { right, tokens, comments, references };
|
4598
|
-
}
|
4599
|
-
function parseVOnExpression(code, locationCalculator, parserOptions) {
|
4600
|
-
if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
|
4601
|
-
return parseExpressionBody(
|
4602
|
-
code,
|
4603
|
-
locationCalculator,
|
4604
|
-
parserOptions
|
4605
|
-
);
|
4606
|
-
}
|
4607
|
-
return parseVOnExpressionBody(
|
4608
|
-
code,
|
4609
|
-
locationCalculator,
|
4610
|
-
parserOptions
|
4611
|
-
);
|
4612
|
-
}
|
4613
|
-
function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
|
4614
|
-
debug('[script] parse v-on expression: "void function($event){%s}"', code);
|
4615
|
-
if (code.trim() === "") {
|
4616
|
-
throwEmptyError(locationCalculator, "statements");
|
4617
|
-
}
|
4618
|
-
try {
|
4619
|
-
const result = parseScriptFragment(
|
4620
|
-
`void function($event){${code}}`,
|
4621
|
-
locationCalculator.getSubCalculatorShift(-22),
|
4622
|
-
parserOptions
|
4623
|
-
);
|
4624
|
-
const { ast } = result;
|
4625
|
-
const references = analyzeExternalReferences(result, parserOptions);
|
4626
|
-
const outermostStatement = ast.body[0];
|
4627
|
-
const functionDecl = outermostStatement.expression.argument;
|
4628
|
-
const block = functionDecl.body;
|
4629
|
-
const body = block.body;
|
4630
|
-
const firstStatement = (0, import_first.default)(body);
|
4631
|
-
const lastStatement = (0, import_last2.default)(body);
|
4632
|
-
const expression = {
|
4633
|
-
type: "VOnExpression",
|
4634
|
-
range: [
|
4635
|
-
firstStatement != null ? firstStatement.range[0] : block.range[0] + 1,
|
4636
|
-
lastStatement != null ? lastStatement.range[1] : block.range[1] - 1
|
4637
|
-
],
|
4638
|
-
loc: {
|
4639
|
-
start: firstStatement != null ? firstStatement.loc.start : locationCalculator.getLocation(1),
|
4640
|
-
end: lastStatement != null ? lastStatement.loc.end : locationCalculator.getLocation(code.length + 1)
|
4641
|
-
},
|
4642
|
-
parent: DUMMY_PARENT2,
|
4643
|
-
body
|
4644
|
-
};
|
4645
|
-
const tokens = ast.tokens || [];
|
4646
|
-
const comments = ast.comments || [];
|
4647
|
-
for (const b of body) {
|
4648
|
-
b.parent = expression;
|
4591
|
+
const variable = scriptVariables.get(name);
|
4592
|
+
if (!variable || variable.identifiers.length === 0) {
|
4593
|
+
return;
|
4594
|
+
}
|
4595
|
+
if (markedVariables.has(name)) {
|
4596
|
+
return;
|
4597
|
+
}
|
4598
|
+
markedVariables.add(name);
|
4599
|
+
const reference = new tsEscopeTypes2.Reference(
|
4600
|
+
variable.identifiers[0],
|
4601
|
+
variable.scope,
|
4602
|
+
1 /* Read */,
|
4603
|
+
void 0,
|
4604
|
+
void 0,
|
4605
|
+
void 0,
|
4606
|
+
isValueReference ? 1 /* Value */ : isTypeReference ? 2 /* Type */ : void 0
|
4607
|
+
);
|
4608
|
+
reference.vueUsedInTemplate = true;
|
4609
|
+
reference.isWrite = () => false;
|
4610
|
+
reference.isWriteOnly = () => false;
|
4611
|
+
reference.isRead = () => true;
|
4612
|
+
reference.isReadOnly = () => true;
|
4613
|
+
reference.isReadWrite = () => false;
|
4614
|
+
variable.references.push(reference);
|
4615
|
+
reference.resolved = variable;
|
4616
|
+
if (reference.isTypeReference) {
|
4617
|
+
;
|
4618
|
+
variable.eslintUsed = true;
|
4649
4619
|
}
|
4650
|
-
tokens.splice(0, 6);
|
4651
|
-
tokens.pop();
|
4652
|
-
return { expression, tokens, comments, references, variables: [] };
|
4653
|
-
} catch (err) {
|
4654
|
-
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
4655
4620
|
}
|
4656
|
-
|
4657
|
-
|
4658
|
-
|
4659
|
-
|
4660
|
-
|
4661
|
-
|
4662
|
-
"an identifier or an array/object pattern"
|
4663
|
-
);
|
4621
|
+
function processVExpressionContainer(node) {
|
4622
|
+
for (const reference of node.references.filter(
|
4623
|
+
(ref) => ref.variable == null
|
4624
|
+
)) {
|
4625
|
+
markVariableAsUsed(reference);
|
4626
|
+
}
|
4664
4627
|
}
|
4665
|
-
|
4666
|
-
|
4667
|
-
|
4668
|
-
locationCalculator.getSubCalculatorShift(-14),
|
4669
|
-
parserOptions
|
4670
|
-
);
|
4671
|
-
const { ast } = result;
|
4672
|
-
const statement = ast.body[0];
|
4673
|
-
const rawExpression = statement.expression;
|
4674
|
-
const functionDecl = rawExpression.argument;
|
4675
|
-
const params = functionDecl.params;
|
4676
|
-
if (params.length === 0) {
|
4677
|
-
return {
|
4678
|
-
expression: null,
|
4679
|
-
tokens: [],
|
4680
|
-
comments: [],
|
4681
|
-
references: [],
|
4682
|
-
variables: []
|
4683
|
-
};
|
4628
|
+
function processVElement(node) {
|
4629
|
+
if (node.rawName === node.name && NATIVE_TAGS.has(node.rawName) || BUILTIN_COMPONENTS.has(node.rawName)) {
|
4630
|
+
return;
|
4684
4631
|
}
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
};
|
4703
|
-
for (const param of params) {
|
4704
|
-
param.parent = expression;
|
4632
|
+
if (!markSetupReferenceVariableAsUsed(node.rawName)) {
|
4633
|
+
const dotIndex = node.rawName.indexOf(".");
|
4634
|
+
if (dotIndex > 0) {
|
4635
|
+
markSetupReferenceVariableAsUsed(
|
4636
|
+
node.rawName.slice(0, dotIndex)
|
4637
|
+
);
|
4638
|
+
}
|
4639
|
+
}
|
4640
|
+
}
|
4641
|
+
function processVAttribute(node) {
|
4642
|
+
if (node.directive) {
|
4643
|
+
if (BUILTIN_DIRECTIVES.has(node.key.name.name)) {
|
4644
|
+
return;
|
4645
|
+
}
|
4646
|
+
markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`);
|
4647
|
+
} else if (node.key.name === "ref" && node.value) {
|
4648
|
+
markVariableAsUsed(node.value.value);
|
4705
4649
|
}
|
4706
|
-
tokens.shift();
|
4707
|
-
tokens.shift();
|
4708
|
-
tokens.shift();
|
4709
|
-
tokens.pop();
|
4710
|
-
tokens.pop();
|
4711
|
-
tokens.pop();
|
4712
|
-
return { expression, tokens, comments, references, variables };
|
4713
|
-
} catch (err) {
|
4714
|
-
return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
|
4715
4650
|
}
|
4651
|
+
traverseNodes(templateRoot, {
|
4652
|
+
enterNode(node) {
|
4653
|
+
if (node.type === "VExpressionContainer") {
|
4654
|
+
processVExpressionContainer(node);
|
4655
|
+
} else if (node.type === "VElement") {
|
4656
|
+
processVElement(node);
|
4657
|
+
} else if (node.type === "VAttribute") {
|
4658
|
+
processVAttribute(node);
|
4659
|
+
}
|
4660
|
+
},
|
4661
|
+
leaveNode() {
|
4662
|
+
}
|
4663
|
+
});
|
4716
4664
|
}
|
4717
4665
|
|
4718
|
-
// src/template/
|
4719
|
-
var
|
4720
|
-
var
|
4721
|
-
|
4722
|
-
|
4723
|
-
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
} else if (directiveName === "bind") {
|
4737
|
-
return "bind";
|
4666
|
+
// src/template/parser.ts
|
4667
|
+
var import_findLastIndex = __toESM(require_findLastIndex());
|
4668
|
+
var import_last3 = __toESM(require_last());
|
4669
|
+
import assert2 from "node:assert";
|
4670
|
+
|
4671
|
+
// src/common/location-calculator.ts
|
4672
|
+
var import_sortedLastIndex2 = __toESM(require_sortedLastIndex());
|
4673
|
+
|
4674
|
+
// src/common/lines-and-columns.ts
|
4675
|
+
var import_sortedLastIndex = __toESM(require_sortedLastIndex());
|
4676
|
+
var LinesAndColumns = class {
|
4677
|
+
ltOffsets;
|
4678
|
+
/**
|
4679
|
+
* Initialize.
|
4680
|
+
* @param ltOffsets The list of the offset of line terminators.
|
4681
|
+
*/
|
4682
|
+
constructor(ltOffsets) {
|
4683
|
+
this.ltOffsets = ltOffsets;
|
4738
4684
|
}
|
4739
|
-
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
tokens: [],
|
4756
|
-
comments: [],
|
4757
|
-
variables: [],
|
4758
|
-
references: []
|
4685
|
+
/**
|
4686
|
+
* Calculate the location of the given index.
|
4687
|
+
* @param index The index to calculate their location.
|
4688
|
+
* @returns The location of the index.
|
4689
|
+
*/
|
4690
|
+
getLocFromIndex(index) {
|
4691
|
+
const line = (0, import_sortedLastIndex.default)(this.ltOffsets, index) + 1;
|
4692
|
+
const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]);
|
4693
|
+
return { line, column };
|
4694
|
+
}
|
4695
|
+
createOffsetLocationCalculator(offset) {
|
4696
|
+
return {
|
4697
|
+
getFixOffset() {
|
4698
|
+
return offset;
|
4699
|
+
},
|
4700
|
+
getLocFromIndex: this.getLocFromIndex.bind(this)
|
4759
4701
|
};
|
4760
|
-
} else if (directiveKind === "for") {
|
4761
|
-
result = parseVForExpression(
|
4762
|
-
node.value,
|
4763
|
-
locationCalculator,
|
4764
|
-
parserOptions
|
4765
|
-
);
|
4766
|
-
} else if (directiveKind === "on" && directiveKey.argument != null) {
|
4767
|
-
result = parseVOnExpression(
|
4768
|
-
node.value,
|
4769
|
-
locationCalculator,
|
4770
|
-
parserOptions
|
4771
|
-
);
|
4772
|
-
} else if (directiveKind === "slot") {
|
4773
|
-
result = parseSlotScopeExpression(
|
4774
|
-
node.value,
|
4775
|
-
locationCalculator,
|
4776
|
-
parserOptions
|
4777
|
-
);
|
4778
|
-
} else if (directiveKind === "bind") {
|
4779
|
-
result = parseExpression(
|
4780
|
-
node.value,
|
4781
|
-
locationCalculator,
|
4782
|
-
parserOptions,
|
4783
|
-
{ allowFilters: true }
|
4784
|
-
);
|
4785
|
-
} else {
|
4786
|
-
result = parseExpression(
|
4787
|
-
node.value,
|
4788
|
-
locationCalculator,
|
4789
|
-
parserOptions
|
4790
|
-
);
|
4791
4702
|
}
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4797
|
-
|
4798
|
-
|
4799
|
-
|
4800
|
-
|
4703
|
+
};
|
4704
|
+
|
4705
|
+
// src/common/location-calculator.ts
|
4706
|
+
var LocationCalculatorForHtml = class _LocationCalculatorForHtml extends LinesAndColumns {
|
4707
|
+
gapOffsets;
|
4708
|
+
baseOffset;
|
4709
|
+
baseIndexOfGap;
|
4710
|
+
shiftOffset;
|
4711
|
+
/**
|
4712
|
+
* Initialize this calculator.
|
4713
|
+
* @param gapOffsets The list of the offset of removed characters in tokenization phase.
|
4714
|
+
* @param ltOffsets The list of the offset of line terminators.
|
4715
|
+
* @param baseOffset The base offset to calculate locations.
|
4716
|
+
* @param shiftOffset The shift offset to calculate locations.
|
4717
|
+
*/
|
4718
|
+
constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) {
|
4719
|
+
super(ltOffsets);
|
4720
|
+
this.gapOffsets = gapOffsets;
|
4721
|
+
this.ltOffsets = ltOffsets;
|
4722
|
+
this.baseOffset = baseOffset || 0;
|
4723
|
+
this.baseIndexOfGap = this.baseOffset === 0 ? 0 : (0, import_sortedLastIndex2.default)(gapOffsets, this.baseOffset);
|
4724
|
+
this.shiftOffset = shiftOffset;
|
4725
|
+
}
|
4726
|
+
/**
|
4727
|
+
* Get sub calculator which have the given base offset.
|
4728
|
+
* @param offset The base offset of new sub calculator.
|
4729
|
+
* @returns Sub calculator.
|
4730
|
+
*/
|
4731
|
+
getSubCalculatorAfter(offset) {
|
4732
|
+
return new _LocationCalculatorForHtml(
|
4733
|
+
this.gapOffsets,
|
4734
|
+
this.ltOffsets,
|
4735
|
+
this.baseOffset + offset,
|
4736
|
+
this.shiftOffset
|
4801
4737
|
);
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4807
|
-
|
4808
|
-
|
4809
|
-
|
4738
|
+
}
|
4739
|
+
/**
|
4740
|
+
* Get sub calculator that shifts the given offset.
|
4741
|
+
* @param offset The shift of new sub calculator.
|
4742
|
+
* @returns Sub calculator.
|
4743
|
+
*/
|
4744
|
+
getSubCalculatorShift(offset) {
|
4745
|
+
return new _LocationCalculatorForHtml(
|
4746
|
+
this.gapOffsets,
|
4747
|
+
this.ltOffsets,
|
4748
|
+
this.baseOffset,
|
4749
|
+
this.shiftOffset + offset
|
4810
4750
|
);
|
4811
4751
|
}
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4752
|
+
/**
|
4753
|
+
* Calculate gap at the given index.
|
4754
|
+
* @param index The index to calculate gap.
|
4755
|
+
*/
|
4756
|
+
_getGap(index) {
|
4757
|
+
const offsets = this.gapOffsets;
|
4758
|
+
let g0 = (0, import_sortedLastIndex2.default)(offsets, index + this.baseOffset);
|
4759
|
+
let pos = index + this.baseOffset + g0 - this.baseIndexOfGap;
|
4760
|
+
while (g0 < offsets.length && offsets[g0] <= pos) {
|
4761
|
+
g0 += 1;
|
4762
|
+
pos += 1;
|
4821
4763
|
}
|
4822
|
-
|
4823
|
-
const directiveKey = {
|
4824
|
-
type: "VDirectiveKey",
|
4825
|
-
range: node.range,
|
4826
|
-
loc: node.loc,
|
4827
|
-
parent: node.parent,
|
4828
|
-
name: null,
|
4829
|
-
argument: null,
|
4830
|
-
modifiers: []
|
4831
|
-
};
|
4832
|
-
let i = 0;
|
4833
|
-
function createIdentifier(start, end, name) {
|
4834
|
-
const id = {
|
4835
|
-
type: "VIdentifier",
|
4836
|
-
parent: directiveKey,
|
4837
|
-
range: [offset + start, offset + end],
|
4838
|
-
loc: {
|
4839
|
-
start: { column: column + start, line },
|
4840
|
-
end: { column: column + end, line }
|
4841
|
-
},
|
4842
|
-
name: name || text.slice(start, end),
|
4843
|
-
rawName: rawText.slice(start, end)
|
4844
|
-
};
|
4845
|
-
return id;
|
4764
|
+
return g0 - this.baseIndexOfGap;
|
4846
4765
|
}
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
directiveKey.name = createIdentifier(0, colon);
|
4855
|
-
i = colon + 1;
|
4856
|
-
}
|
4766
|
+
/**
|
4767
|
+
* Calculate the location of the given index.
|
4768
|
+
* @param index The index to calculate their location.
|
4769
|
+
* @returns The location of the index.
|
4770
|
+
*/
|
4771
|
+
getLocation(index) {
|
4772
|
+
return this.getLocFromIndex(this.getOffsetWithGap(index));
|
4857
4773
|
}
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
|
4863
|
-
|
4774
|
+
/**
|
4775
|
+
* Calculate the offset of the given index.
|
4776
|
+
* @param index The index to calculate their location.
|
4777
|
+
* @returns The offset of the index.
|
4778
|
+
*/
|
4779
|
+
getOffsetWithGap(index) {
|
4780
|
+
return index + this.getFixOffset(index);
|
4864
4781
|
}
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4871
|
-
|
4872
|
-
|
4873
|
-
offset + i,
|
4874
|
-
line,
|
4875
|
-
column + i
|
4876
|
-
)
|
4877
|
-
);
|
4878
|
-
}
|
4879
|
-
i += modifierName.length + 1;
|
4880
|
-
return modifier;
|
4881
|
-
});
|
4882
|
-
if (directiveKey.name == null) {
|
4883
|
-
directiveKey.name = modifiers.shift();
|
4884
|
-
} else if (directiveKey.argument == null && modifiers[0].name !== "") {
|
4885
|
-
directiveKey.argument = modifiers.shift() || null;
|
4782
|
+
/**
|
4783
|
+
* Gets the fix location offset of the given offset with using the base offset of this calculator.
|
4784
|
+
* @param offset The offset to modify.
|
4785
|
+
*/
|
4786
|
+
getFixOffset(offset) {
|
4787
|
+
const shiftOffset = this.shiftOffset;
|
4788
|
+
const gap = this._getGap(offset + shiftOffset);
|
4789
|
+
return this.baseOffset + gap + shiftOffset;
|
4886
4790
|
}
|
4887
|
-
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4893
|
-
|
4894
|
-
|
4895
|
-
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4791
|
+
};
|
4792
|
+
|
4793
|
+
// src/template/intermediate-tokenizer.ts
|
4794
|
+
var import_last2 = __toESM(require_last());
|
4795
|
+
import assert from "node:assert";
|
4796
|
+
var DUMMY_PARENT2 = Object.freeze({});
|
4797
|
+
function concat(text, token) {
|
4798
|
+
return text + token.value;
|
4799
|
+
}
|
4800
|
+
var IntermediateTokenizer = class {
|
4801
|
+
tokenizer;
|
4802
|
+
baseParserOptions;
|
4803
|
+
currentToken;
|
4804
|
+
attribute;
|
4805
|
+
attributeNames;
|
4806
|
+
expressionStartToken;
|
4807
|
+
expressionTokens;
|
4808
|
+
tokens;
|
4809
|
+
comments;
|
4810
|
+
/**
|
4811
|
+
* The source code text.
|
4812
|
+
*/
|
4813
|
+
get text() {
|
4814
|
+
return this.tokenizer.text;
|
4899
4815
|
}
|
4900
|
-
|
4901
|
-
|
4902
|
-
|
4903
|
-
|
4816
|
+
/**
|
4817
|
+
* The parse errors.
|
4818
|
+
*/
|
4819
|
+
get errors() {
|
4820
|
+
return this.tokenizer.errors;
|
4904
4821
|
}
|
4905
|
-
|
4906
|
-
|
4907
|
-
|
4908
|
-
|
4909
|
-
|
4910
|
-
const tokens = [];
|
4911
|
-
if (shorthand) {
|
4912
|
-
tokens.push({
|
4913
|
-
type: "Punctuator",
|
4914
|
-
range: name.range,
|
4915
|
-
loc: name.loc,
|
4916
|
-
value: name.rawName
|
4917
|
-
});
|
4918
|
-
} else {
|
4919
|
-
tokens.push({
|
4920
|
-
type: "HTMLIdentifier",
|
4921
|
-
range: name.range,
|
4922
|
-
loc: name.loc,
|
4923
|
-
value: name.rawName
|
4924
|
-
});
|
4925
|
-
if (argument) {
|
4926
|
-
tokens.push({
|
4927
|
-
type: "Punctuator",
|
4928
|
-
range: [name.range[1], argument.range[0]],
|
4929
|
-
loc: { start: name.loc.end, end: argument.loc.start },
|
4930
|
-
value: ":"
|
4931
|
-
});
|
4932
|
-
}
|
4822
|
+
/**
|
4823
|
+
* The current state.
|
4824
|
+
*/
|
4825
|
+
get state() {
|
4826
|
+
return this.tokenizer.state;
|
4933
4827
|
}
|
4934
|
-
|
4935
|
-
|
4936
|
-
type: "HTMLIdentifier",
|
4937
|
-
range: argument.range,
|
4938
|
-
loc: argument.loc,
|
4939
|
-
value: argument.rawName
|
4940
|
-
});
|
4828
|
+
set state(value) {
|
4829
|
+
this.tokenizer.state = value;
|
4941
4830
|
}
|
4942
|
-
|
4943
|
-
|
4944
|
-
|
4945
|
-
|
4946
|
-
|
4947
|
-
|
4948
|
-
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4831
|
+
/**
|
4832
|
+
* The current namespace.
|
4833
|
+
*/
|
4834
|
+
get namespace() {
|
4835
|
+
return this.tokenizer.namespace;
|
4836
|
+
}
|
4837
|
+
set namespace(value) {
|
4838
|
+
this.tokenizer.namespace = value;
|
4839
|
+
}
|
4840
|
+
/**
|
4841
|
+
* The current flag of expression enabled.
|
4842
|
+
*/
|
4843
|
+
get expressionEnabled() {
|
4844
|
+
return this.tokenizer.expressionEnabled;
|
4845
|
+
}
|
4846
|
+
set expressionEnabled(value) {
|
4847
|
+
this.tokenizer.expressionEnabled = value;
|
4848
|
+
}
|
4849
|
+
/**
|
4850
|
+
* Initialize this intermediate tokenizer.
|
4851
|
+
* @param tokenizer The tokenizer.
|
4852
|
+
*/
|
4853
|
+
constructor(tokenizer, parserOptions) {
|
4854
|
+
this.tokenizer = tokenizer;
|
4855
|
+
this.baseParserOptions = parserOptions;
|
4856
|
+
this.currentToken = null;
|
4857
|
+
this.attribute = null;
|
4858
|
+
this.attributeNames = /* @__PURE__ */ new Set();
|
4859
|
+
this.expressionStartToken = null;
|
4860
|
+
this.expressionTokens = [];
|
4861
|
+
this.tokens = [];
|
4862
|
+
this.comments = [];
|
4863
|
+
}
|
4864
|
+
/**
|
4865
|
+
* Get the next intermediate token.
|
4866
|
+
* @returns The intermediate token or null.
|
4867
|
+
*/
|
4868
|
+
nextToken() {
|
4869
|
+
let token = null;
|
4870
|
+
let result = null;
|
4871
|
+
while (result == null) {
|
4872
|
+
token = this.tokenizer.nextToken();
|
4873
|
+
if (token == null) {
|
4874
|
+
break;
|
4959
4875
|
}
|
4960
|
-
|
4961
|
-
|
4876
|
+
result = this[token.type](token);
|
4877
|
+
}
|
4878
|
+
if (result == null && token == null && this.currentToken != null) {
|
4879
|
+
result = this.commit();
|
4880
|
+
}
|
4881
|
+
return result;
|
4962
4882
|
}
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
4966
|
-
|
4967
|
-
|
4968
|
-
|
4883
|
+
/**
|
4884
|
+
* Commit the current token.
|
4885
|
+
*/
|
4886
|
+
commit() {
|
4887
|
+
assert(this.currentToken != null || this.expressionStartToken != null);
|
4888
|
+
let token = this.currentToken;
|
4889
|
+
this.currentToken = null;
|
4890
|
+
this.attribute = null;
|
4891
|
+
if (this.expressionStartToken != null) {
|
4892
|
+
const start = this.expressionStartToken;
|
4893
|
+
const end = (0, import_last2.default)(this.expressionTokens) || start;
|
4894
|
+
const value = this.expressionTokens.reduce(concat, start.value);
|
4895
|
+
this.expressionStartToken = null;
|
4896
|
+
this.expressionTokens = [];
|
4897
|
+
if (token == null) {
|
4898
|
+
token = {
|
4899
|
+
type: "Text",
|
4900
|
+
range: [start.range[0], end.range[1]],
|
4901
|
+
loc: { start: start.loc.start, end: end.loc.end },
|
4902
|
+
value
|
4903
|
+
};
|
4904
|
+
} else if (token.type === "Text") {
|
4905
|
+
token.range[1] = end.range[1];
|
4906
|
+
token.loc.end = end.loc.end;
|
4907
|
+
token.value += value;
|
4908
|
+
} else {
|
4909
|
+
throw new Error("unreachable");
|
4910
|
+
}
|
4911
|
+
}
|
4912
|
+
return token;
|
4969
4913
|
}
|
4970
|
-
|
4971
|
-
|
4972
|
-
|
4973
|
-
|
4974
|
-
|
4975
|
-
|
4914
|
+
/**
|
4915
|
+
* Report an invalid character error.
|
4916
|
+
* @param token The invalid token.
|
4917
|
+
* @param code The error code.
|
4918
|
+
*/
|
4919
|
+
reportParseError(token, code) {
|
4920
|
+
const error = ParseError.fromCode(
|
4921
|
+
code,
|
4922
|
+
token.range[0],
|
4923
|
+
token.loc.start.line,
|
4924
|
+
token.loc.start.column
|
4976
4925
|
);
|
4977
|
-
|
4978
|
-
|
4979
|
-
|
4980
|
-
|
4981
|
-
|
4982
|
-
|
4983
|
-
|
4984
|
-
|
4985
|
-
|
4986
|
-
|
4926
|
+
this.errors.push(error);
|
4927
|
+
debug("[html] syntax error:", error.message);
|
4928
|
+
}
|
4929
|
+
/**
|
4930
|
+
* Process the given comment token.
|
4931
|
+
* @param token The comment token to process.
|
4932
|
+
*/
|
4933
|
+
processComment(token) {
|
4934
|
+
this.comments.push(token);
|
4935
|
+
if (this.currentToken != null && this.currentToken.type === "Text") {
|
4936
|
+
return this.commit();
|
4987
4937
|
}
|
4988
|
-
|
4989
|
-
|
4990
|
-
|
4991
|
-
|
4992
|
-
|
4993
|
-
|
4994
|
-
|
4995
|
-
|
4996
|
-
|
4997
|
-
|
4998
|
-
|
4999
|
-
|
5000
|
-
|
5001
|
-
|
5002
|
-
|
5003
|
-
|
5004
|
-
|
5005
|
-
|
5006
|
-
|
5007
|
-
|
5008
|
-
|
5009
|
-
|
5010
|
-
|
5011
|
-
|
5012
|
-
type: "VExpressionContainer",
|
5013
|
-
range,
|
5014
|
-
loc,
|
5015
|
-
parent: node,
|
5016
|
-
expression: null,
|
5017
|
-
references: []
|
5018
|
-
};
|
5019
|
-
insertError(templateMeta, error);
|
5020
|
-
} else {
|
5021
|
-
throw error;
|
4938
|
+
return null;
|
4939
|
+
}
|
4940
|
+
/**
|
4941
|
+
* Process the given text token.
|
4942
|
+
* @param token The text token to process.
|
4943
|
+
*/
|
4944
|
+
processText(token) {
|
4945
|
+
this.tokens.push(token);
|
4946
|
+
let result = null;
|
4947
|
+
if (this.expressionStartToken != null) {
|
4948
|
+
const lastToken = (0, import_last2.default)(this.expressionTokens) || this.expressionStartToken;
|
4949
|
+
if (lastToken.range[1] === token.range[0]) {
|
4950
|
+
this.expressionTokens.push(token);
|
4951
|
+
return null;
|
4952
|
+
}
|
4953
|
+
result = this.commit();
|
4954
|
+
} else if (this.currentToken != null) {
|
4955
|
+
if (this.currentToken.type === "Text" && this.currentToken.range[1] === token.range[0]) {
|
4956
|
+
this.currentToken.value += token.value;
|
4957
|
+
this.currentToken.range[1] = token.range[1];
|
4958
|
+
this.currentToken.loc.end = token.loc.end;
|
4959
|
+
return null;
|
4960
|
+
}
|
4961
|
+
result = this.commit();
|
5022
4962
|
}
|
4963
|
+
assert(this.currentToken == null);
|
4964
|
+
this.currentToken = {
|
4965
|
+
type: "Text",
|
4966
|
+
range: [token.range[0], token.range[1]],
|
4967
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
4968
|
+
value: token.value
|
4969
|
+
};
|
4970
|
+
return result;
|
5023
4971
|
}
|
5024
|
-
|
5025
|
-
|
5026
|
-
|
5027
|
-
|
5028
|
-
|
5029
|
-
|
5030
|
-
|
4972
|
+
/**
|
4973
|
+
* Process a HTMLAssociation token.
|
4974
|
+
* @param token The token to process.
|
4975
|
+
*/
|
4976
|
+
HTMLAssociation(token) {
|
4977
|
+
this.tokens.push(token);
|
4978
|
+
if (this.attribute != null) {
|
4979
|
+
this.attribute.range[1] = token.range[1];
|
4980
|
+
this.attribute.loc.end = token.loc.end;
|
4981
|
+
if (this.currentToken == null || this.currentToken.type !== "StartTag") {
|
4982
|
+
throw new Error("unreachable");
|
4983
|
+
}
|
4984
|
+
this.currentToken.range[1] = token.range[1];
|
4985
|
+
this.currentToken.loc.end = token.loc.end;
|
4986
|
+
}
|
4987
|
+
return null;
|
5031
4988
|
}
|
5032
|
-
|
5033
|
-
|
4989
|
+
/**
|
4990
|
+
* Process a HTMLBogusComment token.
|
4991
|
+
* @param token The token to process.
|
4992
|
+
*/
|
4993
|
+
HTMLBogusComment(token) {
|
4994
|
+
return this.processComment(token);
|
5034
4995
|
}
|
5035
|
-
|
5036
|
-
|
5037
|
-
|
5038
|
-
|
5039
|
-
|
5040
|
-
|
5041
|
-
return directiveKey;
|
5042
|
-
}
|
5043
|
-
function convertToDirective(node, code, templateMeta, locationCalculator, vineFixLocationContext, parserOptions) {
|
5044
|
-
debug(
|
5045
|
-
'[template] convert to directive: %s="%s" %j',
|
5046
|
-
node.key.name,
|
5047
|
-
node.value && node.value.value,
|
5048
|
-
node.range
|
5049
|
-
);
|
5050
|
-
const directive = node;
|
5051
|
-
directive.directive = true;
|
5052
|
-
directive.key = createDirectiveKey(
|
5053
|
-
node.key,
|
5054
|
-
templateMeta,
|
5055
|
-
parserOptions,
|
5056
|
-
locationCalculator
|
5057
|
-
);
|
5058
|
-
const { argument } = directive.key;
|
5059
|
-
if (argument && argument.type === "VIdentifier" && argument.name.startsWith("[")) {
|
5060
|
-
const nextChar = code[argument.range[1]];
|
5061
|
-
if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) {
|
5062
|
-
const char = nextChar == null ? "EOF" : JSON.stringify(nextChar).slice(1, -1);
|
5063
|
-
insertError(
|
5064
|
-
templateMeta,
|
5065
|
-
new ParseError(
|
5066
|
-
`Dynamic argument cannot contain the '${char}' character.`,
|
5067
|
-
void 0,
|
5068
|
-
argument.range[1],
|
5069
|
-
argument.loc.end.line,
|
5070
|
-
argument.loc.end.column
|
5071
|
-
)
|
5072
|
-
);
|
5073
|
-
}
|
4996
|
+
/**
|
4997
|
+
* Process a HTMLCDataText token.
|
4998
|
+
* @param token The token to process.
|
4999
|
+
*/
|
5000
|
+
HTMLCDataText(token) {
|
5001
|
+
return this.processText(token);
|
5074
5002
|
}
|
5075
|
-
|
5076
|
-
|
5003
|
+
/**
|
5004
|
+
* Process a HTMLComment token.
|
5005
|
+
* @param token The token to process.
|
5006
|
+
*/
|
5007
|
+
HTMLComment(token) {
|
5008
|
+
return this.processComment(token);
|
5077
5009
|
}
|
5078
|
-
|
5079
|
-
|
5080
|
-
|
5081
|
-
|
5082
|
-
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5086
|
-
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
5090
|
-
|
5091
|
-
|
5092
|
-
|
5093
|
-
references: ret.references
|
5010
|
+
/**
|
5011
|
+
* Process a HTMLEndTagOpen token.
|
5012
|
+
* @param token The token to process.
|
5013
|
+
*/
|
5014
|
+
HTMLEndTagOpen(token) {
|
5015
|
+
this.tokens.push(token);
|
5016
|
+
let result = null;
|
5017
|
+
if (this.currentToken != null || this.expressionStartToken != null) {
|
5018
|
+
result = this.commit();
|
5019
|
+
}
|
5020
|
+
this.currentToken = {
|
5021
|
+
type: "EndTag",
|
5022
|
+
range: [token.range[0], token.range[1]],
|
5023
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
5024
|
+
name: token.value
|
5094
5025
|
};
|
5095
|
-
|
5096
|
-
|
5026
|
+
return result;
|
5027
|
+
}
|
5028
|
+
/**
|
5029
|
+
* Process a HTMLIdentifier token.
|
5030
|
+
* @param token The token to process.
|
5031
|
+
*/
|
5032
|
+
HTMLIdentifier(token) {
|
5033
|
+
this.tokens.push(token);
|
5034
|
+
if (this.currentToken == null || this.currentToken.type === "Text" || this.currentToken.type === "Mustache") {
|
5035
|
+
throw new Error("unreachable");
|
5097
5036
|
}
|
5098
|
-
|
5099
|
-
|
5037
|
+
if (this.currentToken.type === "EndTag") {
|
5038
|
+
this.reportParseError(token, "end-tag-with-attributes");
|
5039
|
+
return null;
|
5100
5040
|
}
|
5101
|
-
|
5102
|
-
|
5103
|
-
|
5104
|
-
|
5105
|
-
|
5106
|
-
|
5107
|
-
|
5108
|
-
|
5109
|
-
|
5110
|
-
|
5111
|
-
|
5112
|
-
|
5041
|
+
if (this.attributeNames.has(token.value)) {
|
5042
|
+
this.reportParseError(token, "duplicate-attribute");
|
5043
|
+
}
|
5044
|
+
this.attributeNames.add(token.value);
|
5045
|
+
this.attribute = {
|
5046
|
+
type: "VAttribute",
|
5047
|
+
range: [token.range[0], token.range[1]],
|
5048
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
5049
|
+
parent: DUMMY_PARENT2,
|
5050
|
+
directive: false,
|
5051
|
+
key: {
|
5052
|
+
type: "VIdentifier",
|
5053
|
+
range: [token.range[0], token.range[1]],
|
5054
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
5055
|
+
parent: DUMMY_PARENT2,
|
5056
|
+
name: token.value,
|
5057
|
+
rawName: this.text.slice(token.range[0], token.range[1])
|
5058
|
+
},
|
5059
|
+
value: null
|
5060
|
+
};
|
5061
|
+
this.attribute.key.parent = this.attribute;
|
5062
|
+
this.currentToken.range[1] = token.range[1];
|
5063
|
+
this.currentToken.loc.end = token.loc.end;
|
5064
|
+
this.currentToken.attributes.push(this.attribute);
|
5065
|
+
return null;
|
5066
|
+
}
|
5067
|
+
/**
|
5068
|
+
* Process a HTMLLiteral token.
|
5069
|
+
* @param token The token to process.
|
5070
|
+
*/
|
5071
|
+
HTMLLiteral(token) {
|
5072
|
+
this.tokens.push(token);
|
5073
|
+
if (this.attribute != null) {
|
5074
|
+
this.attribute.range[1] = token.range[1];
|
5075
|
+
this.attribute.loc.end = token.loc.end;
|
5076
|
+
this.attribute.value = {
|
5077
|
+
type: "VLiteral",
|
5078
|
+
range: [token.range[0], token.range[1]],
|
5079
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
5080
|
+
parent: this.attribute,
|
5081
|
+
value: token.value
|
5113
5082
|
};
|
5114
|
-
|
5115
|
-
|
5116
|
-
|
5083
|
+
if (this.currentToken == null || this.currentToken.type !== "StartTag") {
|
5084
|
+
throw new Error("unreachable");
|
5085
|
+
}
|
5086
|
+
this.currentToken.range[1] = token.range[1];
|
5087
|
+
this.currentToken.loc.end = token.loc.end;
|
5117
5088
|
}
|
5089
|
+
return null;
|
5118
5090
|
}
|
5119
|
-
|
5120
|
-
|
5121
|
-
|
5122
|
-
|
5123
|
-
|
5124
|
-
|
5125
|
-
|
5126
|
-
|
5127
|
-
|
5128
|
-
|
5129
|
-
|
5130
|
-
|
5131
|
-
|
5132
|
-
|
5133
|
-
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5091
|
+
/**
|
5092
|
+
* Process a HTMLRCDataText token.
|
5093
|
+
* @param token The token to process.
|
5094
|
+
*/
|
5095
|
+
HTMLRCDataText(token) {
|
5096
|
+
return this.processText(token);
|
5097
|
+
}
|
5098
|
+
/**
|
5099
|
+
* Process a HTMLRawText token.
|
5100
|
+
* @param token The token to process.
|
5101
|
+
*/
|
5102
|
+
HTMLRawText(token) {
|
5103
|
+
return this.processText(token);
|
5104
|
+
}
|
5105
|
+
/**
|
5106
|
+
* Process a HTMLSelfClosingTagClose token.
|
5107
|
+
* @param token The token to process.
|
5108
|
+
*/
|
5109
|
+
HTMLSelfClosingTagClose(token) {
|
5110
|
+
this.tokens.push(token);
|
5111
|
+
if (this.currentToken == null || this.currentToken.type === "Text") {
|
5112
|
+
throw new Error("unreachable");
|
5138
5113
|
}
|
5139
|
-
|
5140
|
-
|
5141
|
-
} catch (err) {
|
5142
|
-
debug("[template] Parse error: %s", err);
|
5143
|
-
if (ParseError.isParseError(err)) {
|
5144
|
-
insertError(templateMeta, err);
|
5114
|
+
if (this.currentToken.type === "StartTag") {
|
5115
|
+
this.currentToken.selfClosing = true;
|
5145
5116
|
} else {
|
5146
|
-
|
5117
|
+
this.reportParseError(token, "end-tag-with-trailing-solidus");
|
5147
5118
|
}
|
5119
|
+
this.currentToken.range[1] = token.range[1];
|
5120
|
+
this.currentToken.loc.end = token.loc.end;
|
5121
|
+
return this.commit();
|
5148
5122
|
}
|
5149
|
-
|
5150
|
-
|
5151
|
-
|
5152
|
-
|
5153
|
-
|
5154
|
-
|
5155
|
-
|
5156
|
-
|
5157
|
-
return;
|
5158
|
-
}
|
5123
|
+
/**
|
5124
|
+
* Process a HTMLTagClose token.
|
5125
|
+
* @param token The token to process.
|
5126
|
+
*/
|
5127
|
+
HTMLTagClose(token) {
|
5128
|
+
this.tokens.push(token);
|
5129
|
+
if (this.currentToken == null || this.currentToken.type === "Text") {
|
5130
|
+
throw new Error("unreachable");
|
5159
5131
|
}
|
5160
|
-
|
5132
|
+
this.currentToken.range[1] = token.range[1];
|
5133
|
+
this.currentToken.loc.end = token.loc.end;
|
5134
|
+
return this.commit();
|
5161
5135
|
}
|
5162
|
-
|
5163
|
-
|
5164
|
-
|
5165
|
-
|
5166
|
-
|
5136
|
+
/**
|
5137
|
+
* Process a HTMLTagOpen token.
|
5138
|
+
* @param token The token to process.
|
5139
|
+
*/
|
5140
|
+
HTMLTagOpen(token) {
|
5141
|
+
this.tokens.push(token);
|
5142
|
+
let result = null;
|
5143
|
+
if (this.currentToken != null || this.expressionStartToken != null) {
|
5144
|
+
result = this.commit();
|
5145
|
+
}
|
5146
|
+
this.currentToken = {
|
5147
|
+
type: "StartTag",
|
5148
|
+
range: [token.range[0], token.range[1]],
|
5149
|
+
loc: { start: token.loc.start, end: token.loc.end },
|
5150
|
+
name: token.value,
|
5151
|
+
rawName: this.text.slice(token.range[0] + 1, token.range[1]),
|
5152
|
+
selfClosing: false,
|
5153
|
+
attributes: []
|
5154
|
+
};
|
5155
|
+
this.attribute = null;
|
5156
|
+
this.attributeNames.clear();
|
5157
|
+
return result;
|
5167
5158
|
}
|
5168
|
-
|
5169
|
-
|
5170
|
-
|
5159
|
+
/**
|
5160
|
+
* Process a HTMLText token.
|
5161
|
+
* @param token The token to process.
|
5162
|
+
*/
|
5163
|
+
HTMLText(token) {
|
5164
|
+
return this.processText(token);
|
5165
|
+
}
|
5166
|
+
/**
|
5167
|
+
* Process a HTMLWhitespace token.
|
5168
|
+
* @param token The token to process.
|
5169
|
+
*/
|
5170
|
+
HTMLWhitespace(token) {
|
5171
|
+
return this.processText(token);
|
5172
|
+
}
|
5173
|
+
/**
|
5174
|
+
* Process a VExpressionStart token.
|
5175
|
+
* @param token The token to process.
|
5176
|
+
*/
|
5177
|
+
VExpressionStart(token) {
|
5178
|
+
if (this.expressionStartToken != null) {
|
5179
|
+
return this.processText(token);
|
5171
5180
|
}
|
5181
|
+
const separated = this.currentToken != null && this.currentToken.range[1] !== token.range[0];
|
5182
|
+
const result = separated ? this.commit() : null;
|
5183
|
+
this.tokens.push(token);
|
5184
|
+
this.expressionStartToken = token;
|
5185
|
+
return result;
|
5172
5186
|
}
|
5173
|
-
|
5187
|
+
/**
|
5188
|
+
* Process a VExpressionEnd token.
|
5189
|
+
* @param token The token to process.
|
5190
|
+
*/
|
5191
|
+
VExpressionEnd(token) {
|
5192
|
+
if (this.expressionStartToken == null) {
|
5193
|
+
return this.processText(token);
|
5194
|
+
}
|
5195
|
+
const start = this.expressionStartToken;
|
5196
|
+
const end = (0, import_last2.default)(this.expressionTokens) || start;
|
5197
|
+
if (token.range[0] === start.range[1]) {
|
5198
|
+
this.tokens.pop();
|
5199
|
+
this.expressionStartToken = null;
|
5200
|
+
const result2 = this.processText(start);
|
5201
|
+
this.processText(token);
|
5202
|
+
return result2;
|
5203
|
+
}
|
5204
|
+
if (end.range[1] !== token.range[0]) {
|
5205
|
+
const result2 = this.commit();
|
5206
|
+
this.processText(token);
|
5207
|
+
return result2;
|
5208
|
+
}
|
5209
|
+
const value = this.expressionTokens.reduce(concat, "");
|
5210
|
+
this.tokens.push(token);
|
5211
|
+
this.expressionStartToken = null;
|
5212
|
+
this.expressionTokens = [];
|
5213
|
+
const result = this.currentToken != null ? this.commit() : null;
|
5214
|
+
this.currentToken = {
|
5215
|
+
type: "Mustache",
|
5216
|
+
range: [start.range[0], token.range[1]],
|
5217
|
+
loc: { start: start.loc.start, end: token.loc.end },
|
5218
|
+
value,
|
5219
|
+
startToken: start,
|
5220
|
+
endToken: token
|
5221
|
+
};
|
5222
|
+
return result || this.commit();
|
5223
|
+
}
|
5224
|
+
};
|
5174
5225
|
|
5175
5226
|
// src/template/utils/attribute-names.ts
|
5176
5227
|
var SVG_ATTRIBUTE_NAME_MAP = /* @__PURE__ */ new Map([
|