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 model_1 = require("../model/model");
|
25 | const ast_value_1 = require("./ast-value");
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | class InlineHtmlDocumentScanner {
|
33 | scan(document, visit) {
|
34 | return __awaiter(this, void 0, void 0, function* () {
|
35 | const features = [];
|
36 | const myVisitor = {
|
37 | enterTaggedTemplateExpression(node) {
|
38 | const tagName = ast_value_1.getIdentifierName(node.tag);
|
39 | if (tagName === undefined || !/(^|\.)html$/.test(tagName)) {
|
40 | return;
|
41 | }
|
42 | const inlineDocument = getInlineDocument(node, document);
|
43 | if (inlineDocument !== undefined) {
|
44 | features.push(inlineDocument);
|
45 | }
|
46 | }
|
47 | };
|
48 | yield visit(myVisitor);
|
49 | return { features };
|
50 | });
|
51 | }
|
52 | }
|
53 | exports.InlineHtmlDocumentScanner = InlineHtmlDocumentScanner;
|
54 |
|
55 |
|
56 |
|
57 | function getInlineDocument(node, parsedDocument, options = {}) {
|
58 | const sourceRangeForLiteral = parsedDocument.sourceRangeForNode(node.quasi);
|
59 | if (sourceRangeForLiteral === undefined) {
|
60 | return;
|
61 | }
|
62 | const sourceRangeForContents = {
|
63 | file: sourceRangeForLiteral.file,
|
64 | start: {
|
65 | line: sourceRangeForLiteral.start.line,
|
66 | column: sourceRangeForLiteral.start.column + 1
|
67 | },
|
68 | end: {
|
69 | line: sourceRangeForLiteral.end.line,
|
70 | column: sourceRangeForLiteral.end.column - 1
|
71 | }
|
72 | };
|
73 | let contents = '';
|
74 | let previousEnd;
|
75 | for (const quasi of node.quasi.quasis) {
|
76 | if (previousEnd !== undefined) {
|
77 | const fullExpressionTextWithDelimitors = parsedDocument.contents.slice(previousEnd, quasi.start);
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | contents += fullExpressionTextWithDelimitors.replace(/\S/g, ' ');
|
108 | }
|
109 | if (options.useRawContents) {
|
110 | contents += quasi.value.raw;
|
111 | }
|
112 | else {
|
113 | contents += quasi.value.cooked;
|
114 | }
|
115 | previousEnd = quasi.end;
|
116 | }
|
117 | let commentText;
|
118 | if (node.leadingComments != null) {
|
119 | commentText = node.leadingComments.map((c) => c.value).join('\n');
|
120 | }
|
121 | else {
|
122 | commentText = '';
|
123 | }
|
124 | return new model_1.ScannedInlineDocument('html', contents, {
|
125 | filename: sourceRangeForContents.file,
|
126 | col: sourceRangeForContents.start.column,
|
127 | line: sourceRangeForContents.start.line
|
128 | }, commentText, sourceRangeForContents, { language: 'js', node, containingDocument: parsedDocument });
|
129 | }
|
130 | exports.getInlineDocument = getInlineDocument;
|
131 |
|
\ | No newline at end of file |