* Parses the provided source and updates the parser state. * @param {string | Buffer | PreparsedAst} source the source to parse * @param {ParserState} state the parser state * @returns {ParserState} the parser state
(source, state)
| 871 | * @returns {ParserState} the parser state |
| 872 | */ |
| 873 | parse(source, state) { |
| 874 | if (Buffer.isBuffer(source)) { |
| 875 | source = source.toString("utf8"); |
| 876 | } else if (typeof source === "object") { |
| 877 | throw new Error("webpackAst is unexpected for the CssParser"); |
| 878 | } |
| 879 | if (source[0] === "\uFEFF") { |
| 880 | source = source.slice(1); |
| 881 | } |
| 882 | |
| 883 | // Per-parse comment side-array — kept local (like HtmlParser) so nothing is retained on the reused parser instance between modules. |
| 884 | /** @type {Comment[]} */ |
| 885 | const comments = []; |
| 886 | |
| 887 | const module = state.module; |
| 888 | |
| 889 | // All `:export`-style exports are collected into a single |
| 890 | // `CssIcssExportDependency` per module (emitted at parse end) instead of one |
| 891 | // `Dependency` per export — far fewer retained objects on CSS-heavy builds. |
| 892 | /** @type {import("../dependencies/CssIcssExportDependency").CssExportEntry[]} */ |
| 893 | const cssExportEntries = []; |
| 894 | /** |
| 895 | * @param {number} sl start line |
| 896 | * @param {number} sc start column |
| 897 | * @param {number} el end line |
| 898 | * @param {number} ec end column |
| 899 | * @param {string} name export name |
| 900 | * @param {import("../dependencies/CssIcssExportDependency").Value} value value or [localName, importName, request?] |
| 901 | * @param {Range=} range source range to replace, when present |
| 902 | * @param {boolean=} interpolate whether the value needs interpolation |
| 903 | * @param {import("../dependencies/CssIcssExportDependency").ExportMode=} exportMode export mode |
| 904 | * @param {import("../dependencies/CssIcssExportDependency").ExportType=} exportType export type |
| 905 | * @returns {void} |
| 906 | */ |
| 907 | const addCssExport = ( |
| 908 | sl, |
| 909 | sc, |
| 910 | el, |
| 911 | ec, |
| 912 | name, |
| 913 | value, |
| 914 | range, |
| 915 | interpolate = false, |
| 916 | exportMode = CssIcssExportDependency.EXPORT_MODE.REPLACE, |
| 917 | exportType = CssIcssExportDependency.EXPORT_TYPE.NORMAL |
| 918 | ) => { |
| 919 | cssExportEntries.push({ |
| 920 | name, |
| 921 | value, |
| 922 | range, |
| 923 | interpolate, |
| 924 | exportMode, |
| 925 | exportType, |
| 926 | loc: { start: { line: sl, column: sc }, end: { line: el, column: ec } } |
| 927 | }); |
| 928 | }; |
| 929 | |
| 930 | const parsedModuleResource = parseResource( |
no test coverage detected