@node-projects/web-component-designer-htmlparserservice-base-custom-webcomponent 0.1.4 → 1.0.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.
@@ -13,52 +13,47 @@ export class BaseCustomWebcomponentParserService {
13
13
  const sourceFile = this.parseTypescriptFile(code);
14
14
  let htmlCode = "";
15
15
  let cssStyle = "";
16
- //@ts-ignore
16
+ let positionOffset = 0;
17
+ //let cssOffset = 0;
17
18
  const nodes = findAllNodesOfKind(sourceFile, ts.SyntaxKind.TaggedTemplateExpression);
18
19
  for (let nd of nodes) {
19
- if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template")
20
+ if (nd.tag.escapedText == 'html' && nd.parent.name.escapedText == "template") {
21
+ positionOffset = nd.pos;
20
22
  htmlCode = nd.template.rawText;
21
- if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style")
23
+ }
24
+ if (nd.tag.escapedText == 'css' && nd.parent.name.escapedText == "style") {
25
+ //cssOffset = nd.pos;
22
26
  cssStyle = nd.template.rawText;
27
+ }
23
28
  }
29
+ const items = await this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet, positionOffset);
24
30
  if (cssStyle)
25
- instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
26
- return this.htmlParser.parse(htmlCode, serviceContainer, instanceServiceContainer, parseSnippet);
31
+ await instanceServiceContainer.stylesheetService.setStylesheets([{ name: 'css', content: cssStyle }]);
32
+ return items;
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) {
32
- //@ts-ignore
33
38
  if (ts.isTemplateLiteral(node) &&
34
- //@ts-ignore
35
39
  ts.isTaggedTemplateExpression(node.parent) &&
36
40
  node.parent.tag.escapedText == 'html' &&
37
41
  node.parent.parent.name.escapedText == "template") {
38
- //@ts-ignore
39
42
  return ts.factory.createNoSubstitutionTemplateLiteral(html.replaceAll('\n', '\r\n'), html.replaceAll('\n', '\r\n'));
40
43
  }
41
44
  else if (css &&
42
- //@ts-ignore
43
45
  ts.isTemplateLiteral(node) &&
44
- //@ts-ignore
45
46
  ts.isTaggedTemplateExpression(node.parent) &&
46
47
  node.parent.tag.escapedText == 'css' &&
47
48
  node.parent.parent.name.escapedText == "style") {
48
- //@ts-ignore
49
49
  return ts.factory.createNoSubstitutionTemplateLiteral(css.replaceAll('\n', '\r\n'), css.replaceAll('\n', '\r\n'));
50
50
  }
51
- //@ts-ignore
52
51
  return ts.visitEachChild(node, visit, context);
53
52
  }
54
- //@ts-ignore
55
53
  return ts.visitNode(rootNode, visit);
56
54
  };
57
- //@ts-ignore
58
55
  let transformed = ts.transform(sourceFile, [transformTemplateLiterals]).transformed[0];
59
- //@ts-ignore
60
56
  const printer = ts.createPrinter({ newLine: newLineCrLf ? ts.NewLineKind.CarriageReturnLineFeed : ts.NewLineKind.LineFeed });
61
- //@ts-ignore
62
57
  const result = printer.printNode(ts.EmitHint.Unspecified, transformed, transformed);
63
58
  return result;
64
59
  }
@@ -70,7 +65,6 @@ export class BaseCustomWebcomponentParserService {
70
65
  getDefaultLibFileName: () => 'lib.d.ts',
71
66
  getNewLine: () => '\n',
72
67
  getSourceFile: filename => {
73
- //@ts-ignore
74
68
  return ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true);
75
69
  },
76
70
  readFile: () => null,
@@ -78,13 +72,14 @@ export class BaseCustomWebcomponentParserService {
78
72
  writeFile: () => null,
79
73
  };
80
74
  const filename = 'aa.ts';
81
- //@ts-ignore
82
75
  const program = ts.createProgram([filename], {
83
76
  noResolve: true,
84
- //@ts-ignore
85
77
  target: ts.ScriptTarget.Latest,
86
78
  }, compilerHost);
87
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'));
88
83
  return sourceFile;
89
84
  }
90
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": "0.1.4",
4
+ "version": "1.0.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": ">=0.1.1",
16
- "typescript": ">=5.2.2"
16
+ "@node-projects/web-component-designer": "1.0.0",
17
+ "typescript": ">=5.6.3"
17
18
  },
18
19
  "repository": {
19
20
  "type": "git",