• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / bc1d76309b018d77a67f6c8e445b3f8603de06b6

15 Dec 2025 08:23AM UTC coverage: 51.437%. First build
bc1d76309b018d77a67f6c8e445b3f8603de06b6

push

github

thijsoo
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into feature/schema_aggregator

8706 of 16079 branches covered (54.15%)

Branch coverage included in aggregate %.

5 of 29 new or added lines in 12 files covered. (17.24%)

32426 of 63887 relevant lines covered (50.76%)

45133.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/js/src/analysis/worker.js
1
// External dependencies.
2
import { get, merge } from "lodash";
3
import { AnalysisWorkerWrapper, createWorker } from "yoastseo";
4

5
// Internal dependencies.
6
import getContentLocale from "./getContentLocale";
7
import getDefaultQueryParams from "./getDefaultQueryParams";
8
import isContentAnalysisActive from "./isContentAnalysisActive";
9
import isKeywordAnalysisActive from "./isKeywordAnalysisActive";
10
import isInclusiveLanguageAnalysisActive from "./isInclusiveLanguageAnalysisActive";
11
import { enabledFeatures } from "@yoast/feature-flag";
12

13
/**
14
 * Instantiates an analysis worker (wrapper).
15
 *
16
 * @returns {AnalysisWorkerWrapper} The analysis worker.
17
 */
18
export function createAnalysisWorker() {
19
        const url    = get( window, [ "wpseoScriptData", "analysis", "worker", "url" ], "analysis-worker.js" );
×
20
        const worker = createWorker( url );
×
21
        const dependencies = get( window, [ "wpseoScriptData", "analysis", "worker", "dependencies" ], [] );
×
22
        const translations = [];
×
23

24
        for ( const dependency in dependencies ) {
×
25
                if ( ! Object.prototype.hasOwnProperty.call( dependencies, dependency ) ) {
×
26
                        continue;
×
27
                }
28

29
                /*
30
                 * Extract the locale and translation data from the translations script to send off to the worker.
31
                 *
32
                 * Example translationElement:
33
                 * <script id="yoast-seo-analysis-package-js-translations">
34
                 *         ( function( domain, translations ) {
35
                 *                 var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
36
                 *                 localeData[ "" ].domain = domain;
37
                 *                 wp.i18n.setLocaleData( localeData, domain );
38
                 *         } )( "wordpress-seo", { "locale_data": { "messages": { "": {} } } } );
39
                 * </script>
40
                 */
41
                const translationElement = window.document.getElementById( `${dependency}-js-translations` );
×
42
                if ( ! translationElement ) {
×
43
                        continue;
×
44
                }
45
                const text = translationElement.innerHTML.slice( 214 );
×
46
                const split = text.indexOf( "," );
×
47
                const domain = text.slice( 0, split - 1 );
×
48
                try {
×
49
                        // Since WP 6.9 the translation script has some extra code at the end, we need to find the proper end of the JSON.
NEW
50
                        const endRegex = /}}\s*\);/;
×
NEW
51
                        const match = endRegex.exec( text );
×
52
                        // Find the end index of the JSON data, after the curly braces.
NEW
53
                        const jsonEnd = match.index + 2;
×
NEW
54
                        const translationData = JSON.parse( text.slice( split + 1, jsonEnd ) );
×
55
                        translations.push( [ domain, translationData ] );
×
56
                } catch ( e ) {
57
                        console.warn( `Failed to parse translation data for ${dependency} to send to the Yoast SEO worker` );
×
58
                        continue;
×
59
                }
60
        }
61

62
        worker.postMessage( {
×
63
                dependencies,
64
                translations,
65
        } );
66

67
        return new AnalysisWorkerWrapper( worker );
×
68
}
69

70
/**
71
 * Retrieves the analysis configuration for the worker.
72
 *
73
 * @param {Object} [customConfiguration] The custom configuration to use.
74
 *
75
 * @returns {Object} The analysis configuration.
76
 */
77
export function getAnalysisConfiguration( customConfiguration = {} ) {
×
78
        const configuration = {
×
79
                locale: getContentLocale(),
80
                contentAnalysisActive: isContentAnalysisActive(),
81
                keywordAnalysisActive: isKeywordAnalysisActive(),
82
                inclusiveLanguageAnalysisActive: isInclusiveLanguageAnalysisActive(),
83
                defaultQueryParams: getDefaultQueryParams(),
84
                logLevel: get( window, [ "wpseoScriptData", "analysis", "worker", "log_level" ], "ERROR" ),
85
                enabledFeatures: enabledFeatures(),
86
        };
87

88
        return merge( configuration, customConfiguration );
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc