1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const dom5 = require("dom5/lib/index-next");
|
25 | const model_1 = require("../model/model");
|
26 | const html_script_tag_1 = require("./html-script-tag");
|
27 | const p = dom5.predicates;
|
28 | const isJsScriptNode = p.AND(p.hasTagName('script'), p.OR(p.NOT(p.hasAttr('type')), p.hasAttrValue('type', 'text/javascript'), p.hasAttrValue('type', 'application/javascript'), p.hasAttrValue('type', 'module')));
|
29 | class HtmlScriptScanner {
|
30 | scan(document, visit) {
|
31 | return __awaiter(this, void 0, void 0, function* () {
|
32 | const features = [];
|
33 | const myVisitor = (node) => {
|
34 | if (isJsScriptNode(node)) {
|
35 | const src = dom5.getAttribute(node, 'src');
|
36 | if (src) {
|
37 | features.push(new html_script_tag_1.ScannedScriptTagImport(src, document.sourceRangeForNode(node), document.sourceRangeForAttributeValue(node, 'src'), { language: 'html', node, containingDocument: document }, dom5.getAttribute(node, 'type') === 'module'));
|
38 | }
|
39 | else {
|
40 | const locationOffset = model_1.getLocationOffsetOfStartOfTextContent(node, document);
|
41 | const attachedCommentText = model_1.getAttachedCommentText(node) || '';
|
42 | const contents = dom5.getTextContent(node);
|
43 | features.push(new model_1.ScannedInlineDocument('js', contents, locationOffset, attachedCommentText, document.sourceRangeForNode(node), { language: 'html', node, containingDocument: document }));
|
44 | }
|
45 | }
|
46 | };
|
47 | yield visit(myVisitor);
|
48 | return { features };
|
49 | });
|
50 | }
|
51 | }
|
52 | exports.HtmlScriptScanner = HtmlScriptScanner;
|
53 |
|
\ | No newline at end of file |