Skip to content

Commit ccb1593

Browse files
committed
fix nullable checks
Thanks TypeScript for already catching that!
1 parent 6bc194f commit ccb1593

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "@tailwindcss/container-queries",
33
"version": "0.1.0",
4-
"main": "src/index.js",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
56
"license": "MIT",
67
"repository": "https://github.com/tailwindlabs/tailwindcss-container-queries",
78
"publishConfig": {
@@ -11,7 +12,8 @@
1112
"test": "jest",
1213
"swcify": "swc ./src/index.ts --out-dir ./dist",
1314
"build": "npm run swcify",
14-
"dev": "npm run swcify -- --watch"
15+
"dev": "npm run swcify -- --watch",
16+
"postbuild": "tsc --emitDeclarationOnly"
1517
},
1618
"prettier": {
1719
"printWidth": 100,
@@ -43,6 +45,7 @@
4345
"jest": "^29.1.2",
4446
"postcss": "^8.4.17",
4547
"prettier": "^2.7.1",
46-
"tailwindcss": "0.0.0-insiders.4338849"
48+
"tailwindcss": "0.0.0-insiders.4338849",
49+
"typescript": "^4.8.4"
4750
}
4851
}

src/index.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import plugin from 'tailwindcss/plugin'
22
import { normalize } from 'tailwindcss/lib/util/dataTypes'
33

4-
export default plugin(function containerQueries({ matchVariant, theme }) {
5-
let values = theme('containers')
4+
export = plugin(function containerQueries({ matchVariant, theme }) {
5+
let values = theme('containers') ?? {}
66

7-
function parseValue(value: string) {
7+
function parseValue(value: string): {
8+
raw: string
9+
sortable: boolean
10+
minX: number
11+
maxX: number
12+
minY: number
13+
maxY: number
14+
} | null {
815
// _ -> space
916
value = normalize(value)
1017

@@ -40,7 +47,7 @@ export default plugin(function containerQueries({ matchVariant, theme }) {
4047

4148
return {
4249
raw: value,
43-
parsable: minX !== null || maxX !== null || minY !== null || maxY !== null,
50+
sortable: minX !== null || maxX !== null || minY !== null || maxY !== null,
4451
minX: minXf,
4552
maxX: maxXf,
4653
minY: minYf,
@@ -61,15 +68,17 @@ export default plugin(function containerQueries({ matchVariant, theme }) {
6168
let a = parseValue(aVariant.value)
6269
let b = parseValue(bVariant.value)
6370

71+
if (a === null || b === null) return 0
72+
6473
let aLabel = aVariant.modifier ?? ''
6574
let bLabel = bVariant.modifier ?? ''
6675

6776
// Put "raw" values at the end
68-
if (a.parsable === false && b.parsable === false) {
77+
if (a.sortable === false && b.sortable === false) {
6978
return 0
70-
} else if (a.parsable === false) {
79+
} else if (a.sortable === false) {
7180
return 1
72-
} else if (b.parsable === false) {
81+
} else if (b.sortable === false) {
7382
return -1
7483
}
7584

tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2019",
4+
"lib": ["ES2019"],
5+
"module": "CommonJS",
6+
"declaration": true,
7+
"declarationMap": false,
8+
"declarationDir": "dist",
9+
"strict": true,
10+
"esModuleInterop": true,
11+
"moduleResolution": "node",
12+
"stripInternal": true,
13+
"outDir": "dist"
14+
},
15+
"include": [
16+
"src/**/*.ts"
17+
],
18+
"exclude": [
19+
"src/**/*.test.ts"
20+
]
21+
}

0 commit comments

Comments
 (0)