啊鑫
8 天以前 fca192d3c38c5dcfbb6ace8bc71d6078f6a079b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Yuta Hiroto @hiroppy
*/
 
"use strict";
 
const Parser = require("../Parser");
 
/** @typedef {import("../Module").BuildInfo} BuildInfo */
/** @typedef {import("../Module").BuildMeta} BuildMeta */
/** @typedef {import("../Parser").ParserState} ParserState */
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
 
class AssetSourceParser extends Parser {
    /**
     * @param {string | Buffer | PreparsedAst} source the source to parse
     * @param {ParserState} state the parser state
     * @returns {ParserState} the parser state
     */
    parse(source, state) {
        if (typeof source === "object" && !Buffer.isBuffer(source)) {
            throw new Error("AssetSourceParser doesn't accept preparsed AST");
        }
        const { module } = state;
        /** @type {BuildInfo} */
        (module.buildInfo).strict = true;
        /** @type {BuildMeta} */
        (module.buildMeta).exportsType = "default";
        /** @type {BuildMeta} */
        (state.module.buildMeta).defaultObject = false;
 
        return state;
    }
}
 
module.exports = AssetSourceParser;