Skip to content

Commit 7c34b39

Browse files
committed
Merge branch 'es6-module-support' into tinymce-fork
2 parents 0fb04ef + 37b4abb commit 7c34b39

File tree

7 files changed

+114
-94
lines changed

7 files changed

+114
-94
lines changed

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
"repository": {
1010
"url": "https://github.com/fb55/css-what"
1111
},
12-
"main": "lib/index.js",
13-
"types": "lib/index.d.ts",
12+
"main": "lib/commonjs/index.js",
13+
"module": "lib/es/index.js",
14+
"types": "lib/es/index.d.ts",
15+
"sideEffects": false,
1416
"files": [
1517
"lib/**/*"
1618
],
@@ -24,7 +26,7 @@
2426
"format:es": "npm run lint:es -- --fix",
2527
"format:prettier": "npm run prettier -- --write",
2628
"prettier": "prettier '**/*.{ts,md,json,yml}'",
27-
"build": "tsc",
29+
"build": "tsc && tsc -p tsconfig.es.json",
2830
"prepare": "npm run build"
2931
},
3032
"devDependencies": {
@@ -45,7 +47,10 @@
4547
},
4648
"license": "BSD-2-Clause",
4749
"jest": {
48-
"preset": "ts-jest"
50+
"preset": "ts-jest",
51+
"roots": [
52+
"src"
53+
]
4954
},
5055
"prettier": {
5156
"tabWidth": 4

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from "./parse";
2-
export { default as parse } from "./parse";
3-
export { default as stringify } from "./stringify";
1+
export * from "./types";
2+
export { isTraversal, parse } from "./parse";
3+
export { stringify } from "./stringify";

src/parse.ts

Lines changed: 10 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,12 @@
1-
export interface Options {
2-
/**
3-
* When false, tag names will not be lowercased.
4-
* @default true
5-
*/
6-
lowerCaseAttributeNames?: boolean;
7-
/**
8-
* When false, attribute names will not be lowercased.
9-
* @default true
10-
*/
11-
lowerCaseTags?: boolean;
12-
/**
13-
* When `true`, `xmlMode` implies both `lowerCaseTags` and `lowerCaseAttributeNames` are set to `false`.
14-
* Also, `ignoreCase` on attributes will not be inferred based on HTML rules anymore.
15-
* @default false
16-
*/
17-
xmlMode?: boolean;
18-
}
19-
20-
export type Selector =
21-
| PseudoSelector
22-
| PseudoElement
23-
| AttributeSelector
24-
| TagSelector
25-
| UniversalSelector
26-
| Traversal;
27-
28-
export interface AttributeSelector {
29-
type: "attribute";
30-
name: string;
31-
action: AttributeAction;
32-
value: string;
33-
ignoreCase: boolean | null;
34-
namespace: string | null;
35-
}
36-
37-
type DataType = Selector[][] | null | string;
38-
39-
export interface PseudoSelector {
40-
type: "pseudo";
41-
name: string;
42-
data: DataType;
43-
}
44-
45-
export interface PseudoElement {
46-
type: "pseudo-element";
47-
name: string;
48-
}
49-
50-
export interface TagSelector {
51-
type: "tag";
52-
name: string;
53-
namespace: string | null;
54-
}
55-
56-
export interface UniversalSelector {
57-
type: "universal";
58-
namespace: string | null;
59-
}
60-
61-
export interface Traversal {
62-
type: TraversalType;
63-
}
64-
65-
export type AttributeAction =
66-
| "any"
67-
| "element"
68-
| "end"
69-
| "equals"
70-
| "exists"
71-
| "hyphen"
72-
| "not"
73-
| "start";
74-
75-
export type TraversalType =
76-
| "adjacent"
77-
| "child"
78-
| "descendant"
79-
| "parent"
80-
| "sibling";
1+
import {
2+
Options,
3+
Selector,
4+
AttributeSelector,
5+
Traversal,
6+
AttributeAction,
7+
TraversalType,
8+
DataType,
9+
} from "./types";
8110

8211
const reName = /^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/;
8312
const reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi;
@@ -220,10 +149,7 @@ function isWhitespace(c: string) {
220149
* The first dimension represents selectors separated by commas (eg. `sub1, sub2`),
221150
* the second contains the relevant tokens for that selector.
222151
*/
223-
export default function parse(
224-
selector: string,
225-
options?: Options
226-
): Selector[][] {
152+
export function parse(selector: string, options?: Options): Selector[][] {
227153
const subselects: Selector[][] = [];
228154

229155
const endIndex = parseSelector(subselects, `${selector}`, options, 0);

src/stringify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Selector } from "./parse";
1+
import { Selector } from "./types";
22

33
const actionTypes: Record<string, string> = {
44
equals: "",
@@ -29,7 +29,7 @@ const charsToEscape = new Set([
2929
*
3030
* @param selector Selector to stringify.
3131
*/
32-
export default function stringify(selector: Selector[][]): string {
32+
export function stringify(selector: Selector[][]): string {
3333
return selector.map(stringifySubselector).join(", ");
3434
}
3535

src/types.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
export interface Options {
2+
/**
3+
* When false, tag names will not be lowercased.
4+
* @default true
5+
*/
6+
lowerCaseAttributeNames?: boolean;
7+
/**
8+
* When false, attribute names will not be lowercased.
9+
* @default true
10+
*/
11+
lowerCaseTags?: boolean;
12+
/**
13+
* When `true`, `xmlMode` implies both `lowerCaseTags` and `lowerCaseAttributeNames` are set to `false`.
14+
* Also, `ignoreCase` on attributes will not be inferred based on HTML rules anymore.
15+
* @default false
16+
*/
17+
xmlMode?: boolean;
18+
}
19+
20+
export type Selector =
21+
| PseudoSelector
22+
| PseudoElement
23+
| AttributeSelector
24+
| TagSelector
25+
| UniversalSelector
26+
| Traversal;
27+
28+
export interface AttributeSelector {
29+
type: "attribute";
30+
name: string;
31+
action: AttributeAction;
32+
value: string;
33+
ignoreCase: boolean | null;
34+
namespace: string | null;
35+
}
36+
37+
export type DataType = Selector[][] | null | string;
38+
39+
export interface PseudoSelector {
40+
type: "pseudo";
41+
name: string;
42+
data: DataType;
43+
}
44+
45+
export interface PseudoElement {
46+
type: "pseudo-element";
47+
name: string;
48+
}
49+
50+
export interface TagSelector {
51+
type: "tag";
52+
name: string;
53+
namespace: string | null;
54+
}
55+
56+
export interface UniversalSelector {
57+
type: "universal";
58+
namespace: string | null;
59+
}
60+
61+
export interface Traversal {
62+
type: TraversalType;
63+
}
64+
65+
export type AttributeAction =
66+
| "any"
67+
| "element"
68+
| "end"
69+
| "equals"
70+
| "exists"
71+
| "hyphen"
72+
| "not"
73+
| "start";
74+
75+
export type TraversalType =
76+
| "adjacent"
77+
| "child"
78+
| "descendant"
79+
| "parent"
80+
| "sibling";

tsconfig.es.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"target": "ES2019",
5+
"module": "es2015",
6+
"outDir": "lib/es",
7+
"moduleResolution": "node"
8+
}
9+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"declaration": true /* Generates corresponding '.d.ts' file. */,
88
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
99
// "sourceMap": true, /* Generates corresponding '.map' file. */
10-
"outDir": "lib" /* Redirect output structure to the directory. */,
10+
"outDir": "lib/commonjs" /* Redirect output structure to the directory. */,
1111
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
1212

1313
/* Strict Type-Checking Options */

0 commit comments

Comments
 (0)