UNPKG

webpack-preprocessor-loader

Version:
48 lines (47 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDirective = exports.parse = void 0; /** * Convert raw result from basic reader to `IBlock` presentation. * * @param info Result object from reader * @returns */ function parse(info) { const { is_comment, raw, block } = info; let isDirective = false; let directive = ""; let condition = ""; if (is_comment) { [directive, condition] = getDirective(block); isDirective = directive !== ""; } else { isDirective = false; } return { block, condition, directive, isComment: is_comment, isDirective, raw, }; } exports.parse = parse; const REGEX_DIRECTIVE = /#!(\w+)\s*(.*)?/; /** * Extract directive and condition from the given content * * @export * @param {string} content * @returns {[string, string]} [directive, condition] */ function getDirective(content) { const matchGroup = REGEX_DIRECTIVE.exec(content); if (matchGroup !== null) { return [matchGroup[1], matchGroup[2] || ""]; } return ["", ""]; } exports.getDirective = getDirective;