Sha256: 1b87794dd82c00d8ba0dc459ded34f703f0343f3a8f5aa23b4dc2e310032cba2

Contents?: true

Size: 1.59 KB

Versions: 41

Compression:

Stored size: 1.59 KB

Contents

var List = require('../common/List');

function getFirstMatchNode(matchNode) {
    if ('node' in matchNode) {
        return matchNode.node;
    }

    return getFirstMatchNode(matchNode.match[0]);
}

function getLastMatchNode(matchNode) {
    if ('node' in matchNode) {
        return matchNode.node;
    }

    return getLastMatchNode(matchNode.match[matchNode.match.length - 1]);
}

function matchFragments(lexer, ast, match, type, name) {
    function findFragments(matchNode) {
        if (matchNode.syntax !== null &&
            matchNode.syntax.type === type &&
            matchNode.syntax.name === name) {
            var start = getFirstMatchNode(matchNode);
            var end = getLastMatchNode(matchNode);

            lexer.syntax.walk(ast, function(node, item, list) {
                if (node === start) {
                    var nodes = new List();

                    do {
                        nodes.appendData(item.data);

                        if (item.data === end) {
                            break;
                        }

                        item = item.next;
                    } while (item !== null);

                    fragments.push({
                        parent: list,
                        nodes: nodes
                    });
                }
            });
        }

        if (Array.isArray(matchNode.match)) {
            matchNode.match.forEach(findFragments);
        }
    }

    var fragments = [];

    if (match.matched !== null) {
        findFragments(match.matched);
    }

    return fragments;
}

module.exports = {
    matchFragments: matchFragments
};

Version data entries

41 entries across 31 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/css-tree/lib/lexer/search.js
optimacms-0.1.61 spec/dummy/node_modules/csso/node_modules/css-tree/lib/lexer/search.js
disco_app-0.18.0 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.18.2 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.16.1 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.15.2 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.18.4 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.18.1 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.14.0 test/dummy/node_modules/css-tree/lib/lexer/search.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.7 node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.6 node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.5 node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.4 node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.3 node_modules/css-tree/lib/lexer/search.js
isomorfeus-preact-10.5.2 node_modules/css-tree/lib/lexer/search.js
tang-0.2.1 spec/tang_app/node_modules/csso/node_modules/css-tree/lib/lexer/search.js
tang-0.2.1 spec/tang_app/node_modules/css-tree/lib/lexer/search.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/csso/node_modules/css-tree/lib/lexer/search.js