@node-projects/web-component-designer-htmlparserservice-base-custom-webcomponent 0.1.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,6 @@ export class BaseCustomWebcomponentParserService {
|
|
|
15
15
|
let cssStyle = "";
|
|
16
16
|
let positionOffset = 0;
|
|
17
17
|
//let cssOffset = 0;
|
|
18
|
-
//@ts-ignore
|
|
19
18
|
const nodes = findAllNodesOfKind(sourceFile, ts.SyntaxKind.TaggedTemplateExpression);
|
|
20
19
|
for (let nd of nodes) {
|
|
21
20
|
if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template") {
|
|
@@ -27,44 +26,34 @@ export class BaseCustomWebcomponentParserService {
|
|
|
27
26
|
cssStyle = nd.template.rawText;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
29
|
+
const items = await this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet, positionOffset);
|
|
30
30
|
if (cssStyle)
|
|
31
|
-
instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
|
|
32
|
-
return
|
|
31
|
+
await instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
|
|
32
|
+
return items;
|
|
33
33
|
}
|
|
34
34
|
writeBack(code, html, css, newLineCrLf) {
|
|
35
35
|
const sourceFile = this.parseTypescriptFile(code);
|
|
36
36
|
const transformTemplateLiterals = (context) => (rootNode) => {
|
|
37
37
|
function visit(node) {
|
|
38
|
-
//@ts-ignore
|
|
39
38
|
if (ts.isTemplateLiteral(node) &&
|
|
40
|
-
//@ts-ignore
|
|
41
39
|
ts.isTaggedTemplateExpression(node.parent) &&
|
|
42
40
|
node.parent.tag.escapedText == 'html' &&
|
|
43
41
|
node.parent.parent.name.escapedText == "template") {
|
|
44
|
-
//@ts-ignore
|
|
45
42
|
return ts.factory.createNoSubstitutionTemplateLiteral(html.replaceAll('\n', '\r\n'), html.replaceAll('\n', '\r\n'));
|
|
46
43
|
}
|
|
47
44
|
else if (css &&
|
|
48
|
-
//@ts-ignore
|
|
49
45
|
ts.isTemplateLiteral(node) &&
|
|
50
|
-
//@ts-ignore
|
|
51
46
|
ts.isTaggedTemplateExpression(node.parent) &&
|
|
52
47
|
node.parent.tag.escapedText == 'css' &&
|
|
53
48
|
node.parent.parent.name.escapedText == "style") {
|
|
54
|
-
//@ts-ignore
|
|
55
49
|
return ts.factory.createNoSubstitutionTemplateLiteral(css.replaceAll('\n', '\r\n'), css.replaceAll('\n', '\r\n'));
|
|
56
50
|
}
|
|
57
|
-
//@ts-ignore
|
|
58
51
|
return ts.visitEachChild(node, visit, context);
|
|
59
52
|
}
|
|
60
|
-
//@ts-ignore
|
|
61
53
|
return ts.visitNode(rootNode, visit);
|
|
62
54
|
};
|
|
63
|
-
//@ts-ignore
|
|
64
55
|
let transformed = ts.transform(sourceFile, [transformTemplateLiterals]).transformed[0];
|
|
65
|
-
//@ts-ignore
|
|
66
56
|
const printer = ts.createPrinter({ newLine: newLineCrLf ? ts.NewLineKind.CarriageReturnLineFeed : ts.NewLineKind.LineFeed });
|
|
67
|
-
//@ts-ignore
|
|
68
57
|
const result = printer.printNode(ts.EmitHint.Unspecified, transformed, transformed);
|
|
69
58
|
return result;
|
|
70
59
|
}
|
|
@@ -76,7 +65,6 @@ export class BaseCustomWebcomponentParserService {
|
|
|
76
65
|
getDefaultLibFileName: () => 'lib.d.ts',
|
|
77
66
|
getNewLine: () => '\n',
|
|
78
67
|
getSourceFile: filename => {
|
|
79
|
-
//@ts-ignore
|
|
80
68
|
return ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true);
|
|
81
69
|
},
|
|
82
70
|
readFile: () => null,
|
|
@@ -84,13 +72,14 @@ export class BaseCustomWebcomponentParserService {
|
|
|
84
72
|
writeFile: () => null,
|
|
85
73
|
};
|
|
86
74
|
const filename = 'aa.ts';
|
|
87
|
-
//@ts-ignore
|
|
88
75
|
const program = ts.createProgram([filename], {
|
|
89
76
|
noResolve: true,
|
|
90
|
-
//@ts-ignore
|
|
91
77
|
target: ts.ScriptTarget.Latest,
|
|
92
78
|
}, compilerHost);
|
|
93
79
|
const sourceFile = program.getSourceFile(filename);
|
|
80
|
+
const errors = program.getSyntacticDiagnostics(sourceFile);
|
|
81
|
+
if (errors.length)
|
|
82
|
+
throw new SyntaxError(errors.map(error => ts.flattenDiagnosticMessageText(error.messageText, '\n')).join('\n'));
|
|
94
83
|
return sourceFile;
|
|
95
84
|
}
|
|
96
85
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "web-component-designer addon: Parser Service for Templates inside of BaseCustomWebcomponent",
|
|
3
3
|
"name": "@node-projects/web-component-designer-htmlparserservice-base-custom-webcomponent",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/service/htmlParserService/BaseCustomWebcomponentParserService.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"tsc": "tsc",
|
|
11
11
|
"build": "tsc",
|
|
12
|
+
"link": "npm link",
|
|
12
13
|
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@node-projects/web-component-designer": "
|
|
16
|
-
"typescript": ">=5.
|
|
16
|
+
"@node-projects/web-component-designer": "1.1.0",
|
|
17
|
+
"typescript": ">=5.6.3"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|