@emitty/language-scss
Version:
A SCSS language support @emitty
40 lines (39 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const parser = require("scss-symbols-parser");
function parse(_filepath, buffer) {
const symbols = parser.parseSymbols(buffer.toString());
const references = symbols.imports.reduce((collection, symbol) => {
if (hasExtension(symbol.filepath)) {
collection.push(...[
symbol.filepath,
formatPartialImport(symbol.filepath)
]);
}
else {
collection.push(...[
`${symbol.filepath}.sass`,
`${symbol.filepath}.scss`,
// https://sass-lang.com/documentation/at-rules/import#index-files
`${symbol.filepath}/_index.sass`,
`${symbol.filepath}/_index.scss`,
// https://sass-lang.com/documentation/at-rules/import#partials
formatPartialImport(symbol.filepath, '.sass'),
formatPartialImport(symbol.filepath, '.scss')
]);
}
return collection;
}, []);
return Promise.resolve({ references });
}
exports.parse = parse;
function hasExtension(filepath) {
return path.extname(filepath) !== '';
}
function formatPartialImport(filepath, extension = '') {
const directory = path.dirname(filepath);
const name = path.basename(filepath);
const prefix = directory === '.' ? '' : `${directory}/`;
return `${prefix}_${name}${extension}`;
}