index.js.flow 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. // @flow
  2. type Exclude<A, B> = A;
  3. // see https://gist.github.com/thecotne/6e5969f4aaf8f253985ed36b30ac9fe0
  4. type $FlowGen$If<X: boolean, Then, Else = empty> = $Call<
  5. ((true, Then, Else) => Then) & ((false, Then, Else) => Else),
  6. X,
  7. Then,
  8. Else
  9. >;
  10. type $FlowGen$Assignable<A, B> = $Call<
  11. ((...r: [B]) => true) & ((...r: [A]) => false),
  12. A
  13. >;
  14. import type {
  15. Angle,
  16. CssColor,
  17. Rule,
  18. CustomProperty,
  19. EnvironmentVariable,
  20. Function,
  21. Image,
  22. LengthValue,
  23. MediaQuery,
  24. Declaration,
  25. Ratio,
  26. Resolution,
  27. Selector,
  28. SupportsCondition,
  29. Time,
  30. Token,
  31. TokenOrValue,
  32. UnknownAtRule,
  33. Url,
  34. Variable,
  35. StyleRule,
  36. DeclarationBlock,
  37. ParsedComponent,
  38. Multiplier,
  39. StyleSheet,
  40. } from "./ast.js.flow";
  41. import { Targets, Features } from "./targets.js.flow";
  42. declare export * from "./ast.js.flow";
  43. declare export { Targets, Features };
  44. export type TransformOptions<C: CustomAtRules> = {|
  45. /**
  46. * The filename being transformed. Used for error messages and source maps.
  47. */
  48. filename: string,
  49. /**
  50. * The source code to transform.
  51. */
  52. code: Uint8Array,
  53. /**
  54. * Whether to enable minification.
  55. */
  56. minify?: boolean,
  57. /**
  58. * Whether to output a source map.
  59. */
  60. sourceMap?: boolean,
  61. /**
  62. * An input source map to extend.
  63. */
  64. inputSourceMap?: string,
  65. /**
  66. * An optional project root path, used as the source root in the output source map.
  67. * Also used to generate relative paths for sources used in CSS module hashes.
  68. */
  69. projectRoot?: string,
  70. /**
  71. * The browser targets for the generated code.
  72. */
  73. targets?: Targets,
  74. /**
  75. * Features that should always be compiled, even when supported by targets.
  76. */
  77. include?: number,
  78. /**
  79. * Features that should never be compiled, even when unsupported by targets.
  80. */
  81. exclude?: number,
  82. /**
  83. * Whether to enable parsing various draft syntax.
  84. */
  85. drafts?: Drafts,
  86. /**
  87. * Whether to enable various non-standard syntax.
  88. */
  89. nonStandard?: NonStandard,
  90. /**
  91. * Whether to compile this file as a CSS module.
  92. */
  93. cssModules?: boolean | CSSModulesConfig,
  94. /**
  95. * Whether to analyze dependencies (e.g. string).
  96. * When enabled, string dependencies
  97. * are replaced with hashed placeholders that can be replaced with the final
  98. * urls later (after bundling). Dependencies are returned as part of the result.
  99. */
  100. analyzeDependencies?: boolean | DependencyOptions,
  101. /**
  102. * Replaces user action pseudo classes with class names that can be applied from JavaScript.
  103. * This is useful for polyfills, for example.
  104. */
  105. pseudoClasses?: PseudoClasses,
  106. /**
  107. * A list of class names, ids, and custom identifiers (e.g. @keyframes) that are known
  108. * to be unused. These will be removed during minification. Note that these are not
  109. * selectors but individual names (without any . or # prefixes).
  110. */
  111. unusedSymbols?: string[],
  112. /**
  113. * Whether to ignore invalid rules and declarations rather than erroring.
  114. * When enabled, warnings are returned, and the invalid rule or declaration is
  115. * omitted from the output code.
  116. */
  117. errorRecovery?: boolean,
  118. /**
  119. * An AST visitor object. This allows custom transforms or analysis to be implemented in JavaScript.
  120. * Multiple visitors can be composed into one using the string function.
  121. * For optimal performance, visitors should be as specific as possible about what types of values
  122. * they care about so that JavaScript has to be called as little as possible.
  123. */
  124. visitor?: Visitor<C>,
  125. /**
  126. * Defines how to parse custom CSS at-rules. Each at-rule can have a prelude, defined using a CSS
  127. * [syntax string](https://drafts.css-houdini.org/css-properties-values-api/#syntax-strings), and
  128. * a block body. The body can be a declaration list, rule list, or style block as defined in the
  129. * [css spec](https://drafts.csswg.org/css-syntax/#declaration-rule-list).
  130. */
  131. customAtRules?: C,
  132. |};
  133. declare type PropertyStart =
  134. | "-"
  135. | "_"
  136. | "a"
  137. | "b"
  138. | "c"
  139. | "d"
  140. | "e"
  141. | "f"
  142. | "g"
  143. | "h"
  144. | "i"
  145. | "j"
  146. | "k"
  147. | "l"
  148. | "m"
  149. | "n"
  150. | "o"
  151. | "p"
  152. | "q"
  153. | "r"
  154. | "s"
  155. | "t"
  156. | "u"
  157. | "v"
  158. | "w"
  159. | "x"
  160. | "y"
  161. | "z";
  162. export type ReturnedDeclaration =
  163. | Declaration
  164. | {|
  165. /**
  166. * The property name.
  167. */
  168. property: string,
  169. /**
  170. * The raw string value for the declaration.
  171. */
  172. raw: string,
  173. |};
  174. export type ReturnedMediaQuery =
  175. | MediaQuery
  176. | {|
  177. /**
  178. * The raw string value for the media query.
  179. */
  180. raw: string,
  181. |};
  182. declare type FindByType<Union, Name> = $FlowGen$If<
  183. $FlowGen$Assignable<
  184. Union,
  185. {|
  186. type: Name,
  187. |}
  188. >,
  189. Union,
  190. empty
  191. >;
  192. export type ReturnedRule = Rule<ReturnedDeclaration, ReturnedMediaQuery>;
  193. declare type RequiredValue<Rule> = $FlowGen$If<
  194. $FlowGen$Assignable<
  195. Rule,
  196. {|
  197. value: { [key: string]: any },
  198. |}
  199. >,
  200. $FlowGen$If<
  201. $FlowGen$Assignable<$PropertyType<Rule, "value">, StyleRule>,
  202. {|
  203. ...Rule,
  204. ...{|
  205. value: {|
  206. ...Required<StyleRule>,
  207. ...{|
  208. declarations: Required<DeclarationBlock>,
  209. |},
  210. |},
  211. |},
  212. |},
  213. {|
  214. ...Rule,
  215. ...{|
  216. value: Required<$PropertyType<Rule, "value">>,
  217. |},
  218. |}
  219. >,
  220. Rule
  221. >;
  222. declare type RuleVisitor<R = RequiredValue<Rule>> = (
  223. rule: R
  224. ) => ReturnedRule | ReturnedRule[] | void;
  225. declare type MappedRuleVisitors = $ObjMapi<
  226. { [k: Exclude<$PropertyType<Rule, "type">, "unknown" | "custom">]: any },
  227. <Name>(Name) => RuleVisitor<RequiredValue<FindByType<Rule, Name>>>
  228. >;
  229. declare type UnknownVisitors<T> = {
  230. [name: string]: RuleVisitor<T>,
  231. };
  232. declare type CustomVisitors<T: CustomAtRules> = $ObjMapi<
  233. T,
  234. <Name>(Name) => RuleVisitor<CustomAtRule<Name, $ElementType<T, Name>>>
  235. >;
  236. declare type AnyCustomAtRule<C: CustomAtRules> = $ElementType<
  237. $ObjMapi<C, <Key>(Key) => CustomAtRule<Key, $ElementType<C, Key>>>,
  238. $Keys<C>
  239. >;
  240. declare type RuleVisitors<C: CustomAtRules> = {|
  241. ...MappedRuleVisitors,
  242. ...{|
  243. unknown?:
  244. | UnknownVisitors<UnknownAtRule>
  245. | $Diff<
  246. RuleVisitor<UnknownAtRule>,
  247. { [key: $Keys<CallableFunction>]: any }
  248. >,
  249. custom?:
  250. | CustomVisitors<C>
  251. | $Diff<
  252. RuleVisitor<AnyCustomAtRule<C>>,
  253. { [key: $Keys<CallableFunction>]: any }
  254. >,
  255. |},
  256. |};
  257. declare type PreludeTypes = Exclude<
  258. $PropertyType<ParsedComponent, "type">,
  259. "literal" | "repeated" | "token"
  260. >;
  261. declare type SyntaxString = string | string;
  262. declare type ComponentTypes = $ObjMapi<
  263. { [k: PreludeTypes]: any },
  264. <Key>(Key) => FindByType<ParsedComponent, Key>
  265. >;
  266. declare type Repetitions = $ObjMapi<
  267. { [k: PreludeTypes]: any },
  268. <Key>(Key) => {|
  269. type: "repeated",
  270. value: {|
  271. components: FindByType<ParsedComponent, Key>[],
  272. multiplier: Multiplier,
  273. |},
  274. |}
  275. >;
  276. declare type MappedPrelude = {| ...ComponentTypes, ...Repetitions |};
  277. declare type MappedBody<P: $PropertyType<CustomAtRuleDefinition, "body">> =
  278. $FlowGen$If<$FlowGen$Assignable<P, "style-block">, "rule-list", P>;
  279. declare type CustomAtRule<N, R: CustomAtRuleDefinition> = {|
  280. name: N,
  281. prelude: $FlowGen$If<
  282. $FlowGen$Assignable<$PropertyType<R, "prelude">, $Keys<MappedPrelude>>,
  283. $ElementType<MappedPrelude, $PropertyType<R, "prelude">>,
  284. ParsedComponent
  285. >,
  286. body: FindByType<CustomAtRuleBody, MappedBody<$PropertyType<R, "body">>>,
  287. loc: Location,
  288. |};
  289. declare type CustomAtRuleBody =
  290. | {|
  291. type: "declaration-list",
  292. value: Required<DeclarationBlock>,
  293. |}
  294. | {|
  295. type: "rule-list",
  296. value: RequiredValue<Rule>[],
  297. |};
  298. declare type FindProperty<Union, Name> = $FlowGen$If<
  299. $FlowGen$Assignable<
  300. Union,
  301. {|
  302. property: Name,
  303. |}
  304. >,
  305. Union,
  306. empty
  307. >;
  308. declare type DeclarationVisitor<P = Declaration> = (
  309. property: P
  310. ) => ReturnedDeclaration | ReturnedDeclaration[] | void;
  311. declare type MappedDeclarationVisitors = $ObjMapi<
  312. {
  313. [k: Exclude<
  314. $PropertyType<Declaration, "property">,
  315. "unparsed" | "custom"
  316. >]: any,
  317. },
  318. <Name>(
  319. Name
  320. ) => DeclarationVisitor<
  321. FindProperty<Declaration, Name> | FindProperty<Declaration, "unparsed">
  322. >
  323. >;
  324. declare type CustomPropertyVisitors = {
  325. [name: string]: DeclarationVisitor<CustomProperty>,
  326. };
  327. declare type DeclarationVisitors = {|
  328. ...MappedDeclarationVisitors,
  329. ...{|
  330. custom?: CustomPropertyVisitors | DeclarationVisitor<CustomProperty>,
  331. |},
  332. |};
  333. declare type RawValue = {|
  334. /**
  335. * A raw string value which will be parsed like CSS.
  336. */
  337. raw: string,
  338. |};
  339. declare type TokenReturnValue = TokenOrValue | TokenOrValue[] | RawValue | void;
  340. declare type TokenVisitor = (token: Token) => TokenReturnValue;
  341. declare type VisitableTokenTypes =
  342. | "ident"
  343. | "at-keyword"
  344. | "hash"
  345. | "id-hash"
  346. | "string"
  347. | "number"
  348. | "percentage"
  349. | "dimension";
  350. declare type TokenVisitors = $ObjMapi<
  351. { [k: VisitableTokenTypes]: any },
  352. <Name>(Name) => (token: FindByType<Token, Name>) => TokenReturnValue
  353. >;
  354. declare type FunctionVisitor = (fn: Function) => TokenReturnValue;
  355. declare type EnvironmentVariableVisitor = (
  356. env: EnvironmentVariable
  357. ) => TokenReturnValue;
  358. declare type EnvironmentVariableVisitors = {
  359. [name: string]: EnvironmentVariableVisitor,
  360. };
  361. export type Visitor<C: CustomAtRules> = {|
  362. StyleSheet?: (
  363. stylesheet: StyleSheet
  364. ) => StyleSheet<ReturnedDeclaration, ReturnedMediaQuery> | void,
  365. StyleSheetExit?: (
  366. stylesheet: StyleSheet
  367. ) => StyleSheet<ReturnedDeclaration, ReturnedMediaQuery> | void,
  368. Rule?: RuleVisitor<> | RuleVisitors<C>,
  369. RuleExit?: RuleVisitor<> | RuleVisitors<C>,
  370. Declaration?: DeclarationVisitor<> | DeclarationVisitors,
  371. DeclarationExit?: DeclarationVisitor<> | DeclarationVisitors,
  372. Url?: (url: Url) => Url | void,
  373. Color?: (color: CssColor) => CssColor | void,
  374. Image?: (image: Image) => Image | void,
  375. ImageExit?: (image: Image) => Image | void,
  376. Length?: (length: LengthValue) => LengthValue | void,
  377. Angle?: (angle: Angle) => Angle | void,
  378. Ratio?: (ratio: Ratio) => Ratio | void,
  379. Resolution?: (resolution: Resolution) => Resolution | void,
  380. Time?: (time: Time) => Time | void,
  381. CustomIdent?: (ident: string) => string | void,
  382. DashedIdent?: (ident: string) => string | void,
  383. MediaQuery?: (
  384. query: MediaQuery
  385. ) => ReturnedMediaQuery | ReturnedMediaQuery[] | void,
  386. MediaQueryExit?: (
  387. query: MediaQuery
  388. ) => ReturnedMediaQuery | ReturnedMediaQuery[] | void,
  389. SupportsCondition?: (condition: SupportsCondition) => SupportsCondition,
  390. SupportsConditionExit?: (condition: SupportsCondition) => SupportsCondition,
  391. Selector?: (selector: Selector) => Selector | Selector[] | void,
  392. Token?: TokenVisitor | TokenVisitors,
  393. Function?:
  394. | FunctionVisitor
  395. | {
  396. [name: string]: FunctionVisitor,
  397. },
  398. FunctionExit?:
  399. | FunctionVisitor
  400. | {
  401. [name: string]: FunctionVisitor,
  402. },
  403. Variable?: (variable: Variable) => TokenReturnValue,
  404. VariableExit?: (variable: Variable) => TokenReturnValue,
  405. EnvironmentVariable?:
  406. | EnvironmentVariableVisitor
  407. | EnvironmentVariableVisitors,
  408. EnvironmentVariableExit?:
  409. | EnvironmentVariableVisitor
  410. | EnvironmentVariableVisitors,
  411. |};
  412. export type CustomAtRules = {|
  413. [name: string]: CustomAtRuleDefinition,
  414. |};
  415. export type CustomAtRuleDefinition = {|
  416. /**
  417. * Defines the syntax for a custom at-rule prelude. The value should be a
  418. * CSS [syntax string](https://drafts.css-houdini.org/css-properties-values-api/#syntax-strings)
  419. * representing the types of values that are accepted. This property may be omitted or
  420. * set to null to indicate that no prelude is accepted.
  421. */
  422. prelude?: SyntaxString | null,
  423. /**
  424. * Defines the type of body contained within the at-rule block.
  425. * - declaration-list: A CSS declaration list, as in a style rule.
  426. * - rule-list: A list of CSS rules, as supported within a non-nested
  427. * at-rule such as string.
  428. * - style-block: Both a declaration list and rule list, as accepted within
  429. * a nested at-rule within a style rule (e.g. string inside a style rule
  430. * with directly nested declarations).
  431. */
  432. body?: "declaration-list" | "rule-list" | "style-block" | null,
  433. |};
  434. export type DependencyOptions = {|
  435. /**
  436. * Whether to preserve string rules rather than removing them.
  437. */
  438. preserveImports?: boolean,
  439. |};
  440. export type BundleOptions<C: CustomAtRules> = $Diff<
  441. TransformOptions<C>,
  442. {| code: any |}
  443. >;
  444. export type BundleAsyncOptions<C: CustomAtRules> = {|
  445. ...$Exact<BundleOptions<C>>,
  446. resolver?: Resolver,
  447. |};
  448. /**
  449. * Custom resolver to use when loading CSS files.
  450. */
  451. export type Resolver = {|
  452. /**
  453. * Read the given file and return its contents as a string.
  454. */
  455. read?: (file: string) => string | Promise<string>,
  456. /**
  457. * Resolve the given CSS import specifier from the provided originating file to a
  458. * path which gets passed to string.
  459. */
  460. resolve?: (
  461. specifier: string,
  462. originatingFile: string
  463. ) => string | Promise<string>,
  464. |};
  465. export type Drafts = {|
  466. /**
  467. * Whether to enable @custom-media rules.
  468. */
  469. customMedia?: boolean,
  470. |};
  471. export type NonStandard = {|
  472. /**
  473. * Whether to enable the non-standard >>> and /deep/ selector combinators used by Angular and Vue.
  474. */
  475. deepSelectorCombinator?: boolean,
  476. |};
  477. export type PseudoClasses = {|
  478. hover?: string,
  479. active?: string,
  480. focus?: string,
  481. focusVisible?: string,
  482. focusWithin?: string,
  483. |};
  484. export type TransformResult = {|
  485. /**
  486. * The transformed code.
  487. */
  488. code: Uint8Array,
  489. /**
  490. * The generated source map, if enabled.
  491. */
  492. map: Uint8Array | void,
  493. /**
  494. * CSS module exports, if enabled.
  495. */
  496. exports: CSSModuleExports | void,
  497. /**
  498. * CSS module references, if string is enabled.
  499. */
  500. references: CSSModuleReferences,
  501. /**
  502. * string dependencies, if enabled.
  503. */
  504. dependencies: Dependency[] | void,
  505. /**
  506. * Warnings that occurred during compilation.
  507. */
  508. warnings: Warning[],
  509. |};
  510. export type Warning = {|
  511. message: string,
  512. type: string,
  513. value?: any,
  514. loc: ErrorLocation,
  515. |};
  516. export type CSSModulesConfig = {|
  517. /**
  518. * The pattern to use when renaming class names and other identifiers. Default is string.
  519. */
  520. pattern?: string,
  521. /**
  522. * Whether to rename dashed identifiers, e.g. custom properties.
  523. */
  524. dashedIdents?: boolean,
  525. |};
  526. export type CSSModuleExports = {
  527. /**
  528. * Maps exported (i.e. original) names to local names.
  529. */
  530. [name: string]: CSSModuleExport,
  531. };
  532. export type CSSModuleExport = {|
  533. /**
  534. * The local (compiled) name for this export.
  535. */
  536. name: string,
  537. /**
  538. * Whether the export is referenced in this file.
  539. */
  540. isReferenced: boolean,
  541. /**
  542. * Other names that are composed by this export.
  543. */
  544. composes: CSSModuleReference[],
  545. |};
  546. export type CSSModuleReferences = {
  547. /**
  548. * Maps placeholder names to references.
  549. */
  550. [name: string]: DependencyCSSModuleReference,
  551. };
  552. export type CSSModuleReference =
  553. | LocalCSSModuleReference
  554. | GlobalCSSModuleReference
  555. | DependencyCSSModuleReference;
  556. export type LocalCSSModuleReference = {|
  557. type: "local",
  558. /**
  559. * The local (compiled) name for the reference.
  560. */
  561. name: string,
  562. |};
  563. export type GlobalCSSModuleReference = {|
  564. type: "global",
  565. /**
  566. * The referenced global name.
  567. */
  568. name: string,
  569. |};
  570. export type DependencyCSSModuleReference = {|
  571. type: "dependency",
  572. /**
  573. * The name to reference within the dependency.
  574. */
  575. name: string,
  576. /**
  577. * The dependency specifier for the referenced file.
  578. */
  579. specifier: string,
  580. |};
  581. export type Dependency = ImportDependency | UrlDependency;
  582. export type ImportDependency = {|
  583. type: "import",
  584. /**
  585. * The url of the string dependency.
  586. */
  587. url: string,
  588. /**
  589. * The media query for the string rule.
  590. */
  591. media: string | null,
  592. /**
  593. * The string rule.
  594. */
  595. supports: string | null,
  596. /**
  597. * The source location where the string rule was found.
  598. */
  599. loc: SourceLocation,
  600. /**
  601. * The placeholder that the import was replaced with.
  602. */
  603. placeholder: string,
  604. |};
  605. export type UrlDependency = {|
  606. type: "url",
  607. /**
  608. * The url of the dependency.
  609. */
  610. url: string,
  611. /**
  612. * The source location where the string was found.
  613. */
  614. loc: SourceLocation,
  615. /**
  616. * The placeholder that the url was replaced with.
  617. */
  618. placeholder: string,
  619. |};
  620. export type SourceLocation = {|
  621. /**
  622. * The file path in which the dependency exists.
  623. */
  624. filePath: string,
  625. /**
  626. * The start location of the dependency.
  627. */
  628. start: Location,
  629. /**
  630. * The end location (inclusive) of the dependency.
  631. */
  632. end: Location,
  633. |};
  634. export type Location = {|
  635. /**
  636. * The line number (1-based).
  637. */
  638. line: number,
  639. /**
  640. * The column number (0-based).
  641. */
  642. column: number,
  643. |};
  644. export type ErrorLocation = {|
  645. ...$Exact<Location>,
  646. filename: string,
  647. |};
  648. /**
  649. * Compiles a CSS file, including optionally minifying and lowering syntax to the given
  650. * targets. A source map may also be generated, but this is not enabled by default.
  651. */
  652. declare export function transform<C: CustomAtRules>(
  653. options: TransformOptions<C>
  654. ): TransformResult;
  655. export type TransformAttributeOptions = {|
  656. /**
  657. * The filename in which the style attribute appeared. Used for error messages and dependencies.
  658. */
  659. filename?: string,
  660. /**
  661. * The source code to transform.
  662. */
  663. code: Uint8Array,
  664. /**
  665. * Whether to enable minification.
  666. */
  667. minify?: boolean,
  668. /**
  669. * The browser targets for the generated code.
  670. */
  671. targets?: Targets,
  672. /**
  673. * Whether to analyze string dependencies.
  674. * When enabled, string dependencies are replaced with hashed placeholders
  675. * that can be replaced with the final urls later (after bundling).
  676. * Dependencies are returned as part of the result.
  677. */
  678. analyzeDependencies?: boolean,
  679. /**
  680. * Whether to ignore invalid rules and declarations rather than erroring.
  681. * When enabled, warnings are returned, and the invalid rule or declaration is
  682. * omitted from the output code.
  683. */
  684. errorRecovery?: boolean,
  685. /**
  686. * An AST visitor object. This allows custom transforms or analysis to be implemented in JavaScript.
  687. * Multiple visitors can be composed into one using the string function.
  688. * For optimal performance, visitors should be as specific as possible about what types of values
  689. * they care about so that JavaScript has to be called as little as possible.
  690. */
  691. visitor?: Visitor<empty>,
  692. |};
  693. export type TransformAttributeResult = {|
  694. /**
  695. * The transformed code.
  696. */
  697. code: Uint8Array,
  698. /**
  699. * string dependencies, if enabled.
  700. */
  701. dependencies: Dependency[] | void,
  702. /**
  703. * Warnings that occurred during compilation.
  704. */
  705. warnings: Warning[],
  706. |};
  707. /**
  708. * Compiles a single CSS declaration list, such as an inline style attribute in HTML.
  709. */
  710. declare export function transformStyleAttribute(
  711. options: TransformAttributeOptions
  712. ): TransformAttributeResult;
  713. /**
  714. * Converts a browserslist result into targets that can be passed to lightningcss.
  715. * @param browserslist the result of calling string
  716. */
  717. declare export function browserslistToTargets(browserslist: string[]): Targets;
  718. /**
  719. * Bundles a CSS file and its dependencies, inlining @import rules.
  720. */
  721. declare export function bundle<C: CustomAtRules>(
  722. options: BundleOptions<C>
  723. ): TransformResult;
  724. /**
  725. * Bundles a CSS file and its dependencies asynchronously, inlining @import rules.
  726. */
  727. declare export function bundleAsync<C: CustomAtRules>(
  728. options: BundleAsyncOptions<C>
  729. ): Promise<TransformResult>;
  730. /**
  731. * Composes multiple visitor objects into a single one.
  732. */
  733. declare export function composeVisitors<C: CustomAtRules>(
  734. visitors: Visitor<C>[]
  735. ): Visitor<C>;