Skip to content

Commit 64ce1d2

Browse files
committed
chore: Update selector-parser. Use public libs from opticss.
We sometimes hits typescript compilation issues due to opticss and css-blocks both holding their own dependency on postcss and postcss-selector-parser. So opticss now exports those libraries from its dependency and css-blocks dropped our dep on them and typescript doesn't get mad anymore.
1 parent 38e7add commit 64ce1d2

55 files changed

Lines changed: 89 additions & 114 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/css-blocks/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"name": "Launch Program",
1212
"preLaunchTask": "compile",
13-
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
13+
"program": "${workspaceRoot}/../../node_modules/.bin/_mocha",
1414
"args": [
1515
"dist/test",
1616
"--opts",

packages/css-blocks/package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
"description": "Fast, maintainable, optimal, component-oriented CSS.",
55
"main": "dist/src/index.js",
66
"scripts": {
7-
"compile": "rm -rf dist && tsc",
7+
"compile": "../../node_modules/.bin/tsc --version && rm -rf dist && ../../node_modules/.bin/tsc",
88
"pretest": "yarn run compile",
9-
"test": "mocha dist/test --opts test/mocha.opts",
9+
"test": "../../node_modules/.bin/mocha dist/test --opts test/mocha.opts",
1010
"posttest": "yarn run lint",
1111
"prepublish": "yarn run compile && yarn run lintall",
12-
"lint": "tslint -t msbuild --project . -c tslint.cli.json",
13-
"lintall": "tslint -t msbuild --project . -c tslint.release.json",
14-
"lintfix": "tslint -t msbuild --project . -c tslint.cli.json --fix",
15-
"coverage": "istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage node_modules/.bin/_mocha -- dist/test --opts test/mocha.opts",
16-
"remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
17-
"docs": "typedoc --out ./docs .",
12+
"lint": "../../node_modules/.bin/tslint -t msbuild --project . -c tslint.cli.json",
13+
"lintall": "../../node_modules/.bin/tslint -t msbuild --project . -c tslint.release.json",
14+
"lintfix": "../../node_modules/.bin/tslint -t msbuild --project . -c tslint.cli.json --fix",
15+
"coverage": "../../node_modules/.bin/istanbul cover -i \"dist/src/**/*.js\" --dir ./build/coverage node_modules/.bin/_mocha -- dist/test --opts test/mocha.opts",
16+
"remap": "../../node_modules/.bin/remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
17+
"docs": "../../node_modules/.bin/typedoc --out ./docs .",
1818
"watch": "watch 'yarn run test' './src' './test' --wait=3"
1919
},
2020
"repository": {
@@ -53,7 +53,6 @@
5353
"inline-source-map-comment": "^1.0.5",
5454
"json-parse-better-errors": "^1.0.1",
5555
"object.values": "^1.0.4",
56-
"postcss-selector-parser": "3.1.1",
5756
"regexpu-core": "^4.0.11",
5857
"source-map": "^0.6.1",
5958
"watch": "^1.0.2"

packages/css-blocks/src/Analyzer/validations/property-conflict-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MultiMap, TwoKeyMultiMap, objectValues } from "@opticss/util";
22
import * as propParser from "css-property-parser";
3-
import * as postcss from "postcss";
3+
import { postcss } from "opticss";
44

55
import { Ruleset, Style } from "../../BlockTree";
66
import {

packages/css-blocks/src/BlockCompiler/ConflictResolver.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { assertNever } from "@opticss/util";
2-
import { CompoundSelector, ParsedSelector, parseSelector } from "opticss";
3-
import * as postcss from "postcss";
4-
import selectorParser = require("postcss-selector-parser");
2+
import { CompoundSelector, ParsedSelector, parseSelector, postcss, postcssSelectorParser as selectorParser } from "opticss";
53

64
import { getBlockNode } from "../BlockParser";
75
import { RESOLVE_RE } from "../BlockSyntax";
@@ -309,7 +307,7 @@ export class ConflictResolver {
309307
* @param s The compound selector to split.
310308
* @returns [ CompoundSelector, Combinator, CompoundSelector ]
311309
*/
312-
private splitSelector(s: CompoundSelector): [CompoundSelector | undefined, selectorParser.Combinator | undefined, CompoundSelector] {
310+
private splitSelector(s: CompoundSelector): [CompoundSelector, selectorParser.Combinator, CompoundSelector] | [undefined, undefined, CompoundSelector] {
313311
s = s.clone();
314312
let last = s.removeLast();
315313
if (last) {

packages/css-blocks/src/BlockCompiler/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TemplateTypes } from "@opticss/template-api";
2-
import * as postcss from "postcss";
2+
import { postcss } from "opticss";
33

44
import { Analyzer } from "../Analyzer";
55
import {

packages/css-blocks/src/BlockParser/BlockFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ObjectDictionary } from "@opticss/util";
22
import * as debugGenerator from "debug";
3+
import { postcss } from "opticss";
34
import * as path from "path";
4-
import * as postcss from "postcss";
55
import { RawSourceMap } from "source-map";
66

77
import { Block } from "../BlockTree";

packages/css-blocks/src/BlockParser/BlockParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as postcss from "postcss";
1+
import { postcss } from "opticss";
22

33
import { Block } from "../BlockTree";
44
import { Options, ResolvedConfiguration, resolveConfiguration } from "../configuration";

packages/css-blocks/src/BlockParser/block-intermediates.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { assertNever, firstOfType } from "@opticss/util";
2-
import { CompoundSelector } from "opticss";
3-
import selectorParser = require("postcss-selector-parser");
1+
import { assertNever, firstOfType, whatever } from "@opticss/util";
2+
import { CompoundSelector, postcssSelectorParser as selectorParser } from "opticss";
43

54
import { ATTR_PRESENT, AttrToken, ROOT_CLASS, STATE_NAMESPACE } from "../BlockSyntax";
65

@@ -81,26 +80,19 @@ export function isClassLevelObject(object: NodeAndType): boolean {
8180
/**
8281
* Check if given selector node is targeting the root block node
8382
*/
84-
export function isRootNode(node: selectorParser.Node): node is selectorParser.Pseudo {
85-
return node.type === selectorParser.PSEUDO && node.value === ROOT_CLASS;
83+
export function isRootNode(node: whatever): node is selectorParser.Pseudo {
84+
return selectorParser.isPseudoClass(node) && node.value === ROOT_CLASS;
8685
}
8786

88-
/**
89-
* Check if given selector node is a class selector
90-
* @param node The selector to test.
91-
* @return True if class selector, false if not.
92-
*/
93-
export function isClassNode(node: selectorParser.Node): node is selectorParser.ClassName {
94-
return node.type === selectorParser.CLASS;
95-
}
87+
export const isClassNode = selectorParser.isClassName;
9688

9789
/**
9890
* Check if given selector node is an attribute selector
9991
* @param node The selector to test.
10092
* @return True if attribute selector, false if not.
10193
*/
10294
export function isAttributeNode(node: selectorParser.Node): node is selectorParser.Attribute {
103-
return node.type === selectorParser.ATTRIBUTE && node.namespace === STATE_NAMESPACE;
95+
return selectorParser.isAttribute(node) && node.namespace === STATE_NAMESPACE;
10496
}
10597

10698
/**

packages/css-blocks/src/BlockParser/features/assert-foreign-global-attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as postcss from "postcss";
1+
import { postcss } from "opticss";
22

33
import { Block } from "../../BlockTree";
44
import * as errors from "../../errors";

packages/css-blocks/src/BlockParser/features/construct-block.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { assertNever } from "@opticss/util";
2-
import { CompoundSelector, ParsedSelector } from "opticss";
3-
import * as postcss from "postcss";
4-
import selectorParser = require("postcss-selector-parser");
2+
import { CompoundSelector, ParsedSelector, postcss, postcssSelectorParser as selectorParser } from "opticss";
53

64
import { Block, Style } from "../../BlockTree";
75
import * as errors from "../../errors";
@@ -257,9 +255,9 @@ function assertBlockObject(block: Block, sel: CompoundSelector, rule: postcss.Ru
257255

258256
// If selecting a block or tag, check that the referenced block has been imported.
259257
// Otherwise, referencing a tag name is not allowed in blocks, throw an error.
260-
let blockName = sel.nodes.find(n => n.type === selectorParser.TAG);
258+
let blockName = sel.nodes.find(selectorParser.isTag);
261259
if (blockName) {
262-
let refBlock = block.getReferencedBlock(blockName.value!);
260+
let refBlock = block.getReferencedBlock(blockName.value);
263261
if (!refBlock) {
264262
throw new errors.InvalidBlockSyntax(
265263
`Tag name selectors are not allowed: ${rule.selector}`,
@@ -269,7 +267,7 @@ function assertBlockObject(block: Block, sel: CompoundSelector, rule: postcss.Ru
269267
}
270268

271269
// Targeting attributes that are not state selectors is not allowed in blocks, throw.
272-
let nonStateAttribute = sel.nodes.find(n => n.type === selectorParser.ATTRIBUTE && !isAttributeNode(n));
270+
let nonStateAttribute = sel.nodes.find(n => selectorParser.isAttribute(n) && !isAttributeNode(n));
273271
if (nonStateAttribute) {
274272
throw new errors.InvalidBlockSyntax(
275273
`Cannot select attributes other than states: ${rule.selector}`,
@@ -279,7 +277,7 @@ function assertBlockObject(block: Block, sel: CompoundSelector, rule: postcss.Ru
279277

280278
// Disallow pseudoclasses that take selectors as arguments.
281279
sel.nodes.forEach(n => {
282-
if (n.type === selectorParser.PSEUDO) {
280+
if (selectorParser.isPseudoClass(n)) {
283281
let pseudo = n;
284282
if (pseudo.value === ":not" || pseudo.value === ":matches") {
285283
throw new errors.InvalidBlockSyntax(

0 commit comments

Comments
 (0)