执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
const Document = require("../generated/Document");
const { applyDocumentFeatures } = require("../../browser/documentfeatures");
 
exports.implementation = class DOMParserImpl {
  parseFromString(string, contentType) {
    switch (String(contentType)) {
      case "text/html": {
        return createScriptingDisabledDocument("html", contentType, string);
      }
 
      case "text/xml":
      case "application/xml":
      case "application/xhtml+xml":
      case "image/svg+xml": {
        // TODO: use a strict XML parser (sax's strict mode might work?) and create parsererror elements
        try {
          return createScriptingDisabledDocument("xml", contentType, string);
        } catch (error) {
          const document = createScriptingDisabledDocument("xml", contentType);
          const element = document.createElementNS("http://www.mozilla.org/newlayout/xml/parsererror.xml", "parsererror");
 
          element.textContent = error.message;
 
          document.appendChild(element);
          return document;
        }
      }
 
      default:
        throw new TypeError("Invalid contentType");
    }
  }
};
 
function createScriptingDisabledDocument(parsingMode, contentType, string) {
  const document = Document.createImpl([], {
    options: {
      parsingMode,
      encoding: "UTF-8",
      contentType
      // TODO: somehow set URL to active document's URL
    }
  });
 
  // "scripting enabled" set to false
  applyDocumentFeatures(document, {
    FetchExternalResources: [],
    SkipExternalResources: false
  });
 
  if (string !== undefined) {
    document._htmlToDom.appendToDocument(string, document);
  }
  document.close();
  return document;
}