MCPcopy
hub / github.com/webpack/webpack / _parse

Method _parse

lib/javascript/JavascriptParser.js:5852–5928  ·  view source on GitHub ↗

* Returns parse result. * @param {string} code source code * @param {InternalParseOptions} options parsing options * @param {ParseFunction=} customParse custom function to parse * @returns {ParseResult} parse result

(code, options, customParse)

Source from the content-addressed store, hash-verified

5850 * @returns {ParseResult} parse result
5851 */
5852 static _parse(code, options, customParse) {
5853 const type = options ? options.sourceType : "module";
5854 /** @type {ParseOptions} */
5855 const parserOptions = {
5856 ...defaultParserOptions,
5857 allowReturnOutsideFunction: type === "script",
5858 ...options,
5859 sourceType: type === "auto" ? "module" : type
5860 };
5861 /**
5862 * Returns parse result.
5863 * @param {string} code source code
5864 * @param {ParseOptions} options parsing options
5865 * @returns {ParseResult} parse result
5866 */
5867 const internalParse = (code, options) => {
5868 if (typeof customParse === "function") {
5869 return customParse(code, options);
5870 }
5871
5872 /** @type {Comment[]} */
5873 const comments = [];
5874
5875 if (options.comments) {
5876 /** @type {AcornOptions} */
5877 (options).onComment = comments;
5878 }
5879
5880 /** @type {Set<number>} */
5881 const semicolons = new Set();
5882
5883 if (options.semicolons) {
5884 /** @type {AcornOptions} */
5885 (options).onInsertedSemicolon = (pos) => semicolons.add(pos);
5886 }
5887
5888 const ast =
5889 /** @type {Program} */
5890 (parser.parse(code, /** @type {AcornOptions} */ (options)));
5891
5892 return { ast, comments, semicolons };
5893 };
5894
5895 /** @type {Program | undefined} */
5896 let ast;
5897 /** @type {Comment[] | undefined} */
5898 let comments;
5899 /** @type {Set<number> | undefined} */
5900 let semicolons;
5901 let error;
5902 let threw = false;
5903 try {
5904 ({ ast, comments, semicolons } = internalParse(code, parserOptions));
5905 } catch (err) {
5906 error = err;
5907 threw = true;
5908 }
5909

Callers 5

_analyseModuleMethod · 0.80
parseMethod · 0.80
evaluateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected