@node-projects/web-component-designer-htmlparserservice-base-custom-webcomponent 0.1.3 → 0.1.5

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.
@@ -1,4 +1,3 @@
1
- import ts from 'typescript';
2
1
  function* findAllNodesOfKind(node, kind) {
3
2
  if (node.kind == kind)
4
3
  yield node;
@@ -14,40 +13,58 @@ export class BaseCustomWebcomponentParserService {
14
13
  const sourceFile = this.parseTypescriptFile(code);
15
14
  let htmlCode = "";
16
15
  let cssStyle = "";
16
+ let positionOffset = 0;
17
+ //let cssOffset = 0;
18
+ //@ts-ignore
17
19
  const nodes = findAllNodesOfKind(sourceFile, ts.SyntaxKind.TaggedTemplateExpression);
18
20
  for (let nd of nodes) {
19
- if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
21
+ if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template") {
22
+ positionOffset = nd.pos;
20
23
  htmlCode = nd.template.rawText;
21
- if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style")
24
+ }
25
+ if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style") {
26
+ //cssOffset = nd.pos;
22
27
  cssStyle = nd.template.rawText;
28
+ }
23
29
  }
24
30
  if (cssStyle)
25
31
  instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
26
- return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet);
32
+ return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet, positionOffset);
27
33
  }
28
34
  writeBack(code, html, css, newLineCrLf) {
29
35
  const sourceFile = this.parseTypescriptFile(code);
30
36
  const transformTemplateLiterals = (context) => (rootNode) => {
31
37
  function visit(node) {
38
+ //@ts-ignore
32
39
  if (ts.isTemplateLiteral(node) &&
40
+ //@ts-ignore
33
41
  ts.isTaggedTemplateExpression(node.parent) &&
34
42
  node.parent.tag.escapedText == 'html' &&
35
43
  node.parent.parent.name.escapedText == "template") {
44
+ //@ts-ignore
36
45
  return ts.factory.createNoSubstitutionTemplateLiteral(html.replaceAll('\n', '\r\n'), html.replaceAll('\n', '\r\n'));
37
46
  }
38
47
  else if (css &&
48
+ //@ts-ignore
39
49
  ts.isTemplateLiteral(node) &&
50
+ //@ts-ignore
40
51
  ts.isTaggedTemplateExpression(node.parent) &&
41
52
  node.parent.tag.escapedText == 'css' &&
42
53
  node.parent.parent.name.escapedText == "style") {
54
+ //@ts-ignore
43
55
  return ts.factory.createNoSubstitutionTemplateLiteral(css.replaceAll('\n', '\r\n'), css.replaceAll('\n', '\r\n'));
44
56
  }
57
+ //@ts-ignore
45
58
  return ts.visitEachChild(node, visit, context);
46
59
  }
60
+ //@ts-ignore
47
61
  return ts.visitNode(rootNode, visit);
48
62
  };
63
+ //@ts-ignore
49
64
  let transformed = ts.transform(sourceFile, [transformTemplateLiterals]).transformed[0];
65
+ //@ts-ignore
50
66
  const printer = ts.createPrinter({ newLine: newLineCrLf ? ts.NewLineKind.CarriageReturnLineFeed : ts.NewLineKind.LineFeed });
67
+ //@ts-ignore
51
68
  const result = printer.printNode(ts.EmitHint.Unspecified, transformed, transformed);
52
69
  return result;
53
70
  }
@@ -59,6 +76,7 @@ export class BaseCustomWebcomponentParserService {
59
76
  getDefaultLibFileName: () => 'lib.d.ts',
60
77
  getNewLine: () => '\n',
61
78
  getSourceFile: filename => {
79
+ //@ts-ignore
62
80
  return ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true);
63
81
  },
64
82
  readFile: () => null,
@@ -66,8 +84,10 @@ export class BaseCustomWebcomponentParserService {
66
84
  writeFile: () => null,
67
85
  };
68
86
  const filename = 'aa.ts';
87
+ //@ts-ignore
69
88
  const program = ts.createProgram([filename], {
70
89
  noResolve: true,
90
+ //@ts-ignore
71
91
  target: ts.ScriptTarget.Latest,
72
92
  }, compilerHost);
73
93
  const sourceFile = program.getSourceFile(filename);
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": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "main": "./dist/service/htmlParserService/BaseCustomWebcomponentParserService.js",
7
7
  "author": "jochen.kuehner@gmx.de",