Skip to content

Commit

Permalink
chore: remove unused selector engines (#4950)
Browse files Browse the repository at this point in the history
css and id are superseeded by the new css engine.
  • Loading branch information
dgozman authored Jan 8, 2021
1 parent 3f90405 commit f0a8729
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 343 deletions.
66 changes: 0 additions & 66 deletions src/server/injected/attributeSelectorEngine.ts

This file was deleted.

264 changes: 0 additions & 264 deletions src/server/injected/cssSelectorEngine.ts

This file was deleted.

36 changes: 24 additions & 12 deletions src/server/injected/injectedScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

import { createAttributeEngine } from './attributeSelectorEngine';
import { SelectorEngine, SelectorRoot } from './selectorEngine';
import { createTextSelector } from './textSelectorEngine';
import { XPathEngine } from './xpathSelectorEngine';
import { ParsedSelector, ParsedSelectorPart, parseSelector } from '../common/selectorParser';
import { FatalDOMError } from '../common/domErrors';
import { SelectorEvaluatorImpl, isVisible, parentElementOrShadowHost } from './selectorEvaluator';
import { createCSSEngine } from './cssSelectorEngine';
import { CSSComplexSelectorList } from '../common/cssParser';

type Predicate<T> = (progress: InjectedScriptProgress, continuePolling: symbol) => T | symbol;

Expand All @@ -46,20 +45,18 @@ export class InjectedScript {

constructor(customEngines: { name: string, engine: SelectorEngine}[]) {
this._enginesV1 = new Map();
this._enginesV1.set('css', createCSSEngine(true));
this._enginesV1.set('css:light', createCSSEngine(false));
this._enginesV1.set('xpath', XPathEngine);
this._enginesV1.set('xpath:light', XPathEngine);
this._enginesV1.set('text', createTextSelector(true));
this._enginesV1.set('text:light', createTextSelector(false));
this._enginesV1.set('id', createAttributeEngine('id', true));
this._enginesV1.set('id:light', createAttributeEngine('id', false));
this._enginesV1.set('data-testid', createAttributeEngine('data-testid', true));
this._enginesV1.set('data-testid:light', createAttributeEngine('data-testid', false));
this._enginesV1.set('data-test-id', createAttributeEngine('data-test-id', true));
this._enginesV1.set('data-test-id:light', createAttributeEngine('data-test-id', false));
this._enginesV1.set('data-test', createAttributeEngine('data-test', true));
this._enginesV1.set('data-test:light', createAttributeEngine('data-test', false));
this._enginesV1.set('id', this._createAttributeEngine('id', true));
this._enginesV1.set('id:light', this._createAttributeEngine('id', false));
this._enginesV1.set('data-testid', this._createAttributeEngine('data-testid', true));
this._enginesV1.set('data-testid:light', this._createAttributeEngine('data-testid', false));
this._enginesV1.set('data-test-id', this._createAttributeEngine('data-test-id', true));
this._enginesV1.set('data-test-id:light', this._createAttributeEngine('data-test-id', false));
this._enginesV1.set('data-test', this._createAttributeEngine('data-test', true));
this._enginesV1.set('data-test:light', this._createAttributeEngine('data-test', false));
for (const { name, engine } of customEngines)
this._enginesV1.set(name, engine);

Expand Down Expand Up @@ -133,6 +130,21 @@ export class InjectedScript {
return this._enginesV1.get(part.name)!.queryAll(root, part.body);
}

private _createAttributeEngine(attribute: string, shadow: boolean): SelectorEngine {
const toCSS = (selector: string): CSSComplexSelectorList => {
const css = `[${attribute}=${JSON.stringify(selector)}]`;
return [{ simples: [{ selector: { css, functions: [] }, combinator: '' }] }];
};
return {
query: (root: SelectorRoot, selector: string): Element | undefined => {
return this._evaluator.evaluate({ scope: root as Document | Element, pierceShadow: shadow }, toCSS(selector))[0];
},
queryAll: (root: SelectorRoot, selector: string): Element[] => {
return this._evaluator.evaluate({ scope: root as Document | Element, pierceShadow: shadow }, toCSS(selector));
}
};
}

extend(source: string, params: any): any {
const constrFunction = global.eval(source);
return new constrFunction(this, params);
Expand Down
Loading

0 comments on commit f0a8729

Please sign in to comment.