<commit_before>var _ = require('underscore'),
    urlTools = require('urltools'),
    cssom = require('cssom-papandreou'),
    AssetGraph = require('../'),
    uglifyJs = AssetGraph.JavaScript.uglifyJs;

module.exports = function (queryObj, options) {
    options = options || {};
    var bundleStrategyName = options.strategyName || 'oneBundlePerIncludingAsset';

    return function bundleRelations(assetGraph) {
        function getDiscriminatorForRelation(relation) {
            var discriminatorFragments = [];
            if (relation.conditionalComments) {
                Array.prototype.push.apply(discriminatorFragments, _.pluck(relation.conditionalComments, 'nodeValue'));
            }
            if (relation.type === 'HtmlStyle') {
                discriminatorFragments.push(relation.node.getAttribute('media') || 'all');
            }

            if (relation.type === 'HtmlScript') {
                if (relation.isLoaded) {
                    discriminatorFragments.push('isLoaded');
                }

                // Check relation.node.ownerDocument.documentElement,
                // otherwise node.matchesSelector throws an error for document fragments
                if (relation.node.ownerDocument.documentElement && relation.node.matchesSelector('head script')) {
                    discriminatorFragments.push('head');
                } else {
                    discriminatorFragments.push('body');
                }

                if (relation.to.strict) {
                    discriminatorFragments.push('strict');
                    var warning = new Error('Global "use strict"-directive. Splitting into multiple bundles to avoid side effects.');
                    warning.asset = relation.to;
                    assetGraph.emit('info', warning);
                }
            }
            return discriminatorFragments.join(':');
        }<commit_msg>bundleRelations: Don't rely on node.matchesSelector, which does not work for documents that don't have an <html> element.<commit_after>var _ = require('underscore'),
    urlTools = require('urltools'),
    cssom = require('cssom-papandreou'),
    AssetGraph = require('../'),
    uglifyJs = AssetGraph.JavaScript.uglifyJs;

module.exports = function (queryObj, options) {
    options = options || {};
    var bundleStrategyName = options.strategyName || 'oneBundlePerIncludingAsset';

    return function bundleRelations(assetGraph) {
        function getDiscriminatorForRelation(relation) {
            var discriminatorFragments = [];
            if (relation.conditionalComments) {
                Array.prototype.push.apply(discriminatorFragments, _.pluck(relation.conditionalComments, 'nodeValue'));
            }
            if (relation.type === 'HtmlStyle') {
                discriminatorFragments.push(relation.node.getAttribute('media') || 'all');
            }

            if (relation.type === 'HtmlScript') {
                if (relation.isLoaded) {
                    discriminatorFragments.push('isLoaded');
                }

                var isInsideHead = false,
                    parentNode = relation.node.parentNode;
                while (parentNode) {
                    if (parentNode.nodeName.toLowerCase() === 'head') {
                        isInsideHead = true;
                        break;
                    }
                    parentNode = parentNode.parentNode;
                }
                if (isInsideHead) {
                    discriminatorFragments.push('head');
                } else {
                    discriminatorFragments.push('body');
                }

                if (relation.to.strict) {
                    discriminatorFragments.push('strict');
                    var warning = new Error('Global "use strict"-directive. Splitting into multiple bundles to avoid side effects.');
                    warning.asset = relation.to;
                    assetGraph.emit('info', warning);
                }
            }
            return discriminatorFragments.join(':');
        }
{'fraction_non_alphanumeric': 0.10680809077454366, 'fraction_numerical': 0.0, 'mean_word_length': 1.8516174402250352, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6417896', 'n_tokens_mistral': 1021, 'n_tokens_neox': 956, 'n_words': 185}