eslint-plugin-vue-scoped-css
Version:
ESLint plugin for Scoped CSS in Vue.js
33 lines (32 loc) • 1.33 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.unwrapTypesExpression = unwrapTypesExpression;
exports.getStringFromNode = getStringFromNode;
const eslint_utils_1 = __importDefault(require("@eslint-community/eslint-utils"));
const compat_1 = require("../../utils/compat");
function unwrapTypesExpression(node) {
return (node === null || node === void 0 ? void 0 : node.type) === "TSAsExpression" ? node.expression : node;
}
function getStringFromNode(node, context) {
const evaluated = eslint_utils_1.default.getStaticValue(node, getScope((0, compat_1.getSourceCode)(context).scopeManager, node));
if (evaluated && typeof evaluated.value === "string") {
return evaluated.value;
}
return null;
}
function getScope(scopeManager, currentNode) {
const inner = currentNode.type !== "Program";
for (let node = currentNode; node; node = node.parent) {
const scope = scopeManager.acquire(node, inner);
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
}
return scope;
}
}
return scopeManager.scopes[0];
}