eslint-plugin-vue-scoped-css
Version:
ESLint plugin for Scoped CSS in Vue.js
44 lines (43 loc) • 1.83 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getReferenceExpressions = getReferenceExpressions;
const context_1 = require("../../context");
const compat_1 = require("../../../utils/compat");
function getReferenceExpressions(expression, context) {
var _a, _b, _c, _d;
if (expression.type === "ConditionalExpression") {
const { consequent, alternate } = expression;
return [
...((_a = getReferenceExpressions(consequent, context)) !== null && _a !== void 0 ? _a : [consequent]),
...((_b = getReferenceExpressions(alternate, context)) !== null && _b !== void 0 ? _b : [alternate]),
];
}
if (expression.type === "LogicalExpression") {
const { left, right } = expression;
return [
...((_c = getReferenceExpressions(left, context)) !== null && _c !== void 0 ? _c : [left]),
...((_d = getReferenceExpressions(right, context)) !== null && _d !== void 0 ? _d : [right]),
];
}
if (expression.type !== "Identifier") {
return [expression];
}
if (!withinTemplate(expression, context)) {
return [expression];
}
const vueComponent = (0, context_1.getVueComponentContext)(context);
if (!vueComponent) {
return null;
}
const props = vueComponent.findVueComponentProperty(expression.name);
if (props == null) {
return null;
}
return props;
}
function withinTemplate(expr, context) {
var _a;
const templateBody = (0, compat_1.getSourceCode)(context).ast.templateBody;
const templateRange = (_a = templateBody === null || templateBody === void 0 ? void 0 : templateBody.range) !== null && _a !== void 0 ? _a : [0, 0];
return templateRange[0] <= expr.range[0] && expr.range[1] <= templateRange[1];
}
;