Skip to content

Commit c632fff

Browse files
committed
checkpoint
1 parent fb2c5fc commit c632fff

26 files changed

+30
-1701
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222
"check-types": "tsc --noEmit",
2323
"lint-staged": "lint-staged",
2424
"security": "npm audit --audit-level=high --prod",
25-
"test": "ava test/variable.ts"
25+
"test": "ava test/walker.ts"
2626
},
2727
"files": [
2828
"dist",
2929
"LICENSE",
3030
"README.md"
3131
],
3232
"dependencies": {
33-
"@types/color-name": "^1.1.1",
34-
"@types/css-tree": "^1.0.7",
35-
"@types/node": "^18.0.3",
3633
"color-name": "^1.1.4",
3734
"css-tree": "^2.1.0",
3835
"is-url-superb": "^4.0.0",
3936
"quote-unquote": "^1.0.0",
4037
"ts-node": "^10.8.2"
4138
},
4239
"devDependencies": {
40+
"@types/color-name": "^1.1.1",
41+
"@types/css-tree": "^1.0.7",
42+
"@types/node": "^18.0.3",
4343
"ava": "^4.3.0",
4444
"chalk": "^4.1.0",
4545
"eslint-config-shellscape": "^5.0.2",

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
// Breaking Changes:
13+
// - postcss-values-parser is now using css-tree which makes its behavior closers to how browsers parse values
1314
// - Comments and superfluous spaces filtered out (upstream; css-tree)
1415
// - Node interfaces changed
1516
// - Walkers must be manually registered to avoid conflicts between different installed versions of
@@ -18,6 +19,12 @@
1819
// - `.2.3rem` Shouldn't Be Compliant(upstream; https://github.com/csstree/csstree/issues/194)
1920
// - modulus operators no longer spec-compliant https://www.w3.org/TR/css3-values/#calc-notation
2021
// - custom variable prefix no longer supported (upstream; css-tree)
22+
// - at-words (@word) aren't spec compliant within css values and have been removed
23+
// - `variables` option has been removed. only the `--` prefix is spec compliant for variables
24+
// - url-modifiers (e.g. functions within url()) aren't supported (upstream; https://github.com/csstree/csstree/issues/197)
25+
// - a comma (,) is considered an operator
26+
// - strings (Quoted) which are quoted, but unterminated with an ending matching quote mark no longer throw
27+
// - interpolation had to be removed as it is not spec compliant
2128

2229
import { parse } from './parser';
2330
import { stringify } from './stringify';

src/nodes/Node.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ export interface NodeOptions {
2020
export class Node extends PostCssNode {
2121
public readonly value: string = '';
2222

23-
constructor(options: NodeOptions) {
23+
constructor(options?: NodeOptions) {
2424
super(options);
2525

26+
if (!options) return;
27+
2628
const { end, source, start } = options.node.loc as any;
2729

2830
this.source = { end, input: new Input(source), start };

src/nodes/Word.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@ const hexRegex = /^#(.+)/;
1717
const colorRegex = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
1818
const colorNames = Object.keys(colors);
1919

20-
export interface WordOptions extends NodeOptions {
21-
variables: { prefixes: string[] };
22-
}
23-
2420
export class Word extends Node {
25-
readonly isColor: boolean;
26-
readonly isHex: boolean;
27-
readonly isUrl: boolean;
28-
readonly isVariable: boolean;
29-
private readonly options: WordOptions;
21+
readonly isColor: boolean = false;
22+
readonly isHex: boolean = false;
23+
readonly isUrl: boolean = false;
24+
readonly isVariable: boolean = false;
3025

31-
constructor(options: WordOptions) {
26+
constructor(options?: NodeOptions) {
3227
super(options);
3328

34-
this.options = options;
29+
// Note: in the event of something calling .clone
30+
if (!options) return;
3531

3632
const { node } = options;
3733

@@ -58,9 +54,7 @@ export class Word extends Node {
5854
}
5955

6056
testVariable() {
61-
if (!this.options.variables) return false;
62-
63-
const { prefixes } = this.options.variables;
57+
const prefixes = ['--'];
6458
const varRegex = new RegExp(`^(${prefixes.join('|')})`);
6559

6660
return varRegex.test(this.value);

src/parser.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,24 @@ import { Input } from 'postcss';
1313

1414
import { AstError, ParseError } from './errors';
1515
import * as Nodes from './nodes';
16-
import { WordOptions } from './nodes/Word';
1716

18-
export interface ParseOptions extends Pick<WordOptions, 'variables'> {
17+
export interface ParseOptions {
1918
ignoreUnknownWords?: boolean;
2019
interpolation?: boolean | InterpolationOptions;
2120
}
2221

2322
const defaults: ParseOptions = {
2423
ignoreUnknownWords: false,
25-
interpolation: false,
26-
variables: {
27-
prefixes: ['--']
28-
}
24+
interpolation: false
2925
};
3026

3127
export interface InterpolationOptions {
3228
prefix: string;
3329
}
3430

3531
export const parse = (css: string, opts?: ParseOptions) => {
32+
// @ts-ignore
33+
// eslint-disable-next-line
3634
const options = Object.assign({}, defaults, opts);
3735
let ast: Value;
3836
const root = new Nodes.Root({
@@ -70,7 +68,7 @@ export const parse = (css: string, opts?: ParseOptions) => {
7068
root.add(new Nodes.UnicodeRange({ node }));
7169
break;
7270
default:
73-
root.add(new Nodes.Word({ node, variables: options.variables }));
71+
root.add(new Nodes.Word({ node }));
7472
break;
7573
}
7674
}

src/walker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ interface Container {
1616
prototype: any;
1717
}
1818

19+
console.log(Object.values(Nodes));
20+
1921
export const registerWalkers = (container: Container) => {
20-
for (const Constructor of Nodes as any) {
22+
for (const Constructor of Object.values(Nodes)) {
2123
let walkerName = `walk${Constructor.name}`;
2224

2325
// plural sugar

test/atword.test.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/fixtures/atword.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/fixtures/func.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

test/fixtures/interpolation.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)