svelte-preprocess
Version:
A Svelte preprocessor wrapper with baked in support for common used preprocessors
59 lines (58 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLanguage = exports.getLanguageFromAlias = exports.addLanguageAlias = exports.ALIAS_MAP = exports.SOURCE_MAP_PROP_MAP = void 0;
const path_1 = require("path");
exports.SOURCE_MAP_PROP_MAP = {
babel: ['sourceMaps', true],
typescript: ['sourceMap', true],
scss: ['sourceMap', true],
less: ['sourceMap', {}],
stylus: ['sourcemap', true],
postcss: ['map', true],
coffeescript: ['sourceMap', true],
globalStyle: ['sourceMap', true],
};
exports.ALIAS_MAP = new Map([
['pcss', 'css'],
['postcss', 'css'],
['sass', 'scss'],
['styl', 'stylus'],
['js', 'javascript'],
['coffee', 'coffeescript'],
['ts', 'typescript'],
]);
exports.addLanguageAlias = (entries) => entries.forEach((entry) => exports.ALIAS_MAP.set(...entry));
exports.getLanguageFromAlias = (alias) => {
return exports.ALIAS_MAP.get(alias) || alias;
};
exports.getLanguage = (attributes) => {
let alias = null;
if (attributes.lang) {
// istanbul ignore if
if (typeof attributes.lang !== 'string') {
throw new Error('lang attribute must be string');
}
alias = attributes.lang;
}
else if (attributes.type) {
// istanbul ignore if
if (typeof attributes.type !== 'string') {
throw new Error('type attribute must be string');
}
alias = attributes.type.replace(/^(text|application)\/(.*)$/, '$2');
}
else if (attributes.src) {
// istanbul ignore if
if (typeof attributes.src !== 'string') {
throw new Error('src attribute must be string');
}
const parts = path_1.basename(attributes.src).split('.');
if (parts.length > 1) {
alias = parts.pop();
}
}
return {
lang: exports.getLanguageFromAlias(alias),
alias,
};
};