diff --git a/README.md b/README.md index 4a87f134..fe846f79 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,6 @@ the first match, or `null` if there was no match. All options are optional. - `xmlMode`: When enabled, tag names will be case-sensitive. Default: `false`. -- `strict`: Limits the module to only use CSS3 selectors. Default: `false`. - `rootFunc`: The last function in the stack, will be called with the last element that's looked at. - `adapter`: The adapter to use when interacting with the backing DOM @@ -156,9 +155,9 @@ _As defined by CSS 4 and / or jQuery._ - Universal (`*`) - Tag (``) -- Descendant (``) +- Descendant (` `) - Child (`>`) -- Parent (`<`) \* +- Parent (`<`) - Sibling (`+`) - Adjacent (`~`) - Attribute (`[attr=foo]`), with supported comparisons: @@ -169,33 +168,31 @@ _As defined by CSS 4 and / or jQuery._ - `*=` - `^=` - `$=` - - `!=` \* + - `!=` - Also, `i` can be added after the comparison to make the comparison - case-insensitive (eg. `[attr=foo i]`) \* + case-insensitive (eg. `[attr=foo i]`) - Pseudos: - `:not` - - `:contains` \* - - `:icontains` \* (case-insensitive version of `:contains`) - - `:has` \* + - `:contains` + - `:icontains` (case-insensitive version of `:contains`) + - `:has` - `:root` - `:empty` - - `:parent` \* + - `:parent` - `:[first|last]-child[-of-type]` - `:only-of-type`, `:only-child` - `:nth-[last-]child[-of-type]` - `:link`, `:any-link` - - `:visited`, `:hover`, `:active` \* (these depend on optional Adapter + - `:visited`, `:hover`, `:active` (these depend on optional Adapter methods, so these will work only if implemented in Adapter) - - `:selected` \*, `:checked` + - `:selected`, `:checked` - `:enabled`, `:disabled` - `:required`, `:optional` - `:header`, `:button`, `:input`, `:text`, `:checkbox`, `:file`, - `:password`, `:reset`, `:radio` etc. \* - - `:matches`, `:is` \* + `:password`, `:reset`, `:radio` etc. + - `:matches`, `:is` - `:scope` (uses the context from the passed options) -**\***: Not part of CSS3 - --- License: BSD-2-Clause diff --git a/src/general.ts b/src/general.ts index d7f7ca2d..b4e25d44 100644 --- a/src/general.ts +++ b/src/general.ts @@ -25,13 +25,6 @@ export function compileGeneralSelector( throw new Error("Pseudo-elements are not supported by css-select"); case "attribute": - if ( - options.strict && - (selector.ignoreCase || selector.action === "not") - ) { - throw new Error("Unsupported attribute selector"); - } - return attributeRules[selector.action](next, selector, options); case "pseudo": @@ -98,10 +91,6 @@ export function compileGeneralSelector( }; case "parent": - if (options.strict) { - throw new Error("Parent selector isn't part of CSS3"); - } - return function parent(elem: ElementNode): boolean { return adapter .getChildren(elem) diff --git a/src/pseudo-selectors/index.ts b/src/pseudo-selectors/index.ts index 20c3de9e..5548832e 100644 --- a/src/pseudo-selectors/index.ts +++ b/src/pseudo-selectors/index.ts @@ -21,9 +21,6 @@ import { subselects } from "./subselects"; export { filters, pseudos }; -// FIXME This is pretty hacky -const reCSS3 = /^(?:(?:nth|last|first|only)-(?:child|of-type)|root|empty|(?:en|dis)abled|checked|not)$/; - export function compilePseudoSelector( next: CompiledQuery, selector: PseudoSelector, @@ -33,10 +30,6 @@ export function compilePseudoSelector( ): CompiledQuery { const { name, data } = selector; - if (options.strict && !reCSS3.test(name)) { - throw new Error(`:${name} isn't part of CSS3`); - } - if (Array.isArray(data)) { return subselects[name](next, data, options, context, compileToken); } diff --git a/src/pseudo-selectors/subselects.ts b/src/pseudo-selectors/subselects.ts index d15b1234..b6dac3d9 100644 --- a/src/pseudo-selectors/subselects.ts +++ b/src/pseudo-selectors/subselects.ts @@ -53,7 +53,6 @@ export const subselects: Record = { matches(next, token, options, context, compileToken) { const opts = { xmlMode: !!options.xmlMode, - strict: !!options.strict, adapter: options.adapter, equals: options.equals, rootFunc: next, @@ -64,19 +63,10 @@ export const subselects: Record = { not(next, token, options, context, compileToken) { const opts = { xmlMode: !!options.xmlMode, - strict: !!options.strict, adapter: options.adapter, equals: options.equals, }; - if (opts.strict) { - if (token.length > 1 || token.some(containsTraversal)) { - throw new Error( - "complex selectors in :not aren't allowed in strict mode" - ); - } - } - const func = compileToken(token, opts, context); if (func === falseFunc) return next; @@ -96,7 +86,6 @@ export const subselects: Record = { const { adapter } = options; const opts = { xmlMode: !!options.xmlMode, - strict: !!options.strict, adapter, equals: options.equals, }; diff --git a/src/types.ts b/src/types.ts index 2b85c974..eb1c85b7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -102,12 +102,6 @@ export interface Options { * @default false */ xmlMode?: boolean; - /** - * Limits the module to only use CSS3 selectors. - * - * @default false - */ - strict?: boolean; /** * The last function in the stack, will be called with the last element * that's looked at. diff --git a/test/api.ts b/test/api.ts index f02bac65..4b22e615 100644 --- a/test/api.ts +++ b/test/api.ts @@ -140,24 +140,6 @@ describe("API", () => { ).toBe(true); }); - it("should be strict", () => { - const opts = { strict: true }; - expect(() => CSSselect.compile(":checkbox", opts)).toThrow(Error); - expect(() => CSSselect.compile("[attr=val i]", opts)).toThrow( - Error - ); - expect(() => CSSselect.compile("[attr!=val]", opts)).toThrow(Error); - expect(() => CSSselect.compile("[attr!=val i]", opts)).toThrow( - Error - ); - expect(() => CSSselect.compile("foo < bar", opts)).toThrow(Error); - expect(() => CSSselect.compile(":not(:parent)", opts)).toThrow( - Error - ); - expect(() => CSSselect.compile(":not(a > b)", opts)).toThrow(Error); - expect(() => CSSselect.compile(":not(a, b)", opts)).toThrow(Error); - }); - it("should recognize contexts", () => { const div = CSSselect.selectAll("div", [dom]); const p = CSSselect.selectAll("p", [dom]);