@compiled/react 0.16.3 → 0.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/create-strict-api/index.d.ts +6 -4
- package/dist/browser/create-strict-api/index.js +4 -4
- package/dist/browser/create-strict-api/index.js.map +1 -1
- package/dist/browser/utils/error.d.ts +1 -0
- package/dist/browser/utils/error.js +19 -0
- package/dist/browser/utils/error.js.map +1 -1
- package/dist/cjs/create-strict-api/index.d.ts +6 -4
- package/dist/cjs/create-strict-api/index.js +3 -3
- package/dist/cjs/create-strict-api/index.js.map +1 -1
- package/dist/cjs/utils/error.d.ts +1 -0
- package/dist/cjs/utils/error.js +21 -1
- package/dist/cjs/utils/error.js.map +1 -1
- package/dist/esm/create-strict-api/index.d.ts +6 -4
- package/dist/esm/create-strict-api/index.js +4 -4
- package/dist/esm/create-strict-api/index.js.map +1 -1
- package/dist/esm/utils/error.d.ts +1 -0
- package/dist/esm/utils/error.js +19 -0
- package/dist/esm/utils/error.js.map +1 -1
- package/package.json +1 -1
- package/src/create-strict-api/__tests__/__fixtures__/strict-api.ts +1 -1
- package/src/create-strict-api/__tests__/index.test.tsx +116 -0
- package/src/create-strict-api/index.ts +16 -16
- package/src/utils/error.ts +20 -0
|
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
|
|
|
9
9
|
type PickObjects<TObject> = {
|
|
10
10
|
[P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
|
|
13
|
+
type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
|
|
14
|
+
interface CompiledAPI<TSchema extends CompiledSchema> {
|
|
13
15
|
/**
|
|
14
16
|
* ## CSS
|
|
15
17
|
*
|
|
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
|
|
|
25
27
|
* <div css={redText} />
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
|
-
css(styles:
|
|
30
|
+
css(styles: CSSStyles<TSchema>): StrictCSSProperties;
|
|
29
31
|
/**
|
|
30
32
|
* ## CSS Map
|
|
31
33
|
*
|
|
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
|
|
|
42
44
|
* <div css={styles.solid} />
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
cssMap<
|
|
46
|
-
readonly [P in keyof
|
|
47
|
+
cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
|
|
48
|
+
readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* ## CX
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStrictSetupError } from '../utils/error';
|
|
2
2
|
import { cx } from '../xcss-prop';
|
|
3
3
|
/**
|
|
4
4
|
* ## Create Strict API
|
|
@@ -51,14 +51,14 @@ import { cx } from '../xcss-prop';
|
|
|
51
51
|
export function createStrictAPI() {
|
|
52
52
|
return {
|
|
53
53
|
css() {
|
|
54
|
-
throw
|
|
54
|
+
throw createStrictSetupError();
|
|
55
55
|
},
|
|
56
56
|
cssMap() {
|
|
57
|
-
throw
|
|
57
|
+
throw createStrictSetupError();
|
|
58
58
|
},
|
|
59
59
|
cx,
|
|
60
60
|
XCSSProp() {
|
|
61
|
-
throw
|
|
61
|
+
throw createStrictSetupError();
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -17,4 +17,23 @@ export const createSetupError = () => {
|
|
|
17
17
|
Good luck!
|
|
18
18
|
`);
|
|
19
19
|
};
|
|
20
|
+
export const createStrictSetupError = () => {
|
|
21
|
+
return new Error(`
|
|
22
|
+
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
|
|
23
|
+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
|
|
24
|
+
██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
|
|
25
|
+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
|
|
26
|
+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
|
|
27
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
|
|
28
|
+
|
|
29
|
+
@compiled/react
|
|
30
|
+
|
|
31
|
+
Code was executed when it shouldn't have. To resolve make sure to:
|
|
32
|
+
|
|
33
|
+
1. Set up Compiled.
|
|
34
|
+
2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
|
|
35
|
+
|
|
36
|
+
For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
|
|
37
|
+
`);
|
|
38
|
+
};
|
|
20
39
|
//# sourceMappingURL=error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
|
|
|
9
9
|
type PickObjects<TObject> = {
|
|
10
10
|
[P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
|
|
13
|
+
type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
|
|
14
|
+
interface CompiledAPI<TSchema extends CompiledSchema> {
|
|
13
15
|
/**
|
|
14
16
|
* ## CSS
|
|
15
17
|
*
|
|
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
|
|
|
25
27
|
* <div css={redText} />
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
|
-
css(styles:
|
|
30
|
+
css(styles: CSSStyles<TSchema>): StrictCSSProperties;
|
|
29
31
|
/**
|
|
30
32
|
* ## CSS Map
|
|
31
33
|
*
|
|
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
|
|
|
42
44
|
* <div css={styles.solid} />
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
cssMap<
|
|
46
|
-
readonly [P in keyof
|
|
47
|
+
cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
|
|
48
|
+
readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* ## CX
|
|
@@ -54,14 +54,14 @@ const xcss_prop_1 = require("../xcss-prop");
|
|
|
54
54
|
function createStrictAPI() {
|
|
55
55
|
return {
|
|
56
56
|
css() {
|
|
57
|
-
throw (0, error_1.
|
|
57
|
+
throw (0, error_1.createStrictSetupError)();
|
|
58
58
|
},
|
|
59
59
|
cssMap() {
|
|
60
|
-
throw (0, error_1.
|
|
60
|
+
throw (0, error_1.createStrictSetupError)();
|
|
61
61
|
},
|
|
62
62
|
cx: xcss_prop_1.cx,
|
|
63
63
|
XCSSProp() {
|
|
64
|
-
throw (0, error_1.
|
|
64
|
+
throw (0, error_1.createStrictSetupError)();
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":";;;AACA,0CAAwD;AACxD,4CAA+E;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;QACD,EAAE,EAAF,cAAE;QACF,QAAQ;YACN,MAAM,IAAA,8BAAsB,GAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC;AAbD,0CAaC"}
|
package/dist/cjs/utils/error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSetupError = void 0;
|
|
3
|
+
exports.createStrictSetupError = exports.createSetupError = void 0;
|
|
4
4
|
const createSetupError = () => {
|
|
5
5
|
return new Error(`
|
|
6
6
|
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
|
|
@@ -21,4 +21,24 @@ const createSetupError = () => {
|
|
|
21
21
|
`);
|
|
22
22
|
};
|
|
23
23
|
exports.createSetupError = createSetupError;
|
|
24
|
+
const createStrictSetupError = () => {
|
|
25
|
+
return new Error(`
|
|
26
|
+
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
|
|
27
|
+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
|
|
28
|
+
██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
|
|
29
|
+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
|
|
30
|
+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
|
|
31
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
|
|
32
|
+
|
|
33
|
+
@compiled/react
|
|
34
|
+
|
|
35
|
+
Code was executed when it shouldn't have. To resolve make sure to:
|
|
36
|
+
|
|
37
|
+
1. Set up Compiled.
|
|
38
|
+
2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
|
|
39
|
+
|
|
40
|
+
For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
|
|
41
|
+
`);
|
|
42
|
+
};
|
|
43
|
+
exports.createStrictSetupError = createStrictSetupError;
|
|
24
44
|
//# sourceMappingURL=error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B"}
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":";;;AAAO,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B;AAEK,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,sBAAsB,0BAkBjC"}
|
|
@@ -9,7 +9,9 @@ type EnforceSchema<TObject> = {
|
|
|
9
9
|
type PickObjects<TObject> = {
|
|
10
10
|
[P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
|
|
13
|
+
type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
|
|
14
|
+
interface CompiledAPI<TSchema extends CompiledSchema> {
|
|
13
15
|
/**
|
|
14
16
|
* ## CSS
|
|
15
17
|
*
|
|
@@ -25,7 +27,7 @@ interface CompiledAPI<TSchema> {
|
|
|
25
27
|
* <div css={redText} />
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
|
-
css(styles:
|
|
30
|
+
css(styles: CSSStyles<TSchema>): StrictCSSProperties;
|
|
29
31
|
/**
|
|
30
32
|
* ## CSS Map
|
|
31
33
|
*
|
|
@@ -42,8 +44,8 @@ interface CompiledAPI<TSchema> {
|
|
|
42
44
|
* <div css={styles.solid} />
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
cssMap<
|
|
46
|
-
readonly [P in keyof
|
|
47
|
+
cssMap<TStylesMap extends CSSMapStyles<TSchema>>(styles: CSSMapStyles<TSchema>): {
|
|
48
|
+
readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* ## CX
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStrictSetupError } from '../utils/error';
|
|
2
2
|
import { cx } from '../xcss-prop';
|
|
3
3
|
/**
|
|
4
4
|
* ## Create Strict API
|
|
@@ -51,14 +51,14 @@ import { cx } from '../xcss-prop';
|
|
|
51
51
|
export function createStrictAPI() {
|
|
52
52
|
return {
|
|
53
53
|
css() {
|
|
54
|
-
throw
|
|
54
|
+
throw createStrictSetupError();
|
|
55
55
|
},
|
|
56
56
|
cssMap() {
|
|
57
|
-
throw
|
|
57
|
+
throw createStrictSetupError();
|
|
58
58
|
},
|
|
59
59
|
cx,
|
|
60
60
|
XCSSProp() {
|
|
61
|
-
throw
|
|
61
|
+
throw createStrictSetupError();
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/esm/utils/error.js
CHANGED
|
@@ -17,4 +17,23 @@ export const createSetupError = () => {
|
|
|
17
17
|
Good luck!
|
|
18
18
|
`);
|
|
19
19
|
};
|
|
20
|
+
export const createStrictSetupError = () => {
|
|
21
|
+
return new Error(`
|
|
22
|
+
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
|
|
23
|
+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
|
|
24
|
+
██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
|
|
25
|
+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
|
|
26
|
+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
|
|
27
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
|
|
28
|
+
|
|
29
|
+
@compiled/react
|
|
30
|
+
|
|
31
|
+
Code was executed when it shouldn't have. To resolve make sure to:
|
|
32
|
+
|
|
33
|
+
1. Set up Compiled.
|
|
34
|
+
2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
|
|
35
|
+
|
|
36
|
+
For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
|
|
37
|
+
`);
|
|
38
|
+
};
|
|
20
39
|
//# sourceMappingURL=error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -86,6 +86,56 @@ describe('createStrictAPI()', () => {
|
|
|
86
86
|
|
|
87
87
|
expect(getByTestId('div')).toHaveCompiledCss('all', 'inherit');
|
|
88
88
|
});
|
|
89
|
+
|
|
90
|
+
it('should type error with css properties not in the style scope', () => {
|
|
91
|
+
// NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
|
|
92
|
+
// as only one will error at a time when combined into one query
|
|
93
|
+
|
|
94
|
+
const bgStyles = css({
|
|
95
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
96
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
|
|
97
|
+
bg: 'red',
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const colourStyles = css({
|
|
101
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
102
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
|
|
103
|
+
colour: 'var(--ds-text)',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const hoverStyles = css({
|
|
107
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
108
|
+
'&:hover': {
|
|
109
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
110
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
|
|
111
|
+
colour: 'var(--ds-text-hover)',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const invalidPsuedoStyles = css({
|
|
116
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
117
|
+
// @ts-expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
|
|
118
|
+
'&:invalid-pseudo': {
|
|
119
|
+
color: 'var(--ds-text)',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const { getByTestId } = render(
|
|
124
|
+
<div css={[bgStyles, colourStyles, hoverStyles, invalidPsuedoStyles]} data-testid="div" />
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold');
|
|
128
|
+
expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold', {
|
|
129
|
+
target: ':hover',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// These still get compiled to css, even if they're not valid
|
|
133
|
+
expect(getByTestId('div')).toHaveCompiledCss('bg', 'red');
|
|
134
|
+
expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text)');
|
|
135
|
+
expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text-hover)', {
|
|
136
|
+
target: ':hover',
|
|
137
|
+
});
|
|
138
|
+
});
|
|
89
139
|
});
|
|
90
140
|
|
|
91
141
|
describe('cssMap()', () => {
|
|
@@ -152,6 +202,72 @@ describe('createStrictAPI()', () => {
|
|
|
152
202
|
|
|
153
203
|
expect(getByTestId('div')).toHaveCompiledCss('val', 'ok', { target: ':hover' });
|
|
154
204
|
});
|
|
205
|
+
|
|
206
|
+
it('should type error with css properties not in the style scope', () => {
|
|
207
|
+
// NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
|
|
208
|
+
// as only one will error at a time when combined into one query
|
|
209
|
+
|
|
210
|
+
const bgStyles = cssMap({
|
|
211
|
+
primary: {
|
|
212
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
213
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
|
|
214
|
+
bg: 'red',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const colourStyles = cssMap({
|
|
219
|
+
primary: {
|
|
220
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
221
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
|
|
222
|
+
colour: 'var(--ds-text)',
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const hoverStyles = cssMap({
|
|
227
|
+
primary: {
|
|
228
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
229
|
+
'&:hover': {
|
|
230
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
231
|
+
// @ts-expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
|
|
232
|
+
colour: 'var(--ds-text-hover)',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const invalidPsuedoStyles = cssMap({
|
|
238
|
+
primary: {
|
|
239
|
+
fontWeight: 'bold', // just a valid property to ensure the `extends` keyword isn't working as intended
|
|
240
|
+
// @ts-expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
|
|
241
|
+
'&:invalid-pseudo': {
|
|
242
|
+
color: 'var(--ds-text)',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const { getByTestId } = render(
|
|
248
|
+
<div
|
|
249
|
+
css={[
|
|
250
|
+
bgStyles.primary,
|
|
251
|
+
colourStyles.primary,
|
|
252
|
+
hoverStyles.primary,
|
|
253
|
+
invalidPsuedoStyles.primary,
|
|
254
|
+
]}
|
|
255
|
+
data-testid="div"
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold');
|
|
260
|
+
expect(getByTestId('div')).toHaveCompiledCss('font-weight', 'bold', {
|
|
261
|
+
target: ':hover',
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// These still get compiled to css, even if they're not valid
|
|
265
|
+
expect(getByTestId('div')).toHaveCompiledCss('bg', 'red');
|
|
266
|
+
expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text)');
|
|
267
|
+
expect(getByTestId('div')).toHaveCompiledCss('colour', 'var(--ds-text-hover)', {
|
|
268
|
+
target: ':hover',
|
|
269
|
+
});
|
|
270
|
+
});
|
|
155
271
|
});
|
|
156
272
|
|
|
157
273
|
describe('XCSSProp', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StrictCSSProperties, CSSPseudos } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { createStrictSetupError } from '../utils/error';
|
|
3
3
|
import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
|
|
4
4
|
|
|
5
5
|
type PseudosDeclarations = {
|
|
@@ -18,7 +18,12 @@ type PickObjects<TObject> = {
|
|
|
18
18
|
[P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties &
|
|
22
|
+
PseudosDeclarations &
|
|
23
|
+
EnforceSchema<TSchema>;
|
|
24
|
+
type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
|
|
25
|
+
|
|
26
|
+
interface CompiledAPI<TSchema extends CompiledSchema> {
|
|
22
27
|
/**
|
|
23
28
|
* ## CSS
|
|
24
29
|
*
|
|
@@ -34,9 +39,7 @@ interface CompiledAPI<TSchema> {
|
|
|
34
39
|
* <div css={redText} />
|
|
35
40
|
* ```
|
|
36
41
|
*/
|
|
37
|
-
css(
|
|
38
|
-
styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>
|
|
39
|
-
): StrictCSSProperties;
|
|
42
|
+
css(styles: CSSStyles<TSchema>): StrictCSSProperties;
|
|
40
43
|
/**
|
|
41
44
|
* ## CSS Map
|
|
42
45
|
*
|
|
@@ -53,15 +56,12 @@ interface CompiledAPI<TSchema> {
|
|
|
53
56
|
* <div css={styles.solid} />
|
|
54
57
|
* ```
|
|
55
58
|
*/
|
|
56
|
-
cssMap<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
>
|
|
61
|
-
>(
|
|
62
|
-
styles: TStyles
|
|
59
|
+
cssMap<TStylesMap extends CSSMapStyles<TSchema>>(
|
|
60
|
+
// NOTE: This should match the generic `TStylesMap extends …` as we want this arg to strictly satisfy this type, not just extend it.
|
|
61
|
+
// The "extends" functionality is to infer and build the return type, this is to enforce the input type.
|
|
62
|
+
styles: CSSMapStyles<TSchema>
|
|
63
63
|
): {
|
|
64
|
-
readonly [P in keyof
|
|
64
|
+
readonly [P in keyof TStylesMap]: CompiledStyles<TStylesMap[P]>;
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
67
|
* ## CX
|
|
@@ -210,14 +210,14 @@ type CompiledSchema = StrictCSSProperties & PseudosDeclarations;
|
|
|
210
210
|
export function createStrictAPI<TSchema extends CompiledSchema>(): CompiledAPI<TSchema> {
|
|
211
211
|
return {
|
|
212
212
|
css() {
|
|
213
|
-
throw
|
|
213
|
+
throw createStrictSetupError();
|
|
214
214
|
},
|
|
215
215
|
cssMap() {
|
|
216
|
-
throw
|
|
216
|
+
throw createStrictSetupError();
|
|
217
217
|
},
|
|
218
218
|
cx,
|
|
219
219
|
XCSSProp() {
|
|
220
|
-
throw
|
|
220
|
+
throw createStrictSetupError();
|
|
221
221
|
},
|
|
222
222
|
};
|
|
223
223
|
}
|
package/src/utils/error.ts
CHANGED
|
@@ -17,3 +17,23 @@ export const createSetupError = (): Error => {
|
|
|
17
17
|
Good luck!
|
|
18
18
|
`);
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
export const createStrictSetupError = (): Error => {
|
|
22
|
+
return new Error(`
|
|
23
|
+
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
|
|
24
|
+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
|
|
25
|
+
██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
|
|
26
|
+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
|
|
27
|
+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
|
|
28
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
|
|
29
|
+
|
|
30
|
+
@compiled/react
|
|
31
|
+
|
|
32
|
+
Code was executed when it shouldn't have. To resolve make sure to:
|
|
33
|
+
|
|
34
|
+
1. Set up Compiled.
|
|
35
|
+
2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
|
|
36
|
+
|
|
37
|
+
For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
|
|
38
|
+
`);
|
|
39
|
+
};
|