* 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)
| 35 | * @returns {ParserState} the parser state |
| 36 | */ |
| 37 | parse(source, state) { |
| 38 | if (typeof source === "object" && !Buffer.isBuffer(source)) { |
| 39 | throw new Error("AssetParser doesn't accept preparsed AST"); |
| 40 | } |
| 41 | |
| 42 | const buildInfo = |
| 43 | /** @type {AssetModuleBuildInfo} */ |
| 44 | (state.module.buildInfo); |
| 45 | buildInfo.strict = true; |
| 46 | const buildMeta = |
| 47 | /** @type {BuildMeta} */ |
| 48 | (state.module.buildMeta); |
| 49 | buildMeta.exportsType = "default"; |
| 50 | buildMeta.defaultObject = false; |
| 51 | |
| 52 | if (typeof this.dataUrlCondition === "function") { |
| 53 | buildInfo.dataUrl = this.dataUrlCondition(source, { |
| 54 | filename: /** @type {string} */ (state.module.getResource()), |
| 55 | module: state.module |
| 56 | }); |
| 57 | } else if (typeof this.dataUrlCondition === "boolean") { |
| 58 | buildInfo.dataUrl = this.dataUrlCondition; |
| 59 | } else if ( |
| 60 | this.dataUrlCondition && |
| 61 | typeof this.dataUrlCondition === "object" |
| 62 | ) { |
| 63 | buildInfo.dataUrl = |
| 64 | Buffer.byteLength(source) <= |
| 65 | /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */ |
| 66 | (this.dataUrlCondition.maxSize); |
| 67 | } else { |
| 68 | throw new Error("Unexpected dataUrlCondition type"); |
| 69 | } |
| 70 | |
| 71 | return state; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | module.exports = AssetParser; |
nothing calls this directly
no test coverage detected