Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow strict
*/

import type { CSSValueASTNode } from '../../../types/value-parser';

import valueParser from 'postcss-value-parser';
import { CSSVariableReferenceValue } from './CSSVariableReferenceValue';
import { errorMsg, warnMsg } from '../../../shared/logUtils';
Expand All @@ -17,8 +19,8 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue;
const MAX_RESOLVE_DEPTH = 50;

function splitComponentValueListByComma(
input: PostCSSValueASTNode[]
): PostCSSValueASTNode[][] {
input: CSSValueASTNode[]
): CSSValueASTNode[][] {
const output = [];
let current = [];
for (const value of input) {
Expand All @@ -39,7 +41,7 @@ const memoizedValues = new Map<string, CSSUnparsedValue>();

// https://drafts.css-houdini.org/css-typed-om-1/#cssunparsedvalue
export class CSSUnparsedValue /*extends CSSStyleValue*/ {
static _resolveVariableName(input: PostCSSValueASTNode[]): string | null {
static _resolveVariableName(input: CSSValueASTNode[]): string | null {
const cleanedInput = input.filter((i) => i.type === 'word');
if (cleanedInput.length !== 1) {
return null;
Expand All @@ -48,7 +50,7 @@ export class CSSUnparsedValue /*extends CSSStyleValue*/ {
}

static _resolveUnparsedValue(
input: PostCSSValueASTNode[],
input: CSSValueASTNode[],
depth: number = 0
): CSSUnparsedValue {
if (depth > MAX_RESOLVE_DEPTH) {
Expand Down
55 changes: 55 additions & 0 deletions packages/react-strict-dom/src/types/value-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/

export type CSSValueASTNode =
| {
type: 'word' | 'unicode-range',
value: string,
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'string' | 'comment',
value: string,
quote: '"' | "'",
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'comment',
value: string,
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'div',
value: ',' | '/' | ':',
sourceIndex: number,
sourceEndIndex: number,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' '
}
| {
type: 'space',
value: ' ' | ' ' | ' ',
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'function',
value: string,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' ',
nodes: Array<CSSValueASTNode>,
unclosed?: boolean,
sourceIndex: number,
sourceEndIndex: number
};
134 changes: 67 additions & 67 deletions tools/flow-typed/npm/postcss-value-parser_vx.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,75 @@
* @flow strict
*/

type PostCSSValueASTNode =
| {
type: 'word' | 'unicode-range',
value: string,
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'string' | 'comment',
value: string,
quote: '"' | "'",
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'comment',
value: string,
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'div',
value: ',' | '/' | ':',
sourceIndex: number,
sourceEndIndex: number,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' '
}
| {
type: 'space',
value: ' ' | ' ' | ' ',
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'function',
value: string,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' ',
nodes: Array<PostCSSValueASTNode>,
unclosed?: boolean,
sourceIndex: number,
sourceEndIndex: number
};
declare module 'postcss-value-parser' {
declare export type PostCSSValueASTNode =
| {
type: 'word' | 'unicode-range',
value: string,
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'string' | 'comment',
value: string,
quote: '"' | "'",
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'comment',
value: string,
sourceIndex: number,
sourceEndIndex: number,
unclosed?: boolean
}
| {
type: 'div',
value: ',' | '/' | ':',
sourceIndex: number,
sourceEndIndex: number,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' '
}
| {
type: 'space',
value: ' ' | ' ' | ' ',
sourceIndex: number,
sourceEndIndex: number
}
| {
type: 'function',
value: string,
before: '' | ' ' | ' ' | ' ',
after: '' | ' ' | ' ' | ' ',
nodes: Array<PostCSSValueASTNode>,
unclosed?: boolean,
sourceIndex: number,
sourceEndIndex: number
};

declare interface PostCSSValueAST {
nodes: Array<PostCSSValueASTNode>;
walk(
callback: (PostCSSValueASTNode, number, PostCSSValueAST) => ?false,
bubble?: boolean
): void;
}
declare interface PostCSSValueAST {
nodes: Array<PostCSSValueASTNode>;
walk(
callback: (PostCSSValueASTNode, number, PostCSSValueAST) => ?false,
bubble?: boolean
): void;
}

type PostCSSValueParser = {
(string): PostCSSValueAST,
unit(string): { number: string, unit: string } | false,
stringify(
nodes: PostCSSValueAST | PostCSSValueASTNode | PostCSSValueAST['nodes'],
custom?: (PostCSSValueASTNode) => string
): string,
walk(
ast: PostCSSValueAST,
callback: (PostCSSValueASTNode, number, PostCSSValueAST) => ?false,
bubble?: boolean
): void
};
declare type PostCSSValueParser = {
(string): PostCSSValueAST,
unit(string): { number: string, unit: string } | false,
stringify(
nodes: PostCSSValueAST | PostCSSValueASTNode | PostCSSValueAST['nodes'],
custom?: (PostCSSValueASTNode) => string
): string,
walk(
ast: PostCSSValueAST,
callback: (PostCSSValueASTNode, number, PostCSSValueAST) => ?false,
bubble?: boolean
): void
};

declare module 'postcss-value-parser' {
declare module.exports: PostCSSValueParser;
}